[ACT][PATCH] UBUNTU: SAUCE: ubuntu_lxc: make sure to cleanup containers on exit

Andrea Righi andrea.righi at canonical.com
Thu Feb 24 16:19:08 UTC 2022


Some containers may still exist even when the test completes. This can
introduce some false positive failures on systems that are not
reprovisioned between a run and another (e.g., s390x).

Introduce a cleanup routine to explicitly remove some containers that
may be not cleaned up properly ('device_add_remove_test' and
'mount_injection_test').

Signed-off-by: Andrea Righi <andrea.righi at canonical.com>
---
 ubuntu_lxc/ubuntu_lxc.py | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/ubuntu_lxc/ubuntu_lxc.py b/ubuntu_lxc/ubuntu_lxc.py
index 2e5d589b..e5f21da8 100644
--- a/ubuntu_lxc/ubuntu_lxc.py
+++ b/ubuntu_lxc/ubuntu_lxc.py
@@ -105,4 +105,15 @@ class ubuntu_lxc(test.test):
         cmd = fpath + test_name
         utils.system_output(cmd, retain_output=True)
 
+    def cleanup(self, test_name):
+        if test_name == 'setup':
+            return
+
+        # Make sure to properly cleanup containers that may still exist if
+        # sub-tests are failing
+        leftover_containers = ('device_add_remove_test', 'mount_injection_test', )
+        for name in leftover_containers:
+            cmd = "lxc-destroy -f -n {0} 2>/dev/null || true".format(name)
+            utils.system(cmd)
+
 # vi:set ts=4 sw=4 expandtab syntax=python:
-- 
2.34.1




More information about the kernel-team mailing list