Parcourir la source

vm/dispvm: fix DispVM cleanup

First unregister the domain from collection, and only then call
remove_from_disk(). Removing it from collection prevent further calls
being made to it. Or if anything else keep a reference to it (for
example as a netvm), then abort the operation.

Additionally this makes it unnecessary to take startup lock when
cleaning it up in tests.
Marek Marczykowski-Górecki il y a 5 ans
Parent
commit
5be003d539
2 fichiers modifiés avec 2 ajouts et 9 suppressions
  1. 0 7
      qubes/tests/__init__.py
  2. 2 2
      qubes/vm/dispvm.py

+ 0 - 7
qubes/tests/__init__.py

@@ -789,13 +789,6 @@ class SystemTestCase(QubesTestCase):
         vmname = vm.name
         app = vm.app
 
-        # avoid race with DispVM.auto_cleanup=True
-        try:
-            self.loop.run_until_complete(
-                asyncio.wait_for(vm.startup_lock.acquire(), 10))
-        except asyncio.TimeoutError:
-            pass
-
         try:
             # XXX .is_running() may throw libvirtError if undefined
             if vm.is_running():

+ 2 - 2
qubes/vm/dispvm.py

@@ -142,8 +142,8 @@ class DispVM(qubes.vm.qubesvm.QubesVM):
     def _auto_cleanup(self):
         '''Do auto cleanup if enabled'''
         if self.auto_cleanup and self in self.app.domains:
-            yield from self.remove_from_disk()
             del self.app.domains[self]
+            yield from self.remove_from_disk()
             self.app.save()
 
     @classmethod
@@ -193,8 +193,8 @@ class DispVM(qubes.vm.qubesvm.QubesVM):
             pass
         # if auto_cleanup is set, this will be done automatically
         if not self.auto_cleanup:
-            yield from self.remove_from_disk()
             del self.app.domains[self]
+            yield from self.remove_from_disk()
             self.app.save()
 
     @asyncio.coroutine