Browse Source

Avoids unnecessary lock logging every loop

_notify_plugin_on_port_updates is called every loop (default - every
2 seconds), and since it has a lock, every lock aquire / release gets
logged if the debug mode is set to True. This can generate a lot of
useless logs, which will make debugging more difficult.

Change-Id: I29045da42ba03209241cc36e3cf0052ed690afc8
Closes-Bug: #1744751
Claudiu Belu 1 year ago
parent
commit
72c0fc3c3f

+ 2
- 1
networking_hyperv/neutron/agent/layer2.py View File

@@ -416,7 +416,8 @@ class Layer2Agent(base_agent.BaseAgent):
416 416
             self._utils.update_cache()
417 417
             self._refresh_cache = False
418 418
 
419
-        eventlet.spawn_n(self._notify_plugin_on_port_updates)
419
+        if self._bound_ports or self._unbound_ports:
420
+            eventlet.spawn_n(self._notify_plugin_on_port_updates)
420 421
 
421 422
         # notify plugin about port deltas
422 423
         if self._added_ports:

+ 12
- 0
networking_hyperv/tests/unit/neutron/agent/test_layer2.py View File

@@ -613,6 +613,7 @@ class TestLayer2Agent(test_base.HyperVBaseTestCase):
613 613
     def test_work(self, mock_spawn, mock_treat_dev_added,
614 614
                   mock_treat_dev_removed):
615 615
         self._agent._refresh_cache = True
616
+        self._agent._bound_ports = set([mock.sentinel.bound_port])
616 617
         self._agent._added_ports = set([mock.sentinel.bound_port])
617 618
         self._agent._removed_ports = set([mock.sentinel.unbound_port])
618 619
 
@@ -625,6 +626,17 @@ class TestLayer2Agent(test_base.HyperVBaseTestCase):
625 626
         mock_treat_dev_added.assert_called_once_with()
626 627
         mock_treat_dev_removed.assert_called_once_with()
627 628
 
629
+    @mock.patch.object(agent_base.Layer2Agent, '_treat_devices_removed')
630
+    @mock.patch.object(agent_base.Layer2Agent, '_treat_devices_added')
631
+    @mock.patch('eventlet.spawn_n')
632
+    def test_work_noop(self, mock_spawn, mock_treat_dev_added,
633
+                       mock_treat_dev_removed):
634
+        self._agent._work()
635
+
636
+        self.assertFalse(mock_spawn.called)
637
+        self.assertFalse(mock_treat_dev_added.called)
638
+        self.assertFalse(mock_treat_dev_removed.called)
639
+
628 640
     def test_port_update_not_found(self):
629 641
         self._agent._utils.vnic_port_exists.return_value = False
630 642
         port = {'id': mock.sentinel.port_id}

Loading…
Cancel
Save