Skip to content

Commit f0901c7

Browse files
[OVN] Bump revision number after update_virtual_port_host
This patch adds bump revision after updating the hostname of a virtual port (more specifically its associated port). This way there is no misalignment between the revision number of Neutron DB and OVN DB. It also avoids the unnecessary execution of the maintenance task to simply match the revision_number. Closes-Bug: #2069046 Change-Id: I2734984f10341ab97ebbdee11389d214bb1150f3 (cherry picked from commit f210a90)
1 parent 1098929 commit f0901c7

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,16 +1081,22 @@ def update_virtual_port_host(self, port_id, chassis_id):
10811081
hostname = ''
10821082

10831083
# Updates neutron database with hostname for virtual port
1084-
self._plugin.update_virtual_port_host(n_context.get_admin_context(),
1085-
port_id, hostname)
1086-
1084+
context = n_context.get_admin_context()
1085+
self._plugin.update_virtual_port_host(context, port_id, hostname)
1086+
db_port = self._plugin.get_port(context, port_id)
1087+
check_rev_cmd = self.nb_ovn.check_revision_number(
1088+
port_id, db_port, ovn_const.TYPE_PORTS)
10871089
# Updates OVN NB database with hostname for lsp virtual port
10881090
with self.nb_ovn.transaction(check_error=True) as txn:
10891091
ext_ids = ('external_ids',
10901092
{ovn_const.OVN_HOST_ID_EXT_ID_KEY: hostname})
10911093
txn.add(
10921094
self.nb_ovn.db_set(
10931095
'Logical_Switch_Port', port_id, ext_ids))
1096+
txn.add(check_rev_cmd)
1097+
if check_rev_cmd.result == ovn_const.TXN_COMMITTED:
1098+
ovn_revision_numbers_db.bump_revision(context, db_port,
1099+
ovn_const.TYPE_PORTS)
10941100

10951101
def get_workers(self):
10961102
"""Get any worker instances that should have their own process

neutron/tests/functional/plugins/ml2/drivers/ovn/mech_driver/ovsdb/test_ovsdb_monitor.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,30 @@ def _check_port_host_set(self, port_id, host_id):
450450
# Check that both neutron and ovn are the same as given host_id
451451
return port[portbindings.HOST_ID] == host_id == ovn_host_id
452452

453+
def _check_port_and_port_binding_revision_number(self, port_id):
454+
455+
def is_port_and_port_binding_same_revision_number(port_id):
456+
# This function checks if given port matches the revision_number
457+
# in the neutron DB as well as in the OVN DB for the port_binding
458+
core_plugin = directory.get_plugin()
459+
460+
# Get port from neutron DB
461+
port = core_plugin.get_ports(
462+
self.context, filters={'id': [port_id]})[0]
463+
464+
# Get port binding from OVN DB
465+
bp = self._find_port_binding(port_id)
466+
ovn_port_binding_revision_number = bp.external_ids.get(
467+
ovn_const.OVN_REV_NUM_EXT_ID_KEY, ovn_const.INITIAL_REV_NUM)
468+
469+
# Check that both neutron and ovn are the same as given host_id
470+
return port['revision_number'] == int(
471+
ovn_port_binding_revision_number)
472+
473+
check = functools.partial(
474+
is_port_and_port_binding_same_revision_number,port_id)
475+
n_utils.wait_until_true(check, timeout=10)
476+
453477
def test_virtual_port_host_update_upon_failover(self):
454478
# NOTE: we can't simulate traffic, but we can simulate the event that
455479
# would've been triggered by OVN, which is what we do.
@@ -469,6 +493,7 @@ def test_virtual_port_host_update_upon_failover(self):
469493
vip_address = vip['fixed_ips'][0]['ip_address']
470494
allowed_address_pairs = [{'ip_address': vip_address}]
471495
self._check_port_binding_type(vip['id'], '')
496+
self._check_port_and_port_binding_revision_number(vip['id'])
472497

473498
# 3) Create two ports with the allowed address pairs set.
474499
hosts = ('ovs-host1', second_chassis_name)
@@ -485,25 +510,29 @@ def test_virtual_port_host_update_upon_failover(self):
485510
# have been assigned to the port binding
486511
self._check_port_binding_type(vip['id'], ovn_const.LSP_TYPE_VIRTUAL)
487512
self._check_port_virtual_parents(vip['id'], ','.join(port_ids))
513+
self._check_port_and_port_binding_revision_number(vip['id'])
488514

489515
# 5) Bind the ports to a host, so a chassis is bound, which is
490516
# required for the update_virtual_port_host method. Without this
491517
# chassis set, it will not set a hostname in the DB's
492518
self._test_port_binding_and_status(ports[0]['id'], 'bind', 'ACTIVE')
493519
self.chassis = second_chassis
494520
self._test_port_binding_and_status(ports[1]['id'], 'bind', 'ACTIVE')
521+
self._check_port_and_port_binding_revision_number(vip['id'])
495522

496523
# 6) For both ports, bind vip on parent and check hostname in DBs
497524
for idx in range(len(ports)):
498525
# Set port binding to the first port, and update the chassis
499526
self._set_port_binding_virtual_parent(vip['id'], ports[idx]['id'])
527+
self._check_port_and_port_binding_revision_number(vip['id'])
500528

501529
# Check if the host_id has been updated in OVN and DB
502530
# by the event that eventually calls for method
503531
# OVNMechanismDriver.update_virtual_port_host
504532
n_utils.wait_until_true(
505533
lambda: self._check_port_host_set(vip['id'], hosts[idx]),
506534
timeout=10)
535+
self._check_port_and_port_binding_revision_number(vip['id'])
507536

508537

509538
class TestNBDbMonitorOverTcp(TestNBDbMonitor):

0 commit comments

Comments
 (0)