]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
SR-IOV: Fix SR-IOV agent to run ip link commands as root
authorMoshe Levi <moshele@mellanox.com>
Thu, 30 Jul 2015 09:04:15 +0000 (12:04 +0300)
committerIhar Hrachyshka <ihrachys@redhat.com>
Thu, 30 Jul 2015 09:40:46 +0000 (09:40 +0000)
Commit https://review.openstack.org/#/c/155523/
remove the remaining root_helper args, but didn't
update the SR-IOV agent to execute them as root.

This patch updates the agent to execute ip link commands
as root and pass options argument as a list in the
self._as_root method.

Closes-Bug: #1479694
Change-Id: I53cafd61845a69fae3a759fb7526950d655ffa20

neutron/plugins/ml2/drivers/mech_sriov/agent/pci_lib.py
neutron/tests/unit/plugins/ml2/drivers/mech_sriov/agent/test_pci_lib.py

index 05fc0d2f85987eea354fe1c42cc80d8d8f558c9c..3fb04dcd3e892e8a4d158ccbd525e886d2909042 100644 (file)
@@ -53,7 +53,7 @@ class PciDeviceIPWrapper(ip_lib.IPWrapper):
         @return: list of assigned mac addresses
         """
         try:
-            out = self._execute('', "link", ("show", self.dev_name))
+            out = self._as_root([], "link", ("show", self.dev_name))
         except Exception as e:
             LOG.exception(_LE("Failed executing ip command"))
             raise exc.IpCommandError(dev_name=self.dev_name,
@@ -74,7 +74,7 @@ class PciDeviceIPWrapper(ip_lib.IPWrapper):
         @todo: Handle "auto" state
         """
         try:
-            out = self._execute('', "link", ("show", self.dev_name))
+            out = self._as_root([], "link", ("show", self.dev_name))
         except Exception as e:
             LOG.exception(_LE("Failed executing ip command"))
             raise exc.IpCommandError(dev_name=self.dev_name,
@@ -99,7 +99,7 @@ class PciDeviceIPWrapper(ip_lib.IPWrapper):
             self.LinkState.DISABLE
 
         try:
-            self._execute('', "link", ("set", self.dev_name, "vf",
+            self._as_root([], "link", ("set", self.dev_name, "vf",
                                        str(vf_index), "state", status_str))
         except Exception as e:
             LOG.exception(_LE("Failed executing ip command"))
index 62a10f0fba09ba5a97b3c2e809c8156d9c3e89d4..98c02548438694fa7b64a56da2b677987c43a7e4 100644 (file)
@@ -50,51 +50,51 @@ class TestPciLib(base.BaseTestCase):
 
     def test_get_assigned_macs(self):
         with mock.patch.object(self.pci_wrapper,
-                               "_execute") as mock_exec:
-            mock_exec.return_value = self.VF_LINK_SHOW
+                               "_as_root") as mock_as_root:
+            mock_as_root.return_value = self.VF_LINK_SHOW
             result = self.pci_wrapper.get_assigned_macs([self.VF_INDEX])
             self.assertEqual([self.MAC_MAPPING[self.VF_INDEX]], result)
 
     def test_get_assigned_macs_fail(self):
         with mock.patch.object(self.pci_wrapper,
-                               "_execute") as mock_exec:
-            mock_exec.side_effect = Exception()
+                               "_as_root") as mock_as_root:
+            mock_as_root.side_effect = Exception()
             self.assertRaises(exc.IpCommandError,
                               self.pci_wrapper.get_assigned_macs,
                               [self.VF_INDEX])
 
     def test_get_vf_state_enable(self):
         with mock.patch.object(self.pci_wrapper,
-                               "_execute") as mock_exec:
-            mock_exec.return_value = self.VF_LINK_SHOW
+                               "_as_root") as mock_as_root:
+            mock_as_root.return_value = self.VF_LINK_SHOW
             result = self.pci_wrapper.get_vf_state(self.VF_INDEX)
             self.assertTrue(result)
 
     def test_get_vf_state_disable(self):
         with mock.patch.object(self.pci_wrapper,
-                               "_execute") as mock_exec:
-            mock_exec.return_value = self.VF_LINK_SHOW
+                               "_as_root") as mock_as_root:
+            mock_as_root.return_value = self.VF_LINK_SHOW
             result = self.pci_wrapper.get_vf_state(self.VF_INDEX_DISABLE)
             self.assertFalse(result)
 
     def test_get_vf_state_fail(self):
         with mock.patch.object(self.pci_wrapper,
-                               "_execute") as mock_exec:
-            mock_exec.side_effect = Exception()
+                               "_as_root") as mock_as_root:
+            mock_as_root.side_effect = Exception()
             self.assertRaises(exc.IpCommandError,
                               self.pci_wrapper.get_vf_state,
                               self.VF_INDEX)
 
     def test_set_vf_state(self):
-        with mock.patch.object(self.pci_wrapper, "_execute"):
+        with mock.patch.object(self.pci_wrapper, "_as_root"):
             result = self.pci_wrapper.set_vf_state(self.VF_INDEX,
                                                    True)
             self.assertIsNone(result)
 
     def test_set_vf_state_fail(self):
         with mock.patch.object(self.pci_wrapper,
-                               "_execute") as mock_exec:
-            mock_exec.side_effect = Exception()
+                               "_as_root") as mock_as_root:
+            mock_as_root.side_effect = Exception()
             self.assertRaises(exc.IpCommandError,
                               self.pci_wrapper.set_vf_state,
                               self.VF_INDEX,