Skip to content

Commit

Permalink
Move undefining libvirt object to QubesVM class
Browse files Browse the repository at this point in the history
It's more logical to do that in the QubesVM class. Moving this also
avoids protected-access pylint complain (which is very much valid
complain).

(cherry picked from commit 4643a8d)
  • Loading branch information
marmarek committed Dec 8, 2024
1 parent 0ae9993 commit 9f8edec
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
10 changes: 1 addition & 9 deletions qubes/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions qubes/tests/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions qubes/vm/qubesvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down

0 comments on commit 9f8edec

Please sign in to comment.