github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/tests/suites/spaces_ec2/machines_in_spaces.sh (about) 1 # Deploy some machines with spaces constraints and then 2 # check that they have been deployed as expected 3 run_machines_in_spaces() { 4 echo 5 6 file="${TEST_DIR}/test-machines-in-spaces.log" 7 8 ensure "machines-in-spaces" "${file}" 9 10 echo "Setup spaces" 11 juju reload-spaces 12 juju add-space isolated 172.31.254.0/24 13 14 juju add-machine --constraints spaces=alpha -n2 15 juju add-machine --constraints spaces=isolated 16 17 wait_for_machine_agent_status "0" "started" 18 wait_for_machine_agent_status "1" "started" 19 wait_for_machine_agent_status "2" "started" 20 21 echo "Verify machines are assigned to correct spaces" 22 alpha_cidrs="$(juju spaces --format json | jq -r '.spaces[] | select(.name == "alpha").subnets | to_entries[] | select(.value["provider-id"] | contains("INFAN") | not) | .key')" 23 assert_machine_ip_is_in_cidrs "0" "${alpha_cidrs}" 24 machine_1_space_ip=$(assert_machine_ip_is_in_cidrs "1" "${alpha_cidrs}") 25 machine_2_space_ip=$(assert_machine_ip_is_in_cidrs "2" "172.31.254.0/24") 26 27 echo "Verify machines can ping each other within and across spaces" 28 juju ssh 0 "ping -c4 ${machine_1_space_ip}" 29 juju ssh 0 "ping -c4 ${machine_2_space_ip}" 30 31 echo "Attempt assigning a container to a different space to it's host machine and assert this fails" 32 juju add-machine lxd:0 --constraints spaces=isolated 33 wait_for "provisioning error" '.machines["0"].containers["0/lxd/0"]["machine-status"].current' 34 35 # A container lying around in error state will cause destroy_model to return non-zero 36 echo "Destroy container" 37 juju remove-machine "0/lxd/0" 38 wait_for "false" '.machines["0"] | has("containers")' 39 40 destroy_model "machines-in-spaces" 41 } 42 43 test_machines_in_spaces() { 44 if [ "$(skip 'test_machines_in_spaces')" ]; then 45 echo "==> TEST SKIPPED: assert machines added to spaces" 46 return 47 fi 48 49 ( 50 set_verbosity 51 52 cd .. || exit 53 54 run "run_machines_in_spaces" "$@" 55 ) 56 }