From 991ea00e6c115343eabecc62e86072175823f81f Mon Sep 17 00:00:00 2001 From: Moshe Levi Date: Thu, 30 Jul 2015 12:04:15 +0300 Subject: [PATCH] SR-IOV: Fix SR-IOV agent to run ip link commands as root 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 --- .../ml2/drivers/mech_sriov/agent/pci_lib.py | 6 ++--- .../drivers/mech_sriov/agent/test_pci_lib.py | 26 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/neutron/plugins/ml2/drivers/mech_sriov/agent/pci_lib.py b/neutron/plugins/ml2/drivers/mech_sriov/agent/pci_lib.py index 05fc0d2f8..3fb04dcd3 100644 --- a/neutron/plugins/ml2/drivers/mech_sriov/agent/pci_lib.py +++ b/neutron/plugins/ml2/drivers/mech_sriov/agent/pci_lib.py @@ -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")) diff --git a/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/agent/test_pci_lib.py b/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/agent/test_pci_lib.py index 62a10f0fb..98c025484 100644 --- a/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/agent/test_pci_lib.py +++ b/neutron/tests/unit/plugins/ml2/drivers/mech_sriov/agent/test_pci_lib.py @@ -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, -- 2.45.2