Skip to content
25 changes: 25 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 " check-snapd-version: the version of snapd during restore must be the same as during project prepare"
Comment thread
maykathm marked this conversation as resolved.
Outdated
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
}

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

if [[ "$SRU_VALIDATION" = "1" ]] || [[ -n "$PPA_GPG_KEY" ]] || [[ -n "$PPA_VALIDATION_NAME" ]]; then
# The snapd version will not be a testing version
return 0
fi
snap version | grep snapd | MATCH "1337" || {

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.

this isn't exactly the version the test started with. I'd expect something like we do for the check-snap-mount-dir, i.e. record what's at the beginning of the test suite where we install the right package (sru, or a CI build) and check at the end that the version is still the same.

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.

That was my first approach but with that approach the cross-distro-reexec suite fails on amazon so I opted for this approach.

echo "tests.invariant: snapd version mismatch, expected 1337 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"
;;
check-snapd-version)
Comment thread
maykathm marked this conversation as resolved.
Outdated
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
check-snapd-version
"

case "$action" in
Expand Down
Loading