]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Fix namespace exist() method
authorEugene Nikanorov <enikanorov@mirantis.com>
Wed, 19 Mar 2014 14:00:35 +0000 (18:00 +0400)
committerEugene Nikanorov <enikanorov@mirantis.com>
Thu, 27 Mar 2014 18:27:20 +0000 (22:27 +0400)
Fix namespace exist() method for it shall not be called with a root.
Also, don't run it under the namespace so garbage_collect_namespace
method can run without rootwrap and not withi a ns.

As a result of fixing namespace listing the patch also fixes the
regression introduced (bug/1294603) to loadbalancer agent respawning
haproxy due to inability to list namespaces properly.

Change-Id: I0dc4d01b0c1c04887ec6ad5766ec7c6c96903faa
Closes-Bug: #1297594
Closes-Bug: #1294603

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

index 62ba2a7bb2d6ef8c728f25738d6b4e3d3f25d74e..9b7f2c8615e569c2d554ed4078ab42f0931f09d3 100644 (file)
@@ -466,7 +466,7 @@ class IpNetnsCommand(IpCommandBase):
             check_exit_code=check_exit_code)
 
     def exists(self, name):
-        output = self._run('list', options='o')
+        output = self._parent._execute('o', 'netns', ['list'])
 
         for line in output.split('\n'):
             if name == line.strip():
index 74f47ccf67999f613afbaa21e4aa5864f7d2498f..ea23c854971a8ee9deb594877ef476bc9da33631 100644 (file)
@@ -713,17 +713,25 @@ class TestIpNetnsCommand(TestIPCmdBase):
 
     def test_namespace_exists(self):
         retval = '\n'.join(NETNS_SAMPLE)
-        self.parent._run.return_value = retval
-        self.assertTrue(
-            self.netns_cmd.exists('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'))
-        self._assert_call('o', ('list',))
+        # need another instance to avoid mocking
+        netns_cmd = ip_lib.IpNetnsCommand(ip_lib.SubProcessBase())
+        with mock.patch('neutron.agent.linux.utils.execute') as execute:
+            execute.return_value = retval
+            self.assertTrue(
+                netns_cmd.exists('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'))
+            execute.assert_called_once_with(['ip', '-o', 'netns', 'list'],
+                                            root_helper=None)
 
     def test_namespace_doest_not_exist(self):
         retval = '\n'.join(NETNS_SAMPLE)
-        self.parent._run.return_value = retval
-        self.assertFalse(
-            self.netns_cmd.exists('bbbbbbbb-1111-2222-3333-bbbbbbbbbbbb'))
-        self._assert_call('o', ('list',))
+        # need another instance to avoid mocking
+        netns_cmd = ip_lib.IpNetnsCommand(ip_lib.SubProcessBase())
+        with mock.patch('neutron.agent.linux.utils.execute') as execute:
+            execute.return_value = retval
+            self.assertFalse(
+                netns_cmd.exists('bbbbbbbb-1111-2222-3333-bbbbbbbbbbbb'))
+            execute.assert_called_once_with(['ip', '-o', 'netns', 'list'],
+                                            root_helper=None)
 
     def test_execute(self):
         self.parent.namespace = 'ns'