Skip to content

Commit

Permalink
Merge pull request #39 from simondeziel/testflinger
Browse files Browse the repository at this point in the history
Testflinger
  • Loading branch information
tomponline authored Dec 4, 2023
2 parents b1df0b7 + 21885e5 commit c67d440
Show file tree
Hide file tree
Showing 21 changed files with 432 additions and 654 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
out/
50 changes: 50 additions & 0 deletions bin/helpers
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,56 @@ waitVMAgent() (
return 1 # Failed.
)

# waitInstanceReady: waits for the instance to be ready.
waitInstanceReady() (
set +x
maxWait=90
instName="$1"
instProj="${2:-}"
if [ -z "${instProj}" ]; then
# Find the currently selected project.
instProj="$(lxc project list -f csv | sed -n 's/^\([^(]\+\) (current),.*/\1/ p')"
fi
for _ in $(seq "${maxWait}"); do
if lxc info --project "${instProj}" "${instName}" | grep -qF "Status: READY"; then
return 0 # Success.
fi

sleep 1
done

echo "Instance ${instName} (${instProj}) not ready after ${maxWait}s"
lxc list --project "${instProj}" "${instName}"
return 1 # Failed.
)

# setupCloudInitReady: setup a cloud-init script to signal readiness.
setupCloudInitReady() {
instProj="${1}"
profile="${2:-default}"

lxc profile set "${profile}" --project "${instProj}" cloud-init.user-data - << EOF
#cloud-config
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
}

# enableSRIOV: enable SR-IOV on a NIC.
enableNICSRIOV() (
set +x
parentNIC="${1}"
numVFS="${2:-"7"}"

echo "${numVFS}" > "/sys/class/net/${parentNIC}/device/sriov_numvfs"
ip link set "${parentNIC}" up
sleep 10
ethtool "${parentNIC}"
)

