Skip to content

Commit

Permalink
test/suites: Update tests
Browse files Browse the repository at this point in the history
Signed-off-by: Max Asnaashari <max.asnaashari@canonical.com>
  • Loading branch information
masnax committed Jul 25, 2024
1 parent 1f39f13 commit f2d2c2f
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 3 deletions.
34 changes: 31 additions & 3 deletions test/includes/microcloud.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

# unset_interactive_vars: Unsets all variables related to the test console.
unset_interactive_vars() {
unset LOOKUP_IFACE LIMIT_SUBNET SKIP_SERVICE EXPECT_PEERS REUSE_EXISTING REUSE_EXISTING_COUNT \
unset SKIP_LOOKUP 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 CEPH_ENCRYPT SETUP_CEPHFS CEPH_CLUSTER_NETWORK IGNORE_CEPH_NETWORKING \
PROCEED_WITH_NO_OVERLAY_NETWORKING SETUP_OVN OVN_WARNING OVN_FILTER IPV4_SUBNET IPV4_START IPV4_END DNS_ADDRESSES IPV6_SUBNET
PROCEED_WITH_NO_OVERLAY_NETWORKING SETUP_OVN OVN_WARNING OVN_FILTER IPV4_SUBNET IPV4_START IPV4_END DNS_ADDRESSES IPV6_SUBNET \
REPLACE_PROFILE
}

# 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 @@ -39,8 +41,11 @@ microcloud_interactive() {
IPV4_END=${IPV4_END:-} # OVN ipv4 range end.
DNS_ADDRESSES=${DNS_ADDRESSES:-} # OVN custom DNS addresses.
IPV6_SUBNET=${IPV6_SUBNET:-} # OVN ipv6 range.
REPLACE_PROFILE="${REPLACE_PROFILE:-}" # Replace default profile config and devices.

setup="
setup=""
if ! [ "${SKIP_LOOKUP}" = 1 ]; then
setup="
${LOOKUP_IFACE} # filter the lookup interface
$([ -n "${LOOKUP_IFACE}" ] && printf "select") # select the interface
$([ -n "${LOOKUP_IFACE}" ] && printf -- "---")
Expand All @@ -51,6 +56,7 @@ select-all # select all the sys
---
$(true) # workaround for set -e
"
fi

if [ -n "${REUSE_EXISTING}" ]; then
for i in $(seq 1 "${REUSE_EXISTING_COUNT}") ; do
Expand Down Expand Up @@ -122,6 +128,13 @@ ${IPV6_SUBNET}
${DNS_ADDRESSES}
$(true) # workaround for set -e
"
fi

if [ -n "${REPLACE_PROFILE}" ] && [ "${SKIP_LOOKUP}" = 1 ]; then
setup="${setup}
${REPLACE_PROFILE}
$(true) # workaround for set -e
"
fi

# clear comments and empty lines.
Expand Down Expand Up @@ -1237,3 +1250,18 @@ ip_config_to_netaddr () {

echo "${net_addr}$(ip_prefix_by_netmask "${mask}")"
}

set_cluster_subnet() {
num_systems="${1}"
iface="${2}"
prefix="${3}"

shift 3

for n in $(seq 2 $((num_systems + 1))); do
cluster_ip="${prefix}.${n}/24"
name="$(printf "micro%02d" $((n-1)))"
lxc exec "${name}" -- ip addr flush "${iface}"
lxc exec "${name}" -- ip addr add "${cluster_ip}" dev "${iface}"
done
}
130 changes: 130 additions & 0 deletions test/suites/basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1322,3 +1322,133 @@ test_remove_cluster_member() {
lxc exec micro01 --env "TEST_CONSOLE=0" -- ${s} cluster list | grep -q "micro03"
done
}


test_add_services() {
unset_interactive_vars
# Set the default config for interactive setup.

ceph_cluster_subnet_prefix="10.0.1"
ceph_cluster_subnet_iface="enp7s0"
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 DNS_ADDRESSES="10.1.123.1,8.8.8.8"
export IPV6_SUBNET="fd42:1:1234:1234::1/64"
export CEPH_CLUSTER_NETWORK="${ceph_cluster_subnet_prefix}.0/24"
export REPLACE_PROFILE="no"

reset_systems 3 3 3
set_cluster_subnet 3 "${ceph_cluster_subnet_iface}" "${ceph_cluster_subnet_prefix}"
echo Add MicroCeph to MicroCloud that was set up without it, and setup remote storage without updating the profile.
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
set_cluster_subnet 3 "${ceph_cluster_subnet_iface}" "${ceph_cluster_subnet_prefix}"
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"
export REPLACE_PROFILE="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
set_cluster_subnet 3 "${ceph_cluster_subnet_iface}" "${ceph_cluster_subnet_prefix}"

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
set_cluster_subnet 3 "${ceph_cluster_subnet_iface}" "${ceph_cluster_subnet_prefix}"

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
set_cluster_subnet 3 "${ceph_cluster_subnet_iface}" "${ceph_cluster_subnet_prefix}"

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="add"
export SETUP_CEPH="yes"
export SKIP_LOOKUP=1
unset SETUP_ZFS
unset SETUP_OVN
unset CEPH_CLUSTER_NETWORK
microcloud_interactive | lxc exec micro01 -- sh -c "microcloud service add > out"
services_validator

reset_systems 3 3 3
set_cluster_subnet 3 "${ceph_cluster_subnet_iface}" "${ceph_cluster_subnet_prefix}"

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
export CEPH_CLUSTER_NETWORK="${ceph_cluster_subnet_prefix}.0/24"
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 f2d2c2f

Please sign in to comment.