From 5725cc7e36495d42c7165b258c4156befd638fa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alfonso=20S=C3=A1nchez-Beato?= Date: Thu, 5 Jan 2023 13:41:57 +0000 Subject: [PATCH] tests: add test to check layouts are removed properly As in some corner cases this was not the case and the applications could not even start. --- tests/main/layout-remove/task.yaml | 36 +++++++++++++++++++ .../layout-remove/test-layout-v1/bin/test | 3 ++ .../test-layout-v1/meta/snap.yaml | 19 ++++++++++ .../layout-remove/test-layout-v2/bin/test | 3 ++ .../test-layout-v2/meta/snap.yaml | 15 ++++++++ 5 files changed, 76 insertions(+) create mode 100644 tests/main/layout-remove/task.yaml create mode 100755 tests/main/layout-remove/test-layout-v1/bin/test create mode 100644 tests/main/layout-remove/test-layout-v1/meta/snap.yaml create mode 100755 tests/main/layout-remove/test-layout-v2/bin/test create mode 100644 tests/main/layout-remove/test-layout-v2/meta/snap.yaml diff --git a/tests/main/layout-remove/task.yaml b/tests/main/layout-remove/task.yaml new file mode 100644 index 00000000000..a53b643f742 --- /dev/null +++ b/tests/main/layout-remove/task.yaml @@ -0,0 +1,36 @@ +summary: Ensure that removing a layout works as expected + +details: | + This test installs a test snap that uses layout declarations and + then refreshes it with a new version that removes one of the + layouts. + +# No core22 snap for i386 +systems: [-ubuntu-*-32] + +prepare: | + "$TESTSTOOLS"/snaps-state install-local test-snapd-layout + +execute: | + snap pack test-layout-v1 + snap pack test-layout-v2 + snap install --dangerous test-layout_1.0_all.snap + # Check layouts. Note that the mount namespace is created in the first run. + test-layout.test -c "test -d /var/test_tmpfs" + test-layout.test -c "test -d /var/lib/test_common" + test-layout.test -c "test -d /var/lib/test_data" + # Layouts have been configured + MATCH test_tmpfs < /run/snapd/ns/snap.test-layout.fstab + MATCH test_common < /run/snapd/ns/snap.test-layout.fstab + MATCH test_data < /run/snapd/ns/snap.test-layout.fstab + + # Refreshing will update the mount namespace + snap install --dangerous test-layout_1.1_all.snap + # Should run fine + test-layout.test -c "test -d /var/test_tmpfs" + not test-layout.test -c "test -d /var/lib/test_common" + not test-layout.test -c "test -d /var/lib/test_data" + # There is no trace of the removed layouts + MATCH test_tmpfs < /run/snapd/ns/snap.test-layout.fstab + not MATCH test_common < /run/snapd/ns/snap.test-layout.fstab + not MATCH test_data < /run/snapd/ns/snap.test-layout.fstab diff --git a/tests/main/layout-remove/test-layout-v1/bin/test b/tests/main/layout-remove/test-layout-v1/bin/test new file mode 100755 index 00000000000..0f845e07c5a --- /dev/null +++ b/tests/main/layout-remove/test-layout-v1/bin/test @@ -0,0 +1,3 @@ +#!/bin/sh +PS1='$ ' +exec /bin/sh "$@" diff --git a/tests/main/layout-remove/test-layout-v1/meta/snap.yaml b/tests/main/layout-remove/test-layout-v1/meta/snap.yaml new file mode 100644 index 00000000000..8f41322bb7a --- /dev/null +++ b/tests/main/layout-remove/test-layout-v1/meta/snap.yaml @@ -0,0 +1,19 @@ +name: test-layout +version: 1.0 +summary: Test layouts +description: 'Test layout changes' +base: core22 +confinement: strict +grade: devel + +layout: + /var/lib/test_data: + bind: $SNAP_DATA/test_data + /var/lib/test_common: + bind: $SNAP_COMMON/test_common + /var/test_tmpfs: + type: tmpfs + +apps: + test: + command: bin/test diff --git a/tests/main/layout-remove/test-layout-v2/bin/test b/tests/main/layout-remove/test-layout-v2/bin/test new file mode 100755 index 00000000000..0f845e07c5a --- /dev/null +++ b/tests/main/layout-remove/test-layout-v2/bin/test @@ -0,0 +1,3 @@ +#!/bin/sh +PS1='$ ' +exec /bin/sh "$@" diff --git a/tests/main/layout-remove/test-layout-v2/meta/snap.yaml b/tests/main/layout-remove/test-layout-v2/meta/snap.yaml new file mode 100644 index 00000000000..02ada6c17e2 --- /dev/null +++ b/tests/main/layout-remove/test-layout-v2/meta/snap.yaml @@ -0,0 +1,15 @@ +name: test-layout +version: 1.1 +summary: Test layouts +description: 'Test layout changes' +base: core22 +confinement: strict +grade: devel + +layout: + /var/test_tmpfs: + type: tmpfs + +apps: + test: + command: bin/test