From 6e6a8816083c0172988a26e70da027e6f9501db6 Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Thu, 21 Jan 2016 10:53:06 -0800 Subject: [PATCH] libvirt: implement LibvirtConfigGuestInterface.parse_dom This is needed by a follow on change that needs to find an interface in the config by a given MAC address. Change-Id: I6b9ab20570e1db832cc2eec94cbf69dddf4ef3d6 Partial-Bug: #1536671 --- nova/pci/utils.py | 4 + nova/tests/unit/virt/libvirt/test_config.py | 60 +++++++++++++++ nova/tests/unit/virt/libvirt/test_guest.py | 16 +++- nova/virt/libvirt/config.py | 83 +++++++++++++++++++++ 4 files changed, 161 insertions(+), 2 deletions(-) diff --git a/nova/pci/utils.py b/nova/pci/utils.py index 80b8c35f8b99..e10a30315662 100644 --- a/nova/pci/utils.py +++ b/nova/pci/utils.py @@ -69,6 +69,10 @@ def get_pci_address_fields(pci_addr): return (domain, bus, slot, func) +def get_pci_address(domain, bus, slot, func): + return '%s:%s:%s.%s' % (domain, bus, slot, func) + + def get_function_by_ifname(ifname): """Given the device name, returns the PCI address of a device and returns True if the address in a physical function. diff --git a/nova/tests/unit/virt/libvirt/test_config.py b/nova/tests/unit/virt/libvirt/test_config.py index 08d570c0ad15..98a22df57f3a 100644 --- a/nova/tests/unit/virt/libvirt/test_config.py +++ b/nova/tests/unit/virt/libvirt/test_config.py @@ -1302,6 +1302,12 @@ class LibvirtConfigGuestInterfaceTest(LibvirtConfigBaseTest): """) + # parse the xml from the first object into a new object and make sure + # they are the same + obj2 = config.LibvirtConfigGuestInterface() + obj2.parse_str(xml) + self.assertXmlEqual(xml, obj2.to_xml()) + def test_config_driver_options(self): obj = config.LibvirtConfigGuestInterface() obj.net_type = "ethernet" @@ -1320,6 +1326,12 @@ class LibvirtConfigGuestInterfaceTest(LibvirtConfigBaseTest): """) + # parse the xml from the first object into a new object and make sure + # they are the same + obj2 = config.LibvirtConfigGuestInterface() + obj2.parse_str(xml) + self.assertXmlEqual(xml, obj2.to_xml()) + def test_config_bridge(self): obj = config.LibvirtConfigGuestInterface() obj.net_type = "bridge" @@ -1352,6 +1364,12 @@ class LibvirtConfigGuestInterfaceTest(LibvirtConfigBaseTest): """) + # parse the xml from the first object into a new object and make sure + # they are the same + obj2 = config.LibvirtConfigGuestInterface() + obj2.parse_str(xml) + self.assertXmlEqual(xml, obj2.to_xml()) + def test_config_bridge_ovs(self): obj = config.LibvirtConfigGuestInterface() obj.net_type = "bridge" @@ -1374,6 +1392,12 @@ class LibvirtConfigGuestInterfaceTest(LibvirtConfigBaseTest): """) + # parse the xml from the first object into a new object and make sure + # they are the same + obj2 = config.LibvirtConfigGuestInterface() + obj2.parse_str(xml) + self.assertXmlEqual(xml, obj2.to_xml()) + def test_config_bridge_xen(self): obj = config.LibvirtConfigGuestInterface() obj.net_type = "bridge" @@ -1389,6 +1413,12 @@ class LibvirtConfigGuestInterfaceTest(LibvirtConfigBaseTest):