]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix IpNetnsCommand to execute without root_wrapper when no netns
authorMiguel Angel Ajo <mangelajo@redhat.com>
Mon, 18 Aug 2014 10:50:58 +0000 (12:50 +0200)
committerMiguel Angel Ajo <mangelajo@redhat.com>
Mon, 25 Aug 2014 19:21:21 +0000 (21:21 +0200)
IpNetnsCommand accept execution with a network namespace, and
that requires root privileges and a root_wrapper.
IpNetnsCommand does accept no namespace too, in that case, the
root_wrapper doesn't have to be present necessarily, unless the
command we're executing requires root privileges itself.

This patch fixes the check condition on IpNetnsCommand execute
method.

Change-Id: I5ab2f3f1daf4a5a080611dbcd3dbd43292f6766a
Closes-Bug: #1358196

neutron/agent/linux/ip_lib.py
neutron/tests/unit/test_linux_ip_lib.py

index afc27f788ec29429ec8e698c4d4218f8170e3689..c7808871abde25411bf2d13e8940baa9272031ca 100644 (file)
@@ -524,10 +524,10 @@ class IpNetnsCommand(IpCommandBase):
         self._as_root('delete', name, use_root_namespace=True)
 
     def execute(self, cmds, addl_env={}, check_exit_code=True):
-        if not self._parent.root_helper:
-            raise exceptions.SudoRequired()
         ns_params = []
         if self._parent.namespace:
+            if not self._parent.root_helper:
+                raise exceptions.SudoRequired()
             ns_params = ['ip', 'netns', 'exec', self._parent.namespace]
 
         env_params = []
index 08dc98fb63570337dec580ca87df869f0c8694ae..874dfbaeec8fee281adb4158473ef9d887dc46d8 100644 (file)
@@ -826,6 +826,15 @@ class TestIpNetnsCommand(TestIPCmdBase):
                  'ip', 'link', 'list'],
                 root_helper='sudo', check_exit_code=True)
 
+    def test_execute_nosudo_with_no_namespace(self):
+        with mock.patch('neutron.agent.linux.utils.execute') as execute:
+            self.parent.namespace = None
+            self.parent.root_helper = None
+            self.netns_cmd.execute(['test'])
+            execute.assert_called_once_with(['test'],
+                                            root_helper=None,
+                                            check_exit_code=True)
+
 
 class TestDeviceExists(base.BaseTestCase):
     def test_device_exists(self):