diff --git a/qubes/app.py b/qubes/app.py index 75c532639..3f00d6a67 100644 --- a/qubes/app.py +++ b/qubes/app.py @@ -527,15 +527,7 @@ def __delitem__(self, key): if not vm.is_halted(): raise qubes.exc.QubesVMNotHaltedError(vm) self.app.fire_event('domain-pre-delete', pre_event=True, vm=vm) - try: - if vm.libvirt_domain: - vm.libvirt_domain.undefine() - # pylint: disable=protected-access - vm._libvirt_domain = None - except libvirt.libvirtError as e: - if e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN: - # already undefined - pass + vm.libvirt_undefine() del self._dict[vm.qid] self.app.fire_event('domain-delete', vm=vm) diff --git a/qubes/tests/init.py b/qubes/tests/init.py index fa4cc66c6..e52605032 100644 --- a/qubes/tests/init.py +++ b/qubes/tests/init.py @@ -351,6 +351,9 @@ def is_halted(self): def get_power_state(self): return "Halted" + def libvirt_undefine(self): + pass + class TestApp(qubes.tests.TestEmitter): pass diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index 3dcaa46e1..cc2831b08 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -1916,6 +1916,18 @@ async def clone_disk_files(self, src, pool=None, pools=None, ): # fire hooks await self.fire_event_async('domain-clone-files', src=src) + def libvirt_undefine(self): + """Undefine domain object in libvirt""" + try: + if self.libvirt_domain: + self.libvirt_domain.undefine() + except libvirt.libvirtError as e: + if e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN: + # already undefined + pass + if self._libvirt_domain is not None: + self._libvirt_domain = None + # # methods for querying domain state #