summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIhar Hrachyshka <ihrachys@redhat.com>2017-04-10 12:21:41 -0700
committerIhar Hrachyshka <ihrachys@redhat.com>2017-04-13 15:03:06 -0700
commit1ae91ce9be56fd6952d53ce3f8b094a6958b2709 (patch)
treeadaff8835323bb8293ecd9346308dd1a9d143c11
parent91c15edf54c07da77ecf4fc335b0ba3951ff1f90 (diff)
ip_lib: ignore gre and lo devices in get_devices by default
This is the most common use pattern for the method, so it makes sense to make it default. (Actually, it may be that there are no usage for the arguments whatsoever, but better safe than sorry.) NeutronLibImpact this change potentially breaks callers of get_devices that may want to get the automatic devices by default. Those imaginary callers may need to set exclude_gre_devices and/or exclude_loopback to True from now on. Change-Id: Ic32b8abc7f8502b8907ae21c996e13cb8fd5401d Related-Bug: #1604115
Notes
Notes (review): Code-Review+2: Kevin Benton <kevin@benton.pub> Code-Review+2: Brian Haley <haleyb.dev@gmail.com> Workflow+1: Brian Haley <haleyb.dev@gmail.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Mon, 17 Apr 2017 18:16:02 +0000 Reviewed-on: https://review.openstack.org/455431 Project: openstack/neutron Branch: refs/heads/master
-rw-r--r--neutron/agent/l3/dvr_edge_router.py3
-rw-r--r--neutron/agent/l3/dvr_fip_ns.py3
-rw-r--r--neutron/agent/l3/dvr_snat_ns.py3
-rw-r--r--neutron/agent/l3/namespaces.py3
-rw-r--r--neutron/agent/l3/router_info.py3
-rw-r--r--neutron/agent/linux/dhcp.py3
-rw-r--r--neutron/agent/linux/ip_lib.py5
-rw-r--r--neutron/cmd/netns_cleanup.py3
-rw-r--r--neutron/tests/functional/agent/linux/test_dhcp.py11
-rw-r--r--neutron/tests/unit/agent/linux/test_ip_lib.py4
-rw-r--r--neutron/tests/unit/cmd/test_netns_cleanup.py4
11 files changed, 15 insertions, 30 deletions
diff --git a/neutron/agent/l3/dvr_edge_router.py b/neutron/agent/l3/dvr_edge_router.py
index 11f31bc..514a83a 100644
--- a/neutron/agent/l3/dvr_edge_router.py
+++ b/neutron/agent/l3/dvr_edge_router.py
@@ -251,8 +251,7 @@ class DvrEdgeRouter(dvr_local_router.DvrLocalRouter):
251 return 251 return
252 252
253 ns_ip = ip_lib.IPWrapper(namespace=self.snat_namespace.name) 253 ns_ip = ip_lib.IPWrapper(namespace=self.snat_namespace.name)
254 for d in ns_ip.get_devices(exclude_loopback=True, 254 for d in ns_ip.get_devices():
255 exclude_gre_devices=True):
256 if (d.name.startswith(router.EXTERNAL_DEV_PREFIX) and 255 if (d.name.startswith(router.EXTERNAL_DEV_PREFIX) and
257 d.name != interface_name): 256 d.name != interface_name):
258 LOG.debug('Deleting stale external router device: %s', d.name) 257 LOG.debug('Deleting stale external router device: %s', d.name)
diff --git a/neutron/agent/l3/dvr_fip_ns.py b/neutron/agent/l3/dvr_fip_ns.py
index 09c1281..f86ab4c 100644
--- a/neutron/agent/l3/dvr_fip_ns.py
+++ b/neutron/agent/l3/dvr_fip_ns.py
@@ -207,8 +207,7 @@ class FipNamespace(namespaces.Namespace):
207 @namespaces.check_ns_existence 207 @namespaces.check_ns_existence
208 def _delete(self): 208 def _delete(self):
209 ip_wrapper = ip_lib.IPWrapper(namespace=self.name) 209 ip_wrapper = ip_lib.IPWrapper(namespace=self.name)
210 for d in ip_wrapper.get_devices(exclude_loopback=True, 210 for d in ip_wrapper.get_devices():
211 exclude_gre_devices=True):
212 if d.name.startswith(FIP_2_ROUTER_DEV_PREFIX): 211 if d.name.startswith(FIP_2_ROUTER_DEV_PREFIX):
213 # internal link between IRs and FIP NS 212 # internal link between IRs and FIP NS
214 ip_wrapper.del_veth(d.name) 213 ip_wrapper.del_veth(d.name)
diff --git a/neutron/agent/l3/dvr_snat_ns.py b/neutron/agent/l3/dvr_snat_ns.py
index 085dc5c..f5f76fe 100644
--- a/neutron/agent/l3/dvr_snat_ns.py
+++ b/neutron/agent/l3/dvr_snat_ns.py
@@ -41,8 +41,7 @@ class SnatNamespace(namespaces.Namespace):
41 @namespaces.check_ns_existence 41 @namespaces.check_ns_existence
42 def delete(self): 42 def delete(self):
43 ns_ip = ip_lib.IPWrapper(namespace=self.name) 43 ns_ip = ip_lib.IPWrapper(namespace=self.name)
44 for d in ns_ip.get_devices(exclude_loopback=True, 44 for d in ns_ip.get_devices():
45 exclude_gre_devices=True):
46 if d.name.startswith(constants.SNAT_INT_DEV_PREFIX): 45 if d.name.startswith(constants.SNAT_INT_DEV_PREFIX):
47 LOG.debug('Unplugging DVR device %s', d.name) 46 LOG.debug('Unplugging DVR device %s', d.name)
48 self.driver.unplug(d.name, namespace=self.name, 47 self.driver.unplug(d.name, namespace=self.name,
diff --git a/neutron/agent/l3/namespaces.py b/neutron/agent/l3/namespaces.py
index f65c706..6db124e 100644
--- a/neutron/agent/l3/namespaces.py
+++ b/neutron/agent/l3/namespaces.py
@@ -123,8 +123,7 @@ class RouterNamespace(Namespace):
123 @check_ns_existence 123 @check_ns_existence
124 def delete(self): 124 def delete(self):
125 ns_ip = ip_lib.IPWrapper(namespace=self.name) 125 ns_ip = ip_lib.IPWrapper(namespace=self.name)
126 for d in ns_ip.get_devices(exclude_loopback=True, 126 for d in ns_ip.get_devices():
127 exclude_gre_devices=True):
128 if d.name.startswith(INTERNAL_DEV_PREFIX): 127 if d.name.startswith(INTERNAL_DEV_PREFIX):
129 # device is on default bridge 128 # device is on default bridge
130 self.driver.unplug(d.name, namespace=self.name, 129 self.driver.unplug(d.name, namespace=self.name,
diff --git a/neutron/agent/l3/router_info.py b/neutron/agent/l3/router_info.py
index 459a882..45ce625 100644
--- a/neutron/agent/l3/router_info.py
+++ b/neutron/agent/l3/router_info.py
@@ -468,8 +468,7 @@ class RouterInfo(object):
468 468
469 def _get_existing_devices(self): 469 def _get_existing_devices(self):
470 ip_wrapper = ip_lib.IPWrapper(namespace=self.ns_name) 470 ip_wrapper = ip_lib.IPWrapper(namespace=self.ns_name)
471 ip_devs = ip_wrapper.get_devices(exclude_loopback=True, 471 ip_devs = ip_wrapper.get_devices()
472 exclude_gre_devices=True)
473 return [ip_dev.name for ip_dev in ip_devs] 472 return [ip_dev.name for ip_dev in ip_devs]
474 473
475 @staticmethod 474 @staticmethod
diff --git a/neutron/agent/linux/dhcp.py b/neutron/agent/linux/dhcp.py
index 810f01f..6628a8d 100644
--- a/neutron/agent/linux/dhcp.py
+++ b/neutron/agent/linux/dhcp.py
@@ -1337,8 +1337,7 @@ class DeviceManager(object):
1337 ns_ip = ip_lib.IPWrapper(namespace=network.namespace) 1337 ns_ip = ip_lib.IPWrapper(namespace=network.namespace)
1338 if not ns_ip.netns.exists(network.namespace): 1338 if not ns_ip.netns.exists(network.namespace):
1339 return 1339 return
1340 for d in ns_ip.get_devices(exclude_loopback=True, 1340 for d in ns_ip.get_devices():
1341 exclude_gre_devices=True):
1342 # delete all devices except current active DHCP port device 1341 # delete all devices except current active DHCP port device
1343 if d.name != skip_dev_name: 1342 if d.name != skip_dev_name:
1344 LOG.debug("Found stale device %s, deleting", d.name) 1343 LOG.debug("Found stale device %s, deleting", d.name)
diff --git a/neutron/agent/linux/ip_lib.py b/neutron/agent/linux/ip_lib.py
index ff931d5..c715588 100644
--- a/neutron/agent/linux/ip_lib.py
+++ b/neutron/agent/linux/ip_lib.py
@@ -122,7 +122,7 @@ class IPWrapper(SubProcessBase):
122 def device(self, name): 122 def device(self, name):
123 return IPDevice(name, namespace=self.namespace) 123 return IPDevice(name, namespace=self.namespace)
124 124
125 def get_devices(self, exclude_loopback=False, exclude_gre_devices=False): 125 def get_devices(self, exclude_loopback=True, exclude_gre_devices=True):
126 retval = [] 126 retval = []
127 if self.namespace: 127 if self.namespace:
128 # we call out manually because in order to avoid screen scraping 128 # we call out manually because in order to avoid screen scraping
@@ -215,8 +215,7 @@ class IPWrapper(SubProcessBase):
215 return ip 215 return ip
216 216
217 def namespace_is_empty(self): 217 def namespace_is_empty(self):
218 return not self.get_devices(exclude_loopback=True, 218 return not self.get_devices()
219 exclude_gre_devices=True)
220 219
221 def garbage_collect_namespace(self): 220 def garbage_collect_namespace(self):
222 """Conditionally destroy the namespace if it is empty.""" 221 """Conditionally destroy the namespace if it is empty."""
diff --git a/neutron/cmd/netns_cleanup.py b/neutron/cmd/netns_cleanup.py
index 3729560..b16f82b 100644
--- a/neutron/cmd/netns_cleanup.py
+++ b/neutron/cmd/netns_cleanup.py
@@ -248,8 +248,7 @@ def destroy_namespace(conf, namespace, force=False):
248 # the error and continue with the cleanup 248 # the error and continue with the cleanup
249 LOG.error(_LE('Not all processes were killed in %s'), 249 LOG.error(_LE('Not all processes were killed in %s'),
250 namespace) 250 namespace)
251 for device in ip.get_devices(exclude_loopback=True, 251 for device in ip.get_devices():
252 exclude_gre_devices=True):
253 unplug_device(conf, device) 252 unplug_device(conf, device)
254 253
255 ip.garbage_collect_namespace() 254 ip.garbage_collect_namespace()
diff --git a/neutron/tests/functional/agent/linux/test_dhcp.py b/neutron/tests/functional/agent/linux/test_dhcp.py
index 6ac3bf8..f66fbc3 100644
--- a/neutron/tests/functional/agent/linux/test_dhcp.py
+++ b/neutron/tests/functional/agent/linux/test_dhcp.py
@@ -12,8 +12,6 @@
12# License for the specific language governing permissions and limitations 12# License for the specific language governing permissions and limitations
13# under the License. 13# under the License.
14 14
15import functools
16
17import mock 15import mock
18from oslo_config import cfg 16from oslo_config import cfg
19 17
@@ -77,19 +75,16 @@ class TestDhcp(functional_base.BaseSudoTestCase):
77 "10:22:33:44:55:69", 75 "10:22:33:44:55:69",
78 namespace="qdhcp-foo_id") 76 namespace="qdhcp-foo_id")
79 ipw = ip_lib.IPWrapper(namespace="qdhcp-foo_id") 77 ipw = ip_lib.IPWrapper(namespace="qdhcp-foo_id")
80 get_devices = functools.partial( 78 devices = ipw.get_devices()
81 ipw.get_devices,
82 exclude_loopback=True, exclude_gre_devices=True)
83 devices = get_devices()
84 self.addCleanup(ipw.netns.delete, 'qdhcp-foo_id') 79 self.addCleanup(ipw.netns.delete, 'qdhcp-foo_id')
85 self.assertEqual(sorted(["tapfoo_id2", "tapfoo_id3"]), 80 self.assertEqual(sorted(["tapfoo_id2", "tapfoo_id3"]),
86 sorted(map(str, devices))) 81 sorted(map(str, devices)))
87 # setting up dhcp for the network 82 # setting up dhcp for the network
88 dev_mgr.setup(tests_base.AttributeDict(network)) 83 dev_mgr.setup(tests_base.AttributeDict(network))
89 common_utils.wait_until_true( 84 common_utils.wait_until_true(
90 lambda: 1 == len(get_devices()), 85 lambda: 1 == len(ipw.get_devices()),
91 timeout=5, 86 timeout=5,
92 sleep=0.1, 87 sleep=0.1,
93 exception=RuntimeError("only one non-loopback device must remain")) 88 exception=RuntimeError("only one non-loopback device must remain"))
94 devices = get_devices() 89 devices = ipw.get_devices()
95 self.assertEqual("tapfoo_port_id", devices[0].name) 90 self.assertEqual("tapfoo_port_id", devices[0].name)
diff --git a/neutron/tests/unit/agent/linux/test_ip_lib.py b/neutron/tests/unit/agent/linux/test_ip_lib.py
index 3c0a4bc..c287b09 100644
--- a/neutron/tests/unit/agent/linux/test_ip_lib.py
+++ b/neutron/tests/unit/agent/linux/test_ip_lib.py
@@ -275,7 +275,7 @@ class TestIpWrapper(base.BaseTestCase):
275 def test_get_devices(self, mocked_listdir, mocked_islink): 275 def test_get_devices(self, mocked_listdir, mocked_islink):
276 retval = ip_lib.IPWrapper().get_devices() 276 retval = ip_lib.IPWrapper().get_devices()
277 mocked_islink.assert_called_once_with('/sys/class/net/lo') 277 mocked_islink.assert_called_once_with('/sys/class/net/lo')
278 self.assertEqual(retval, [ip_lib.IPDevice('lo')]) 278 self.assertEqual([], retval)
279 279
280 @mock.patch('neutron.agent.common.utils.execute') 280 @mock.patch('neutron.agent.common.utils.execute')
281 def test_get_devices_namespaces(self, mocked_execute): 281 def test_get_devices_namespaces(self, mocked_execute):
@@ -288,7 +288,7 @@ class TestIpWrapper(base.BaseTestCase):
288 '-maxdepth', '1', '-type', 'l', '-printf', '%f '], 288 '-maxdepth', '1', '-type', 'l', '-printf', '%f '],
289 run_as_root=True, log_fail_as_error=True) 289 run_as_root=True, log_fail_as_error=True)
290 self.assertTrue(fake_str.split.called) 290 self.assertTrue(fake_str.split.called)
291 self.assertEqual(retval, [ip_lib.IPDevice('lo', namespace='foo')]) 291 self.assertEqual([], retval)
292 292
293 @mock.patch('neutron.agent.common.utils.execute') 293 @mock.patch('neutron.agent.common.utils.execute')
294 def test_get_devices_namespaces_ns_not_exists(self, mocked_execute): 294 def test_get_devices_namespaces_ns_not_exists(self, mocked_execute):
diff --git a/neutron/tests/unit/cmd/test_netns_cleanup.py b/neutron/tests/unit/cmd/test_netns_cleanup.py
index cbf030d..5ce69fb 100644
--- a/neutron/tests/unit/cmd/test_netns_cleanup.py
+++ b/neutron/tests/unit/cmd/test_netns_cleanup.py
@@ -335,9 +335,7 @@ class TestNetnsCleanup(base.BaseTestCase):
335 if force: 335 if force:
336 expected.extend([ 336 expected.extend([
337 mock.call().netns.exists(ns), 337 mock.call().netns.exists(ns),
338 mock.call().get_devices( 338 mock.call().get_devices()])
339 exclude_loopback=True,
340 exclude_gre_devices=True)])
341 self.assertTrue(kill_dhcp.called) 339 self.assertTrue(kill_dhcp.called)
342 unplug.assert_has_calls( 340 unplug.assert_has_calls(
343 [mock.call(conf, d) for d in 341 [mock.call(conf, d) for d in