@@ -450,6 +450,30 @@ def _check_port_host_set(self, port_id, host_id):
450
450
# Check that both neutron and ovn are the same as given host_id
451
451
return port [portbindings .HOST_ID ] == host_id == ovn_host_id
452
452
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
+
453
477
def test_virtual_port_host_update_upon_failover (self ):
454
478
# NOTE: we can't simulate traffic, but we can simulate the event that
455
479
# would've been triggered by OVN, which is what we do.
@@ -469,6 +493,7 @@ def test_virtual_port_host_update_upon_failover(self):
469
493
vip_address = vip ['fixed_ips' ][0 ]['ip_address' ]
470
494
allowed_address_pairs = [{'ip_address' : vip_address }]
471
495
self ._check_port_binding_type (vip ['id' ], '' )
496
+ self ._check_port_and_port_binding_revision_number (vip ['id' ])
472
497
473
498
# 3) Create two ports with the allowed address pairs set.
474
499
hosts = ('ovs-host1' , second_chassis_name )
@@ -485,25 +510,29 @@ def test_virtual_port_host_update_upon_failover(self):
485
510
# have been assigned to the port binding
486
511
self ._check_port_binding_type (vip ['id' ], ovn_const .LSP_TYPE_VIRTUAL )
487
512
self ._check_port_virtual_parents (vip ['id' ], ',' .join (port_ids ))
513
+ self ._check_port_and_port_binding_revision_number (vip ['id' ])
488
514
489
515
# 5) Bind the ports to a host, so a chassis is bound, which is
490
516
# required for the update_virtual_port_host method. Without this
491
517
# chassis set, it will not set a hostname in the DB's
492
518
self ._test_port_binding_and_status (ports [0 ]['id' ], 'bind' , 'ACTIVE' )
493
519
self .chassis = second_chassis
494
520
self ._test_port_binding_and_status (ports [1 ]['id' ], 'bind' , 'ACTIVE' )
521
+ self ._check_port_and_port_binding_revision_number (vip ['id' ])
495
522
496
523
# 6) For both ports, bind vip on parent and check hostname in DBs
497
524
for idx in range (len (ports )):
498
525
# Set port binding to the first port, and update the chassis
499
526
self ._set_port_binding_virtual_parent (vip ['id' ], ports [idx ]['id' ])
527
+ self ._check_port_and_port_binding_revision_number (vip ['id' ])
500
528
501
529
# Check if the host_id has been updated in OVN and DB
502
530
# by the event that eventually calls for method
503
531
# OVNMechanismDriver.update_virtual_port_host
504
532
n_utils .wait_until_true (
505
533
lambda : self ._check_port_host_set (vip ['id' ], hosts [idx ]),
506
534
timeout = 10 )
535
+ self ._check_port_and_port_binding_revision_number (vip ['id' ])
507
536
508
537
509
538
class TestNBDbMonitorOverTcp (TestNBDbMonitor ):
0 commit comments