Created
October 27, 2016 10:31
-
-
Save zioproto/926bc58873ad2638953b6436a773e113 to your computer and use it in GitHub Desktop.
neutron-liberty-namespaces-check.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/neutron/agent/linux/ip_lib.py b/neutron/agent/linux/ip_lib.py | |
| index 115686f..9b26552 100644 | |
| --- a/neutron/agent/linux/ip_lib.py | |
| +++ b/neutron/agent/linux/ip_lib.py | |
| @@ -114,16 +114,19 @@ class IPWrapper(SubProcessBase): | |
| def get_devices(self, exclude_loopback=False): | |
| retval = [] | |
| + output = [] | |
| if self.namespace: | |
| - # we call out manually because in order to avoid screen scraping | |
| - # iproute2 we use find to see what is in the sysfs directory, as | |
| - # suggested by Stephen Hemminger (iproute2 dev). | |
| - output = utils.execute(['ip', 'netns', 'exec', self.namespace, | |
| - 'find', SYS_NET_PATH, '-maxdepth', '1', | |
| - '-type', 'l', '-printf', '%f '], | |
| - run_as_root=True, | |
| - log_fail_as_error=self.log_fail_as_error | |
| - ).split() | |
| + if self.netns.exists(self.namespace): | |
| + # we call out manually because in order to avoid screen | |
| + # scraping iproute2 we use find to see what is in the sysfs | |
| + # directory, as suggested by Stephen Hemminger (iproute2 dev). | |
| + output = utils.execute(['ip', 'netns', 'exec', self.namespace, | |
| + 'find', SYS_NET_PATH, '-maxdepth', '1', | |
| + '-type', 'l', '-printf', '%f '], | |
| + run_as_root=True, | |
| + log_fail_as_error=self.log_fail_as_error | |
| + ).split() | |
| + # if self.namespace is not defined handle the default namespace devices | |
| else: | |
| output = ( | |
| i for i in os.listdir(SYS_NET_PATH) | |
| diff --git a/neutron/agent/linux/ipset_manager.py b/neutron/agent/linux/ipset_manager.py | |
| index a0fc702..b740f08 100644 | |
| --- a/neutron/agent/linux/ipset_manager.py | |
| +++ b/neutron/agent/linux/ipset_manager.py | |
| @@ -16,6 +16,7 @@ import copy | |
| import netaddr | |
| from neutron.agent.linux import utils as linux_utils | |
| +from neutron.agent.linux import ip_lib | |
| from neutron.common import utils | |
| IPSET_ADD_BULK_THRESHOLD = 5 | |
| @@ -138,9 +139,15 @@ class IpsetManager(object): | |
| cmd_ns = [] | |
| if self.namespace: | |
| cmd_ns.extend(['ip', 'netns', 'exec', self.namespace]) | |
| - cmd_ns.extend(cmd) | |
| - self.execute(cmd_ns, run_as_root=True, process_input=input, | |
| - check_exit_code=fail_on_errors) | |
| + cmd_ns.extend(cmd) | |
| + ip = ip_lib.IPWrapper() | |
| + if ip.netns.exists(self.namespace): | |
| + self.execute(cmd_ns, run_as_root=True, process_input=input, | |
| + check_exit_code=fail_on_errors) | |
| + else: | |
| + cmd_ns.extend(cmd) | |
| + self.execute(cmd_ns, run_as_root=True, process_input=input, | |
| + check_exit_code=fail_on_errors) | |
| def _get_new_set_ips(self, set_name, expected_ips): | |
| new_member_ips = (set(expected_ips) - | |
| diff --git a/neutron/tests/unit/agent/linux/test_ip_lib.py b/neutron/tests/unit/agent/linux/test_ip_lib.py | |
| index a33f36e..bf3c4f6 100644 | |
| --- a/neutron/tests/unit/agent/linux/test_ip_lib.py | |
| +++ b/neutron/tests/unit/agent/linux/test_ip_lib.py | |
| @@ -273,13 +273,15 @@ class TestIpWrapper(base.BaseTestCase): | |
| fake_str = mock.Mock() | |
| fake_str.split.return_value = ['lo'] | |
| mocked_execute.return_value = fake_str | |
| - retval = ip_lib.IPWrapper(namespace='foo').get_devices() | |
| - mocked_execute.assert_called_once_with( | |
| - ['ip', 'netns', 'exec', 'foo', 'find', '/sys/class/net', | |
| - '-maxdepth', '1', '-type', 'l', '-printf', '%f '], | |
| - run_as_root=True, log_fail_as_error=True) | |
| - self.assertTrue(fake_str.split.called) | |
| - self.assertEqual(retval, [ip_lib.IPDevice('lo', namespace='foo')]) | |
| + with mock.patch.object(ip_lib, 'IpNetnsCommand') as ip_ns_cmd: | |
| + ip_ns_cmd.exists.return_value = True | |
| + retval = ip_lib.IPWrapper(namespace='foo').get_devices() | |
| + mocked_execute.assert_called_once_with( | |
| + ['ip', 'netns', 'exec', 'foo', 'find', '/sys/class/net', | |
| + '-maxdepth', '1', '-type', 'l', '-printf', '%f '], | |
| + run_as_root=True, log_fail_as_error=True) | |
| + self.assertTrue(fake_str.split.called) | |
| + self.assertEqual(retval, [ip_lib.IPDevice('lo', namespace='foo')]) | |
| def test_get_namespaces(self): | |
| self.execute.return_value = '\n'.join(NETNS_SAMPLE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment