]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
fix netns delete so that it works when a ns is set
authorMark McClain <mark.mcclain@dreamhost.com>
Sun, 19 Aug 2012 20:10:00 +0000 (16:10 -0400)
committerMark McClain <mark.mcclain@dreamhost.com>
Sun, 19 Aug 2012 20:12:31 +0000 (16:12 -0400)
bug 1038759

This fixes the bug by ensuring that the netns deletion always runs in the root
namespace.  Tests were updated to reflect the change in execute
invocation.

Change-Id: I008e8ecbc4bae86129af7f4a7b5d33c6ae423e5c

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

index 3670fccf58daac7c82949c404fc8af30ef2090a4..9d548b9d9537a2ed5bced3820b4577f7e82c0b25 100644 (file)
@@ -262,7 +262,12 @@ class IpNetnsCommand(IpCommandBase):
         return IPWrapper(self._parent.root_helper, name)
 
     def delete(self, name):
-        self._as_root('delete', name)
+        if not self._parent.root_helper:
+            raise exceptions.SudoRequired()
+        else:
+            return utils.execute(
+                ['ip', 'netns', 'delete', name],
+                root_helper=self._parent.root_helper)
 
     def execute(self, cmds):
         if not self._parent.root_helper:
index 068aaf1e1d79dc23d120409127c847c80293f0dd..cb432e7f0f0836febb9201bd9926ad4320c3b34a 100644 (file)
@@ -423,8 +423,10 @@ class TestIpNetnsCommand(TestIPCmdBase):
         self.assertEqual(ns.namespace, 'ns')
 
     def test_delete_namespace(self):
-        self.netns_cmd.delete('ns')
-        self._assert_sudo([], ('delete', 'ns'))
+        with mock.patch('quantum.agent.linux.utils.execute') as execute:
+            self.netns_cmd.delete('ns')
+            execute.assert_called_once_with(['ip', 'netns', 'delete', 'ns'],
+                                            root_helper='sudo')
 
     def test_namespace_exists(self):
         retval = '\n'.join(NETNS_SAMPLE)