Skip to content

Commit

Permalink
tests: Refactor existing tests to work with no custom encapsulation I…
Browse files Browse the repository at this point in the history
…P (default)

/canonical/self-hosted-runners/run-workflows 6b00c91

Signed-off-by: Gabriel Mougard <gabriel.mougard@canonical.com>
  • Loading branch information
gabrielmougard committed Jan 17, 2024
1 parent 5a299ab commit 09bb538
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 5 deletions.
4 changes: 2 additions & 2 deletions tests/scaleup_cluster.bats
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ teardown() {
$container \
"$(test_is_ipv6_test && echo inet6 || echo inet)")
if [ $i -eq 1 ]; then
microovn_init_create_cluster "$container" "$addr"
microovn_init_create_cluster "$container" "$addr" ""
else
local token
token=$(microovn_cluster_get_join_token \
"${containers[0]}" \
"$container")
microovn_init_join_cluster "$container" "$addr" "$token"
microovn_init_join_cluster "$container" "$addr" "$token" ""
fi
starttimes_ovn_controller[$container]=$(\
microovn_wait_for_service_starttime $container ovn-controller)
Expand Down
51 changes: 50 additions & 1 deletion tests/test_helper/microovn.bash
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,28 @@ function wait_ovn_services() {
function microovn_init_create_cluster() {
local container=$1; shift
local address=$1; shift
local custom_encapsulation_ip=$1; shift

custom_encapsulation_ip_dialog=""
if [ -n "$custom_encapsulation_ip" ]; then
custom_encapsulation_ip_dialog=$(cat <<EOF
expect "Would you like to define a custom encapsulation IP address for $container?" {
send "yes\n"
}
expect "Please enter the custom encapsulation IP address for $container" {
send "$custom_encapsulation_ip\n"
}
EOF
)
else
custom_encapsulation_ip_dialog=$(cat <<EOF
expect "Would you like to define a custom encapsulation IP address for $container?" {
send "\n"
}
EOF
)
fi

cat << EOF | lxc_exec "$container" "expect -"
spawn "sudo" "microovn" "init"
Expand All @@ -120,9 +142,11 @@ expect "Would you like to create a new MicroOVN cluster?" {
}
expect "Please choose a name for this system" {
send "\n"
send "$container\n"
}
$custom_encapsulation_ip_dialog
expect "Would you like to add additional servers to the cluster?" {
send "no\n"
}
Expand All @@ -135,6 +159,29 @@ function microovn_init_join_cluster() {
local container=$1; shift
local address=$1; shift
local token=$1; shift
local custom_encapsulation_ip=$1; shift

custom_encapsulation_ip_dialog=""
if [ -n "$custom_encapsulation_ip" ]; then
custom_encapsulation_ip_dialog=$(cat <<EOF
expect "Would you like to define a custom encapsulation IP address for $container?" {
send "yes\n"
}
expect "Please enter the custom encapsulation IP address for $container" {
send "$custom_encapsulation_ip\n"
}
EOF
)
else
custom_encapsulation_ip_dialog=$(cat <<EOF
expect "Would you like to define a custom encapsulation IP address for $container?" {
send "\n"
}
EOF
)
fi

cat << EOF | lxc_exec "$container" "expect -"
spawn "sudo" "microovn" "init"
Expand All @@ -150,6 +197,8 @@ expect "Please enter your join token:" {
send "$token\n"
}
$custom_encapsulation_ip_dialog
expect eof
EOF
}
Expand Down
4 changes: 2 additions & 2 deletions tests/test_helper/setup_teardown/init_cluster.bash
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ setup_file() {
"$(test_is_ipv6_test && echo inet6 || echo inet)")
assert [ -n "$addr" ]
if [ -z "$leader" ]; then
microovn_init_create_cluster "$container" "$addr"
microovn_init_create_cluster "$container" "$addr" ""
leader="$container"
else
local token
token=$(microovn_cluster_get_join_token "$leader" "$container")
microovn_init_join_cluster "$container" "$addr" "$token"
microovn_init_join_cluster "$container" "$addr" "$token" ""
fi
done
}
Expand Down

0 comments on commit 09bb538

Please sign in to comment.