From 078869814c576cd2560d71e619e8a938b30a796f Mon Sep 17 00:00:00 2001 From: Mark McClain Date: Sun, 19 Aug 2012 16:10:00 -0400 Subject: [PATCH] fix netns delete so that it works when a ns is set 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 | 7 ++++++- quantum/tests/unit/test_linux_ip_lib.py | 6 ++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/quantum/agent/linux/ip_lib.py b/quantum/agent/linux/ip_lib.py index 3670fccf5..9d548b9d9 100644 --- a/quantum/agent/linux/ip_lib.py +++ b/quantum/agent/linux/ip_lib.py @@ -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: diff --git a/quantum/tests/unit/test_linux_ip_lib.py b/quantum/tests/unit/test_linux_ip_lib.py index 068aaf1e1..cb432e7f0 100644 --- a/quantum/tests/unit/test_linux_ip_lib.py +++ b/quantum/tests/unit/test_linux_ip_lib.py @@ -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) -- 2.45.2