diff options
author | Jakub Libosvar <libosvar@redhat.com> | 2016-10-06 09:49:14 -0400 |
---|---|---|
committer | Ihar Hrachyshka <ihrachys@redhat.com> | 2017-01-09 18:57:19 +0000 |
commit | b407e927c84191d883df0c4e10cb4b63dee9eb30 (patch) | |
tree | ab0e17754310457159a85b761f3d808215bfb0a8 | |
parent | 01b82c8e5d6ae31d20995b81986c0540e60141f2 (diff) | |
download | neutron-b407e927c84191d883df0c4e10cb4b63dee9eb30.tar.gz |
Ignore gre0 and gretap0 devices in netns cleanup script.
This is tested by
http://git.openstack.org/cgit/openstack/neutron/tree/neutron/tests/functional/cmd/test_netns_cleanup.py?h=9.0.0#n49
Conflicts:
neutron/tests/unit/agent/linux/test_ip_lib.py
Change-Id: I24ac257cafc7a2617215f1072509e70e40d23fea
Closes-Bug: #1631004
(cherry picked from commit 0e5caebd452518b6be9c99248187ddc9926818ce)
-rw-r--r-- | neutron/agent/linux/ip_lib.py | 9 | ||||
-rw-r--r-- | neutron/tests/unit/agent/linux/test_ip_lib.py | 14 |
2 files changed, 18 insertions, 5 deletions
diff --git a/neutron/agent/linux/ip_lib.py b/neutron/agent/linux/ip_lib.py index e8ca9eeea2..3c9d78f2a4 100644 --- a/neutron/agent/linux/ip_lib.py +++ b/neutron/agent/linux/ip_lib.py @@ -40,6 +40,7 @@ OPTS = [ IP_NONLOCAL_BIND = 'net.ipv4.ip_nonlocal_bind' LOOPBACK_DEVNAME = 'lo' +GRE_TUNNEL_DEVICE_NAMES = ['gre0', 'gretap0'] SYS_NET_PATH = '/sys/class/net' DEFAULT_GW_PATTERN = re.compile(r"via (\S+)") @@ -118,7 +119,7 @@ class IPWrapper(SubProcessBase): def device(self, name): return IPDevice(name, namespace=self.namespace) - def get_devices(self, exclude_loopback=False): + def get_devices(self, exclude_loopback=False, exclude_gre_devices=False): retval = [] if self.namespace: # we call out manually because in order to avoid screen scraping @@ -146,7 +147,8 @@ class IPWrapper(SubProcessBase): ) for name in output: - if exclude_loopback and name == LOOPBACK_DEVNAME: + if (exclude_loopback and name == LOOPBACK_DEVNAME or + exclude_gre_devices and name in GRE_TUNNEL_DEVICE_NAMES): continue retval.append(IPDevice(name, namespace=self.namespace)) @@ -210,7 +212,8 @@ class IPWrapper(SubProcessBase): return ip def namespace_is_empty(self): - return not self.get_devices(exclude_loopback=True) + return not self.get_devices(exclude_loopback=True, + exclude_gre_devices=True) def garbage_collect_namespace(self): """Conditionally destroy the namespace if it is empty.""" diff --git a/neutron/tests/unit/agent/linux/test_ip_lib.py b/neutron/tests/unit/agent/linux/test_ip_lib.py index 99e7901d48..aea037e6ef 100644 --- a/neutron/tests/unit/agent/linux/test_ip_lib.py +++ b/neutron/tests/unit/agent/linux/test_ip_lib.py @@ -282,6 +282,16 @@ class TestIpWrapper(base.BaseTestCase): self.assertEqual(retval, [ip_lib.IPDevice('lo', namespace='foo')]) @mock.patch('neutron.agent.common.utils.execute') + def test_get_devices_exclude_loopback_and_gre(self, mocked_execute): + device_name = 'somedevice' + mocked_execute.return_value = 'lo gre0 gretap0 ' + device_name + devices = ip_lib.IPWrapper(namespace='foo').get_devices( + exclude_loopback=True, exclude_gre_devices=True) + somedevice = devices.pop() + self.assertEqual(device_name, somedevice.name) + self.assertFalse(devices) + + @mock.patch('neutron.agent.common.utils.execute') def test_get_devices_namespaces_ns_not_exists(self, mocked_execute): mocked_execute.side_effect = RuntimeError( "Cannot open network namespace") @@ -402,7 +412,7 @@ class TestIpWrapper(base.BaseTestCase): get_devices.return_value = [] self.assertTrue(ip.namespace_is_empty()) - get_devices.assert_called_once_with(exclude_loopback=True) + self.assertTrue(get_devices.called) def test_namespace_is_empty(self): ip = ip_lib.IPWrapper(namespace='ns') @@ -410,7 +420,7 @@ class TestIpWrapper(base.BaseTestCase): get_devices.return_value = [mock.Mock()] self.assertFalse(ip.namespace_is_empty()) - get_devices.assert_called_once_with(exclude_loopback=True) + self.assertTrue(get_devices.called) def test_garbage_collect_namespace_does_not_exist(self): with mock.patch.object(ip_lib, 'IpNetnsCommand') as ip_ns_cmd_cls: |