Skip to content

Commit

Permalink
updated failing tests ude to new re-execution mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiocazzolato committed Oct 5, 2024
1 parent b50e533 commit 7172083
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 34 deletions.
2 changes: 2 additions & 0 deletions spread.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ environment:
SNAPD_DEB_FROM_REPO: '$(HOST: echo "${SPREAD_SNAPD_DEB_FROM_REPO:-true}")'
# Build and use snapd from current branch
BUILD_SNAPD_FROM_CURRENT: '$(HOST: echo "${SPREAD_BUILD_SNAPD_FROM_CURRENT:-true}")'
# Directory where the built snapd snaps and other assets are stored
SNAPD_WORK_DIR: '$(HOST: echo "${SPREAD_SNAPD_WORK_DIR:-/tmp/work-dir}")'

# Directory where the nested images and test assets are stored
NESTED_WORK_DIR: '$(HOST: echo "${NESTED_WORK_DIR:-/tmp/work-dir}")'
Expand Down
23 changes: 11 additions & 12 deletions tests/lib/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ set -eux
# shellcheck source=tests/lib/state.sh
. "$TESTSLIB/state.sh"

: "${WORK_DIR:=/tmp/work-dir}"

disable_kernel_rate_limiting() {
# kernel rate limiting hinders debugging security policy so turn it off
echo "Turning off kernel rate-limiting"
Expand Down Expand Up @@ -420,15 +418,16 @@ prepare_classic() {
# This also prevents snapd from automatically installing snapd snap as
# prerequisite for installing any non-base snap introduced in PR#14173.
if snap list snapd ; then
snap info snapd
echo "Error: not expecting snapd snap to be installed"
exit 1
snap info snapd
echo "Error: not expecting snapd snap to be installed"
exit 1
else
build_dir="$WORK_DIR/snapd_snap_for_classic"
rm -rf "$build_dir"
mkdir -p "$build_dir"
build_snapd_snap "$build_dir"
snap install --dangerous "$build_dir/"snapd_*.snap
build_dir="$SNAPD_WORK_DIR/snapd_snap_for_classic"
rm -rf "$build_dir"
mkdir -p "$build_dir"
build_snapd_snap "$build_dir"
snap install --dangerous "$build_dir/"snapd_*.snap
snap wait system seed.loaded
fi
snap list snapd

Expand Down Expand Up @@ -549,7 +548,7 @@ build_snapd_snap() {
local snapd_snap_cache
TARGET="${1}"

snapd_snap_cache="$WORK_DIR/snapd_snap"
snapd_snap_cache="$SNAPD_WORK_DIR/snapd_snap"
mkdir -p "${snapd_snap_cache}"
for snap in "${snapd_snap_cache}"/snapd_*.snap; do
if ! [ -f "${snap}" ]; then
Expand Down Expand Up @@ -592,7 +591,7 @@ build_snapd_snap_with_run_mode_firstboot_tweaks() {

TARGET="${1}"

snapd_snap_cache="$WORK_DIR/snapd_snap_with_tweaks"
snapd_snap_cache="$SNAPD_WORK_DIR/snapd_snap_with_tweaks"
mkdir -p "${snapd_snap_cache}"
for snap in "${snapd_snap_cache}"/snapd_*.snap; do
if [ -f "${snap}" ]; then
Expand Down
44 changes: 34 additions & 10 deletions tests/main/preseed-lxd/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,45 @@ execute: |
lxc config device add my-ubuntu mounted-ubuntu-image disk source="$IMAGE_MOUNTPOINT" path="$IMAGE_MOUNTPOINT"
lxc restart my-ubuntu
echo "Make latest snap-preseed command available in the lxd container"
echo "Prepare container to run snap-preseed command"
lxc exec my-ubuntu -- mkdir -p "$GOHOME"
SNAP_PRESEED=/usr/lib/snapd/snap-preseed
if tests.info is-snapd-pkg-repo; then
MOUNT_DIR="$(os.paths snap-mount-dir)"
SNAP_PRESEED="$MOUNT_DIR/snapd/current$SNAP_PRESEED"
fi
lxc file push "$SNAP_PRESEED" "my-ubuntu/$GOHOME/"
lxc file push cloudimg.img "my-ubuntu/$GOHOME/"
lxc file push preseed-prepare.sh "my-ubuntu/$GOHOME/"
echo "Running preseeding in the lxd container"
# mount /dev, /proc, /sys under mounted ubuntu image in the container.
lxc exec my-ubuntu -- "$GOHOME"/preseed-prepare.sh "$IMAGE_MOUNTPOINT"
lxc exec my-ubuntu -- "$GOHOME"/snap-preseed "$IMAGE_MOUNTPOINT"
echo "Make latest snap-preseed command available in the lxd container"
echo "Running preseeding in the lxd container"
SNAP_PRESEED=/usr/lib/snapd/snap-preseed
if tests.info is-snapd-pkg-repo; then
# We use the snap preseed from the current snapd snap
# The current snapd snap is installed in the lxd container to make
# sure all the dependencies are in place, otherwise it fails to access to
# /snap/snapd/current/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2
CURRENT_SNAPD_SNAP="$(ls $SNAPD_WORK_DIR/snapd_snap/snapd_*.snap)"
CURRENT_SNAPD_SNAP_NAME="$(basename $CURRENT_SNAPD_SNAP)"
if [ "$(wc -w <<< $CURRENT_SNAPD_SNAP)" != 1 ]; then
echo "It is expected just 1 snapd snap in $SNAPD_WORK_DIR/snapd_snap"
exit 1
fi
lxc file push "$CURRENT_SNAPD_SNAP" "my-ubuntu/$GOHOME/"
for iter in $(seq 30); do
echo "checking snapd ready in container: iter $iter"
if lxc exec my-ubuntu -- sh -c 'snap changes' | MATCH "Done.*Initialize system state"; then
break
fi
sleep 1
done
lxc exec my-ubuntu -- snap install --dangerous "$GOHOME/$CURRENT_SNAPD_SNAP_NAME"
MOUNT_DIR="$(os.paths snap-mount-dir)"
SNAP_PRESEED="$MOUNT_DIR/snapd/current$SNAP_PRESEED"
lxc exec my-ubuntu -- "$SNAP_PRESEED" "$IMAGE_MOUNTPOINT"
else
lxc file push "$SNAP_PRESEED" "my-ubuntu/$GOHOME/"
lxc exec my-ubuntu -- "$GOHOME"/snap-preseed "$IMAGE_MOUNTPOINT"
fi
echo "Precondition check of mount units"
# preseeded image is mounted on the host, so we can directly inspect
Expand Down
3 changes: 2 additions & 1 deletion tests/main/snap-confine-tmp-mount/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ debug: |
cat /tmp/snap-confine-stderr.log || true
execute: |
MOUNT_DIR="$(os.paths snap-mount-dir)"
SNAP_CONFINE=$(os.paths libexec-dir)/snapd/snap-confine
if tests.info is-snapd-pkg-repo; then
SNAP_CONFINE="/snap/snapd/current$SNAP_CONFINE"
SNAP_CONFINE="$MOUNT_DIR/snapd/current$SNAP_CONFINE"
fi
# on Ubuntu Core we need to use the correct path to ensure it is
Expand Down
38 changes: 28 additions & 10 deletions tests/main/snapd-reexec/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,19 @@ execute: |
fi
echo "Ensure we re-exec by default"
/usr/bin/env SNAPD_DEBUG=1 snap list 2>&1 | MATCH "DEBUG: restarting into \"$SNAPD_MOUNT_DIR/current/usr/bin/snap\""
IS_REEXEC=true
if [ "$SNAPD_SRC" = core ] && tests.info is-snapd-pkg-repo; then
# In this scenario it is possible that the core snap version is older
# than the distribution package because the core snap comes from latest/edge
# which is not updated regularly.
# TODO: Compare manually the snap and deb versions and determine which string needs to be in MATCH
if /usr/bin/env SNAPD_DEBUG=1 snap list 2>&1 | MATCH "snap \(at .*\) is older \(.*\) than distribution package"; then
IS_REEXEC=false
fi
fi
if [ "$IS_REEXEC" = true ]; then
/usr/bin/env SNAPD_DEBUG=1 snap list 2>&1 | MATCH "DEBUG: restarting into \"$SNAPD_MOUNT_DIR/current/usr/bin/snap\""
fi
echo "Ensure that we do not re-exec into older versions"
systemctl stop snapd.service snapd.socket
Expand Down Expand Up @@ -118,11 +130,13 @@ execute: |
systemctl daemon-reload
systemctl start snapd.service snapd.socket
echo "Ensure SNAP_REEXEC=0 is honored for snap"
mount --bind /tmp/broken-snapd "$SNAPD_MOUNT_DIR/current/usr/bin/snap"
snap list|MATCH "from the $SNAPD_SRC snap"
if [ "$IS_REEXEC" = true ]; then
echo "Ensure SNAP_REEXEC=0 is honored for snap"
mount --bind /tmp/broken-snapd "$SNAPD_MOUNT_DIR/current/usr/bin/snap"
snap list | MATCH "from the $SNAPD_SRC snap"
umount "$SNAPD_MOUNT_DIR/current/usr/bin/snap"
fi
SNAP_REEXEC=0 SNAPD_DEBUG=1 snap list 2>&1 |MATCH "DEBUG: re-exec disabled by user"
umount "$SNAPD_MOUNT_DIR/current/usr/bin/snap"
echo "Ensure a snapd source refresh restarts snapd"
prev_src=$(snap list | awk "/^$SNAPD_SRC / {print(\$3)}")
Expand All @@ -135,8 +149,12 @@ execute: |
echo "Test broken $now_src and $prev_src are the same"
exit 1
fi
SNAPD_PATH=$(readlink -f "/proc/$(pidof snapd)/exe")
if [ "$SNAPD_PATH" != "/snap/$SNAPD_SRC/${now_src}/usr/lib/snapd/snapd" ]; then
echo "unexpected $SNAPD_PATH for $now_src snap (previous $prev_src)"
exit 1
fi
# This check is valid only if snap command is re-executing to the snap
if [ "$IS_REEXEC" = true ]; then
SNAPD_PATH=$(readlink -f "/proc/$(pidof snapd)/exe")
if [ "$SNAPD_PATH" != "/snap/$SNAPD_SRC/${now_src}/usr/lib/snapd/snapd" ]; then
echo "unexpected $SNAPD_PATH for $now_src snap (previous $prev_src)"
exit 1
fi
fi
2 changes: 1 addition & 1 deletion tests/main/user-session-env/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ systems:
- -amazon-linux-2-* # no fish package for AMZN2
- -amazon-linux-2023-* # no fish package for AL2023
- -centos-9-* # no fish package

- -debian-11-* # not supposed to work as snapd is very old in the repository

environment:
TEST_ZSH_USER: test-zsh
Expand Down

0 comments on commit 7172083

Please sign in to comment.