def test_sriov_vm(self): params = { 'name': 'SRiovVm', 'displaySecurePort': '-1', 'memSize': '256', 'displayPort': '-1', 'display': 'qxl'} devices = [{'device': 'bridge', 'nicModel': 'virtio', 'macAddr': '52:54:00:59:FF:FF', 'type': 'interface', 'network': ''}, {'device': 'hostdev', 'type': hwclass.NIC, 'alias': 'hostdev2', 'hostdev': 'pci_0000_05_00_1', 'deviceId': '6940d5e7-9814-4ae0-94ef-f78e68229e76', 'macAddr': '00:00:00:00:00:43', 'specParams': {'vlanid': 12}}, ] test_path = os.path.realpath(__file__) dir_name = os.path.split(test_path)[0] api_path = os.path.join( dir_name, '..', 'data', 'testSRiovVm.xml') domain = None with open(api_path, 'r') as domxml: domain = domxml.read() with fake.VM(params=params, devices=devices, create_device_objects=True) as vm: vm._domain = domain_descriptor.DomainDescriptor(domain) vm._getUnderlyingVmDevicesInfo() self.verifyDevicesConf(vm.conf['devices']) self._assert_guest_device_adress_is_reported(vm) self._assert_host_address_is_reported(devices, vm)
def test_correct_disk_and_metadata(self): vmParams = { 'vmId': '627f1f31-752b-4e7c-bfb5-4313d191ed7b', # from XML 'restoreState': '/dev/null', # unused here 'restoreFromSnapshot': True, '_srcDomXML': read_data('vm_replace_md_base.xml'), 'xml': read_data('vm_replace_md_update.xml'), } with fake.VM(vmParams) as testvm: updated_dom_xml = testvm.conf['xml'] # shortcut make_params = vmdevices.common.storage_device_params_from_domain_xml dom_desc = domain_descriptor.DomainDescriptor(updated_dom_xml) with dom_desc.metadata_descriptor() as md_desc: disk_params = make_params(dom_desc.id, dom_desc, md_desc, self._log) sda = find_drive_conf_by_name(disk_params, 'sda') self.assertIsNotNone(sda) self.assertEqual(sda['path'], '/rhev/data-center/path/updated') self.assertEqual(sda['imageID'], 'imageID_updated') self.assertEqual(sda['poolID'], 'poolID_updated') self.assertEqual(sda['domainID'], 'domainID_updated') self.assertEqual(sda['volumeID'], 'volumeID_updated')
def test_complex_vm(self): params = { 'nicModel': 'rtl8139,pv', 'name': 'complexVm', 'displaySecurePort': '-1', 'memSize': '256', 'displayPort': '-1', 'display': 'qxl'} devices = [{'device': 'bridge', 'nicModel': 'virtio', 'macAddr': '52:54:00:59:F5:3F', 'type': 'interface', 'network': ''}, {'device': 'bridge', 'nicModel': 'virtio', 'macAddr': '52:54:00:59:FF:FF', 'type': 'interface', 'network': ''}] test_path = os.path.realpath(__file__) dir_name = os.path.split(test_path)[0] api_path = os.path.join( dir_name, '..', 'data', 'testComplexVm.xml') domain = None with open(api_path, 'r') as domxml: domain = domxml.read() with fake.VM(params=params, devices=devices, create_device_objects=True) as vm: vm._domain = domain_descriptor.DomainDescriptor(domain) vm._getUnderlyingVmDevicesInfo() self.verifyDevicesConf(vm.conf['devices'])
def prepare_map(self, dom_xml): xml_str = dom_xml.format(self=self) dom_desc = domain_descriptor.DomainDescriptor(xml_str) md_desc = metadata.Descriptor.from_xml(xml_str) return vmdevices.common.dev_map_from_domain_xml( self.vmid, dom_desc, md_desc, self._log )
def _make_disk_devices(engine_xml, log): """ Build disk devices, the same way VM class does. To process placeholders, we actually need the disk device parameters, but we use device instances out of convenience. Performance-wise the hardest part is the parsing of the XML, so using device instances is almost free. """ engine_domain = domain_descriptor.DomainDescriptor(engine_xml) engine_md = metadata.Descriptor.from_xml(engine_xml) params = vmdevices.common.storage_device_params_from_domain_xml( engine_domain.id, engine_domain, engine_md, log) return [vmdevices.storage.Drive(log, **p) for p in params]
def test_complex_vm(self): params = { 'nicModel': 'rtl8139,pv', 'name': 'complexVm', 'displaySecurePort': '-1', 'memSize': '256', 'displayPort': '-1', 'display': 'qxl'} devices = [{'device': 'ac97', 'type': 'sound'}, {'device': 'ich6', 'type': 'sound'}, {'device': 'qxl', 'type': 'video'}, {'device': 'qxl', 'type': 'video'}, {'device': 'spice', 'type': 'graphics'}, {'device': 'virtio-serial', 'type': 'controller'}, {'device': 'usb', 'type': 'controller'}, {'device': 'memballoon', 'specParams': {'model': 'virtio'}, 'type': 'balloon'}, {'device': 'watchdog', 'type': 'watchdog'}, {'device': 'smartcard', 'specParams': {'type': 'spicevmc', 'mode': 'passthrough'}, 'type': 'smartcard'}, {'device': 'console', 'type': 'console'}, {'device': 'bridge', 'nicModel': 'virtio', 'macAddr': '52:54:00:59:F5:3F', 'type': 'interface', 'network': ''}, {'device': 'bridge', 'nicModel': 'virtio', 'macAddr': '52:54:00:59:FF:FF', 'type': 'interface', 'network': ''}, {'device': 'rng', 'specParams': {'source': 'random'}, 'model': 'virtio', 'type': 'rng'}, {'device': 'rng', 'specParams': {'source': 'random'}, 'model': 'virtio', 'type': 'rng'}, {'device': 'memory', 'type': 'memory', 'size': 524288, 'alias': 'dimm0', 'address': '0x100000000'}] test_path = os.path.realpath(__file__) dir_name = os.path.split(test_path)[0] api_path = os.path.join( dir_name, '..', 'data', 'testComplexVm.xml') domain = None with open(api_path, 'r') as domxml: domain = domxml.read() with fake.VM(params=params, devices=devices, create_device_objects=True) as vm: vm._domain = domain_descriptor.DomainDescriptor(domain) vm._getUnderlyingVmDevicesInfo() self.verifyDevicesConf(vm.conf['devices'])
def prepare_map(self, dom_xml): dom_desc = domain_descriptor.DomainDescriptor( dom_xml.format(self=self) ) return vmdevices.common.dev_map_from_domain_xml( self.vmid, dom_desc, self._log)