@@ -286,7 +286,7 @@ def match_fn(self, event, row, old=None):
286
286
# ``LogicalSwitchPortUpdateUpEvent`` events.
287
287
return False
288
288
289
- return bool (lsp . up )
289
+ return utils . is_lsp_enabled (lsp ) and utils . is_lsp_up ( lsp )
290
290
291
291
def run (self , event , row , old = None ):
292
292
self .driver .set_port_status_up (row .logical_port )
@@ -461,81 +461,84 @@ def run(self, event, row, old):
461
461
router , host )
462
462
463
463
464
- class LogicalSwitchPortCreateUpEvent (row_event .RowEvent ):
465
- """Row create event - Logical_Switch_Port 'up' = True .
464
+ class LogicalSwitchPortCreateEvent (row_event .RowEvent ):
465
+ """Row create event - Checks Logical_Switch_Port is UP and enabled .
466
466
467
467
On connection, we get a dump of all ports, so if there is a neutron
468
- port that is down that has since been activated, we'll catch it here.
469
- This event will not be generated for new ports getting created.
468
+ port that has been activated or deactivated, we'll catch it here.
470
469
"""
471
470
472
471
def __init__ (self , driver ):
473
472
self .driver = driver
474
473
table = 'Logical_Switch_Port'
475
474
events = (self .ROW_CREATE ,)
476
- super (LogicalSwitchPortCreateUpEvent , self ).__init__ (
477
- events , table , (('up' , '=' , True ),))
478
- self .event_name = 'LogicalSwitchPortCreateUpEvent'
475
+ super ().__init__ (events , table , [])
476
+ self .event_name = 'LogicalSwitchPortCreateEvent'
479
477
480
478
def run (self , event , row , old ):
481
- self .driver .set_port_status_up (row .name )
482
-
483
-
484
- class LogicalSwitchPortCreateDownEvent (row_event .RowEvent ):
485
- """Row create event - Logical_Switch_Port 'up' = False
486
-
487
- On connection, we get a dump of all ports, so if there is a neutron
488
- port that is up that has since been deactivated, we'll catch it here.
489
- This event will not be generated for new ports getting created.
490
- """
491
- def __init__ (self , driver ):
492
- self .driver = driver
493
- table = 'Logical_Switch_Port'
494
- events = (self .ROW_CREATE ,)
495
- super (LogicalSwitchPortCreateDownEvent , self ).__init__ (
496
- events , table , (('up' , '=' , False ),))
497
- self .event_name = 'LogicalSwitchPortCreateDownEvent'
498
-
499
- def run (self , event , row , old ):
500
- self .driver .set_port_status_down (row .name )
479
+ if utils .is_lsp_up (row ) and utils .is_lsp_enabled (row ):
480
+ self .driver .set_port_status_up (row .name )
481
+ else :
482
+ self .driver .set_port_status_down (row .name )
501
483
502
484
503
485
class LogicalSwitchPortUpdateUpEvent (row_event .RowEvent ):
504
- """Row update event - Logical_Switch_Port 'up' going from False to True
486
+ """Row update event - Logical_Switch_Port UP or enabled going True
505
487
506
488
This happens when the VM goes up.
507
- New value of Logical_Switch_Port 'up' will be True and the old value will
508
- be False.
509
489
"""
510
490
def __init__ (self , driver ):
511
491
self .driver = driver
512
492
table = 'Logical_Switch_Port'
513
493
events = (self .ROW_UPDATE ,)
514
494
super (LogicalSwitchPortUpdateUpEvent , self ).__init__ (
515
- events , table , (('up' , '=' , True ),),
516
- old_conditions = (('up' , '!=' , True ),))
495
+ events , table , None )
517
496
self .event_name = 'LogicalSwitchPortUpdateUpEvent'
518
497
498
+ def match_fn (self , event , row , old ):
499
+ if not (utils .is_lsp_up (row ) and utils .is_lsp_enabled (row )):
500
+ return False
501
+
502
+ if hasattr (old , 'up' ) and not utils .is_lsp_up (old ):
503
+ # The port has transitioned from DOWN to UP, and the admin state
504
+ # is UP (lsp.enabled=True)
505
+ return True
506
+ if hasattr (old , 'enabled' ) and not utils .is_lsp_enabled (old ):
507
+ # The user has set the admin state to UP and the port is UP too.
508
+ return True
509
+ return False
510
+
519
511
def run (self , event , row , old ):
520
512
self .driver .set_port_status_up (row .name )
521
513
522
514
523
515
class LogicalSwitchPortUpdateDownEvent (row_event .RowEvent ):
524
- """Row update event - Logical_Switch_Port 'up' going from True to False
516
+ """Row update event - Logical_Switch_Port UP or enabled going to False
525
517
526
- This happens when the VM goes down.
527
- New value of Logical_Switch_Port 'up' will be False and the old value will
528
- be True.
518
+ This happens when the VM goes down or the port is disabled.
529
519
"""
530
520
def __init__ (self , driver ):
531
521
self .driver = driver
532
522
table = 'Logical_Switch_Port'
533
523
events = (self .ROW_UPDATE ,)
534
524
super (LogicalSwitchPortUpdateDownEvent , self ).__init__ (
535
- events , table , (('up' , '=' , False ),),
536
- old_conditions = (('up' , '=' , True ),))
525
+ events , table , None )
537
526
self .event_name = 'LogicalSwitchPortUpdateDownEvent'
538
527
528
+ def match_fn (self , event , row , old ):
529
+ if (hasattr (old , 'up' ) and
530
+ utils .is_lsp_up (old ) and
531
+ not utils .is_lsp_up (row )):
532
+ # If the port goes DOWN, update the port status to DOWN.
533
+ return True
534
+ if (hasattr (old , 'enabled' ) and
535
+ utils .is_lsp_enabled (old ) and
536
+ not utils .is_lsp_enabled (row )):
537
+ # If the port is disabled by the user, update the port status to
538
+ # DOWN.
539
+ return True
540
+ return False
541
+
539
542
def run (self , event , row , old ):
540
543
self .driver .set_port_status_down (row .name )
541
544
@@ -779,12 +782,10 @@ def __init__(self, driver, remote, schema):
779
782
super (OvnNbIdl , self ).__init__ (driver , remote , schema )
780
783
self ._lsp_update_up_event = LogicalSwitchPortUpdateUpEvent (driver )
781
784
self ._lsp_update_down_event = LogicalSwitchPortUpdateDownEvent (driver )
782
- self ._lsp_create_up_event = LogicalSwitchPortCreateUpEvent (driver )
783
- self ._lsp_create_down_event = LogicalSwitchPortCreateDownEvent (driver )
785
+ self ._lsp_create_event = LogicalSwitchPortCreateEvent (driver )
784
786
self ._fip_create_delete_event = FIPAddDeleteEvent (driver )
785
787
786
- self .notify_handler .watch_events ([self ._lsp_create_up_event ,
787
- self ._lsp_create_down_event ,
788
+ self .notify_handler .watch_events ([self ._lsp_create_event ,
788
789
self ._lsp_update_up_event ,
789
790
self ._lsp_update_down_event ,
790
791
self ._fip_create_delete_event ])
@@ -804,10 +805,8 @@ def unwatch_logical_switch_port_create_events(self):
804
805
After the startup, there is no need to watch these events.
805
806
So unwatch these events.
806
807
"""
807
- self .notify_handler .unwatch_events ([self ._lsp_create_up_event ,
808
- self ._lsp_create_down_event ])
809
- self ._lsp_create_up_event = None
810
- self ._lsp_create_down_event = None
808
+ self .notify_handler .unwatch_events ([self ._lsp_create_event ])
809
+ del self ._lsp_create_event
811
810
812
811
def post_connect (self ):
813
812
self .unwatch_logical_switch_port_create_events ()
0 commit comments