Skip to content

Commit 5af90c6

Browse files
authored
Merge pull request #83 from stackhpc/2023.1-proper-fix-for-lb-fips
2023.1 proper fix for lb fips
2 parents 9c8b2c1 + e285374 commit 5af90c6

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,14 +1082,15 @@ def _update_dnat_entry_if_needed(self, port_id, up=True):
10821082
{ovn_const.OVN_FIP_EXT_MAC_KEY:
10831083
nat['external_mac']})).execute()
10841084

1085-
if up and ovn_conf.is_ovn_distributed_floating_ip():
1086-
mac = nat['external_ids'][ovn_const.OVN_FIP_EXT_MAC_KEY]
1087-
if nat['external_mac'] != mac:
1088-
LOG.debug("Setting external_mac of port %s to %s",
1089-
port_id, mac)
1090-
self.nb_ovn.db_set(
1091-
'NAT', nat['_uuid'], ('external_mac', mac)).execute(
1092-
check_error=True)
1085+
if ovn_conf.is_ovn_distributed_floating_ip():
1086+
if up:
1087+
mac = nat['external_ids'].get(ovn_const.OVN_FIP_EXT_MAC_KEY)
1088+
if mac and nat['external_mac'] != mac:
1089+
LOG.debug("Setting external_mac of port %s to %s",
1090+
port_id, mac)
1091+
self.nb_ovn.db_set(
1092+
'NAT', nat['_uuid'], ('external_mac', mac)).execute(
1093+
check_error=True)
10931094
else:
10941095
if nat['external_mac']:
10951096
LOG.debug("Clearing up external_mac of port %s", port_id)

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

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,14 +1175,14 @@ 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'],
11821182
resources.PORT,
11831183
provisioning_blocks.L2_AGENT_ENTITY
11841184
)
1185-
ude.assert_called_once_with(port1['port']['id'])
1185+
ude.assert_called_once_with(port1['port']['id'], False)
11861186

11871187
def test_bind_port_unsupported_vnic_type(self):
11881188
fake_port = fakes.FakePort.create_one_port(
@@ -2382,33 +2382,49 @@ def test_agent_with_nb_cfg_timestamp_not_timeout(self):
23822382
self.assertTrue(agent.alive, "Agent of type %s alive=%s" % (
23832383
agent.agent_type, agent.alive))
23842384

2385-
def _test__update_dnat_entry_if_needed(self, up=True):
2386-
ovn_conf.cfg.CONF.set_override(
2387-
'enable_distributed_floating_ip', True, group='ovn')
2385+
def _test__update_dnat_entry_if_needed(self, up=True, dvr=True):
2386+
if dvr:
2387+
ovn_conf.cfg.CONF.set_override(
2388+
'enable_distributed_floating_ip', True, group='ovn')
23882389
port_id = 'fake-port-id'
23892390
fake_ext_mac_key = 'fake-ext-mac-key'
23902391
fake_nat_uuid = uuidutils.generate_uuid()
23912392
nat_row = fakes.FakeOvsdbRow.create_one_ovsdb_row(
23922393
attrs={'_uuid': fake_nat_uuid, 'external_ids': {
23932394
ovn_const.OVN_FIP_EXT_MAC_KEY: fake_ext_mac_key},
23942395
'external_mac': 'aa:aa:aa:aa:aa:aa'})
2396+
23952397
fake_db_find = mock.Mock()
23962398
fake_db_find.execute.return_value = [nat_row]
23972399
self.nb_ovn.db_find.return_value = fake_db_find
2400+
23982401
self.mech_driver._update_dnat_entry_if_needed(port_id, up=up)
2399-
if up:
2402+
2403+
if up and dvr:
24002404
# Assert that we are setting the external_mac in the NAT table
24012405
self.nb_ovn.db_set.assert_called_once_with(
24022406
'NAT', fake_nat_uuid, ('external_mac', fake_ext_mac_key))
24032407
else:
2404-
# Assert that we are cleaning the external_mac from the NAT table
2405-
self.nb_ovn.db_clear.assert_called_once_with(
2406-
'NAT', fake_nat_uuid, 'external_mac')
2407-
def test__update_dnat_entry_if_needed_up(self):
2408+
if dvr:
2409+
self.nb_ovn.db_set.assert_not_called()
2410+
else:
2411+
# Assert that we are cleaning the external_mac from the NAT
2412+
# table
2413+
self.nb_ovn.db_clear.assert_called_once_with(
2414+
'NAT', fake_nat_uuid, 'external_mac')
2415+
2416+
def test__update_dnat_entry_if_needed_up_dvr(self):
24082417
self._test__update_dnat_entry_if_needed()
2409-
def test__update_dnat_entry_if_needed_down(self):
2418+
2419+
def test__update_dnat_entry_if_needed_up_no_dvr(self):
2420+
self._test__update_dnat_entry_if_needed(dvr=False)
2421+
2422+
def test__update_dnat_entry_if_needed_down_dvr(self):
24102423
self._test__update_dnat_entry_if_needed(up=False)
24112424

2425+
def test__update_dnat_entry_if_needed_down_no_dvr(self):
2426+
self._test__update_dnat_entry_if_needed(up=False, dvr=False)
2427+
24122428
@mock.patch('neutron.plugins.ml2.drivers.ovn.mech_driver.ovsdb.'
24132429
'ovn_client.OVNClient._get_router_ports')
24142430
def _test_update_network_fragmentation(self, new_mtu, expected_opts, grps):

0 commit comments

Comments
 (0)