Skip to content

Commit

Permalink
Kill paused qubes on system shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
alimirjamali committed Sep 5, 2024
1 parent 68070df commit aa7fd22
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
13 changes: 13 additions & 0 deletions qubes/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1233,6 +1233,19 @@ def shutdown_and_wait(self, vm, timeout=60):
del vm
self.fail("Timeout while waiting for VM {} shutdown".format(name))

def shutdown_paused(self, vm, timeout=60):
try:
self.loop.run_until_complete(vm.pause())
with self.assertRaises(qubes.exc.QubesVMNotRunningError):
self.loop.run_until_complete(
vm.shutdown(wait=True, timeout=timeout, force=False))
self.loop.run_until_complete(
vm.shutdown(wait=True, timeout=timeout, force=True))
except qubes.exc.QubesException:
name = vm.name
del vm
self.fail("Timeout while waiting for VM {} shutdown".format(name))

def prepare_hvm_system_linux(self, vm, init_script, extra_files=None):
if not os.path.exists('/usr/lib/grub/i386-pc'):
self.skipTest('grub2 not installed')
Expand Down
9 changes: 8 additions & 1 deletion qubes/vm/qubesvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1382,10 +1382,17 @@ async def shutdown(self, force=False, wait=False, timeout=None):
await self.fire_event_async('domain-pre-shutdown',
pre_event=True, force=force)

if self.is_paused() and not force:
raise qubes.exc.QubesVMNotRunningError(self)

if self.__waiter is None:
self.__waiter = asyncio.get_running_loop().create_future()
waiter = self.__waiter
self.libvirt_domain.shutdown()

if self.is_paused():
self.libvirt_domain.destroy()
else:
self.libvirt_domain.shutdown()

if wait:
if timeout is None:
Expand Down

0 comments on commit aa7fd22

Please sign in to comment.