From a4b528245a180f7c43e712f326cfb58e1466f2a0 Mon Sep 17 00:00:00 2001 From: Sergio Cazzolato Date: Thu, 23 Nov 2023 21:00:57 +0200 Subject: [PATCH] tests: avoid removing preinstalled snaps in external devices (#13372) Save preinstalled snaps when tests are executed in external systems The preinstalled snaps shouldn't be removed during tests clean up This is needed just for external devices because those could be using custom images with pre-installed snaps which cannot be removed, such as the network-manager. --- tests/lib/prepare.sh | 10 ++++++++++ tests/lib/reset.sh | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/lib/prepare.sh b/tests/lib/prepare.sh index 44b13c5f077..292bb769aa6 100755 --- a/tests/lib/prepare.sh +++ b/tests/lib/prepare.sh @@ -1443,6 +1443,16 @@ prepare_ubuntu_core() { # Create the file with the initial environment before saving the state tests.env start initial + # save preinstalled snaps when tests are executed in external systems + # the preinstalled snaps shouldn't be removed during tests clean up + # this is needed just for external devices because those could be using + # custom images with pre-installed snaps which cannot be removed, such + # as the network-manager. + if [ "$SPREAD_BACKEND" == "external" ]; then + PREINSTALLED_SNAPS="$(snap list | tail -n +2 | awk '{print $1}' | tr '\n' ' ')" + tests.env set initial PREINSTALLED_SNAPS "$PREINSTALLED_SNAPS" + fi + # important to remove disabled snaps before calling save_snapd_state # or restore will break remove_disabled_snaps diff --git a/tests/lib/reset.sh b/tests/lib/reset.sh index 6969dd6c862..5b6845529ff 100755 --- a/tests/lib/reset.sh +++ b/tests/lib/reset.sh @@ -127,7 +127,9 @@ reset_all_snap() { fi skip_snaps="" - for skip_remove_snap in $SKIP_REMOVE_SNAPS; do + + PREINSTALLED_SNAPS="$(tests.env get initial PREINSTALLED_SNAPS)" + for skip_remove_snap in $SKIP_REMOVE_SNAPS $PREINSTALLED_SNAPS; do skip_snaps="$skip_snaps --skip $skip_remove_snap" done # shellcheck disable=SC2086