From e938aa61ab04aaf2199b215d0e32e5dbf7343dcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Thu, 29 Sep 2016 01:57:37 +0200 Subject: [PATCH] tests: cleanup test LVM volumes Handle the case when vm.remove_from_disk does not cleanup all the things. --- qubes/tests/__init__.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/qubes/tests/__init__.py b/qubes/tests/__init__.py index bc086ef0..9dc7f3fa 100644 --- a/qubes/tests/__init__.py +++ b/qubes/tests/__init__.py @@ -579,6 +579,25 @@ class SystemTestsMixin(object): else: os.unlink(dirpath) + @staticmethod + def _remove_vm_disk_lvm(prefix=VMPREFIX): + ''' Remove LVM volumes with given prefix + + This is "a bit" drastic, as it removes volumes regardless of volume + group, thin pool etc. But we assume no important data on test system. + ''' + try: + volumes = subprocess.check_output( + ['sudo', 'lvs', '--noheadings', '-o', 'vg_name,name', + '--separator', '/']) + if ('/' + prefix) not in volumes: + return + subprocess.check_call(['sudo', 'lvremove', '-f'] + + [vol.strip() for vol in volumes.splitlines() + if ('/' + prefix) in vol], + stdout=open(os.devnull, 'w')) + except subprocess.CalledProcessError: + pass @classmethod def remove_vms(cls, vms): @@ -623,6 +642,7 @@ class SystemTestsMixin(object): vmnames.add(name) for vmname in vmnames: cls._remove_vm_disk(vmname) + cls._remove_vm_disk_lvm(prefix) def qrexec_policy(self, service, source, destination, allow=True): """