Browse Source

Fix unbound "mac" variable

There's a DEBUG trace which is using a non existent variable in
that scope and that caused a failure when DEBUG level was enabled.

Closes-Bug: #1816031
Change-Id: I6c77623bd199bcbb3f4ad46a7fee3b2fac325790
Signed-off-by: Daniel Alvarez <dalvarez@redhat.com>
Co-Authored-By: Lucas Alvares Gomes <lucasagomes@gmail.com>
tags/6.0.0.0b1
Daniel Alvarez 3 months ago
parent
commit
a61907e6e2

+ 1
- 1
networking_ovn/ml2/mech_driver.py View File

@@ -743,7 +743,7 @@ class OVNMechanismDriver(api.MechanismDriver):
743 743
                 'NAT', nat['_uuid'],
744 744
                 ('external_mac', mac)).execute(check_error=True)
745 745
         else:
746
-            LOG.debug("Clearing up external_mac of port %s", port_id, mac)
746
+            LOG.debug("Clearing up external_mac of port %s", port_id)
747 747
             self._nb_ovn.db_clear(
748 748
                 'NAT', nat['_uuid'], 'external_mac').execute(check_error=True)
749 749
 

+ 3
- 0
networking_ovn/tests/unit/fakes.py View File

@@ -135,6 +135,9 @@ class FakeOvsdbNbOvnIdl(object):
135 135
         self.nb_global = mock.Mock()
136 136
         self.db_list_rows = mock.Mock()
137 137
         self.lsp_list = mock.MagicMock()
138
+        self.db_find = mock.Mock()
139
+        self.db_set = mock.Mock()
140
+        self.db_clear = mock.Mock()
138 141
 
139 142
 
140 143
 class FakeOvsdbSbOvnIdl(object):

+ 32
- 0
networking_ovn/tests/unit/ml2/test_mech_driver.py View File

@@ -33,6 +33,7 @@ from oslo_config import cfg
33 33
 from oslo_db import exception as os_db_exc
34 34
 from oslo_serialization import jsonutils
35 35
 from oslo_utils import timeutils
36
+from oslo_utils import uuidutils
36 37
 
37 38
 from neutron.db import api  # noqa
38 39
 from neutron.db import provisioning_blocks
@@ -1445,6 +1446,37 @@ class TestOVNMechanismDriver(test_plugin.Ml2PluginV2TestCase):
1445 1446
         # shows it as "dead" instead of blowing up with an exception
1446 1447
         self.assertFalse(self.mech_driver.agent_alive(chassis, agent_type))
1447 1448
 
1449
+    def _test__update_dnat_entry_if_needed(self, up=True):
1450
+        ovn_config.cfg.CONF.set_override(
1451
+            'enable_distributed_floating_ip', True, group='ovn')
1452
+        port_id = 'fake-port-id'
1453
+        fake_ext_mac_key = 'fake-ext-mac-key'
1454
+        fake_nat_uuid = uuidutils.generate_uuid()
1455
+        nat_row = fakes.FakeOvsdbRow.create_one_ovsdb_row(
1456
+            attrs={'_uuid': fake_nat_uuid, 'external_ids': {
1457
+                ovn_const.OVN_FIP_EXT_MAC_KEY: fake_ext_mac_key}})
1458
+
1459
+        fake_db_find = mock.Mock()
1460
+        fake_db_find.execute.return_value = [nat_row]
1461
+        self.nb_ovn.db_find.return_value = fake_db_find
1462
+
1463
+        self.mech_driver._update_dnat_entry_if_needed(port_id, up=up)
1464
+
1465
+        if up:
1466
+            # Assert that we are setting the external_mac in the NAT table
1467
+            self.nb_ovn.db_set.assert_called_once_with(
1468
+                'NAT', fake_nat_uuid, ('external_mac', fake_ext_mac_key))
1469
+        else:
1470
+            # Assert that we are cleaning the external_mac from the NAT table
1471
+            self.nb_ovn.db_clear.assert_called_once_with(
1472
+                'NAT', fake_nat_uuid, 'external_mac')
1473
+
1474
+    def test__update_dnat_entry_if_needed_up(self):
1475
+        self._test__update_dnat_entry_if_needed()
1476
+
1477
+    def test__update_dnat_entry_if_needed_down(self):
1478
+        self._test__update_dnat_entry_if_needed(up=False)
1479
+
1448 1480
 
1449 1481
 class OVNMechanismDriverTestCase(test_plugin.Ml2PluginV2TestCase):
1450 1482
     _mechanism_drivers = ['logger', 'ovn']

Loading…
Cancel
Save