Skip to content

Commit 7b1671e

Browse files
silentirkralonsoh
authored andcommitted
[OVN] Update lsp host id when cr port is updated with chassis
When a chassisredirect port is updated with chassis, the PortBindingChassisEvent event would only update the binding host id in the neutron database, while it is also usefull to keep the information in the OVN database up to date with the host information. Similar to change [1], but for router's gateway ports. [1] https://review.opendev.org/c/openstack/neutron/+/896883 Other plugins that connect to the OVN database can then also rely on the information stored in the OVN DB's Closes-Bug: #2083832 Change-Id: Ibe8bda2f81bda7a89e3a994db55cd394a18decb8 (cherry picked from commit 4b032bd)
1 parent a75051c commit 7b1671e

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

neutron/services/ovn_l3/plugin.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,18 @@ def update_router_gateway_port_bindings(self, router, host):
366366
port = self._plugin.update_port(
367367
context, port['id'],
368368
{'port': {portbindings.HOST_ID: host}})
369-
369+
# Updates OVN NB database with hostname for lsp router
370+
# gateway port
371+
with self._nb_ovn.transaction(check_error=True) as txn:
372+
ext_ids = (
373+
"external_ids",
374+
{ovn_const.OVN_HOST_ID_EXT_ID_KEY: host},
375+
)
376+
txn.add(
377+
self._nb_ovn.db_set(
378+
"Logical_Switch_Port", port["id"], ext_ids
379+
)
380+
)
370381
if port['status'] != status:
371382
self._plugin.update_port_status(context, port['id'], status)
372383

neutron/tests/functional/services/ovn_l3/test_plugin.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,12 @@ def fake_select(*args, **kwargs):
443443
self.assertGreaterEqual(client_select.call_count, 3)
444444
self.assertGreaterEqual(plugin_select.call_count, 3)
445445

446+
def _find_port_binding(self, port_id):
447+
cmd = self.sb_api.db_find_rows('Port_Binding',
448+
('logical_port', '=', port_id))
449+
rows = cmd.execute(check_error=True)
450+
return rows[0] if rows else None
451+
446452
def test_router_gateway_port_binding_host_id(self):
447453
# Test setting chassis on chassisredirect port in Port_Binding table,
448454
# will update host_id of corresponding router gateway port
@@ -465,14 +471,30 @@ def test_router_gateway_port_binding_host_id(self):
465471
may_exist=True).execute(check_error=True)
466472

467473
def check_port_binding_host_id(port_id):
474+
# Get port from Neutron DB
468475
port = core_plugin.get_ports(
469476
self.context, filters={'id': [port_id]})[0]
470-
return port[portbindings.HOST_ID] == host_id
477+
# Get port from OVN DB
478+
bp = self._find_port_binding(port_id)
479+
ovn_host_id = bp.external_ids.get(ovn_const.OVN_HOST_ID_EXT_ID_KEY)
480+
return port[portbindings.HOST_ID] == host_id == ovn_host_id
471481

472482
# Test if router gateway port updated with this chassis
473483
n_utils.wait_until_true(lambda: check_port_binding_host_id(
474484
gw_port_id))
475485

486+
# Simulate failover to another chassis and check host_id in Neutron DB
487+
# and external_ids:neutron:host_id in OVN DB are updated
488+
chassis = idlutils.row_by_value(
489+
self.sb_api.idl, "Chassis", "name", self.chassis2
490+
)
491+
host_id = chassis.hostname
492+
self.sb_api.lsp_unbind(logical_port).execute(check_error=True)
493+
self.sb_api.lsp_bind(logical_port, self.chassis2).execute(
494+
check_error=True
495+
)
496+
n_utils.wait_until_true(lambda: check_port_binding_host_id(gw_port_id))
497+
476498
def _validate_router_ipv6_ra_configs(self, lrp_name, expected_ra_confs):
477499
lrp = idlutils.row_by_value(self.nb_api.idl,
478500
'Logical_Router_Port', 'name', lrp_name)

0 commit comments

Comments
 (0)