From 28b4f64c06df81aed7144b0c74c7851d8cb4402d Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Mon, 21 May 2018 17:38:50 +0100 Subject: Error when adding SR-IOV interfaces in SR-IOV context Method "add_sriov_interfaces" in Libvirt class throws an error when trying to add SR-IOV interfaces in the XML file. Function "setup_sriov_context" in SriovContext if passing to "_enable_interfaces" method the XML file name instead of passing the XML string. JIRA: YARDSTICK-1189 Change-Id: If021c102311ecb98cb26934f78067dfc720e4291 Signed-off-by: Rodolfo Alonso Hernandez (cherry picked from commit 72df0eaac4a2a1f23439af7f249c2b5d18d1b819) --- yardstick/benchmark/contexts/standalone/sriov.py | 6 +++--- .../benchmark/contexts/standalone/test_sriov.py | 24 ++++++++++++++-------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/yardstick/benchmark/contexts/standalone/sriov.py b/yardstick/benchmark/contexts/standalone/sriov.py index 5db419e6a..d4c27fa9c 100644 --- a/yardstick/benchmark/contexts/standalone/sriov.py +++ b/yardstick/benchmark/contexts/standalone/sriov.py @@ -197,10 +197,10 @@ class SriovContext(Context): slot = index + idx + 10 vf['vpci'] = \ "{}:{}:{:02x}.{}".format(vpci.domain, vpci.bus, slot, vpci.function) - model.Libvirt.add_sriov_interfaces( - vf['vpci'], vf['vf_pci']['vf_pci'], vf['mac'], str(cfg)) self.connection.execute("ifconfig %s up" % vf['interface']) self.connection.execute(vf_spoofchk.format(vf['interface'])) + return model.Libvirt.add_sriov_interfaces( + vf['vpci'], vf['vf_pci']['vf_pci'], vf['mac'], str(cfg)) def setup_sriov_context(self): nodes = [] @@ -223,7 +223,7 @@ class SriovContext(Context): network_ports = collections.OrderedDict( {k: v for k, v in vnf["network_ports"].items() if k != 'mgmt'}) for idx, vfs in enumerate(network_ports.values()): - self._enable_interfaces(index, idx, vfs, cfg) + xml_str = self._enable_interfaces(index, idx, vfs, xml_str) # copy xml to target... model.Libvirt.write_file(cfg, xml_str) diff --git a/yardstick/tests/unit/benchmark/contexts/standalone/test_sriov.py b/yardstick/tests/unit/benchmark/contexts/standalone/test_sriov.py index e70ab0ae8..b426985be 100644 --- a/yardstick/tests/unit/benchmark/contexts/standalone/test_sriov.py +++ b/yardstick/tests/unit/benchmark/contexts/standalone/test_sriov.py @@ -242,18 +242,19 @@ class SriovContextTestCase(unittest.TestCase): self.assertIsNone(self.sriov.configure_nics_for_sriov()) @mock.patch.object(ssh, 'SSH', return_value=(0, "a", "")) - @mock.patch.object(model, 'Libvirt') - def test__enable_interfaces(self, mock_libvirt, mock_ssh): - # pylint: disable=unused-argument - # NOTE(ralonsoh): the pylint exception should be removed. + @mock.patch.object(model.Libvirt, 'add_sriov_interfaces', + return_value='out_xml') + def test__enable_interfaces(self, mock_add_sriov, mock_ssh): self.sriov.vm_deploy = True self.sriov.connection = mock_ssh self.sriov.vm_names = ['vm_0', 'vm_1'] self.sriov.drivers = [] self.sriov.networks = self.NETWORKS - self.sriov.get_vf_data = mock.Mock(return_value="") - self.assertIsNone(self.sriov._enable_interfaces( - 0, 0, ["private_0"], 'test')) + self.assertEqual( + 'out_xml', + self.sriov._enable_interfaces(0, 0, ['private_0'], 'test')) + mock_add_sriov.assert_called_once_with( + '0000:00:0a.0', 0, self.NETWORKS['private_0']['mac'], 'test') @mock.patch.object(model.Libvirt, 'build_vm_xml') @mock.patch.object(model.Libvirt, 'check_if_vm_exists_and_delete') @@ -282,7 +283,9 @@ class SriovContextTestCase(unittest.TestCase): mock_build_vm_xml.return_value = (xml_out, '00:00:00:00:00:01') with mock.patch.object(self.sriov, 'vnf_node') as mock_vnf_node, \ - mock.patch.object(self.sriov, '_enable_interfaces'): + mock.patch.object(self.sriov, '_enable_interfaces') as \ + mock_enable_interfaces: + mock_enable_interfaces.return_value = 'out_xml' mock_vnf_node.generate_vnf_instance = mock.Mock( return_value='node') nodes_out = self.sriov.setup_sriov_context() @@ -294,7 +297,10 @@ class SriovContextTestCase(unittest.TestCase): connection, 'flavor', vm_name, 0) mock_create_vm.assert_called_once_with(connection, cfg) mock_check.assert_called_once_with(vm_name, connection) - mock_write_file.assert_called_once_with(cfg, xml_out) + mock_write_file.assert_called_once_with(cfg, 'out_xml') + mock_enable_interfaces.assert_has_calls([ + mock.call(0, mock.ANY, ['private_0'], mock.ANY), + mock.call(0, mock.ANY, ['public_0'], mock.ANY)], any_order=True) def test__get_vf_data(self): with mock.patch("yardstick.ssh.SSH") as ssh: -- cgit 1.2.3-korg