Browse Source

Check for agent restarted after checking for DVR port

This is a stable-only fix since code around the change was removed 
in master: https://review.opendev.org/#/c/641866

Commit a5244d6d44 changed the check
order so regular non-dvr ports are checked for agent restarted.
However regular ports may be unbound already, which leads to the
error in the bug description: agent_restarted check is done against
a 'None' agent.
This patch fixed logic back - only check agent_restarted for dvr ports.

This also adds some logging to have a clue why update port up/down fails.

Change-Id: I3ad59864eeb42916d2cf15a5292d5aa9484f6e91
Closes-Bug: #1835731
(cherry picked from commit c3a3031f78)
changes/65/671965/3
Oleg Bondarev 2 months ago
parent
commit
3ba9c03c05
2 changed files with 21 additions and 9 deletions
  1. 11
    9
      neutron/plugins/ml2/rpc.py
  2. 10
    0
      neutron/tests/unit/plugins/ml2/test_rpc.py

+ 11
- 9
neutron/plugins/ml2/rpc.py View File

@@ -326,11 +326,13 @@ class RpcCallbacks(type_tunnel.TunnelRpcCallbackMixin):
326 326
         # and so we don't need to update it again here. But, l2pop did not
327 327
         # handle DVR ports while restart neutron-*-agent, we need to handle
328 328
         # it here.
329
-        if agent_restarted is None:
330
-            agent_restarted = l2pop_driver.obj.agent_restarted(port_context)
331
-        if (port['device_owner'] == n_const.DEVICE_OWNER_DVR_INTERFACE and
332
-                not agent_restarted):
333
-            return
329
+        if port['device_owner'] == n_const.DEVICE_OWNER_DVR_INTERFACE:
330
+            if agent_restarted is None:
331
+                agent_restarted = l2pop_driver.obj.agent_restarted(
332
+                    port_context)
333
+            if not agent_restarted:
334
+                return
335
+
334 336
         port = port_context.current
335 337
         if (port['device_owner'] != n_const.DEVICE_OWNER_DVR_INTERFACE and
336 338
                 status == n_const.PORT_STATUS_ACTIVE and
@@ -362,9 +364,9 @@ class RpcCallbacks(type_tunnel.TunnelRpcCallbackMixin):
362 364
                         rpc_context,
363 365
                         device=device,
364 366
                         **kwargs)
365
-                except Exception:
367
+                except Exception as e:
366 368
                     failed_devices_up.append(device)
367
-                    LOG.error("Failed to update device %s up", device)
369
+                    LOG.error("Failed to update device %s up: %s", device, e)
368 370
                 else:
369 371
                     devices_up.append(device)
370 372
 
@@ -376,9 +378,9 @@ class RpcCallbacks(type_tunnel.TunnelRpcCallbackMixin):
376 378
                         rpc_context,
377 379
                         device=device,
378 380
                         **kwargs)
379
-                except Exception:
381
+                except Exception as e:
380 382
                     failed_devices_down.append(device)
381
-                    LOG.error("Failed to update device %s down", device)
383
+                    LOG.error("Failed to update device %s down: %s", device, e)
382 384
                 else:
383 385
                     devices_down.append(dev)
384 386
 

+ 10
- 0
neutron/tests/unit/plugins/ml2/test_rpc.py View File

@@ -259,6 +259,16 @@ class RpcCallbacksTestCase(base.BaseTestCase):
259 259
             mock.ANY, 'fake_port_id', constants.PORT_STATUS_DOWN,
260 260
             'fake_host')
261 261
 
262
+    def test_notify_l2pop_port_wiring_non_dvr_port(self):
263
+        port = {'device_owner': constants.DEVICE_OWNER_COMPUTE_PREFIX}
264
+        l2pop_driver = (
265
+            self.plugin.mechanism_manager.mech_drivers.get.return_value)
266
+        with mock.patch.object(ml2_db, 'get_port') as ml2_db_get_port:
267
+            ml2_db_get_port.return_value = port
268
+            self.callbacks.notify_l2pop_port_wiring(
269
+                'port_id', mock.Mock(), 'DOWN', 'host', agent_restarted=None)
270
+            self.assertFalse(l2pop_driver.obj.agent_restarted.called)
271
+
262 272
     def test_update_device_down_call_update_port_status_failed(self):
263 273
         self.plugin.update_port_status.side_effect = exc.StaleDataError
264 274
         self.assertEqual({'device': 'fake_device', 'exists': False},

Loading…
Cancel
Save