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 be197f0
Show file tree
Hide file tree
Showing 3 changed files with 30 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: 9 additions & 0 deletions qubes/tests/integ/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,15 @@ def test_204_udev_block_exclude_custom_file(self):
pool=pool))
self.assertVolumesExcludedFromUdev(self.vm)

def test_206_shutdown_paused(self):
vmname = self.make_vm_name('vm')
self.vm = self.app.add_new_vm(qubes.vm.appvm.AppVM,
name=vmname, template=self.app.default_template,
label='red')
self.loop.run_until_complete(self.vm.create_on_disk())
self.loop.run_until_complete(self.vm.start())
self.shutdown_paused(self.vm)


class TC_01_Properties(qubes.tests.SystemTestCase):
# pylint: disable=attribute-defined-outside-init
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 be197f0

Please sign in to comment.