Set promote_secondaries when creating namespaces

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
This commit is contained in:
Zang MingJie 2014-07-17 23:06:07 +08:00
parent ffe34d35e8
commit 141a00bd27
2 changed files with 19 additions and 10 deletions

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

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