Skip to content

Commit

Permalink
Merge pull request #556 from simondeziel/intergation-tests-in-lxd
Browse files Browse the repository at this point in the history
Fix script to run integration tests in LXD
  • Loading branch information
tomponline committed Jul 14, 2023
2 parents 89617a6 + 5095564 commit 6545b57
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
15 changes: 13 additions & 2 deletions integration/run-integration-tests
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,27 @@ if [ -e /var/snap/lxd/common/lxd/server.crt ]; then
cp /var/snap/lxd/common/lxd/server.crt ~/snap/lxd/common/config/servercerts/127.0.0.1.crt
fi

# LXD 4 has a different `lxc config trust list` output format
LXD_MAJOR_VER="$(lxc version | awk -F. '/Server version:/ {print $1}' | cut -d" " -f 3)"
save_trust_list() {
if [ "${LXD_MAJOR_VER}" -gt 4 ]; then
lxc config trust list --format csv | awk -F, '{print $4}' | sort
else
lxc config trust list --format csv | awk -F, '{print $1}' | sort
fi
}

# Save the list of trusted certs
OLD_TRUST_LIST="$(mktemp)"
lxc config trust list --format csv | awk -F, '{print $4}' | sort > "${OLD_TRUST_LIST}"
save_trust_list > "${OLD_TRUST_LIST}"

# finally run the integration tests
tox -e integration

# Remove any cert added to the trusted list by the integration tests
NEW_TRUST_LIST="$(mktemp)"
lxc config trust list --format csv | awk -F, '{print $4}' | sort > "${NEW_TRUST_LIST}"
save_trust_list > "${NEW_TRUST_LIST}"

for cert in $(comm -13 "${OLD_TRUST_LIST}" "${NEW_TRUST_LIST}"); do
lxc config trust remove "${cert}"
done
Expand Down
22 changes: 13 additions & 9 deletions integration/run-integration-tests-in-lxd
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,34 @@
DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")"

declare -A RELEASE_IMAGES=(
[bionic]="18.04"
[focal]="20.04"
[jammy]="22.04"
)

function run_tests {
local target="$1"
local image="${RELEASE_IMAGES[$target]}"
local container_name
container_name="pylxd-$target-$(uuidgen | cut -d- -f1)"
local container_name="pylxd-${target}-$$"
local container_image="ubuntu:${image}"
echo "Running ${image} integration tests"

lxc launch --ephemeral "$container_image" "$container_name" -c security.nesting=true
lxc exec "$container_name" -- cloud-init status --long --wait

lxc exec "$container_name" -- mkdir -p /opt/pylxd
# NOTE: rockstar (13 Sep 2016) - --recursive is not supported in lxd <2.1, so
# until we have pervasive support for that, we'll do this tar hack.
local ldir="$DIR/.."
env -C "$ldir" tar cf - ./* .git | lxc exec "$container_name" -- tar xf - -C /opt/pylxd
lxc exec "$container_name" -- /bin/sh -c "env -C /opt/pylxd integration/run-integration-tests"
{ cd "$DIR/.." && git archive --format=tar HEAD; } | lxc exec "$container_name" -- tar -xf - -C /opt/pylxd

lxc exec "$container_name" -- cloud-init status --long --wait
lxc exec "$container_name" --cwd /opt/pylxd -- integration/run-integration-tests
lxc delete --force "$container_name"
}

# Make sure unprivileged userns clone is enabled otherwise security.nesting=true
# won't work.
if [ "$(cat /proc/sys/kernel/unprivileged_userns_clone)" -eq 0 ]; then
echo "unpriviliged userns clone disabled, unable to run tests" >&2
exit 1
fi

declare -a images
if [ $# -gt 0 ]; then
images=("$@")
Expand Down

0 comments on commit 6545b57

Please sign in to comment.