diff --git a/quantum/agent/linux/ip_lib.py b/quantum/agent/linux/ip_lib.py index 3670fccf58..9d548b9d95 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 068aaf1e1d..cb432e7f0f 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)