Browse Source

tests: fix some FD leaks

There are still much more of them...
Marek Marczykowski-Górecki 6 năm trước cách đây
mục cha
commit
7aa8d74ad4
1 tập tin đã thay đổi với 8 bổ sung7 xóa
  1. 8 7
      qubes/tests/__init__.py

+ 8 - 7
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])