From bd5d73444327ceb1f7547e79c01690af712a745d Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Wed, 15 Apr 2020 15:07:20 +0200 Subject: [PATCH] test: Make tests non-destructive Use recent Cockpit standard test API to handle the directory restoration. Clean up/restore user state as well. Closes #356 --- Makefile | 2 +- test/check-application | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 3d26a061e..d36d9313f 100644 --- a/Makefile +++ b/Makefile @@ -162,7 +162,7 @@ bots: # checkout Cockpit's test API; this has no API stability guarantee, so check out a stable tag # when you start a new project, use the latest release, and update it from time to time test/common: - git fetch --depth=1 https://github.com/cockpit-project/cockpit.git 210 + git fetch --depth=1 https://github.com/cockpit-project/cockpit.git 216 git checkout --force FETCH_HEAD -- test/common git reset test/common diff --git a/test/check-application b/test/check-application index 379248bd1..bad330984 100755 --- a/test/check-application +++ b/test/check-application @@ -34,13 +34,18 @@ def checkImage(browser, name, owner): return false; })""", name, owner) +@testlib.nondestructive class TestApplication(testlib.MachineCase): def setUp(self): + super().setUp() # backup/restore pristine podman state, so that tests can run on existing testbeds + self.restore_dir("/var/lib/containers") # HACK: sometimes podman leaks mounts - super().setUp() - self.machine.execute("cp -a /var/lib/containers /var/lib/containers.orig") + self.addCleanup(self.machine.execute, "podman rm --force --all && " + "findmnt --list -otarget | grep /var/lib/containers/. | xargs -r umount || true") + + self.machine.execute("systemctl stop io.podman.service; systemctl --now enable io.podman.socket") # Create admin session self.machine.execute(""" @@ -55,13 +60,11 @@ class TestApplication(testlib.MachineCase): identity_file=self.machine.identity_file) # Enable user service as well - self.admin_s.execute("systemctl --now --user enable io.podman.socket") + self.admin_s.execute("systemctl --user stop io.podman.service; systemctl --now --user enable io.podman.socket") + self.restore_dir("/home/admin/.local/share/containers") + self.addCleanup(self.admin_s.execute, "podman rm --force --all") self.allow_journal_messages("/run.*/podman/io.podman: couldn't connect.*") - self.addCleanup(self.machine.execute, "podman rm --force --all && " - "findmnt --list -otarget | grep /var/lib/containers | xargs -r umount && " - "rm -r /var/lib/containers && " - "mv /var/lib/containers.orig /var/lib/containers") def execute(self, system, cmd): if system: