Browse Source

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
tags/11.0.0.0b2
Ihar Hrachyshka 2 years ago
parent
commit
1ae91ce9be

+ 1
- 2
neutron/agent/l3/dvr_edge_router.py View File

@@ -251,8 +251,7 @@ class DvrEdgeRouter(dvr_local_router.DvrLocalRouter):
251 251
             return
252 252
 
253 253
         ns_ip = ip_lib.IPWrapper(namespace=self.snat_namespace.name)
254
-        for d in ns_ip.get_devices(exclude_loopback=True,
255
-                                   exclude_gre_devices=True):
254
+        for d in ns_ip.get_devices():
256 255
             if (d.name.startswith(router.EXTERNAL_DEV_PREFIX) and
257 256
                     d.name != interface_name):
258 257
                 LOG.debug('Deleting stale external router device: %s', d.name)

+ 1
- 2
neutron/agent/l3/dvr_fip_ns.py View File

@@ -207,8 +207,7 @@ class FipNamespace(namespaces.Namespace):
207 207
     @namespaces.check_ns_existence
208 208
     def _delete(self):
209 209
         ip_wrapper = ip_lib.IPWrapper(namespace=self.name)
210
-        for d in ip_wrapper.get_devices(exclude_loopback=True,
211
-                                        exclude_gre_devices=True):
210
+        for d in ip_wrapper.get_devices():
212 211
             if d.name.startswith(FIP_2_ROUTER_DEV_PREFIX):
213 212
                 # internal link between IRs and FIP NS
214 213
                 ip_wrapper.del_veth(d.name)

+ 1
- 2
neutron/agent/l3/dvr_snat_ns.py View File

@@ -41,8 +41,7 @@ class SnatNamespace(namespaces.Namespace):
41 41
     @namespaces.check_ns_existence
42 42
     def delete(self):
43 43
         ns_ip = ip_lib.IPWrapper(namespace=self.name)
44
-        for d in ns_ip.get_devices(exclude_loopback=True,
45
-                                   exclude_gre_devices=True):
44
+        for d in ns_ip.get_devices():
46 45
             if d.name.startswith(constants.SNAT_INT_DEV_PREFIX):
47 46
                 LOG.debug('Unplugging DVR device %s', d.name)
48 47
                 self.driver.unplug(d.name, namespace=self.name,

+ 1
- 2
neutron/agent/l3/namespaces.py View File

@@ -123,8 +123,7 @@ class RouterNamespace(Namespace):
123 123
     @check_ns_existence
124 124
     def delete(self):
125 125
         ns_ip = ip_lib.IPWrapper(namespace=self.name)
126
-        for d in ns_ip.get_devices(exclude_loopback=True,
127
-                                   exclude_gre_devices=True):
126
+        for d in ns_ip.get_devices():
128 127
             if d.name.startswith(INTERNAL_DEV_PREFIX):
129 128
                 # device is on default bridge
130 129
                 self.driver.unplug(d.name, namespace=self.name,

+ 1
- 2
neutron/agent/l3/router_info.py View File

@@ -468,8 +468,7 @@ class RouterInfo(object):
468 468
 
469 469
     def _get_existing_devices(self):
470 470
         ip_wrapper = ip_lib.IPWrapper(namespace=self.ns_name)
471
-        ip_devs = ip_wrapper.get_devices(exclude_loopback=True,
472
-                                         exclude_gre_devices=True)
471
+        ip_devs = ip_wrapper.get_devices()
473 472
         return [ip_dev.name for ip_dev in ip_devs]
474 473
 
475 474
     @staticmethod

+ 1
- 2
neutron/agent/linux/dhcp.py View File

@@ -1337,8 +1337,7 @@ class DeviceManager(object):
1337 1337
         ns_ip = ip_lib.IPWrapper(namespace=network.namespace)
1338 1338
         if not ns_ip.netns.exists(network.namespace):
1339 1339
             return
1340
-        for d in ns_ip.get_devices(exclude_loopback=True,
1341
-                                   exclude_gre_devices=True):
1340
+        for d in ns_ip.get_devices():
1342 1341
             # delete all devices except current active DHCP port device
1343 1342
             if d.name != skip_dev_name:
1344 1343
                 LOG.debug("Found stale device %s, deleting", d.name)

+ 2
- 3
neutron/agent/linux/ip_lib.py View File

@@ -122,7 +122,7 @@ class IPWrapper(SubProcessBase):
122 122
     def device(self, name):
123 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 126
         retval = []
127 127
         if self.namespace:
128 128
             # we call out manually because in order to avoid screen scraping
@@ -215,8 +215,7 @@ class IPWrapper(SubProcessBase):
215 215
         return ip
216 216
 
217 217
     def namespace_is_empty(self):
218
-        return not self.get_devices(exclude_loopback=True,
219
-                                    exclude_gre_devices=True)
218
+        return not self.get_devices()
220 219
 
221 220
     def garbage_collect_namespace(self):
222 221
         """Conditionally destroy the namespace if it is empty."""

+ 1
- 2
neutron/cmd/netns_cleanup.py View File

@@ -248,8 +248,7 @@ def destroy_namespace(conf, namespace, force=False):
248 248
                     # the error and continue with the cleanup
249 249
                     LOG.error(_LE('Not all processes were killed in %s'),
250 250
                               namespace)
251
-                for device in ip.get_devices(exclude_loopback=True,
252
-                                             exclude_gre_devices=True):
251
+                for device in ip.get_devices():
253 252
                     unplug_device(conf, device)
254 253
 
255 254
         ip.garbage_collect_namespace()

+ 3
- 8
neutron/tests/functional/agent/linux/test_dhcp.py View File

@@ -12,8 +12,6 @@
12 12
 #    License for the specific language governing permissions and limitations
13 13
 #    under the License.
14 14
 
15
-import functools
16
-
17 15
 import mock
18 16
 from oslo_config import cfg
19 17
 
@@ -77,19 +75,16 @@ class TestDhcp(functional_base.BaseSudoTestCase):
77 75
                             "10:22:33:44:55:69",
78 76
                             namespace="qdhcp-foo_id")
79 77
         ipw = ip_lib.IPWrapper(namespace="qdhcp-foo_id")
80
-        get_devices = functools.partial(
81
-            ipw.get_devices,
82
-            exclude_loopback=True, exclude_gre_devices=True)
83
-        devices = get_devices()
78
+        devices = ipw.get_devices()
84 79
         self.addCleanup(ipw.netns.delete, 'qdhcp-foo_id')
85 80
         self.assertEqual(sorted(["tapfoo_id2", "tapfoo_id3"]),
86 81
                          sorted(map(str, devices)))
87 82
         # setting up dhcp for the network
88 83
         dev_mgr.setup(tests_base.AttributeDict(network))
89 84
         common_utils.wait_until_true(
90
-            lambda: 1 == len(get_devices()),
85
+            lambda: 1 == len(ipw.get_devices()),
91 86
             timeout=5,
92 87
             sleep=0.1,
93 88
             exception=RuntimeError("only one non-loopback device must remain"))
94
-        devices = get_devices()
89
+        devices = ipw.get_devices()
95 90
         self.assertEqual("tapfoo_port_id", devices[0].name)

+ 2
- 2
neutron/tests/unit/agent/linux/test_ip_lib.py View File

@@ -275,7 +275,7 @@ class TestIpWrapper(base.BaseTestCase):
275 275
     def test_get_devices(self, mocked_listdir, mocked_islink):
276 276
         retval = ip_lib.IPWrapper().get_devices()
277 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 280
     @mock.patch('neutron.agent.common.utils.execute')
281 281
     def test_get_devices_namespaces(self, mocked_execute):
@@ -288,7 +288,7 @@ class TestIpWrapper(base.BaseTestCase):
288 288
                  '-maxdepth', '1', '-type', 'l', '-printf', '%f '],
289 289
                 run_as_root=True, log_fail_as_error=True)
290 290
         self.assertTrue(fake_str.split.called)
291
-        self.assertEqual(retval, [ip_lib.IPDevice('lo', namespace='foo')])
291
+        self.assertEqual([], retval)
292 292
 
293 293
     @mock.patch('neutron.agent.common.utils.execute')
294 294
     def test_get_devices_namespaces_ns_not_exists(self, mocked_execute):

+ 1
- 3
neutron/tests/unit/cmd/test_netns_cleanup.py View File

@@ -335,9 +335,7 @@ class TestNetnsCleanup(base.BaseTestCase):
335 335
                         if force:
336 336
                             expected.extend([
337 337
                                 mock.call().netns.exists(ns),
338
-                                mock.call().get_devices(
339
-                                    exclude_loopback=True,
340
-                                    exclude_gre_devices=True)])
338
+                                mock.call().get_devices()])
341 339
                             self.assertTrue(kill_dhcp.called)
342 340
                             unplug.assert_has_calls(
343 341
                                 [mock.call(conf, d) for d in

Loading…
Cancel
Save