Skip to content

Commit

Permalink
Merge pull request #178 from masnax/test-instances
Browse files Browse the repository at this point in the history
Test instances
  • Loading branch information
tomponline authored Oct 10, 2023
2 parents 08effe5 + 9d04def commit e2ef50b
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 0 deletions.
8 changes: 8 additions & 0 deletions microcloud/test/includes/microcloud.sh
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,14 @@ cluster_reset() {
fi

lxc exec ${name} -- sh -c "
for m in \$(lxc ls -f csv -c n) ; do
lxc rm \$m -f
done
for f in \$(lxc image ls -f csv -c f) ; do
lxc image rm \$f
done
echo 'config: {}' | lxc profile edit default || true
lxc storage rm local || true
"
Expand Down
1 change: 1 addition & 0 deletions microcloud/test/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ fi
new_systems 4 3 3

if [ "${1:-"all"}" != "cluster" ]; then
run_test test_instances "instances"
run_test test_interactive "interactive"
run_test test_service_mismatch "service mismatch"
run_test test_disk_mismatch "disk mismatch"
Expand Down
149 changes: 149 additions & 0 deletions microcloud/test/suites/basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,155 @@ test_interactive() {
done
}

test_instances() {
reset_systems 3 3 2

# Setup a MicroCloud with 3 systems, ZFS storage, and a FAN network.
addr=$(lxc ls micro01 -f csv -c4 | grep enp5s0 | cut -d' ' -f1)
lxc exec micro01 -- sh -c "
cat << EOF > /root/preseed.yaml
lookup_subnet: ${addr}/24
systems:
- name: micro01
storage:
local:
path: /dev/sdb
wipe: true
- name: micro02
storage:
local:
path: /dev/sdb
wipe: true
- name: micro03
storage:
local:
path: /dev/sdb
wipe: true
"

lxc exec micro01 -- sh -c "TEST_CONSOLE=0 microcloud init --preseed /root/preseed.yaml"

# Add cloud-init entry for checking ready state on launched instances.
lxc exec micro01 -- sh -c "
for m in \$(lxc ls -f csv -c n) ; do
lxc rm \$m -f
done
cat << EOF | lxc profile edit default
config:
cloud-init.user-data: |
#cloud-config
packages:
- curl
write_files:
- content: |
#!/bin/sh
exec curl --unix-socket /dev/lxd/sock lxd/1.0 -X PATCH -d '{\"state\": \"Ready\"}'
path: /var/lib/cloud/scripts/per-boot/ready.sh
permissions: \"0755\"
EOF
"

# Launch a container and VM with ZFS storage & FAN network.
lxc exec micro01 -- sh -c "lxc launch ubuntu:22.04 v1 --vm -s local -n lxdfan0"
lxc exec micro01 -- sh -c "lxc launch ubuntu:22.04 c1 -s local -n lxdfan0"

# Ensure we can reach the launched instances.
for m in c1 v1 ; do
echo "Waiting up to 5 mins for ${m} to start"
lxc exec micro01 -- sh -ceu "
for round in \$(seq 300); do
if lxc info ${m} | grep -qF \"Status: READY\" ; then
lxc rm ${m} -f
return 0
fi
sleep 1
done
return 1
"
done

reset_systems 3 3 2

# Create a MicroCloud with ceph and ovn setup.
addr=$(lxc ls micro01 -f csv -c4 | grep enp5s0 | cut -d' ' -f1)
lxc exec micro01 -- sh -c "
cat << EOF > /root/preseed.yaml
lookup_subnet: ${addr}/24
systems:
- name: micro01
storage:
ceph:
- path: /dev/sdc
wipe: true
- path: /dev/sdd
wipe: true
- name: micro02
storage:
ceph:
- path: /dev/sdc
wipe: true
- path: /dev/sdd
wipe: true
- name: micro03
storage:
ceph:
- path: /dev/sdc
wipe: true
- path: /dev/sdd
wipe: true
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
"

lxc exec micro01 -- sh -c "TEST_CONSOLE=0 microcloud init --preseed /root/preseed.yaml"

# Add cloud-init entry for checking ready state on launched instances.
lxc exec micro01 -- sh -c "
for m in \$(lxc ls -f csv -c n) ; do
lxc rm \$m -f
done
cat << EOF | lxc profile edit default
config:
cloud-init.user-data: |
#cloud-config
packages:
- curl
write_files:
- content: |
#!/bin/sh
exec curl --unix-socket /dev/lxd/sock lxd/1.0 -X PATCH -d '{\"state\": \"Ready\"}'
path: /var/lib/cloud/scripts/per-boot/ready.sh
permissions: \"0755\"
EOF
"

# Launch a container and VM with CEPH storage & OVN network.
lxc exec micro01 -- sh -c "lxc launch ubuntu:22.04 v1 --vm -s remote -n default"
lxc exec micro01 -- sh -c "lxc launch ubuntu:22.04 c1 -s remote -n default"

# Ensure we can reach the launched instances.
for m in c1 v1 ; do
echo "Waiting up to 5 mins for ${m} to start"
lxc exec micro01 -- sh -ceu "
for round in \$(seq 300); do
if lxc info ${m} | grep -qF \"Status: READY\" ; then
lxc rm ${m} -f
return 0
fi
sleep 1
done
return 1
"
done

}

test_case() {
# Number of systems to use in the test.
local num_systems num_disks num_ifaces skip_services
Expand Down
4 changes: 4 additions & 0 deletions microcloud/test/suites/preseed.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ test_preseed() {
reset_systems 4 3 2
addr=$(lxc ls micro01 -f csv -c4 | grep enp5s0 | cut -d' ' -f1)

# Create a MicroCloud with storage directly given by-path on one node, and by filter on other nodes.
lxc exec micro01 -- sh -c "
cat << EOF > /root/preseed.yaml
lookup_subnet: ${addr}/24
Expand Down Expand Up @@ -59,6 +60,7 @@ EOF
validate_system_microceph micro02 disk1 disk3
validate_system_microovn micro02

# Grow the MicroCloud with a new node, with filter-based storage selection.
lxc exec micro01 -- sh -c "
cat << EOF > /root/preseed.yaml
lookup_subnet: ${addr}/24
Expand Down Expand Up @@ -87,6 +89,7 @@ EOF
reset_systems 3 3 2
addr=$(lxc ls micro01 -f csv -c4 | grep enp5s0 | cut -d' ' -f1)

# Create a MicroCloud but don't set up storage or network (Should get a FAN setup).
lxc exec micro01 -- sh -c "
cat << EOF > /root/preseed.yaml
lookup_subnet: ${addr}/24
Expand All @@ -107,6 +110,7 @@ EOF
reset_systems 3 3 2
addr=$(lxc ls micro01 -f csv -c4 | grep enp5s0 | cut -d' ' -f1)

# Create a MicroCloud if we don't have MicroOVN or MicroCeph installed.
lxc exec micro01 -- sh -c "
snap disable microceph
snap disable microovn
Expand Down

0 comments on commit e2ef50b

Please sign in to comment.