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

     1  run_juju_bind() {
     2  	echo
     3  
     4  	file="${TEST_DIR}/test-juju-bind.log"
     5  
     6  	ensure "spaces-juju-bind" "${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  	# Mutate bindings
    37  	juju bind space-defender defend-a=alpha defend-b=alpha
    38  
    39  	# After the upgrade, defend-a should remain attached to ens5 but
    40  	# defend-b which has now been bound to alpha should also get ens5
    41  	assert_net_iface_for_endpoint_matches "space-defender" "defend-a" "${primary_iface}"
    42  	assert_net_iface_for_endpoint_matches "space-defender" "defend-b" "${primary_iface}"
    43  
    44  	assert_endpoint_binding_matches "space-defender" "" "alpha"
    45  	assert_endpoint_binding_matches "space-defender" "defend-a" "alpha"
    46  	assert_endpoint_binding_matches "space-defender" "defend-b" "alpha"
    47  
    48  	destroy_model "spaces-juju-bind"
    49  }
    50  
    51  test_juju_bind() {
    52  	if [ "$(skip 'test_juju_bind')" ]; then
    53  		echo "==> TEST SKIPPED: juju bind"
    54  		return
    55  	fi
    56  
    57  	(
    58  		set_verbosity
    59  
    60  		cd .. || exit
    61  
    62  		run "run_juju_bind" "$@"
    63  	)
    64  }