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
This commit is contained in:
Mark McClain 2012-08-19 16:10:00 -04:00
parent 23715d972d
commit 4ad296c591
2 changed files with 10 additions and 3 deletions

View 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:

View 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)