Error when adding SR-IOV interfaces in SR-IOV context 83/58783/2
authorRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
Mon, 21 May 2018 16:38:50 +0000 (17:38 +0100)
committerEmma Foley <emma.l.foley@intel.com>
Thu, 21 Jun 2018 12:42:51 +0000 (12:42 +0000)
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 <rodolfo.alonso.hernandez@intel.com>
(cherry picked from commit 72df0eaac4a2a1f23439af7f249c2b5d18d1b819)

yardstick/benchmark/contexts/standalone/sriov.py
yardstick/tests/unit/benchmark/contexts/standalone/test_sriov.py

index 5db419e..d4c27fa 100644 (file)
@@ -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)
index e70ab0a..b426985 100644 (file)
@@ -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: