Skip to content

Commit

Permalink
Merge pull request #44 from simondeziel/faster-repeated-runs
Browse files Browse the repository at this point in the history
Faster repeated runs
  • Loading branch information
tomponline authored Dec 11, 2023
2 parents d71b230 + ae0ce8d commit 46e713f
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 82 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
# Running tests
# Running tests locally

To run a test locally (directly where you invoke it), use the `bin/local-run` helper:

```
./bin/local-run tests/interception latest/edge
```

For faster repeated runs, you might want to tell `snap` that it can purge the LXD snap
without taking any snapshot:

```
export PURGE_LXD=1
./bin/local-run tests/interception latest/edge
```


# Running tests on OpenStack (ProdStack)

The tests need to be run from PS6's LXD bastion `lxd-bastion-ps6.internal`. Once connected, the proper environment can be loaded with:

Expand All @@ -9,7 +26,7 @@ pe
Then to run all the tests on OpenStack VMs:

```
./tests/main.sh
./tests/main-openstack
```

Or to run individual tests (`tests/pylxd` against `latest/edge`):
Expand Down
33 changes: 31 additions & 2 deletions bin/helpers
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,41 @@ enableNICSRIOV() (
ethtool "${parentNIC}"
)

# install_deps: install dependencies if needed.
install_deps() (
PKGS="${*}"
missing=""
PKGS_LIST="$(dpkg --get-selections | awk '{print $1}')"
for pkg in ${PKGS}; do
grep -qxF "${pkg}" <<< "${PKGS_LIST}" && continue
missing="${missing} ${pkg}"
break
done

if [ "${missing}" != "" ]; then
apt-get update
if [ "${INSTALL_RECOMMENDS:-"no"}" = "yes" ]; then
apt-get install --yes ${PKGS}
else
apt-get install --no-install-recommends --yes ${PKGS}
fi
fi
)

# install_lxd: install LXD from a specific channel or `latest/edge` if none is provided.
install_lxd() (
# Wait for snapd seeding
waitSnapdSeed

snap remove lxd || true
snap install lxd --channel="${LXD_SNAP_CHANNEL:-"latest/edge"}"
# Prior to removal, snap takes a snapshot of the user data. This is
# slow and IO intensive so best skipped if possible by a purge.
if [ -n "${GITHUB_ACTIONS:-}" ] || [ -n "${PURGE_LXD:-}" ]; then
snap remove --purge lxd || true
else
snap remove lxd || true
fi

snap install lxd --channel="${LXD_SNAP_CHANNEL}"
snap list lxd
uname -a
cat /proc/cmdline
Expand Down Expand Up @@ -134,5 +162,6 @@ cleanup() {
exit 0
}

export DEBIAN_FRONTEND=noninteractive
FAIL=1
trap cleanup EXIT HUP INT TERM
5 changes: 1 addition & 4 deletions tests/cgroup
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#!/bin/sh
set -eu

# Refresh apt
apt-get update

# Install dependencies
apt-get install --no-install-recommends --yes jq iperf3
install_deps jq iperf3

# Install LXD
install_lxd
Expand Down
7 changes: 2 additions & 5 deletions tests/devlxd-vm
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#!/bin/sh
set -eux

# Refresh apt
apt-get update

# Install dependencies
apt-get install --no-install-recommends --yes jq
install_deps jq

# Install LXD
install_lxd
Expand Down Expand Up @@ -87,7 +84,7 @@ lxc start v1
waitVMAgent v1

# Configure to use the proxy
lxc exec v1 -- snap wait system seed.loaded || true
lxc exec v1 -- snap wait system seed.loaded
lxc exec v1 -- snap remove --purge lxd || true
lxc exec v1 -- snap install lxd --channel="${LXD_SNAP_CHANNEL}"
lxc exec v1 -- /snap/bin/lxd init --auto
Expand Down
5 changes: 3 additions & 2 deletions tests/gpu-container
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ deb [arch=${ARCH}] http://archive.ubuntu.com/ubuntu/ ${DISTRO}-updates restricte
EOF
fi
fi
apt-get update
apt-get install --yes nvidia-utils-525 nvidia-driver-525

# Install dependencies
INSTALL_RECOMMENDS=yes install_deps nvidia-utils-525 nvidia-driver-525

# Install LXD
install_lxd
Expand Down
7 changes: 2 additions & 5 deletions tests/interception
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#!/bin/sh
set -eu

# Refresh apt
apt-get update

# Install dependencies
apt-get install --no-install-recommends --yes attr
install_deps attr

# Install LXD
install_lxd
Expand Down Expand Up @@ -57,7 +54,7 @@ if hasNeededAPIExtension container_syscall_intercept_mount; then
truncate -s 10G loop.img
LOOP=$(losetup -f --show loop.img)
lxc config device add c1 loop unix-block source="${LOOP}" path=/dev/sda
lxc exec c1 -- mkfs.ext4 -f /dev/sda
lxc exec c1 -- mkfs.ext4 -F /dev/sda
! lxc exec c1 -- mount /dev/sda /mnt || false
lxc config set c1 security.syscalls.intercept.mount=true

Expand Down
3 changes: 3 additions & 0 deletions tests/network
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/sh
set -eux

# Install dependencies
install_deps jq

# Install LXD
install_lxd

Expand Down
5 changes: 2 additions & 3 deletions tests/network-bridge-firewall
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/sh
set -eu

# Refresh apt
apt-get update
# Install dependencies
install_deps nftables iptables ebtables

# Install LXD
install_lxd
Expand All @@ -19,7 +19,6 @@ lxc network create lxdbr0 \
lxc profile device add default root disk path=/ pool=default

echo "=> Setting up firewall tooling and checking versions"
apt-get install --no-install-recommends --yes nftables iptables ebtables
update-alternatives --set iptables /usr/sbin/iptables-legacy
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
update-alternatives --set ebtables /usr/sbin/ebtables-legacy
Expand Down
7 changes: 2 additions & 5 deletions tests/network-ovn
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#!/bin/sh
set -eux

# Refresh apt
apt-get update
# Install dependencies
install_deps ovn-host ovn-central bind9-dnsutils jq

# Install LXD
install_lxd

# Install dependencies
apt-get install --no-install-recommends --yes ovn-host ovn-central bind9-dnsutils jq

# Configure OVN.
ovs-vsctl set open_vswitch . \
external_ids:ovn-remote=unix:/var/run/ovn/ovnsb_db.sock \
Expand Down
63 changes: 13 additions & 50 deletions tests/rbac
Original file line number Diff line number Diff line change
@@ -1,50 +1,12 @@
#!/bin/sh
set -eu
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
}

