Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions spread.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2074,12 +2074,14 @@ suites:
prepare-each: |
"$TESTSLIB"/prepare-restore.sh --prepare-suite-each
SNAP_MOUNT_DIR="$(os.paths snap-mount-dir)"
case "$SNAP_MOUNT_DIR" in
/var/lib/snapd/snap)
ln -sf "$SNAP_MOUNT_DIR" /snap
tests.cleanup defer rm -f /snap
;;
esac
if ! os.query is-amazon-linux; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed for this change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazon should have the cleanup in its packaging so this is a correction. It's needed for this change because without it during cleanup in the cross-distro-reexec suite when the /snap dir is removed, snapd from the RPM package is used instead of the snap.

case "$SNAP_MOUNT_DIR" in
/var/lib/snapd/snap)
ln -sf "$SNAP_MOUNT_DIR" /snap
tests.cleanup defer rm -f /snap
;;
esac
fi

systemctl restart snapd.service

Expand Down
2 changes: 2 additions & 0 deletions tests/lib/prepare-restore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,8 @@ prepare_suite() {

# make sure that reset did not break anything
tests.invariant check snap-mount-dir

tests.invariant set snapd-version "$(snap version | grep snapd | awk '{print $2}')"
}

prepare_suite_each() {
Expand Down
29 changes: 29 additions & 0 deletions tests/lib/tools/tests.invariant
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ show_help() {
echo " leftover-defer-sh: defer.sh must not be left over by tests"
echo " broken-snaps: snaps must not be left around that are in a broken state"
echo " segmentation-violations: snapd must not have segmentation-violation errors in journal logs"
echo " snapd-version: the version of snapd during restore must be the same as during project prepare"
echo " snap-mount-dir: assert that reported snap mount directory is the same as at test start"
echo
echo "Supported invariants for 'set' action:"
Expand Down Expand Up @@ -261,6 +262,26 @@ check_snap_mount_dir() {
fi
}

set_snapd_version() {
echo "$1" > "$TESTSTMP/tests.invariant.snapd-version"
}

check_snapd_version() {
if tests.nested is-nested; then
return 0
fi
if command -v snap && systemctl is-active snapd.socket && systemctl is-active snapd.service; then
if tests.info is-snapd-from-archive && not tests.info is-reexec-enabled; then
# re-exec may be explicitly disabled in the test variant, in which case the version will not match
return 0
fi
Comment on lines +274 to +277

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we still need this branch?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because some tests disable re-exec

snap version | grep snapd | grep -qF "$(cat "${TESTSTMP}"/tests.invariant.snapd-version)" || {
echo "tests.invariant: snapd version mismatch, expected $(cat "${TESTSTMP}"/tests.invariant.snapd-version) but got $(snap version | grep snapd | awk '{print $2}')" >&2
return 1
}
fi
}

check_invariant() {
case "$1" in
root-files-in-home)
Expand Down Expand Up @@ -296,6 +317,9 @@ check_invariant() {
snap-mount-dir)
check_snap_mount_dir "$1"
;;
snapd-version)
check_snapd_version
;;
*)
echo "tests.invariant: unknown invariant $1" >&2
exit 1
Expand All @@ -316,6 +340,7 @@ main() {
segmentation-violations
check-fakestore-cleaned
snap-mount-dir
snapd-version
"

case "$action" in
Expand Down Expand Up @@ -345,6 +370,10 @@ main() {
shift
set_snap_mount_dir "$*"
;;
snapd-version)
shift
set_snapd_version "$*"
;;
*)
echo "tests.invariant: unsupported set action"
exit 1
Expand Down
Loading