Skip to content

Commit

Permalink
microcloud/test/suites: Add reuse-cluster 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 May 3, 2024
1 parent 5636937 commit 3424df4
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 21 deletions.
42 changes: 22 additions & 20 deletions microcloud/test/includes/microcloud.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,28 @@ unset_interactive_vars() {
# The lines that are output are based on the values passed to the listed environment variables.
# Any unset variables will be omitted.
microcloud_interactive() {
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.
EXPECT_PEERS=${EXPECT_PEERS:-} # wait for this number of systems to be available to join the cluster.
SETUP_ZFS=${SETUP_ZFS:-} # (yes/no) input for initiating ZFS storage pool setup.
ZFS_FILTER=${ZFS_FILTER:-} # filter string for ZFS disks.
ZFS_WIPE=${ZFS_WIPE:-} # (yes/no) to wipe all disks.
SETUP_CEPH=${SETUP_CEPH:-} # (yes/no) input for initiating CEPH storage pool setup.
SETUP_CEPHFS=${SETUP_CEPHFS:-} # (yes/no) input for initialising CephFS storage pool setup.
CEPH_WARNING=${CEPH_WARNING:-} # (yes/no) input for warning about eligible disk detection.
CEPH_FILTER=${CEPH_FILTER:-} # filter string for CEPH disks.
CEPH_WIPE=${CEPH_WIPE:-} # (yes/no) to wipe all disks.
SETUP_OVN=${SETUP_OVN:-} # (yes/no) input for initiating OVN network setup.
OVN_WARNING=${OVN_WARNING:-} # (yes/no) input for warning about eligible interface detection.
OVN_FILTER=${OVN_FILTER:-} # filter string for OVN interfaces.
IPV4_SUBNET=${IPV4_SUBNET:-} # OVN ipv4 gateway subnet.
IPV4_START=${IPV4_START:-} # OVN ipv4 range start.
IPV4_END=${IPV4_END:-} # OVN ipv4 range end.
DNS_ADDRESSES=${DNS_ADDRESSES:-} # OVN custom DNS addresses.
IPV6_SUBNET=${IPV6_SUBNET:-} # OVN ipv6 range.
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.
EXPECT_PEERS=${EXPECT_PEERS:-} # wait for this number of systems to be available to join the cluster.
REUSE_EXISTING=${REUSE_EXISTING:-} # (yes/no) incorporate an existing clustered service.
REUSE_EXISTING_COUNT=${REUSE_EXISTING_COUNT:-0} # (number) number of existing clusters to incorporate.
SETUP_ZFS=${SETUP_ZFS:-} # (yes/no) input for initiating ZFS storage pool setup.
ZFS_FILTER=${ZFS_FILTER:-} # filter string for ZFS disks.
ZFS_WIPE=${ZFS_WIPE:-} # (yes/no) to wipe all disks.
SETUP_CEPH=${SETUP_CEPH:-} # (yes/no) input for initiating CEPH storage pool setup.
SETUP_CEPHFS=${SETUP_CEPHFS:-} # (yes/no) input for initialising CephFS storage pool setup.
CEPH_WARNING=${CEPH_WARNING:-} # (yes/no) input for warning about eligible disk detection.
CEPH_FILTER=${CEPH_FILTER:-} # filter string for CEPH disks.
CEPH_WIPE=${CEPH_WIPE:-} # (yes/no) to wipe all disks.
SETUP_OVN=${SETUP_OVN:-} # (yes/no) input for initiating OVN network setup.
OVN_WARNING=${OVN_WARNING:-} # (yes/no) input for warning about eligible interface detection.
OVN_FILTER=${OVN_FILTER:-} # filter string for OVN interfaces.
IPV4_SUBNET=${IPV4_SUBNET:-} # OVN ipv4 gateway subnet.
IPV4_START=${IPV4_START:-} # OVN ipv4 range start.
IPV4_END=${IPV4_END:-} # OVN ipv4 range end.
DNS_ADDRESSES=${DNS_ADDRESSES:-} # OVN custom DNS addresses.
IPV6_SUBNET=${IPV6_SUBNET:-} # OVN ipv6 range.

setup="
${LOOKUP_IFACE} # filter the lookup interface
Expand Down
1 change: 1 addition & 0 deletions microcloud/test/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ run_basic_tests() {
run_test test_instances_launch "instances launch"
run_test test_service_mismatch "service mismatch"
run_test test_disk_mismatch "disk mismatch"
run_test test_reuse_cluster "reuse_cluster"
}

run_interactive_tests() {
Expand Down
133 changes: 132 additions & 1 deletion microcloud/test/suites/basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ test_interactive() {
export IPV4_START="10.1.123.100"
export IPV4_END="10.1.123.254"
export IPV6_SUBNET="fd42:1:1234:1234::1/64"
export DNS_ADDRESSES="10.1.123.1,8.8.8.8"
export DNS_ADDRESSES="10.1.123.1,8.8.8.8"
microcloud_interactive | lxc exec micro01 -- sh -c "microcloud init > out"

lxc exec micro01 -- tail -1 out | grep "MicroCloud is ready" -q
Expand Down Expand Up @@ -822,3 +822,134 @@ test_auto() {
! lxc exec ${m} -- lxc network ls -f csv | grep -q "^UPLINK," || false
done
}

# services_validator: A basic validator of 3 systems with typical expected inputs.
services_validator() {
for m in micro01 micro02 micro03 ; do
validate_system_lxd ${m} 3 disk1 1 1 enp6s0 10.1.123.1/24 10.1.123.100-10.1.123.254 fd42:1:1234:1234::1/64 10.1.123.1,8.8.8.8
validate_system_microceph ${m} 1 disk2
validate_system_microovn ${m}
done
}

test_reuse_cluster() {
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 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 "Create a MicroCloud that re-uses an existing service"
export REUSE_EXISTING_COUNT=1
export REUSE_EXISTING="add"
lxc exec micro02 -- microceph cluster bootstrap
microcloud_interactive | lxc exec micro01 -- sh -c "microcloud init > out"
services_validator

reset_systems 3 3 3
echo "Create a MicroCloud that re-uses an existing service on the local node"
lxc exec micro01 -- microceph cluster bootstrap
microcloud_interactive | lxc exec micro01 -- sh -c "microcloud init > out"
services_validator

reset_systems 3 3 3
echo "Create a MicroCloud that re-uses an existing MicroCeph and MicroOVN"
export REUSE_EXISTING_COUNT=2
export REUSE_EXISTING="add"
lxc exec micro02 -- microceph cluster bootstrap
lxc exec micro02 -- microovn cluster bootstrap
microcloud_interactive | lxc exec micro01 -- sh -c "microcloud init > out"
services_validator

reset_systems 3 3 3
echo "Create a MicroCloud that re-uses an existing MicroCeph and MicroOVN on different nodes"
lxc exec micro02 -- microceph cluster bootstrap
lxc exec micro03 -- microovn cluster bootstrap
microcloud_interactive | lxc exec micro01 -- sh -c "microcloud init > out"
services_validator

reset_systems 3 3 3
echo "Create a MicroCloud that re-uses an existing service with multiple nodes from this cluster"
export REUSE_EXISTING_COUNT=1
export REUSE_EXISTING="add"
lxc exec micro02 -- microceph cluster bootstrap
token="$(lxc exec micro02 -- microceph cluster add micro01)"
lxc exec micro01 -- microceph cluster join "${token}"
microcloud_interactive | lxc exec micro01 -- sh -c "microcloud init > out"
services_validator

reset_systems 3 3 3
echo "Create a MicroCloud that re-uses an existing existing service with all nodes from this cluster"
lxc exec micro02 -- microceph cluster bootstrap
token="$(lxc exec micro02 -- microceph cluster add micro01)"
lxc exec micro01 -- microceph cluster join "${token}"
token="$(lxc exec micro02 -- microceph cluster add micro03)"
lxc exec micro03 -- microceph cluster join "${token}"
microcloud_interactive | lxc exec micro01 -- sh -c "microcloud init > out"
services_validator

reset_systems 4 3 3
echo "Create a MicroCloud that re-uses an existing existing service with foreign cluster members"
lxc exec micro04 -- snap disable microcloud
lxc exec micro02 -- microceph cluster bootstrap
token="$(lxc exec micro02 -- microceph cluster add micro04)"
lxc exec micro04 -- microceph cluster join "${token}"
microcloud_interactive | lxc exec micro01 -- sh -c "microcloud init > out"
services_validator
validate_system_microceph micro04 1

reset_systems 3 3 3
echo "Fail to create a MicroCloud due to an existing service if --auto specified"
lxc exec micro02 -- microceph cluster bootstrap
! lxc exec micro01 -- sh -c "TEST_CONSOLE=0 microcloud init --auto > out" || true



echo "Fail to create a MicroCloud due to conflicting existing services"
lxc exec micro03 -- microceph cluster bootstrap
! microcloud_interactive | lxc exec micro01 -- sh -c "microcloud init > out" || true

reset_systems 3 3 3
echo "Create a MicroCloud that re-uses an existing service with preseed"
addr=$(lxc ls micro01 -f csv -c4 | grep enp5s0 | cut -d' ' -f1)
lxc exec micro01 --env TEST_CONSOLE=0 -- microcloud init --preseed << EOF
lookup_subnet: ${addr}/24
lookup_interface: enp5s0
reuse_existing_clusters: true
systems:
- name: micro01
- name: micro02
- name: micro03
ovn:
ipv4_gateway: 10.1.123.1/24
ipv4_range: 10.1.123.100-10.1.123.254
ipv6_gateway: fd42:1:1234:1234::1/64
dns_servers: 10.1.123.1,8.8.8.8
storage:
local:
- find: id == sdb
wipe: true
ceph:
- find: id == sdc
wipe: true
cephfs: true
EOF

services_validator
}

0 comments on commit 3424df4

Please sign in to comment.