FAIL=1
trap cleanup EXIT HUP INT TERM

# Wait for snapd seeding
waitSnapdSeed

# Configure to use the proxy
curl -s http://canonical-lxd.stgraber.org/config/snapd.sh | sh
# Install dependencies
install_deps jq

# Install LXD
while [ -e /usr/bin/lxd ]; do
apt-get remove --purge --yes lxd lxd-client lxcfs liblxc1
done
apt-get remove --purge cloud-init --yes
snap remove lxd || true
snap install lxd --channel=latest/edge
apt-get install --no-install-recommends --yes jq
install_lxd
snap install bhttp
lxd waitready --timeout=300

# Configure LXD
lxc storage create default zfs
Expand Down Expand Up @@ -126,10 +88,10 @@ lxc project create test-auditor -c features.profiles=false

# Create containers in all projects
echo "==> Creating some instances in those projects"
lxc launch images:alpine/edge a1 --project test-admin
lxc launch images:alpine/edge a2 --project test-operator
lxc launch images:alpine/edge a3 --project test-user
lxc launch images:alpine/edge a4 --project test-auditor
lxc launch ubuntu-daily:22.04 a1 --project test-admin
lxc launch ubuntu-daily:22.04 a2 --project test-operator
lxc launch ubuntu-daily:22.04 a3 --project test-user
lxc launch ubuntu-daily:22.04 a4 --project test-auditor

echo "==> Configuring rbac-user for access to projects"
bhttp --raw --agent /var/snap/bhttp/common/rbac-test.admin https://services.stgraber.org/rbac/api/rbac/v1/resource > resources.json
Expand Down Expand Up @@ -176,10 +138,10 @@ lxc snapshot a3 --project test-user

# Validate create permissions
echo "==> Validate create permissions"
lxc launch images:alpine/edge a5 --project test-admin
lxc launch images:alpine/edge a6 --project test-operator
! lxc launch images:alpine/edge a7 --project test-user || false
! lxc launch images:alpine/edge a8 --project test-auditor || false
lxc launch ubuntu-daily:22.04 a5 --project test-admin
lxc launch ubuntu-daily:22.04 a6 --project test-operator
! lxc launch ubuntu-daily:22.04 a7 --project test-user || false
! lxc launch ubuntu-daily:22.04 a8 --project test-auditor || false

# Validate project permissions
echo "==> Validate project permissions"
Expand All @@ -188,4 +150,5 @@ lxc project set test-admin limits.containers 10
! lxc project set test-user limits.containers 10 || false
! lxc project set test-auditor limits.containers 10 || false

# shellcheck disable=SC2034
FAIL=0
8 changes: 4 additions & 4 deletions tests/storage-volumes-vm
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#!/bin/sh
set -eux

# Install dependencies
install_deps genisoimage

# Install LXD
install_lxd

# Install dependencies
apt-get update
apt-get install --no-install-recommends --yes genisoimage

poolDriverList="${1:-dir btrfs lvm lvm-thin zfs ceph}"

# Configure LXD
Expand Down Expand Up @@ -117,6 +116,7 @@ do
lxc exec v2 -- umount /mnt

echo "==> Detaching volumes"
lxc exec v1 -- "sync"
lxc stop -f v1
lxc delete -f v2
lxc storage volume detach "${poolName}" vol2 v1
Expand Down

0 comments on commit 46e713f

Please sign in to comment.