]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Add compatibility with iproute2 >= 4.0
authorJames Page <james.page@ubuntu.com>
Fri, 18 Sep 2015 15:38:47 +0000 (16:38 +0100)
committerJames Page <james.page@ubuntu.com>
Tue, 29 Sep 2015 19:07:45 +0000 (20:07 +0100)
The ip netns list command adds additional id data in more recent
versions of iproute2 of the format:

  qdhcp-35fc068a-750d-4add-b1d2-af392dbd8790 (id: 1)

Update parsing to deal with old and new formats.

Change-Id: I0d3fc4262284172f5ad31e4f2f78ae1fb33b4228
Closes-Bug: 1497309

neutron/agent/linux/ip_lib.py
neutron/tests/functional/agent/test_l3_agent.py
neutron/tests/unit/agent/linux/test_ip_lib.py

index 551341a181444f988955018f9d24f3e19517ea4c..a717bf623144e5f45cce04a08bd80170cc82125e 100644 (file)
@@ -208,7 +208,7 @@ class IPWrapper(SubProcessBase):
     @classmethod
     def get_namespaces(cls):
         output = cls._execute([], 'netns', ('list',))
-        return [l.strip() for l in output.split('\n')]
+        return [l.split()[0] for l in output.splitlines()]
 
 
 class IPDevice(SubProcessBase):
@@ -819,8 +819,8 @@ class IpNetnsCommand(IpCommandBase):
         output = self._parent._execute(
             ['o'], 'netns', ['list'],
             run_as_root=cfg.CONF.AGENT.use_helper_for_ns_read)
-        for line in output.split('\n'):
-            if name == line.strip():
+        for line in [l.split()[0] for l in output.splitlines()]:
+            if name == line:
                 return True
         return False
 
index ffa20e6dda76f29653f3ae3ca2d3dacd1feb72ad..84b16dfb36245b86accab98ea1c71bd369bd0235 100644 (file)
@@ -790,7 +790,7 @@ class L3HATestFramework(L3AgentTestFramework):
         get_ns_name = mock.patch.object(
             namespaces.RouterNamespace, '_get_ns_name').start()
         get_ns_name.return_value = "%s%s%s" % (
-            namespaces.RouterNamespace._get_ns_name(router_info['id']),
+            'qrouter-' + router_info['id'],
             self.NESTED_NAMESPACE_SEPARATOR, self.agent.host)
         router1 = self.manage_router(self.agent, router_info)
 
index 2de408d7686029aa1cd95ed965d21ab1f77888f9..bdfc9d7f3469b680f029599d9042de84b8955aa5 100644 (file)
@@ -27,6 +27,11 @@ NETNS_SAMPLE = [
     'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
     'cccccccc-cccc-cccc-cccc-cccccccccccc']
 
+NETNS_SAMPLE_IPROUTE2_4 = [
+    '12345678-1234-5678-abcd-1234567890ab (id: 1)',
+    'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb (id: 0)',
+    'cccccccc-cccc-cccc-cccc-cccccccccccc (id: 2)']
+
 LINK_SAMPLE = [
     '1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN \\'
     'link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 promiscuity 0',
@@ -279,6 +284,16 @@ class TestIpWrapper(base.BaseTestCase):
 
         self.execute.assert_called_once_with([], 'netns', ('list',))
 
+    def test_get_namespaces_iproute2_4(self):
+        self.execute.return_value = '\n'.join(NETNS_SAMPLE_IPROUTE2_4)
+        retval = ip_lib.IPWrapper.get_namespaces()
+        self.assertEqual(retval,
+                         ['12345678-1234-5678-abcd-1234567890ab',
+                          'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
+                          'cccccccc-cccc-cccc-cccc-cccccccccccc'])
+
+        self.execute.assert_called_once_with([], 'netns', ('list',))
+
     def test_add_tuntap(self):
         ip_lib.IPWrapper().add_tuntap('tap0')
         self.execute.assert_called_once_with([], 'tuntap',