mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +00:00
fix(instances): a VM starts only with host devices the host can give now
A device is checked when it is given to a VM, but a start later did not check it again: a PCI device bound back to a host driver for the host's own network or disks, or a USB device the host no longer has as named, was taken from the host or failed in libvirt. Power On and Power Cycle now check the definition the VM starts from (its saved state's when restored) as a snapshot revert does, and refuse with the reasons; Power Cycle checks before it stops the VM.
This commit is contained in:
parent
4045819b8d
commit
a36ffcd3ba
4 changed files with 59 additions and 1 deletions
|
|
@ -48,6 +48,17 @@ class VMRowTests(TestCase):
|
|||
self.proxy.start.assert_called_once_with(libvirt.VIR_DOMAIN_START_FORCE_BOOT)
|
||||
self.assertEqual(self.rows(), [("VM vm: power on without the saved state", True)])
|
||||
|
||||
def test_a_start_the_host_cannot_give_the_devices_of_does_not_stop_or_start_the_vm(self):
|
||||
self.proxy.check_start_hostdevs.side_effect = OperationError("PCI device 0000:00:0a.0 holds the host's eth0")
|
||||
for view, restore in (("poweron", True), ("powercycle", False)):
|
||||
self.post(view)
|
||||
with self.subTest(view=view):
|
||||
self.assertEqual(self.proxy.check_start_hostdevs.call_args.kwargs.get("restore", True), restore)
|
||||
self.proxy.force_shutdown.assert_not_called()
|
||||
self.proxy.start.assert_not_called()
|
||||
self.assertEqual(self.rows(), [("VM vm: power on: PCI device 0000:00:0a.0 holds the host's eth0", False),
|
||||
("VM vm: power cycle: PCI device 0000:00:0a.0 holds the host's eth0", False)])
|
||||
|
||||
def test_a_power_cycle_that_does_not_start_again_says_the_vm_stays_off(self):
|
||||
self.proxy.start.side_effect = libvirtError("Cannot access storage file")
|
||||
response = self.post("powercycle")
|
||||
|
|
|
|||
|
|
@ -811,9 +811,11 @@ def poweron(request, pk):
|
|||
messages.warning(request, _("Templates cannot be started."))
|
||||
elif options.validated_data["fresh"]: # the saved state is discarded: the VM boots anew
|
||||
with audit_vm(request, instance, "power on without the saved state"):
|
||||
instance.proxy.check_start_hostdevs(restore=False)
|
||||
instance.proxy.start(VIR_DOMAIN_START_FORCE_BOOT)
|
||||
else:
|
||||
with audit_vm(request, instance, "power on"):
|
||||
instance.proxy.check_start_hostdevs()
|
||||
instance.proxy.start()
|
||||
|
||||
return get_safe_redirect(
|
||||
|
|
@ -829,6 +831,7 @@ def powercycle(request, pk):
|
|||
messages.warning(request, _("Templates cannot be started."))
|
||||
else:
|
||||
with audit_vm(request, instance, "power cycle") as entry:
|
||||
instance.proxy.check_start_hostdevs(restore=False) # before it stops
|
||||
instance.proxy.force_shutdown()
|
||||
try:
|
||||
instance.proxy.start()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue