Skip to content

Commit

Permalink
tests: Check that creating / joining a MicroOVN cluster works and tha…
Browse files Browse the repository at this point in the history
…t the cluster state is healthy

Signed-off-by: Gabriel Mougard <[email protected]>
  • Loading branch information
gabrielmougard committed Feb 9, 2024
1 parent ef09fdb commit 543bca5
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 0 deletions.
40 changes: 40 additions & 0 deletions tests/init_cluster_custom_encap.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# 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" ]
assert [ -n "$EAST_WEST_ADDRS" ]
}

@test "Check that custom IP encapsulation works" {
local container_services

for container in $TEST_CONTAINERS; do
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 "${EAST_WEST_ADDRS[$container]}"
done

run bats -F junit test_helper/bats/cluster.bats

echo "# $output" >&3
echo "#" >&3

[ "$status" -eq 0 ]
}
1 change: 1 addition & 0 deletions tests/init_cluster_custom_encap_ipv6.bats
45 changes: 45 additions & 0 deletions tests/test_helper/setup_teardown/init_cluster_custom_encap.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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")
IFS='|' read -r ipv4_subnet ipv6_subnet <<< "$network_output"

# 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[*]}"
export EAST_WEST_ADDRS

install_microovn "$MICROOVN_SNAP_PATH" $TEST_CONTAINERS
local leader
for container in $TEST_CONTAINERS; do
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" "${east_west_addrs[$container]}"
leader="$container"
else
local token
token=$(microovn_cluster_get_join_token "$leader" "$container")
microovn_init_join_cluster "$container" "$addr" "$token" "${east_west_addrs[$container]}"
fi
done
}

teardown_file() {
delete_containers $TEST_CONTAINERS
delete_lxd_network "br-east-west"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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")
IFS='|' read -r ipv4_subnet ipv6_subnet <<< "$network_output"

# Give each container an IP address from the subnet
east_west_ips_to_containers=$(connect_containers_to_network_ipv6 "$TEST_CONTAINERS" "br-east-west")
IFS=',' read -ra east_west_addrs <<< "$east_west_ips_to_containers"

install_microovn "$MICROOVN_SNAP_PATH" $TEST_CONTAINERS
local leader
for container in $TEST_CONTAINERS; do
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" "${east_west_addrs[$container]}"
leader="$container"
else
local token
token=$(microovn_cluster_get_join_token "$leader" "$container")
microovn_init_join_cluster "$container" "$addr" "$token" "${east_west_addrs[$container]}"
fi
done
}

teardown_file() {
delete_containers $TEST_CONTAINERS
delete_lxd_network "br-east-west"
}

0 comments on commit 543bca5

Please sign in to comment.