]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Set promote_secondaries when creating namespaces
authorZang MingJie <zealot0630@gmail.com>
Thu, 17 Jul 2014 15:06:07 +0000 (23:06 +0800)
committerZang MingJie <zealot0630@gmail.com>
Mon, 28 Jul 2014 09:32:14 +0000 (17:32 +0800)
there is a sysconf entry which controls how deletion of the primary ip
is performed (/proc/sys/net/ipv4/conf/all/promote_secondaries). when set
instead of deleting the secondary addresses, one of them will be
promoted to primary ip.

Without it, when init_l3 called on a port, it may unexpectedly delete
some useful ips.

Change-Id: I0b1b3bd6ade21129532c842daa31059ea164719e
Closes-bug: 1343320

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

index 9b6b18b3d07c090b6af752a0f1a7b4e3e5b7cfa0..bbfa087491a6ca66a8911e9c67a79fbfd4804c95 100644 (file)
@@ -511,7 +511,10 @@ class IpNetnsCommand(IpCommandBase):
 
     def add(self, name):
         self._as_root('add', name, use_root_namespace=True)
-        return IPWrapper(self._parent.root_helper, name)
+        wrapper = IPWrapper(self._parent.root_helper, name)
+        wrapper.netns.execute(['sysctl', '-w',
+                               'net.ipv4.conf.all.promote_secondaries=1'])
+        return wrapper
 
     def delete(self, name):
         self._as_root('delete', name, use_root_namespace=True)
index d405c04a756ae8ab8a896f8a8211396365c7f168..202ae933c5408802c920e0fae1af6315fa4ce866 100644 (file)
@@ -287,12 +287,13 @@ class TestIpWrapper(base.BaseTestCase):
         with mock.patch.object(ip_lib, 'IPDevice') as ip_dev:
             ip = ip_lib.IPWrapper('sudo')
             with mock.patch.object(ip.netns, 'exists') as ns_exists:
-                ns_exists.return_value = False
-                ip.ensure_namespace('ns')
-                self.execute.assert_has_calls(
-                    [mock.call([], 'netns', ('add', 'ns'), 'sudo', None)])
-                ip_dev.assert_has_calls([mock.call('lo', 'sudo', 'ns'),
-                                         mock.call().link.set_up()])
+                with mock.patch('neutron.agent.linux.utils.execute'):
+                    ns_exists.return_value = False
+                    ip.ensure_namespace('ns')
+                    self.execute.assert_has_calls(
+                        [mock.call([], 'netns', ('add', 'ns'), 'sudo', None)])
+                    ip_dev.assert_has_calls([mock.call('lo', 'sudo', 'ns'),
+                                             mock.call().link.set_up()])
 
     def test_ensure_namespace_existing(self):
         with mock.patch.object(ip_lib, 'IpNetnsCommand') as ip_ns_cmd:
@@ -764,9 +765,14 @@ class TestIpNetnsCommand(TestIPCmdBase):
         self.netns_cmd = ip_lib.IpNetnsCommand(self.parent)
 
     def test_add_namespace(self):
-        ns = self.netns_cmd.add('ns')
-        self._assert_sudo([], ('add', 'ns'), force_root_namespace=True)
-        self.assertEqual(ns.namespace, 'ns')
+        with mock.patch('neutron.agent.linux.utils.execute') as execute:
+            ns = self.netns_cmd.add('ns')
+            self._assert_sudo([], ('add', 'ns'), force_root_namespace=True)
+            self.assertEqual(ns.namespace, 'ns')
+            execute.assert_called_once_with(
+                ['ip', 'netns', 'exec', 'ns',
+                 'sysctl', '-w', 'net.ipv4.conf.all.promote_secondaries=1'],
+                root_helper='sudo', check_exit_code=True)
 
     def test_delete_namespace(self):
         with mock.patch('neutron.agent.linux.utils.execute'):