From 7aa8d74ad48ae17fcbc3cd073a273ecbc91ed333 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Wed, 12 Jul 2017 10:41:22 +0200 Subject: [PATCH] tests: fix some FD leaks There are still much more of them... --- qubes/tests/__init__.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/qubes/tests/__init__.py b/qubes/tests/__init__.py index 0dac54f2..73b02e4f 100644 --- a/qubes/tests/__init__.py +++ b/qubes/tests/__init__.py @@ -692,7 +692,7 @@ class SystemTestsMixin(object): try: vm.remove_from_disk() - except: # pylint: disable=bare-except + except: # pylint: disable=bare-except pass del app.domains[vm.qid] @@ -706,10 +706,11 @@ class SystemTestsMixin(object): try: conn = libvirt.open(qubes.config.defaults['libvirt_uri']) dom = conn.lookupByName(vmname) - except: # pylint: disable=bare-except + except: # pylint: disable=bare-except pass else: cls._remove_vm_libvirt(dom) + conn.close() cls._remove_vm_disk(vmname) @@ -753,7 +754,7 @@ class SystemTestsMixin(object): subprocess.check_call(['sudo', 'lvremove', '-f'] + [vol.strip() for vol in volumes.splitlines() if ('/' + prefix) in vol], - stdout=open(os.devnull, 'w')) + stdout=subprocess.DEVNULL) except subprocess.CalledProcessError: pass @@ -827,7 +828,7 @@ class SystemTestsMixin(object): wait_count = 0 while subprocess.call(['xdotool', 'search', '--name', title], - stdout=open(os.path.devnull, 'w'), stderr=subprocess.STDOUT) \ + stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) \ == int(show): wait_count += 1 if wait_count > timeout*10: @@ -873,7 +874,7 @@ class SystemTestsMixin(object): # create a single partition p = subprocess.Popen(['sfdisk', '-q', '-L', vm.storage.root_img], stdin=subprocess.PIPE, - stdout=open(os.devnull, 'w'), + stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) p.communicate('2048,\n') assert p.returncode == 0, 'sfdisk failed' @@ -892,7 +893,7 @@ class SystemTestsMixin(object): '--target', 'i386-pc', '--modules', 'part_msdos ext2', '--boot-directory', mountpoint, loopdev], - stderr=open(os.devnull, 'w') + stderr=subprocess.DEVNULL ) grub_cfg = '{}/grub2/grub.cfg'.format(mountpoint) subprocess.check_call( @@ -927,7 +928,7 @@ class SystemTestsMixin(object): subprocess.check_call( ['dracut'] + dracut_args + [os.path.join(mountpoint, 'initrd')], - stderr=open(os.devnull, 'w') + stderr=subprocess.DEVNULL ) finally: subprocess.check_call(['sudo', 'umount', mountpoint])