# install_lxd: install LXD from a specific channel or `latest/edge` if none is provided.
install_lxd() (
Expand Down
2 changes: 1 addition & 1 deletion bin/openstack-run
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ if [ "${kernel}" != "default" ]; then
fi

# Connect and run something
echo "==> Running the job (${test_name})" >&2
echo "==> Running the job ${test_name} against ${lxd_snap_channel}" >&2
sed -e "1 a LXD_SNAP_CHANNEL=${lxd_snap_channel}" -e "1 r bin/helpers" "${script}" > "${_script}"
if echo "${IP}" | grep -q ":"; then
scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "${_script}" "ubuntu@[${IP}]:test-script"
Expand Down
58 changes: 58 additions & 0 deletions bin/testflinger-run
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/sh
set -eux

serie="${1}"
kernel="${2}"
script="${3}"
lxd_snap_channel="${4}"
shift 4
_script="$(mktemp)"
test_name="$(basename "${script}")"

testflinger_yaml_job() {
cat << EOF
job_queue: anything
provision_data:
distro: ${serie}
test_data:
test_cmds: |
#!/bin/bash
set -eux
export SSH_OPTS="-q -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ServerAliveInterval=30 -o ServerAliveCountMax=3"
SCP="scp \$SSH_OPTS"
SSH="ssh -n \$SSH_OPTS"
# Get lxd-ci scripts
git clone https://github.com/canonical/lxd-ci.git
cd lxd-ci
echo "Desired kernel: ${kernel}"
# Copy test script to DUT
_script="\$(mktemp)"
sed -e "1 a LXD_SNAP_CHANNEL=${lxd_snap_channel}" -e "1 r bin/helpers" "${script}" > "\${_script}"
\$SCP "\${_script}" "ubuntu@\${DEVICE_IP}:test-script"
# Run the test
\$SSH "ubuntu@\${DEVICE_IP}" -- sudo sh test-script
EOF
}

setup_testflinger() {
# Test connectivity
if ! wget --method HEAD -qO /dev/null https://testflinger.canonical.com/agents; then
echo "Failed to connect to testflinger.canonical.com, make sure you are connected to the VPN" >&2
exit 1
fi

command -v testflinger >/dev/null && return

echo "Installing testflinger snap" >&2
snap install testflinger-cli
}

setup_testflinger

# Submit the job
echo "==> Running the job ${test_name} against ${lxd_snap_channel}" >&2
testflinger_yaml_job | testflinger submit --poll -
28 changes: 11 additions & 17 deletions tests/cluster
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/sh -eu
PREFIX="cluster-$(uuidgen)"
#!/bin/sh
set -eu

PREFIX="cluster-$$"

if [ -z "${1:-""}" ] || [ -z "${2:-""}" ] || [ -z "${3:-""}" ]; then
echo "Usage: ${0} <count> <source channel> <destination channel>"
Expand Down Expand Up @@ -31,21 +33,11 @@ cleanup() {
trap cleanup EXIT HUP INT TERM

# Launch the container
lxc launch images:ubuntu/jammy "${PREFIX}-1" -c security.nesting=true
lxc launch ubuntu-daily:22.04 "${PREFIX}-1" -c security.nesting=true

sleep 10

lxc file push - "${PREFIX}-1"/etc/apt/sources.list << EOF
deb http://us.archive.ubuntu.com/ubuntu jammy main universe
deb http://us.archive.ubuntu.com/ubuntu jammy-updates main universe
deb http://us.archive.ubuntu.com/ubuntu jammy-security main universe
EOF

lxc exec "${PREFIX}-1" -- apt-get update
lxc exec "${PREFIX}-1" -- apt-get install --no-install-recommends snapd fuse3 curl --yes
lxc exec "${PREFIX}-1" -- snap install core20
lxc exec "${PREFIX}-1" -- snap install core22
lxc exec "${PREFIX}-1" -- snap install lxd --channel="$2"
lxc exec "${PREFIX}-1" -- snap refresh lxd --channel="$2"

for i in $(seq 2 "$1"); do
lxc copy "${PREFIX}-1" "${PREFIX}-$i"
Expand All @@ -55,7 +47,6 @@ done
for i in $(seq "$1"); do
sleep 10


# Configure the cluster
if [ "$i" = "1" ]; then
CLUSTER_IP=$(lxc exec "${PREFIX}-$i" -- ip -4 addr show dev eth0 scope global | grep inet | cut -d' ' -f6 | cut -d/ -f1)
Expand Down Expand Up @@ -92,8 +83,8 @@ lxc exec "${PREFIX}-1" -- lxc cluster list

# Test fan networking (intra fan from container and host, as well as external NAT comms)
echo "==> Test fan networking"
lxc exec "${PREFIX}-1" -- lxc launch images:ubuntu/focal u1
lxc exec "${PREFIX}-1" -- lxc launch images:ubuntu/focal u2
lxc exec "${PREFIX}-1" -- lxc launch ubuntu-daily:22.04 u1
lxc exec "${PREFIX}-1" -- lxc launch ubuntu-daily:22.04 u2

echo "==> Wait for addresses"
sleep 10
Expand Down Expand Up @@ -121,3 +112,6 @@ sleep 5m
echo "==> Validating the cluster"
lxc exec "${PREFIX}-1" -- lxc info
lxc exec "${PREFIX}-1" -- lxc cluster list

# shellcheck disable=SC2034
FAIL=0
56 changes: 3 additions & 53 deletions tests/cpu-vm
Original file line number Diff line number Diff line change
@@ -1,64 +1,13 @@
#!/bin/sh
set -eux

waitSnapdSeed() (
set +x
for i in $(seq 60); do # Wait up to 60s.
if systemctl show snapd.seeded.service --value --property SubState | grep -qx exited; then
return 0 # Success.
fi

sleep 1
done

echo "snapd not seeded after ${i}s"
return 1 # Failed.
)

cleanup() {
echo ""
if [ "${FAIL}" = "1" ]; then
echo "Test failed"
exit 1
fi

echo "Test passed"
exit 0
}

architecture="$(uname -m)"

if [ "${architecture}" != "x86_64" ] && [ "${architecture}" != "s390x" ]; then
echo "Skipping test as CPU hotplugging not supported on ${architecture}"
fi

FAIL=1
trap cleanup EXIT HUP INT TERM

# Wait for snapd seeding
waitSnapdSeed

# Install LXD
snap remove lxd || true
snap install lxd --channel=latest/edge
lxd waitready --timeout=300

waitVMAgent() (
set +x
# shellcheck disable=SC3043
local vmName="$1"
for i in $(seq 90) # Wait up to 90s.
do
if lxc info "${vmName}" | grep -qF 127.0.0.1; then
return 0 # Success.
fi

sleep 1
done

echo "VM ${vmName} agent not running after ${i}s"
return 1 # Failed.
)
install_lxd

# Configure LXD
lxc network create lxdbr0
Expand All @@ -71,7 +20,7 @@ echo "==> Create storage pool using driver ${poolDriver}"
lxc storage create "${poolName}" "${poolDriver}"

echo "==> Create ephemeral VM and boot"
lxc launch images:ubuntu/22.04 v1 --vm -s "${poolName}" --ephemeral
lxc launch ubuntu-daily:22.04 v1 --vm -s "${poolName}" --ephemeral
waitVMAgent v1
lxc info v1

Expand Down Expand Up @@ -123,4 +72,5 @@ lxc storage delete "${poolName}"
echo "==> Deleting storage pool"
lxc network delete lxdbr0

# shellcheck disable=SC2034
FAIL=0
67 changes: 9 additions & 58 deletions tests/devlxd-vm
Original file line number Diff line number Diff line change
@@ -1,59 +1,14 @@
#!/bin/sh
set -eux

waitSnapdSeed() (
set +x
for i in $(seq 60); do # Wait up to 60s.
if systemctl show snapd.seeded.service --value --property SubState | grep -qx exited; then
return 0 # Success.
fi
# Refresh apt
apt-get update

sleep 1
done

echo "snapd not seeded after ${i}s"
return 1 # Failed.
)

cleanup() {
echo ""
if [ "${FAIL}" = "1" ]; then
echo "Test failed"
exit 1
fi

echo "Test passed"
exit 0
}

FAIL=1
trap cleanup EXIT HUP INT TERM

# Wait for snapd seeding
waitSnapdSeed

# Install LXD
snap remove lxd || true
snap install lxd --channel=latest/edge
# Install dependencies
apt-get install --no-install-recommends --yes jq
lxd waitready --timeout=300

waitVMAgent() (
set +x
# shellcheck disable=SC3043
local vmName="$1"
for i in $(seq 90) # Wait up to 90s.
do
if lxc info "${vmName}" | grep -qF 127.0.0.1; then
return 0 # Success.
fi

sleep 1
done

echo "VM ${vmName} agent not running after ${i}s"
return 1 # Failed.
)
# Install LXD
install_lxd

# Configure LXD
lxc network create lxdbr0
Expand All @@ -66,14 +21,10 @@ echo "==> Create storage pool using driver ${poolDriver}"
lxc storage create "${poolName}" "${poolDriver}"

echo "==> Create VM and boot"
lxc init images:ubuntu/22.04/cloud v1 --vm -s "${poolName}"
lxc start v1
lxc launch ubuntu-daily:22.04 v1 --vm -s "${poolName}"
waitVMAgent v1
lxc info v1

# Install curl
lxc exec v1 -- sh -c "apt-get update && apt-get install --no-install-recommends --yes curl"

echo "==> Checking devlxd is working"

# devlxd is enabled by default and should work
Expand Down Expand Up @@ -136,10 +87,9 @@ lxc start v1
waitVMAgent v1

# Configure to use the proxy
lxc exec v1 -- apt-get install --no-install-recommends snapd --yes
lxc exec v1 -- snap install lxd --channel=latest/edge
lxc exec v1 -- snap install lxd --channel="${LXD_SNAP_CHANNEL:-"latest/edge"}"
lxc exec v1 -- /snap/bin/lxd init --auto
lxc exec v1 -- /snap/bin/lxc launch images:ubuntu/22.04/cloud v1v1 --vm
lxc exec v1 -- /snap/bin/lxc launch ubuntu-daily:22.04 v1v1 --vm
sleep 30
lxc exec v1 -- /snap/bin/lxc info v1v1 | grep -F RUNNING

Expand All @@ -153,4 +103,5 @@ lxc storage delete "${poolName}"
echo "==> Deleting storage pool"
lxc network delete lxdbr0

# shellcheck disable=SC2034
FAIL=0
Loading

0 comments on commit c67d440

Please sign in to comment.