mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 01:16:10 +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
|
|
@ -72,7 +72,7 @@ from lxml import etree
|
|||
|
||||
from vrtManager import util
|
||||
from vrtManager.connection import NVRAM_DIR, wvmConnect
|
||||
from vrtManager.nodedevs import pci_address, usb_selector
|
||||
from vrtManager.nodedevs import check_hostdevs, pci_address, usb_selector
|
||||
from vrtManager.storage import wvmStorage, wvmStorages
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -652,6 +652,17 @@ class wvmInstance(wvmConnect):
|
|||
def start(self, flags=0):
|
||||
self.instance.createWithFlags(flags)
|
||||
|
||||
def check_start_hostdevs(self, restore=True):
|
||||
"""Refuses a start whose host devices the host cannot give now
|
||||
(check_hostdevs): a device given while free may since be another
|
||||
VM's or the host's, and libvirt takes a managed one from its host
|
||||
driver as the VM starts. The definition checked is the one the VM
|
||||
starts from: its saved state's when restored."""
|
||||
dom = self.instance
|
||||
restore = restore and dom.hasManagedSaveImage(0)
|
||||
xml = dom.managedSaveGetXMLDesc(0) if restore else dom.XMLDesc(VIR_DOMAIN_XML_INACTIVE)
|
||||
check_hostdevs(self, dom.name(), [etree.fromstring(xml)], restore)
|
||||
|
||||
def shutdown(self):
|
||||
self.instance.shutdown()
|
||||
|
||||
|
|
|
|||
|
|
@ -82,6 +82,39 @@ class UsbUnmatchedTests(SimpleTestCase):
|
|||
check_hostdevs(conn, "kiosk-1", [tree])
|
||||
|
||||
|
||||
class StartCheckTests(SimpleTestCase):
|
||||
"""A start checks the host devices of the definition it starts from."""
|
||||
|
||||
def proxy(self, persistent, saved=None):
|
||||
from vrtManager.instance import wvmInstance
|
||||
|
||||
proxy = wvmInstance.__new__(wvmInstance)
|
||||
proxy.wvm = MagicMock(**{"listAllDevices.return_value": [node(*n) for n in NODES], "listAllDomains.return_value": []})
|
||||
proxy.instance = MagicMock(**{"name.return_value": "kiosk-1", "hasManagedSaveImage.return_value": int(saved is not None),
|
||||
"XMLDesc.return_value": f"<domain><devices>{persistent}</devices></domain>",
|
||||
"managedSaveGetXMLDesc.return_value": f"<domain><devices>{saved}</devices></domain>"})
|
||||
return proxy
|
||||
|
||||
def test_the_host_s_own_nic_refuses_the_start(self):
|
||||
own_nic = PCI_01.replace("0x01", "0x06")
|
||||
with self.assertRaisesRegex(util.OperationError, "holds the host's eth0"):
|
||||
self.proxy(own_nic).check_start_hostdevs()
|
||||
self.proxy(PCI_0A).check_start_hostdevs() # bound to vfio-pci, alone in its group
|
||||
|
||||
def test_a_restore_checks_the_saved_state_a_fresh_boot_the_definition(self):
|
||||
proxy = self.proxy(PCI_0A, saved=USB_MODEL)
|
||||
with self.assertRaisesRegex(util.OperationError, "the host has 2 of"):
|
||||
proxy.check_start_hostdevs()
|
||||
proxy.check_start_hostdevs(restore=False)
|
||||
|
||||
def test_a_restore_drops_a_missing_requisite_device_a_boot_does_not(self):
|
||||
gone = USB_MODEL.replace("<source>", "<source startupPolicy='requisite'>")
|
||||
gone = gone.replace("</source>", "<address bus='1' device='9'/></source>")
|
||||
self.proxy(gone, saved=gone).check_start_hostdevs()
|
||||
with self.assertRaisesRegex(util.OperationError, "is not on the host"):
|
||||
self.proxy(gone, saved=gone).check_start_hostdevs(restore=False)
|
||||
|
||||
|
||||
class NodeDevicesTests(SimpleTestCase):
|
||||
def test_pci_devices_by_group_with_what_the_host_has_on_them(self):
|
||||
pci_devices, _ = devices()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue