github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/tests/suites/spaces_ec2/upgrade_charm_with_bind.sh (about)

     1  run_upgrade_charm_with_bind() {
     2  	echo
     3  
     4  	file="${TEST_DIR}/test-upgrade-charm-with-bind-ec2.log"
     5  
     6  	ensure "spaces-upgrade-charm-with-bind-ec2" "${file}"
     7  
     8  	## Setup spaces
     9  	juju reload-spaces
    10  	juju add-space isolated 172.31.254.0/24
    11  
    12  	# Create machine
    13  	# Note that due to the way that run_* funcs are executed, $1 holds the
    14  	# test name so the NIC ID is actually provided in $2
    15  	hotplug_nic_id=$2
    16  	add_multi_nic_machine "$hotplug_nic_id"
    17  
    18  	juju_machine_id=$(juju show-machine --format json | jq -r '.["machines"] | keys[0]')
    19  	ifaces=$(juju ssh ${juju_machine_id} 'ip -j link' | jq -r '.[].ifname | select(. | startswith("en") or startswith("eth"))')
    20  	primary_iface=$(echo $ifaces | cut -d " " -f1)
    21  	hotplug_iface=$(echo $ifaces | cut -d " " -f2)
    22  	configure_multi_nic_netplan "$juju_machine_id" "$hotplug_iface"
    23  
    24  	# Deploy test charm to dual-nic machine
    25  	juju deploy ./testcharms/charms/space-defender --bind "defend-a=alpha defend-b=isolated" --to "${juju_machine_id}"
    26  	unit_index=$(get_unit_index "space-defender")
    27  	wait_for "space-defender" "$(idle_condition "space-defender" 0 "${unit_index}")"
    28  
    29  	assert_net_iface_for_endpoint_matches "space-defender" "defend-a" "${primary_iface}"
    30  	assert_net_iface_for_endpoint_matches "space-defender" "defend-b" "${hotplug_iface}"
    31  
    32  	assert_endpoint_binding_matches "space-defender" "" "alpha"
    33  	assert_endpoint_binding_matches "space-defender" "defend-a" "alpha"
    34  	assert_endpoint_binding_matches "space-defender" "defend-b" "isolated"
    35  
    36  	# Upgrade the space-defender charm and modify its bindings
    37  	juju refresh space-defender --bind "defend-a=alpha defend-b=alpha" --path ./testcharms/charms/space-defender
    38  	wait_for "space-defender" "$(idle_condition "space-defender" 0 "${unit_index}")"
    39  
    40  	# After the upgrade, defend-a should remain attached to ens5 but
    41  	# defend-b which has now been bound to alpha should also get ens5
    42  	assert_net_iface_for_endpoint_matches "space-defender" "defend-a" "${primary_iface}"
    43  	assert_net_iface_for_endpoint_matches "space-defender" "defend-b" "${primary_iface}"
    44  
    45  	assert_endpoint_binding_matches "space-defender" "" "alpha"
    46  	assert_endpoint_binding_matches "space-defender" "defend-a" "alpha"
    47  	assert_endpoint_binding_matches "space-defender" "defend-b" "alpha"
    48  
    49  	destroy_model "spaces-upgrade-charm-with-bind-ec2"
    50  }
    51  
    52  test_upgrade_charm_with_bind() {
    53  	if [ "$(skip 'test_upgrade_charm_with_bind')" ]; then
    54  		echo "==> TEST SKIPPED: upgrade charm with --bind"
    55  		return
    56  	fi
    57  
    58  	(
    59  		set_verbosity
    60  
    61  		cd .. || exit
    62  
    63  		run "run_upgrade_charm_with_bind" "$@"
    64  	)
    65  }