-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Check that creating / joining a MicroOVN cluster works and tha…
…t the cluster state is healthy Signed-off-by: Gabriel Mougard <gabriel.mougard@canonical.com>
- Loading branch information
1 parent
33b9edd
commit 4163931
Showing
4 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# This is a bash shell fragment -*- bash -*- | ||
|
||
load "test_helper/setup_teardown/$(basename "${BATS_TEST_FILENAME//.bats/.bash}")" | ||
|
||
setup() { | ||
load test_helper/common.bash | ||
load test_helper/lxd.bash | ||
load test_helper/microovn.bash | ||
load ../.bats/bats-support/load.bash | ||
load ../.bats/bats-assert/load.bash | ||
|
||
# Ensure TEST_CONTAINERS and EAST_WEST_ADDRS are populated, otherwise the tests below will | ||
# provide false positive results. | ||
assert [ -n "$TEST_CONTAINERS" ] | ||
} | ||
|
||
@test "Check that custom IP encapsulation works" { | ||
local container_services | ||
EAST_WEST_ADDRS=() | ||
while IFS= read -r line; do | ||
EAST_WEST_ADDRS+=("$line") | ||
done < "$BATS_TMPDIR/east_west_addrs.txt" | ||
|
||
for pair in "${EAST_WEST_ADDRS[@]}"; do | ||
IFS='@' read -r container ip_east_west <<< "$pair" | ||
|
||
container_services=$(microovn_get_cluster_services "$container") | ||
if [[ "$container_services" != *"chassis"* ]]; then | ||
echo "Skip $container, no chassis services" >&3 | ||
continue | ||
fi | ||
|
||
run lxc_exec \ | ||
"$container" \ | ||
"microovn.ovs-vsctl get Open_vSwitch . external_ids:ovn-encap-ip" | ||
assert_output -p $ip_east_west | ||
done | ||
|
||
local test_filename=tests/init_cluster | ||
test_filename+=$(test_is_ipv6_test && echo _ipv6 || true) | ||
test_filename+=.bats | ||
|
||
# Run the cluster test with the custom IP encapsulation | ||
run bats -F junit $test_filename | ||
|
||
echo "# $output" >&3 | ||
echo "#" >&3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
init_cluster_custom_encap.bats |
48 changes: 48 additions & 0 deletions
48
tests/test_helper/setup_teardown/init_cluster_custom_encap.bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
setup_file() { | ||
load test_helper/common.bash | ||
load test_helper/lxd.bash | ||
load test_helper/microovn.bash | ||
load ../.bats/bats-support/load.bash | ||
load ../.bats/bats-assert/load.bash | ||
|
||
|
||
TEST_CONTAINERS=$(container_names "$BATS_TEST_FILENAME" 3) | ||
export TEST_CONTAINERS | ||
launch_containers jammy $TEST_CONTAINERS | ||
wait_containers_ready $TEST_CONTAINERS | ||
|
||
# Create a dedicated bridge for the east-west traffic | ||
network_output=$(create_lxd_network "br-east-west") | ||
ipv4_subnet=$(echo "$network_output" | cut -d'|' -f1) | ||
|
||
# Give each container an IP address from the subnet | ||
east_west_ips_to_containers=$(connect_containers_to_network_ipv4 "$TEST_CONTAINERS" "br-east-west" $ipv4_subnet) | ||
IFS=',' read -ra east_west_addrs <<< "$east_west_ips_to_containers" | ||
EAST_WEST_ADDRS=("${east_west_addrs[@]}") | ||
printf '%s\n' "${EAST_WEST_ADDRS[@]}" > "$BATS_TMPDIR/east_west_addrs.txt" | ||
|
||
install_microovn "$MICROOVN_SNAP_PATH" $TEST_CONTAINERS | ||
local leader | ||
for pair in "${EAST_WEST_ADDRS[@]}"; do | ||
IFS='@' read -r container ip_east_west <<< "$pair" | ||
|
||
local addr | ||
addr=$(container_get_default_ip "$container" \ | ||
"$(test_is_ipv6_test && echo inet6 || echo inet)") | ||
assert [ -n "$addr" ] | ||
if [ -z "$leader" ]; then | ||
microovn_init_create_cluster "$container" "$addr" "$ip_east_west" | ||
leader="$container" | ||
else | ||
local token | ||
token=$(microovn_cluster_get_join_token "$leader" "$container") | ||
microovn_init_join_cluster "$container" "$addr" "$token" "$ip_east_west" | ||
fi | ||
done | ||
} | ||
|
||
teardown_file() { | ||
delete_containers $TEST_CONTAINERS | ||
delete_lxd_network "br-east-west" | ||
rm -f "$BATS_TMPDIR/east_west_addrs.txt" | ||
} |
49 changes: 49 additions & 0 deletions
49
tests/test_helper/setup_teardown/init_cluster_custom_encap_ipv6.bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
setup_file() { | ||
load test_helper/common.bash | ||
load test_helper/lxd.bash | ||
load test_helper/microovn.bash | ||
load ../.bats/bats-support/load.bash | ||
load ../.bats/bats-assert/load.bash | ||
|
||
|
||
TEST_CONTAINERS=$(container_names "$BATS_TEST_FILENAME" 3) | ||
export TEST_CONTAINERS | ||
launch_containers jammy $TEST_CONTAINERS | ||
wait_containers_ready $TEST_CONTAINERS | ||
|
||
# Create a dedicated bridge for the east-west traffic | ||
network_output=$(create_lxd_network "br-east-west") | ||
ipv6_subnet=$(echo "$network_output" | cut -d'|' -f2) | ||
|
||
# Give each container an IP address from the subnet | ||
east_west_ips_to_containers=$(connect_containers_to_network_ipv6 "$TEST_CONTAINERS" "br-east-west" $ipv6_subnet) | ||
|
||
IFS=',' read -ra east_west_addrs <<< "$east_west_ips_to_containers" | ||
EAST_WEST_ADDRS=("${east_west_addrs[@]}") | ||
printf '%s\n' "${EAST_WEST_ADDRS[@]}" > "$BATS_TMPDIR/east_west_addrs.txt" | ||
|
||
install_microovn "$MICROOVN_SNAP_PATH" $TEST_CONTAINERS | ||
local leader | ||
for pair in "${EAST_WEST_ADDRS[@]}"; do | ||
IFS='@' read -r container ip_east_west <<< "$pair" | ||
|
||
local addr | ||
addr=$(container_get_default_ip "$container" \ | ||
"$(test_is_ipv6_test && echo inet6 || echo inet)") | ||
assert [ -n "$addr" ] | ||
if [ -z "$leader" ]; then | ||
microovn_init_create_cluster "$container" "$addr" "$ip_east_west" | ||
leader="$container" | ||
else | ||
local token | ||
token=$(microovn_cluster_get_join_token "$leader" "$container") | ||
microovn_init_join_cluster "$container" "$addr" "$token" "$ip_east_west" | ||
fi | ||
done | ||
} | ||
|
||
teardown_file() { | ||
delete_containers $TEST_CONTAINERS | ||
delete_lxd_network "br-east-west" | ||
rm -f "$BATS_TMPDIR/east_west_addrs.txt" | ||
} |