diff --git a/nova/tests/test_libvirt_config.py b/nova/tests/test_libvirt_config.py index a00d5b57..c285d46c 100644 --- a/nova/tests/test_libvirt_config.py +++ b/nova/tests/test_libvirt_config.py @@ -483,6 +483,7 @@ class LibvirtConfigGuestInterfaceTest(LibvirtConfigBaseTest): obj.source_dev = "br0" obj.mac_addr = "DE:AD:BE:EF:CA:FE" obj.model = "virtio" + obj.target_dev = "tap12345678" obj.filtername = "clean-traffic" obj.filterparams.append({"key": "IP", "value": "192.168.122.1"}) @@ -492,6 +493,7 @@ class LibvirtConfigGuestInterfaceTest(LibvirtConfigBaseTest): + @@ -503,6 +505,7 @@ class LibvirtConfigGuestInterfaceTest(LibvirtConfigBaseTest): obj.source_dev = "br0" obj.mac_addr = "DE:AD:BE:EF:CA:FE" obj.model = "virtio" + obj.target_dev = "tap12345678" obj.vporttype = "openvswitch" obj.vportparams.append({"key": "instanceid", "value": "foobar"}) @@ -512,6 +515,7 @@ class LibvirtConfigGuestInterfaceTest(LibvirtConfigBaseTest): + @@ -522,6 +526,7 @@ class LibvirtConfigGuestInterfaceTest(LibvirtConfigBaseTest): obj.net_type = "direct" obj.mac_addr = "DE:AD:BE:EF:CA:FE" obj.model = "virtio" + obj.target_dev = "tap12345678" obj.source_dev = "eth0" obj.vporttype = "802.1Qbh" @@ -531,6 +536,7 @@ class LibvirtConfigGuestInterfaceTest(LibvirtConfigBaseTest): + """) diff --git a/nova/tests/test_libvirt_vif.py b/nova/tests/test_libvirt_vif.py index bb434451..d67f47f5 100644 --- a/nova/tests/test_libvirt_vif.py +++ b/nova/tests/test_libvirt_vif.py @@ -39,7 +39,8 @@ class LibvirtVifTestCase(test.TestCase): 'vlan': 99, 'gateway': '101.168.1.1', 'broadcast': '101.168.1.255', - 'dns1': '8.8.8.8' + 'dns1': '8.8.8.8', + 'id': 'network-id-xxx-yyy-zzz' } mapping = { @@ -78,6 +79,48 @@ class LibvirtVifTestCase(test.TestCase): conf.add_device(nic) return conf.to_xml() + def test_multiple_nics(self): + conf = vconfig.LibvirtConfigGuest() + conf.virt_type = "qemu" + conf.name = "fake-name" + conf.uuid = "fake-uuid" + conf.memory = 100 * 1024 + conf.vcpus = 4 + + # Tests multiple nic configuration and that target_dev is + # set for each + nics = [{'net_type': 'bridge', + 'mac_addr': '00:00:00:00:00:0b', + 'source_dev': 'b_source_dev', + 'target_dev': 'b_target_dev'}, + {'net_type': 'ethernet', + 'mac_addr': '00:00:00:00:00:0e', + 'source_dev': 'e_source_dev', + 'target_dev': 'e_target_dev'}, + {'net_type': 'direct', + 'mac_addr': '00:00:00:00:00:0d', + 'source_dev': 'd_source_dev', + 'target_dev': 'd_target_dev'}] + + for nic in nics: + nic_conf = vconfig.LibvirtConfigGuestInterface() + nic_conf.net_type = nic['net_type'] + nic_conf.target_dev = nic['target_dev'] + nic_conf.mac_addr = nic['mac_addr'] + nic_conf.source_dev = nic['source_dev'] + conf.add_device(nic_conf) + + xml = conf.to_xml() + doc = etree.fromstring(xml) + for nic in nics: + path = "./devices/interface/[@type='%s']" % nic['net_type'] + node = doc.find(path) + self.assertEqual(nic['net_type'], node.get("type")) + self.assertEqual(nic['mac_addr'], + node.find("mac").get("address")) + self.assertEqual(nic['target_dev'], + node.find("target").get("dev")) + def test_bridge_driver(self): d = vif.LibvirtBridgeDriver() xml = self._get_instance_xml(d) @@ -146,13 +189,13 @@ class LibvirtVifTestCase(test.TestCase): ret = doc.findall('./devices/interface') self.assertEqual(len(ret), 1) node = ret[0] - self.assertEqual(node.get("type"), "ethernet") + self.assertEqual(node.get("type"), "bridge") dev_name = node.find("target").get("dev") self.assertTrue(dev_name.startswith("tap")) mac = node.find("mac").get("address") self.assertEqual(mac, self.mapping['mac']) - script = node.find("script").get("path") - self.assertEquals(script, "") + br_name = node.find("source").get("bridge") + self.assertTrue(br_name.startswith("brq")) d.unplug(None, (self.net, self.mapping))