tests: fix some memory leaks
This is work in progress. There are still more leaks.
This commit is contained in:
parent
5aa9fa2db4
commit
bd123a3812
@ -160,6 +160,17 @@ class TC_30_VMCollection(qubes.tests.QubesTestCase):
|
||||
self.testvm2 = qubes.tests.init.TestVM(
|
||||
None, None, qid=2, name='testvm2')
|
||||
|
||||
self.addCleanup(self.cleanup_vmcollection)
|
||||
|
||||
def cleanup_vmcollection(self):
|
||||
self.testvm1.close()
|
||||
self.testvm2.close()
|
||||
self.vms.close()
|
||||
del self.testvm1
|
||||
del self.testvm2
|
||||
del self.vms
|
||||
del self.app
|
||||
|
||||
def test_000_contains(self):
|
||||
self.vms._dict = {1: self.testvm1}
|
||||
|
||||
|
@ -320,6 +320,16 @@ class TC_30_VMCollection(qubes.tests.QubesTestCase):
|
||||
|
||||
self.testvm1 = TestVM(None, None, qid=1, name='testvm1')
|
||||
self.testvm2 = TestVM(None, None, qid=2, name='testvm2')
|
||||
self.addCleanup(self.cleanup_testvm)
|
||||
|
||||
def cleanup_testvm(self):
|
||||
self.vms.close()
|
||||
self.testvm1.close()
|
||||
self.testvm2.close()
|
||||
del self.testvm1
|
||||
del self.testvm2
|
||||
del self.vms
|
||||
del self.app
|
||||
|
||||
def test_000_contains(self):
|
||||
self.vms._dict = {1: self.testvm1}
|
||||
|
@ -75,6 +75,8 @@ class TC_00_FilePool(qubes.tests.QubesTestCase):
|
||||
|
||||
def tearDown(self):
|
||||
self.app.cleanup()
|
||||
self.app.close()
|
||||
del self.app
|
||||
super(TC_00_FilePool, self).tearDown()
|
||||
|
||||
def test000_default_pool_dir(self):
|
||||
@ -120,6 +122,8 @@ class TC_01_FileVolumes(qubes.tests.QubesTestCase):
|
||||
""" Remove the file based storage pool after testing """
|
||||
self.app.remove_pool("test-pool")
|
||||
self.app.cleanup()
|
||||
self.app.close()
|
||||
del self.app
|
||||
super(TC_01_FileVolumes, self).tearDown()
|
||||
shutil.rmtree(self.POOL_DIR, ignore_errors=True)
|
||||
|
||||
@ -328,6 +332,8 @@ class TC_03_FilePool(qubes.tests.QubesTestCase):
|
||||
""" Remove the file based storage pool after testing """
|
||||
self.app.remove_pool("test-pool")
|
||||
self.app.cleanup()
|
||||
self.app.close()
|
||||
del self.app
|
||||
self.base_dir_patch3.stop()
|
||||
self.base_dir_patch2.stop()
|
||||
self.base_dir_patch.stop()
|
||||
|
@ -80,6 +80,8 @@ class TC_01_KernelVolumes(qubes.tests.QubesTestCase):
|
||||
""" Remove the file based storage pool after testing """
|
||||
self.app.remove_pool("test-pool")
|
||||
self.app.cleanup()
|
||||
self.app.close()
|
||||
del self.app
|
||||
super(TC_01_KernelVolumes, self).tearDown()
|
||||
shutil.rmtree(self.POOL_DIR, ignore_errors=True)
|
||||
|
||||
@ -233,6 +235,8 @@ class TC_03_KernelPool(qubes.tests.QubesTestCase):
|
||||
""" Remove the file based storage pool after testing """
|
||||
self.app.remove_pool("test-pool")
|
||||
self.app.cleanup()
|
||||
self.app.close()
|
||||
del self.app
|
||||
super(TC_03_KernelPool, self).tearDown()
|
||||
shutil.rmtree(self.POOL_DIR, ignore_errors=True)
|
||||
if os.path.exists('/tmp/qubes-test'):
|
||||
|
@ -39,11 +39,16 @@ class TC_00_AdminVM(qubes.tests.QubesTestCase):
|
||||
self.vm = qubes.vm.adminvm.AdminVM(self.app,
|
||||
xml=None)
|
||||
mock_qdb.assert_called_once_with('dom0')
|
||||
self.addCleanup(self.cleanup_adminvm)
|
||||
except: # pylint: disable=bare-except
|
||||
if self.id().endswith('.test_000_init'):
|
||||
raise
|
||||
self.skipTest('setup failed')
|
||||
|
||||
def cleanup_adminvm(self):
|
||||
self.vm.close()
|
||||
del self.vm
|
||||
|
||||
def test_000_init(self):
|
||||
pass
|
||||
|
||||
|
@ -67,12 +67,21 @@ class TC_90_AppVM(qubes.tests.vm.qubesvm.QubesVMTestsMixin,
|
||||
qid=1, name=qubes.tests.VMPREFIX + 'template')
|
||||
self.app.domains[self.template.name] = self.template
|
||||
self.app.domains[self.template] = self.template
|
||||
self.addCleanup(self.cleanup_appvm)
|
||||
|
||||
def cleanup_appvm(self):
|
||||
self.template.close()
|
||||
del self.template
|
||||
self.app.domains.clear()
|
||||
self.app.pools.clear()
|
||||
|
||||
def get_vm(self, **kwargs):
|
||||
return qubes.vm.appvm.AppVM(self.app, None,
|
||||
vm = qubes.vm.appvm.AppVM(self.app, None,
|
||||
qid=2, name=qubes.tests.VMPREFIX + 'test',
|
||||
template=self.template,
|
||||
**kwargs)
|
||||
self.addCleanup(vm.close)
|
||||
return vm
|
||||
|
||||
def test_000_init(self):
|
||||
self.get_vm()
|
||||
|
@ -57,6 +57,15 @@ class TC_00_DispVM(qubes.tests.QubesTestCase):
|
||||
name='test-vm', template=self.template, label='red')
|
||||
self.app.domains[self.appvm.name] = self.appvm
|
||||
self.app.domains[self.appvm] = self.appvm
|
||||
self.addCleanup(self.cleanup_dispvm)
|
||||
|
||||
def cleanup_dispvm(self):
|
||||
self.template.close()
|
||||
self.appvm.close()
|
||||
del self.template
|
||||
del self.appvm
|
||||
self.app.domains.clear()
|
||||
self.app.pools.clear()
|
||||
|
||||
@asyncio.coroutine
|
||||
def mock_coro(self, *args, **kwargs):
|
||||
|
@ -52,6 +52,18 @@ class TC_00_NetVMMixin(
|
||||
self.app.domains._dict[domain.qid] = domain
|
||||
self.app.default_netvm = self.netvm1
|
||||
self.app.default_fw_netvm = self.netvm1
|
||||
self.addCleanup(self.cleanup_netvms)
|
||||
|
||||
def cleanup_netvms(self):
|
||||
self.netvm1.close()
|
||||
self.netvm2.close()
|
||||
self.nonetvm.close()
|
||||
self.app.domains.close()
|
||||
del self.netvm1
|
||||
del self.netvm2
|
||||
del self.nonetvm
|
||||
del self.app.default_netvm
|
||||
del self.app.default_fw_netvm
|
||||
|
||||
|
||||
@qubes.tests.skipUnlessDom0
|
||||
@ -81,6 +93,7 @@ class TC_00_NetVMMixin(
|
||||
def test_143_netvm_loopback(self):
|
||||
vm = self.get_vm()
|
||||
self.app.domains = {1: vm, vm: vm}
|
||||
self.addCleanup(self.app.domains.clear)
|
||||
self.assertPropertyInvalidValue(vm, 'netvm', vm)
|
||||
|
||||
def test_150_ip(self):
|
||||
|
@ -122,9 +122,11 @@ class QubesVMTestsMixin(object):
|
||||
self.app.vmm.offline_mode = True
|
||||
|
||||
def get_vm(self, **kwargs):
|
||||
return qubes.vm.qubesvm.QubesVM(self.app, None,
|
||||
vm = qubes.vm.qubesvm.QubesVM(self.app, None,
|
||||
qid=1, name=qubes.tests.VMPREFIX + 'test',
|
||||
**kwargs)
|
||||
self.addCleanup(vm.close)
|
||||
return vm
|
||||
|
||||
def assertPropertyValue(self, vm, prop_name, set_value, expected_value,
|
||||
expected_xml_content=None):
|
||||
|
@ -710,6 +710,8 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
|
||||
if self._qdb_connection is not None:
|
||||
self._qdb_connection.close()
|
||||
self._qdb_connection = None
|
||||
if self._libvirt_domain is not None:
|
||||
self._libvirt_domain = None
|
||||
super().close()
|
||||
|
||||
def __hash__(self):
|
||||
|
Loading…
Reference in New Issue
Block a user