Merge "Set promote_secondaries when creating namespaces"
This commit is contained in:
commit
5b32c7dc9b
@ -511,7 +511,10 @@ class IpNetnsCommand(IpCommandBase):
|
|||||||
|
|
||||||
def add(self, name):
|
def add(self, name):
|
||||||
self._as_root('add', name, use_root_namespace=True)
|
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):
|
def delete(self, name):
|
||||||
self._as_root('delete', name, use_root_namespace=True)
|
self._as_root('delete', name, use_root_namespace=True)
|
||||||
|
@ -287,12 +287,13 @@ class TestIpWrapper(base.BaseTestCase):
|
|||||||
with mock.patch.object(ip_lib, 'IPDevice') as ip_dev:
|
with mock.patch.object(ip_lib, 'IPDevice') as ip_dev:
|
||||||
ip = ip_lib.IPWrapper('sudo')
|
ip = ip_lib.IPWrapper('sudo')
|
||||||
with mock.patch.object(ip.netns, 'exists') as ns_exists:
|
with mock.patch.object(ip.netns, 'exists') as ns_exists:
|
||||||
ns_exists.return_value = False
|
with mock.patch('neutron.agent.linux.utils.execute'):
|
||||||
ip.ensure_namespace('ns')
|
ns_exists.return_value = False
|
||||||
self.execute.assert_has_calls(
|
ip.ensure_namespace('ns')
|
||||||
[mock.call([], 'netns', ('add', 'ns'), 'sudo', None)])
|
self.execute.assert_has_calls(
|
||||||
ip_dev.assert_has_calls([mock.call('lo', 'sudo', 'ns'),
|
[mock.call([], 'netns', ('add', 'ns'), 'sudo', None)])
|
||||||
mock.call().link.set_up()])
|
ip_dev.assert_has_calls([mock.call('lo', 'sudo', 'ns'),
|
||||||
|
mock.call().link.set_up()])
|
||||||
|
|
||||||
def test_ensure_namespace_existing(self):
|
def test_ensure_namespace_existing(self):
|
||||||
with mock.patch.object(ip_lib, 'IpNetnsCommand') as ip_ns_cmd:
|
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)
|
self.netns_cmd = ip_lib.IpNetnsCommand(self.parent)
|
||||||
|
|
||||||
def test_add_namespace(self):
|
def test_add_namespace(self):
|
||||||
ns = self.netns_cmd.add('ns')
|
with mock.patch('neutron.agent.linux.utils.execute') as execute:
|
||||||
self._assert_sudo([], ('add', 'ns'), force_root_namespace=True)
|
ns = self.netns_cmd.add('ns')
|
||||||
self.assertEqual(ns.namespace, '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):
|
def test_delete_namespace(self):
|
||||||
with mock.patch('neutron.agent.linux.utils.execute'):
|
with mock.patch('neutron.agent.linux.utils.execute'):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user