Skip to content

Commit 2acbbcf

Browse files
committed
Revert: Revert: Ensure traffic is not centralized if DVR is enabled
1 parent adc066b commit 2acbbcf

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

neutron/plugins/ml2/drivers/ovn/mech_driver/mech_driver.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,7 @@ def get_workers(self):
10561056
# See doc/source/design/ovn_worker.rst for more details.
10571057
return [worker.MaintenanceWorker()]
10581058

1059-
def _update_dnat_entry_if_needed(self, port_id, up=True):
1059+
def _update_dnat_entry_if_needed(self, port_id):
10601060
"""Update DNAT entry if using distributed floating ips."""
10611061
if not self.nb_ovn:
10621062
self.nb_ovn = self._ovn_client._nb_idl
@@ -1077,9 +1077,9 @@ def _update_dnat_entry_if_needed(self, port_id, up=True):
10771077
{ovn_const.OVN_FIP_EXT_MAC_KEY:
10781078
nat['external_mac']})).execute()
10791079

1080-
if up and ovn_conf.is_ovn_distributed_floating_ip():
1081-
mac = nat['external_ids'][ovn_const.OVN_FIP_EXT_MAC_KEY]
1082-
if nat['external_mac'] != mac:
1080+
if ovn_conf.is_ovn_distributed_floating_ip():
1081+
mac = nat['external_ids'].get(ovn_const.OVN_FIP_EXT_MAC_KEY)
1082+
if mac and nat['external_mac'] != mac:
10831083
LOG.debug("Setting external_mac of port %s to %s",
10841084
port_id, mac)
10851085
self.nb_ovn.db_set(
@@ -1147,7 +1147,7 @@ def set_port_status_down(self, port_id):
11471147
# to prevent another entity from bypassing the block with its own
11481148
# port status update.
11491149
LOG.info("OVN reports status down for port: %s", port_id)
1150-
self._update_dnat_entry_if_needed(port_id, False)
1150+
self._update_dnat_entry_if_needed(port_id)
11511151
admin_context = n_context.get_admin_context()
11521152
try:
11531153
db_port = ml2_db.get_port(admin_context, port_id)

neutron/tests/unit/plugins/ml2/drivers/ovn/mech_driver/test_mech_driver.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ def _test_set_port_status_down(self, is_compute_port=False):
11301130
resources.PORT,
11311131
provisioning_blocks.L2_AGENT_ENTITY
11321132
)
1133-
ude.assert_called_once_with(port1['port']['id'], False)
1133+
ude.assert_called_once_with(port1['port']['id'])
11341134

11351135
# If the port does NOT bellong to compute, do not notify Nova
11361136
# about it's status changes
@@ -1175,7 +1175,7 @@ def test_set_port_status_concurrent_delete(self):
11751175
side_effect=exc) as apc, \
11761176
mock.patch.object(self.mech_driver,
11771177
'_update_dnat_entry_if_needed') as ude:
1178-
self.mech_driver.set_port_status_down(port1['port']['id'], False)
1178+
self.mech_driver.set_port_status_down(port1['port']['id'])
11791179
apc.assert_called_once_with(
11801180
mock.ANY,
11811181
port1['port']['id'],
@@ -2376,32 +2376,40 @@ def test_agent_with_nb_cfg_timestamp_not_timeout(self):
23762376
self.assertTrue(agent.alive, "Agent of type %s alive=%s" % (
23772377
agent.agent_type, agent.alive))
23782378

2379-
def _test__update_dnat_entry_if_needed(self, up=True):
2380-
ovn_conf.cfg.CONF.set_override(
2381-
'enable_distributed_floating_ip', True, group='ovn')
2379+
def _test__update_dnat_entry_if_needed(self, dvr=True):
2380+
if dvr:
2381+
ovn_conf.cfg.CONF.set_override(
2382+
'enable_distributed_floating_ip', True, group='ovn')
23822383
port_id = 'fake-port-id'
23832384
fake_ext_mac_key = 'fake-ext-mac-key'
23842385
fake_nat_uuid = uuidutils.generate_uuid()
23852386
nat_row = fakes.FakeOvsdbRow.create_one_ovsdb_row(
23862387
attrs={'_uuid': fake_nat_uuid, 'external_ids': {
23872388
ovn_const.OVN_FIP_EXT_MAC_KEY: fake_ext_mac_key},
23882389
'external_mac': 'aa:aa:aa:aa:aa:aa'})
2390+
23892391
fake_db_find = mock.Mock()
23902392
fake_db_find.execute.return_value = [nat_row]
23912393
self.nb_ovn.db_find.return_value = fake_db_find
2392-
self.mech_driver._update_dnat_entry_if_needed(port_id, up=up)
2393-
if up:
2394+
2395+
self.mech_driver._update_dnat_entry_if_needed(port_id)
2396+
2397+
if dvr:
23942398
# Assert that we are setting the external_mac in the NAT table
23952399
self.nb_ovn.db_set.assert_called_once_with(
23962400
'NAT', fake_nat_uuid, ('external_mac', fake_ext_mac_key))
2401+
self.nb_ovn.db_clear.assert_not_called()
23972402
else:
2403+
self.nb_ovn.db_set.assert_not_called()
23982404
# Assert that we are cleaning the external_mac from the NAT table
23992405
self.nb_ovn.db_clear.assert_called_once_with(
24002406
'NAT', fake_nat_uuid, 'external_mac')
2401-
def test__update_dnat_entry_if_needed_up(self):
2407+
2408+
def test__update_dnat_entry_if_needed_dvr(self):
24022409
self._test__update_dnat_entry_if_needed()
2403-
def test__update_dnat_entry_if_needed_down(self):
2404-
self._test__update_dnat_entry_if_needed(up=False)
2410+
2411+
def test__update_dnat_entry_if_needed_no_dvr(self):
2412+
self._test__update_dnat_entry_if_needed(dvr=False)
24052413

24062414
@mock.patch('neutron.plugins.ml2.drivers.ovn.mech_driver.ovsdb.'
24072415
'ovn_client.OVNClient._get_router_ports')

0 commit comments

Comments
 (0)