Skip to content

Commit

Permalink
microcloud/test/suites: Add tests for adding services
Browse files Browse the repository at this point in the history
Signed-off-by: Max Asnaashari <[email protected]>
  • Loading branch information
masnax committed Feb 1, 2024
1 parent e2d37fc commit 23d2c09
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 2 deletions.
9 changes: 7 additions & 2 deletions microcloud/test/includes/microcloud.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ unset_interactive_vars() {
unset LOOKUP_IFACE LIMIT_SUBNET SKIP_SERVICE EXPECT_PEERS REUSE_EXISTING REUSE_EXISTING_COUNT \
SETUP_ZFS ZFS_FILTER ZFS_WIPE \
SETUP_CEPH CEPH_WARNING CEPH_FILTER CEPH_WIPE SETUP_CEPHFS \
SETUP_OVN OVN_WARNING OVN_FILTER IPV4_SUBNET IPV4_START IPV4_END CUSTOM_DNS_ADDRESSES IPV6_SUBNET
SETUP_OVN OVN_WARNING OVN_FILTER IPV4_SUBNET IPV4_START IPV4_END CUSTOM_DNS_ADDRESSES IPV6_SUBNET \
SKIP_LOOKUP
}

# microcloud_interactive: outputs text that can be passed to `TEST_CONSOLE=1 microcloud init`
# to simulate terminal input to the interactive CLI.
# The lines that are output are based on the values passed to the listed environment variables.
# Any unset variables will be omitted.
microcloud_interactive() {
SKIP_LOOKUP=${SKIP_LOOKUP:-} # whether or not to skip the whole lookup block in the interactive command list.
LOOKUP_IFACE=${LOOKUP_IFACE:-} # filter string for the lookup interface table.
LIMIT_SUBNET=${LIMIT_SUBNET:-} # (yes/no) input for limiting lookup of systems to the above subnet.
SKIP_SERVICE=${SKIP_SERVICE:-} # (yes/no) input to skip any missing services. Should be unset if all services are installed.
Expand All @@ -34,7 +36,9 @@ microcloud_interactive() {
CUSTOM_DNS_ADDRESSES=${CUSTOM_DNS_ADDRESSES:-} # OVN custom DNS addresses.
IPV6_SUBNET=${IPV6_SUBNET:-} # OVN ipv6 range.

setup=$(cat << EOF
setup=""
if ! [ "${SKIP_LOOKUP}" = 1 ]; then
setup=$(cat << EOF
${LOOKUP_IFACE} # filter the lookup interface
$([ -n "${LOOKUP_IFACE}" ] && printf "select") # select the interface
$([ -n "${LOOKUP_IFACE}" ] && printf -- "---")
Expand All @@ -45,6 +49,7 @@ select-all # select all the sys
---
EOF
)
fi

if [ -n "${REUSE_EXISTING}" ]; then
for i in $(seq 1 "${REUSE_EXISTING_COUNT}") ; do
Expand Down
1 change: 1 addition & 0 deletions microcloud/test/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ if [ "${1:-"all"}" != "cluster" ]; then
run_test test_add_auto "add auto"
run_test test_preseed "preseed"
run_test test_reuse_cluster "reuse_cluster"
run_test test_add_services "add services"
fi

# shellcheck disable=SC2034
Expand Down
98 changes: 98 additions & 0 deletions microcloud/test/suites/basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,7 @@ services_validator() {
}

test_reuse_cluster() {
unset_interactive_vars
# Set the default config for interactive setup.
export LOOKUP_IFACE="enp5s0"
export LIMIT_SUBNET="yes"
Expand Down Expand Up @@ -809,3 +810,100 @@ storage:
lxc exec micro01 -- sh -c "cat /root/preseed.yaml | TEST_CONSOLE=0 microcloud init --preseed"
services_validator
}

test_add_services() {
unset_interactive_vars
# Set the default config for interactive setup.
export LOOKUP_IFACE="enp5s0"
export LIMIT_SUBNET="yes"
export EXPECT_PEERS=2
export SETUP_ZFS="yes"
export ZFS_FILTER="lxd_disk1"
export ZFS_WIPE="yes"
export SETUP_CEPH="yes"
export SETUP_CEPHFS="yes"
export CEPH_FILTER="lxd_disk2"
export CEPH_WIPE="yes"
export SETUP_OVN="yes"
export OVN_FILTER="enp6s0"
export IPV4_SUBNET="10.1.123.1/24"
export IPV4_START="10.1.123.100"
export IPV4_END="10.1.123.254"
export CUSTOM_DNS_ADDRESSES="10.1.123.1,8.8.8.8"
export IPV6_SUBNET="fd42:1:1234:1234::1/64"

reset_systems 3 3 3
echo Add MicroCeph to MicroCloud that was set up without it, and setup remote storage
lxc exec micro01 -- snap disable microceph
unset SETUP_CEPH
export SKIP_SERVICE="yes"
microcloud_interactive | lxc exec micro01 -- sh -c "microcloud init > out"
lxc exec micro01 -- snap enable microceph
export SETUP_CEPH="yes"
export SKIP_LOOKUP=1
unset SETUP_ZFS
unset SETUP_OVN
microcloud_interactive | lxc exec micro01 -- sh -c "microcloud service add > out"
services_validator

reset_systems 3 3 3
echo Add MicroOVN to MicroCloud that was set up without it, and setup ovn network
lxc exec micro01 -- snap disable microovn
export SETUP_ZFS="yes"
unset SKIP_LOOKUP
microcloud_interactive | lxc exec micro01 -- sh -c "microcloud init > out"
lxc exec micro01 -- snap enable microovn
export SETUP_OVN="yes"
export SKIP_LOOKUP=1
unset SETUP_ZFS
unset SETUP_CEPH
microcloud_interactive | lxc exec micro01 -- sh -c "microcloud service add > out"
services_validator

reset_systems 3 3 3
echo Add both MicroOVN and MicroCeph to a MicroCloud that was set up without it
lxc exec micro01 -- snap disable microovn
lxc exec micro01 -- snap disable microceph
export SETUP_ZFS="yes"
unset SKIP_LOOKUP
unset SETUP_OVN
microcloud_interactive | lxc exec micro01 -- sh -c "microcloud init > out"
lxc exec micro01 -- snap enable microovn
lxc exec micro01 -- snap enable microceph
export SETUP_OVN="yes"
export SETUP_CEPH="yes"
export SKIP_LOOKUP=1
unset SETUP_ZFS
microcloud_interactive | lxc exec micro01 -- sh -c "microcloud service add > out"
services_validator

reset_systems 3 3 3
echo Reuse a MicroCeph that was set up on one node of the MicroCloud
lxc exec micro01 -- snap disable microceph
lxc exec micro02 -- microceph cluster bootstrap
export SETUP_ZFS="yes"
unset SETUP_CEPH
unset SKIP_LOOKUP
microcloud_interactive | lxc exec micro01 -- sh -c "microcloud init > out"
lxc exec micro01 -- snap enable microceph
export REUSE_EXISTING_COUNT=1
export REUSE_EXISTING="reuse"
export SETUP_CEPH="yes"
export SKIP_LOOKUP=1
unset SETUP_ZFS
unset SETUP_OVN
microcloud_interactive | lxc exec micro01 -- sh -c "microcloud service add > out"
services_validator

reset_systems 3 3 3
echo Fail to add any services if they have been set up
export SETUP_ZFS="yes"
export SETUP_OVN="yes"
unset REUSE_EXISTING
unset REUSE_EXISTING_COUNT
unset SKIP_LOOKUP
unset SKIP_SERVICE
microcloud_interactive | lxc exec micro01 -- sh -c "microcloud init > out"
export SKIP_LOOKUP=1
! microcloud_interactive | lxc exec micro01 -- sh -c "microcloud service add > out" || true
}

0 comments on commit 23d2c09

Please sign in to comment.