Ido Barkan has uploaded a new change for review. Change subject: net: Report correct (guest) pci address fot hostdev interfaces. ......................................................................
net: Report correct (guest) pci address fot hostdev interfaces. For network interfaces, the address is a direct child of the interface node. For host device interfaces, the host address may appear before the guest address and be reported instead. Change-Id: I4542dd9e0a70db4b9a6526442118d610c1b2c615 Signed-off-by: Ido Barkan <[email protected]> Bug-Url: https://bugzilla.redhat.com/1261352 --- A tests/devices/data/testSRiovVm.xml M tests/devices/parsing/complex_vm_tests.py M vdsm/virt/vm.py 3 files changed, 161 insertions(+), 1 deletion(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/05/47705/1 diff --git a/tests/devices/data/testSRiovVm.xml b/tests/devices/data/testSRiovVm.xml new file mode 100644 index 0000000..457a40c --- /dev/null +++ b/tests/devices/data/testSRiovVm.xml @@ -0,0 +1,94 @@ +<domain type='kvm' id='5'> + <name>SRiovVm</name> + <uuid>77777777-ffff-3333-bbbb-222222222222</uuid> + <memory unit='KiB'>262144</memory> + <currentMemory unit='KiB'>262144</currentMemory> + <vcpu placement='static'>1</vcpu> + <cputune> + <shares>1020</shares> + <period>25000</period> + <quota>100000</quota> + </cputune> + <resource> + <partition>/machine</partition> + </resource> + <sysinfo type='smbios'> + <system> + <entry name='manufacturer'>oVirt</entry> + <entry name='product'>oVirt Node</entry> + <entry name='version'>7.1-1.el7</entry> + <entry name='serial'>0121A278-8EFE-D511-9C82-80C16E726398</entry> + <entry name='uuid'>77777777-ffff-3333-bbbb-222222222222</entry> + </system> + </sysinfo> + <os> + <type arch='x86_64' machine='pc-i440fx-rhel7.1.0'>hvm</type> + <kernel>/boot/vmlinuz-3.10.0-229.el7.x86_64</kernel> + <initrd>/boot/initramfs-3.10.0-229.el7.x86_64.img</initrd> + <cmdline>rd.break=cmdline rd.shell rd.skipfsck</cmdline> + <boot dev='hd'/> + <smbios mode='sysinfo'/> + </os> + <features> + <acpi/> + </features> + <cpu mode='custom' match='exact'> + <model fallback='allow'>qemu64</model> + <feature policy='disable' name='svm'/> + </cpu> + <clock offset='variable' adjustment='0' basis='utc'> + <timer name='rtc' tickpolicy='catchup'/> + <timer name='pit' tickpolicy='delay'/> + <timer name='hpet' present='no'/> + </clock> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/libexec/qemu-kvm</emulator> + <controller type='virtio-serial' index='0' ports='16'> + <alias name='virtio-serial0'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/> + </controller> + <controller type='pci' index='0' model='pci-root'> + <alias name='pci.0'/> + </controller> + <interface type='bridge'> + <mac address='52:54:00:59:ff:ff'/> + <source bridge=';vdsmdummy;'/> + <target dev='vnet2'/> + <model type='virtio'/> + <alias name='net1'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/> + </interface> + <interface type='hostdev'> + <mac address='00:00:00:00:00:43'/> + <driver name='vfio'/> + <source> + <address type='pci' domain='0x0000' bus='0x05' slot='0x00' function='0x1'/> + </source> + <alias name='hostdev2'/> + <address type='pci' domain='0x0000' bus='0x99' slot='0x07' function='0x0'/> + </interface> + <channel type='unix'> + <source mode='bind' path='/var/lib/libvirt/qemu/channels/77777777-ffff-3333-bbbb-222222222222.com.redhat.rhevm.vdsm'/> + <target type='virtio' name='com.redhat.rhevm.vdsm' state='disconnected'/> + <alias name='channel0'/> + <address type='virtio-serial' controller='0' bus='0' port='1'/> + </channel> + <channel type='unix'> + <source mode='bind' path='/var/lib/libvirt/qemu/channels/77777777-ffff-3333-bbbb-222222222222.org.qemu.guest_agent.0'/> + <target type='virtio' name='org.qemu.guest_agent.0' state='disconnected'/> + <alias name='channel1'/> + <address type='virtio-serial' controller='0' bus='0' port='2'/> + </channel> + <memballoon model='virtio'> + <alias name='balloon0'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/> + </memballoon> + </devices> + <seclabel type='dynamic' model='selinux' relabel='yes'> + <label>system_u:system_r:svirt_t:s0:c117,c189</label> + <imagelabel>system_u:object_r:svirt_image_t:s0:c117,c189</imagelabel> + </seclabel> +</domain> \ No newline at end of file diff --git a/tests/devices/parsing/complex_vm_tests.py b/tests/devices/parsing/complex_vm_tests.py index 8eeb404..0cb2365 100644 --- a/tests/devices/parsing/complex_vm_tests.py +++ b/tests/devices/parsing/complex_vm_tests.py @@ -3,6 +3,7 @@ from testlib import XMLTestCase from virt import domain_descriptor +from virt.vmdevices import hwclass import vmfakelib as fake import verify @@ -55,3 +56,58 @@ vm._domain = domain_descriptor.DomainDescriptor(domain) vm._getUnderlyingVmDevicesInfo() self.verifyDevicesConf(vm.conf['devices']) + + +class TestSRiovXmlParsing(XMLTestCase, verify.DeviceMixin): + + def test_sriov_vm(self): + params = { + 'nicModel': 'rtl8139,pv', 'name': 'SRiovVm', + 'displaySecurePort': '-1', 'memSize': '256', 'displayPort': '-1', + 'display': 'qxl'} + + devices = [{'device': 'virtio-serial', 'type': 'controller'}, + {'device': 'memballoon', 'specParams': {'model': 'virtio'}, + 'type': 'balloon'}, + {'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 _assert_host_address_is_reported(self, devices, vm): + reported = _reported_host_device(vm) + self.assertEqual(reported['hostdev'], devices[3]['hostdev']) + + def _assert_guest_device_adress_is_reported(self, vm): + reported = _reported_host_device(vm) + self.assertEqual( + reported['address'], + {'slot': '0x07', 'bus': '0x99', 'domain': '0x0000', 'type': 'pci', + 'function': '0x0'}) + + +def _reported_host_device(vm): + for dev in vm.conf['devices']: + if dev['device'] == 'hostdev': + return dev diff --git a/vdsm/virt/vm.py b/vdsm/virt/vm.py index bf1c659..1cc44b6 100644 --- a/vdsm/virt/vm.py +++ b/vdsm/virt/vm.py @@ -22,6 +22,7 @@ # stdlib imports from collections import namedtuple from contextlib import contextmanager +from xml.dom import Node from xml.dom.minidom import parseString as _domParseStr import logging import os @@ -4394,7 +4395,16 @@ network = network[len(netinfo.LIBVIRT_NET_PREFIX):] # Get nic address - address = self._getUnderlyingDeviceAddress(x) + address = {} + # TODO: fix _getUnderlyingDeviceAddress and its users to have this + # TODO: code. + for child in x.childNodes: + if (child.nodeType != Node.TEXT_NODE and + child.tagName == 'address'): + address = dict((k.strip(), child.getAttribute(k).strip()) + for k in child.attributes.keys()) + break + for nic in self._devices[hwclass.NIC]: if nic.macAddr.lower() == mac.lower(): nic.name = name -- To view, visit https://gerrit.ovirt.org/47705 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4542dd9e0a70db4b9a6526442118d610c1b2c615 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: ovirt-3.6 Gerrit-Owner: Ido Barkan <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
