Skip to content

Commit 3dd9756

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "[OVN] Bump revision number after update_virtual_port_host" into stable/2023.1
2 parents 675eba6 + 2786954 commit 3dd9756

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
@@ -1055,16 +1055,22 @@ def update_virtual_port_host(self, port_id, chassis_id):
10551055
hostname = ''
10561056

10571057
# Updates neutron database with hostname for virtual port
1058-
self._plugin.update_virtual_port_host(n_context.get_admin_context(),
1059-
port_id, hostname)
1060-
1058+
context = n_context.get_admin_context()
1059+
self._plugin.update_virtual_port_host(context, port_id, hostname)
1060+
db_port = self._plugin.get_port(context, port_id)
1061+
check_rev_cmd = self.nb_ovn.check_revision_number(
1062+
port_id, db_port, ovn_const.TYPE_PORTS)
10611063
# Updates OVN NB database with hostname for lsp virtual port
10621064
with self.nb_ovn.transaction(check_error=True) as txn:
10631065
ext_ids = ('external_ids',
10641066
{ovn_const.OVN_HOST_ID_EXT_ID_KEY: hostname})
10651067
txn.add(
10661068
self.nb_ovn.db_set(
10671069
'Logical_Switch_Port', port_id, ext_ids))
1070+
txn.add(check_rev_cmd)
1071+
if check_rev_cmd.result == ovn_const.TXN_COMMITTED:
1072+
ovn_revision_numbers_db.bump_revision(context, db_port,
1073+
ovn_const.TYPE_PORTS)
10681074

10691075
def get_workers(self):
10701076
"""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
@@ -446,6 +446,30 @@ def _check_port_host_set(self, port_id, host_id):
446446
# Check that both neutron and ovn are the same as given host_id
447447
return port[portbindings.HOST_ID] == host_id == ovn_host_id
448448

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

469494
# 3) Create two ports with the allowed address pairs set.
470495
hosts = ('ovs-host1', second_chassis_name)
@@ -481,25 +506,29 @@ def test_virtual_port_host_update_upon_failover(self):
481506
# have been assigned to the port binding
482507
self._check_port_binding_type(vip['id'], ovn_const.LSP_TYPE_VIRTUAL)
483508
self._check_port_virtual_parents(vip['id'], ','.join(port_ids))
509+
self._check_port_and_port_binding_revision_number(vip['id'])
484510

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

492519
# 6) For both ports, bind vip on parent and check hostname in DBs
493520
for idx in range(len(ports)):
494521
# Set port binding to the first port, and update the chassis
495522
self._set_port_binding_virtual_parent(vip['id'], ports[idx]['id'])
523+
self._check_port_and_port_binding_revision_number(vip['id'])
496524

497525
# Check if the host_id has been updated in OVN and DB
498526
# by the event that eventually calls for method
499527
# OVNMechanismDriver.update_virtual_port_host
500528
n_utils.wait_until_true(
501529
lambda: self._check_port_host_set(vip['id'], hosts[idx]),
502530
timeout=10)
531+
self._check_port_and_port_binding_revision_number(vip['id'])
503532

504533

505534
class TestNBDbMonitorOverTcp(TestNBDbMonitor):

0 commit comments

Comments
 (0)