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)

Check warning on line 1386 in qubes/vm/qubesvm.py

View check run for this annotation

Codecov / codecov/patch

qubes/vm/qubesvm.py#L1385-L1386

Added lines #L1385 - L1386 were not covered by tests

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()

Check warning on line 1393 in qubes/vm/qubesvm.py

View check run for this annotation

Codecov / codecov/patch

qubes/vm/qubesvm.py#L1392-L1393

Added lines #L1392 - L1393 were not covered by tests
else:
self.libvirt_domain.shutdown()

Check warning on line 1395 in qubes/vm/qubesvm.py

View check run for this annotation

Codecov / codecov/patch

qubes/vm/qubesvm.py#L1395

Added line #L1395 was not covered by tests

if wait:
if timeout is None:
Expand Down

0 comments on commit aa7fd22

Please sign in to comment.