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 059171e
Show file tree
Hide file tree
Showing 3 changed files with 22 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
1 change: 1 addition & 0 deletions qubes/tests/integ/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ def _do_test(self):
self.loop.run_until_complete(self.test_template.start())
self.loop.run_until_complete(self.wait_for_session(self.test_template))
self.shutdown_and_wait(self.test_template)
self.shutdown_paused(self.test_template)
checksum_changed = self.get_rootimg_checksum()
if checksum_before == checksum_changed:
self.log.warning("template not modified, test result will be "
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 059171e

Please sign in to comment.