def _recovery_params(vm_id, dom_xml, external): params = { 'xml': dom_xml, 'external': external, } dom = DomainDescriptor(dom_xml) params['vmType'] = dom.vm_type() params['vmName'] = dom.name params['vmId'] = dom.id return params
def _recovery_params(vm_id, dom_xml, external): params = { 'xml': dom_xml, 'external': external, } dom = DomainDescriptor(dom_xml) params['vmType'] = dom.vm_type() params['vmName'] = dom.name params['smp'] = dom.get_number_of_cpus() params['memSize'] = dom.get_memory_size() return params
def __init__(self, config): self._dom = FakeDomain(config) self.log = logging.getLogger() self.cif = fake.ClientIF() self._domain = DomainDescriptor(config.xmls["00-before.xml"]) self.id = self._domain.id self._md_desc = metadata.Descriptor.from_xml( config.xmls["00-before.xml"]) drive = config.values["drive"] self._devices = { "disk": [ storage.Drive(**drive, volumeChain=xml_chain( config.xmls["00-before.xml"]), log=self.log) ] } # Add the drives to to IRS: self.cif.irs.prepared_volumes = { (drive["domainID"], drive["imageID"], vol_id): vol_info for vol_id, vol_info in config.values["volumes"].items() } self.conf = self._conf_devices(config) self.conf["vmId"] = config.values["vm-id"] self.conf["xml"] = config.xmls["00-before.xml"] self._external = False # Used when syncing metadata. self.volume_monitor = thinp.VolumeMonitor(self, self.log) self._confLock = threading.Lock() self._drive_merger = DriveMerger(self) self._migrationSourceThread = migration.SourceThread(self)
def testGetUnderlyingGraphicsDeviceInfo(self): port = '6000' tlsPort = '6001' graphicsXML = """<?xml version="1.0" encoding="utf-8"?> <domain type="kvm" xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0"> <devices> <graphics autoport="yes" keymap="en-us" passwd="*****" passwdValidTo="1970-01-01T00:00:01" port="%s" tlsPort="%s" type="spice"> <listen network="vdsm-vmDisplay" type="network"/> </graphics> </devices> </domain>""" % (port, tlsPort) with fake.VM() as testvm: graphConf = { 'type': hwclass.GRAPHICS, 'device': 'spice', 'port': '-1', 'tlsPort': '-1'} graphDev = vmdevices.graphics.Graphics( testvm.log, device='spice', port='-1', tlsPort='-1') testvm.conf['devices'] = [graphConf] device_conf = [graphDev] testvm._domain = DomainDescriptor(graphicsXML) vmdevices.graphics.Graphics.update_device_info(testvm, device_conf) self.assertEqual(graphDev.port, port) self.assertEqual(graphDev.tlsPort, tlsPort) self.assertEqual(graphDev.port, graphConf['port']) self.assertEqual(graphDev.tlsPort, graphConf['tlsPort'])
def test_display_info_display_network(self): xml = ('<domain><devices>%s</devices></domain>' % (self.GRAPHICS_DISPLAY_NETWORK,)) domain = DomainDescriptor(xml) info = vmdevices.graphics.display_info(domain) assert info == [{'type': 'spice', 'port': '5900', 'tlsPort': '5901', 'ipAddress': '1.2.3.4'}]
def test_metadata_descriptor(self, values, expected_metadata): desc = MutableDomainDescriptor(METADATA) with desc.metadata_descriptor() as md: with md.values() as vals: vals.update(values) desc2 = DomainDescriptor(desc.xml) self.assertXMLEqual(expected_metadata, xmlutils.tostring(desc2.metadata, pretty=True))
def setup_vm(vm): vm.conf['xml'] = MINIMAL_DOM_XML # needed by _init_from_metadata vm._external = False vm._exit_info = {} vm._domain = DomainDescriptor(vm.conf['xml']) # now the real metadata section vm._md_desc = metadata.Descriptor.from_xml(vm.conf['xml']) vm._init_from_metadata()
def test_device_core_attributes_present_and_never_none(self): he_xml = read_data('hostedengine.xml') dom_desc = DomainDescriptor(he_xml) md_desc = metadata.Descriptor.from_xml(he_xml) dev_objs = vmdevices.common.dev_map_from_domain_xml( 'HE', dom_desc, md_desc, self.log ) for devices in dev_objs.values(): for dev in devices: print(dev) # debug aid assert dev.type is not None assert dev.device is not None
def test_update_teaming_interfaces_with_same_mac(self): failover_xml = """<interface type='bridge'> <mac address='01:23:45:67:89:ab'/> <source bridge='ovirtmgmt'/> <model type='virtio'/> <filterref filter='vdsm-no-mac-spoofing'/> <teaming type='persistent'/> <link state='up'/> <mtu size='1500'/> <alias name='ua-failover'/> <address type='pci' domain='0x0000' bus='0x02' slot='0x00' function='0x0'/> </interface>""" vf_xml = """<?xml version="1.0" encoding="utf-8"?> <domain type="kvm" xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0"> <devices> <interface type='hostdev'> <mac address='01:23:45:67:89:ab'/> <driver name='vfio'/> <source> <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/> </source> <teaming type='transient' persistent='ua-failover'/> <alias name='ua-vf'/> <address type='pci' domain='0x0000' bus='0x06' slot='0x00' function='0x0'/> </interface> </devices> </domain>""" meta = {'vmid': 'VMID'} with fake.VM() as testvm: failover_nic = vmdevices.network.Interface.from_xml_tree( self.log, xmlutils.fromstring(failover_xml), meta=meta ) testvm._devices[hwclass.NIC].append(failover_nic) testvm._domain = DomainDescriptor(vf_xml) vmdevices.network.Interface.update_device_info( testvm, testvm._devices[hwclass.NIC] ) assert failover_nic.macAddr == '01:23:45:67:89:ab' assert failover_nic.teaming assert failover_nic.alias == 'ua-failover'
def testGetUpdateHostDeviceInfo(self, device_xml, conf): xml = """<?xml version="1.0" encoding="utf-8"?> <domain type="kvm" xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0"> <devices> %s </devices> </domain>""" % (device_xml,) with fake.VM() as testvm: device = vmdevices.hostdevice.HostDevice(testvm.log, **conf) testvm.conf['devices'] = [conf] device_conf = [device] testvm._domain = DomainDescriptor(xml) vmdevices.hostdevice.HostDevice.update_device_info(testvm, device_conf)
def test_interface_update_disappear_queues(self): interface_xml = """<interface type="bridge"> <model type="virtio" /> <link state="up" /> <source bridge="ovirtmgmt" /> <driver name="vhost" queues="1" /> <alias name="ua-604c7957-9aaf-4e86-bcaa-87e12571449b" /> <mac address="00:1a:4a:16:01:50" /> <mtu size="1500" /> <filterref filter="vdsm-no-mac-spoofing" /> <bandwidth /> </interface> """ updated_xml = """<?xml version="1.0" encoding="utf-8"?> <domain type="kvm" xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0"> <devices> <interface type='bridge'> <mac address='00:1a:4a:16:01:50'/> <source bridge='ovirtmgmt'/> <target dev='vnet0'/> <model type='virtio'/> <driver name='vhost'/> <filterref filter='vdsm-no-mac-spoofing'/> <link state='up'/> <mtu size='1500'/> <alias name='ua-604c7957-9aaf-4e86-bcaa-87e12571449b'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> </interface> </devices> </domain>""" meta = {'vmid': 'VMID'} # noone cares about the actual ID with fake.VM() as testvm: nic = vmdevices.network.Interface.from_xml_tree( self.log, xmlutils.fromstring(interface_xml), meta=meta ) saved_driver = nic.driver.copy() testvm._devices[hwclass.NIC].append(nic) testvm._domain = DomainDescriptor(updated_xml) vmdevices.network.Interface.update_device_info( testvm, testvm._devices[hwclass.NIC] ) self.assertEqual(nic.driver, saved_driver)
def testUpdateDriverInSriovInterface(self): interface_xml = """<?xml version="1.0" encoding="utf-8"?> <domain type="kvm" xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0"> <devices> <interface type='hostdev' managed='no'> <source> <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/> </source> <driver name='vfio' queues='10'/> <mac address='ff:ff:ff:ff:ff:ff'/> <vlan> <tag id='3'/> </vlan> <boot order='9'/> </interface> </devices> </domain>""" with fake.VM() as testvm: interface_conf = { 'type': hwclass.NIC, 'device': 'hostdev', 'hostdev': 'pci_0000_05_00_1', 'macAddr': 'ff:ff:ff:ff:ff:ff', 'specParams': { 'vlanid': 3 }, 'bootOrder': '9' } interface_dev = vmdevices.network.Interface( testvm.log, **interface_conf) testvm.conf['devices'] = [interface_conf] device_conf = [interface_dev] testvm._domain = DomainDescriptor(interface_xml) vmdevices.network.Interface.update_device_info(testvm, device_conf) self.assertEqual(interface_dev.driver, { 'queues': '10', 'name': 'vfio' })
def __init__(self, config): self._dom = FakeDomain(config) self.log = logging.getLogger() self.cif = fake.ClientIF() self._domain = DomainDescriptor(config.xmls["00-before.xml"]) self.id = self._domain.id self._md_desc = metadata.Descriptor.from_xml( config.xmls["00-before.xml"]) drive = config.values["drive"] self._devices = { "disk": [ storage.Drive(**drive, volumeChain=xml_chain( config.xmls["00-before.xml"]), log=self.log) ] } # Add the drives to to IRS: self.cif.irs.prepared_volumes = { (drive["domainID"], drive["imageID"], vol_id): vol_info for vol_id, vol_info in config.values["volumes"].items() } # Add the drive block info to fake domain. This value is returned by # FakeDomain.blockInfo(). top_volume = config.values["volumes"][drive["volumeID"]] self._dom.drives[drive["path"]] = { "capacity": top_volume["capacity"], "alloc": 0, "physical": top_volume["apparentsize"], } self.conf = self._conf_devices(config) self.conf["vmId"] = config.values["vm-id"] self.conf["xml"] = config.xmls["00-before.xml"] self._external = False # Used when syncing metadata. self.drive_monitor = FakeDriveMonitor() self._confLock = threading.Lock() self._drive_merger = DriveMerger(self)
def testBalloonDeviceAliasUpdateConfig(self, alias, memballoonXML): domainXML = """<domain> <devices> %s </devices> </domain>""" % memballoonXML dev = {'device': 'memballoon', 'type': 'none', 'specParams': {}} with fake.VM(self.conf, [dev]) as testvm: testvm._domain = DomainDescriptor(domainXML) devs = testvm._devSpecMapFromConf() testvm._updateDevices(devs) testvm._devices = vmdevices.common.dev_map_from_dev_spec_map( devs, testvm.log) self.assertNotRaises( vmdevices.core.Balloon.update_device_info, testvm, testvm._devices[hwclass.BALLOON], ) dev = testvm._devices[hwclass.BALLOON][0] if alias is None: self.assertFalse(hasattr(dev, 'alias')) else: self.assertEqual(dev.alias, alias)
def test_memory_size(self, domain_xml, result): desc = DomainDescriptor(domain_xml) self.assertEqual(desc.get_memory_size(), result)
def test_metadata(self, xml_data, expected): desc = DomainDescriptor(xml_data) found = desc.metadata is not None self.assertEqual(found, expected)
def test_device_element_with_attrs_selection(self, attrs, expected_devs): desc = DomainDescriptor(SOME_DISK_DEVICES) self.assertEqual( len(list(desc.get_device_elements_with_attrs('disk', **attrs))), expected_devs)
def test_memory_size(self, domain_xml, result): desc = DomainDescriptor(domain_xml) assert desc.get_memory_size() == result
def test_no_devices(self): desc1 = DomainDescriptor(NO_DEVICES) desc2 = DomainDescriptor(EMPTY_DEVICES) self.assertNotEqual(desc1.devices_hash, desc2.devices_hash)
def test_different_devices(self): desc1 = DomainDescriptor(EMPTY_DEVICES) desc2 = DomainDescriptor(SOME_DEVICES) assert desc1.devices_hash != desc2.devices_hash
def test_different_order(self): desc1 = DomainDescriptor(SOME_DEVICES) desc2 = DomainDescriptor(REORDERED_DEVICES) assert desc1.devices_hash != desc2.devices_hash
def test_on_reboot_config(self, xml_data, expected): desc = DomainDescriptor(xml_data) reboot_config = desc.on_reboot_config() assert reboot_config == expected
def test_metadata(self, xml_data, expected): desc = DomainDescriptor(xml_data) found = desc.metadata is not None assert found == expected
def test_on_reboot_config(self, xml_data, expected): desc = DomainDescriptor(xml_data) reboot_config = desc.on_reboot_config() self.assertEqual(reboot_config, expected)
def _updateDomainDescriptor(_=None): fake._domain = DomainDescriptor(fake._buildDomainXML())
def test_different_devices(self): desc1 = DomainDescriptor(EMPTY_DEVICES) desc2 = DomainDescriptor(SOME_DEVICES) self.assertNotEqual(desc1.devices_hash, desc2.devices_hash)
def test_different_order(self): desc1 = DomainDescriptor(SOME_DEVICES) desc2 = DomainDescriptor(REORDERED_DEVICES) self.assertNotEqual(desc1.devices_hash, desc2.devices_hash)
def test_stable_hash(self): desc1 = DomainDescriptor(SOME_DEVICES) desc2 = DomainDescriptor(SOME_DEVICES) self.assertEqual(desc1.devices_hash, desc2.devices_hash)
def _recovery_params(dom_xml): params = {'xml': dom_xml} dom = DomainDescriptor(dom_xml) params['vmType'] = dom.vm_type() return params
def test_stable_hash(self): desc1 = DomainDescriptor(SOME_DEVICES) desc2 = DomainDescriptor(SOME_DEVICES) assert desc1.devices_hash == desc2.devices_hash