54
54
INCONSISTENCY_TYPE_DELETE = 'delete'
55
55
56
56
57
- def has_lock_periodic (* args , ** kwargs ):
57
+ def has_lock_periodic (* args , periodic_run_limit = 0 , ** kwargs ):
58
58
def wrapper (f ):
59
+ _retries = 0
60
+
59
61
@functools .wraps (f )
60
62
@periodics .periodic (* args , ** kwargs )
61
63
def decorator (self , * args , ** kwargs ):
62
64
# This periodic task is included in DBInconsistenciesPeriodics
63
65
# since it uses the lock to ensure only one worker is executing
66
+ # additonally, if periodic_run_limit parameter with value > 0 is
67
+ # provided and lock is not acquired for periodic_run_limit
68
+ # times, task will not be run anymore by this maintenance worker
69
+ nonlocal _retries
64
70
if not self .has_lock :
71
+ if periodic_run_limit > 0 :
72
+ if _retries >= periodic_run_limit :
73
+ LOG .debug ("Have not been able to acquire lock to run "
74
+ "task '%s' after %s tries, limit reached. "
75
+ "No more attempts will be made." ,
76
+ f , _retries )
77
+ raise periodics .NeverAgain ()
78
+ _retries += 1
65
79
return
66
80
return f (self , * args , ** kwargs )
67
81
return decorator
@@ -481,7 +495,10 @@ def _delete_floatingip_and_pf(self, context, fip_id):
481
495
482
496
# A static spacing value is used here, but this method will only run
483
497
# once per lock due to the use of periodics.NeverAgain().
484
- @has_lock_periodic (spacing = 600 , run_immediately = True )
498
+ @has_lock_periodic (
499
+ periodic_run_limit = ovn_const .MAINTENANCE_TASK_RETRY_LIMIT ,
500
+ spacing = ovn_const .MAINTENANCE_ONE_RUN_TASK_SPACING ,
501
+ run_immediately = True )
485
502
def check_global_dhcp_opts (self ):
486
503
if (not ovn_conf .get_global_dhcpv4_opts () and
487
504
not ovn_conf .get_global_dhcpv6_opts ()):
@@ -511,7 +528,10 @@ def check_global_dhcp_opts(self):
511
528
512
529
# A static spacing value is used here, but this method will only run
513
530
# once per lock due to the use of periodics.NeverAgain().
514
- @has_lock_periodic (spacing = 600 , run_immediately = True )
531
+ @has_lock_periodic (
532
+ periodic_run_limit = ovn_const .MAINTENANCE_TASK_RETRY_LIMIT ,
533
+ spacing = ovn_const .MAINTENANCE_ONE_RUN_TASK_SPACING ,
534
+ run_immediately = True )
515
535
def check_for_igmp_snoop_support (self ):
516
536
with self ._nb_idl .transaction (check_error = True ) as txn :
517
537
value = ('true' if ovn_conf .is_igmp_snooping_enabled ()
@@ -531,7 +551,10 @@ def check_for_igmp_snoop_support(self):
531
551
# TODO(czesla): Remove this in the A+4 cycle
532
552
# A static spacing value is used here, but this method will only run
533
553
# once per lock due to the use of periodics.NeverAgain().
534
- @has_lock_periodic (spacing = 600 , run_immediately = True )
554
+ @has_lock_periodic (
555
+ periodic_run_limit = ovn_const .MAINTENANCE_TASK_RETRY_LIMIT ,
556
+ spacing = ovn_const .MAINTENANCE_ONE_RUN_TASK_SPACING ,
557
+ run_immediately = True )
535
558
def check_port_has_address_scope (self ):
536
559
ports = self ._nb_idl .db_find_rows (
537
560
"Logical_Switch_Port" , ("type" , "!=" , ovn_const .LSP_TYPE_LOCALNET )
@@ -574,7 +597,10 @@ def _delete_default_ha_chassis_group(self, txn):
574
597
575
598
# A static spacing value is used here, but this method will only run
576
599
# once per lock due to the use of periodics.NeverAgain().
577
- @has_lock_periodic (spacing = 600 , run_immediately = True )
600
+ @has_lock_periodic (
601
+ periodic_run_limit = ovn_const .MAINTENANCE_TASK_RETRY_LIMIT ,
602
+ spacing = ovn_const .MAINTENANCE_ONE_RUN_TASK_SPACING ,
603
+ run_immediately = True )
578
604
def check_for_ha_chassis_group (self ):
579
605
# If external ports is not supported stop running
580
606
# this periodic task
@@ -604,7 +630,10 @@ def check_for_ha_chassis_group(self):
604
630
# TODO(lucasagomes): Remove this in the B+3 cycle
605
631
# A static spacing value is used here, but this method will only run
606
632
# once per lock due to the use of periodics.NeverAgain().
607
- @has_lock_periodic (spacing = 600 , run_immediately = True )
633
+ @has_lock_periodic (
634
+ periodic_run_limit = ovn_const .MAINTENANCE_TASK_RETRY_LIMIT ,
635
+ spacing = ovn_const .MAINTENANCE_ONE_RUN_TASK_SPACING ,
636
+ run_immediately = True )
608
637
def check_for_mcast_flood_reports (self ):
609
638
cmds = []
610
639
for port in self ._nb_idl .lsp_list ().execute (check_error = True ):
@@ -703,7 +732,10 @@ def update_port_qos_with_external_ids_reference(self):
703
732
704
733
# A static spacing value is used here, but this method will only run
705
734
# once per lock due to the use of periodics.NeverAgain().
706
- @has_lock_periodic (spacing = 600 , run_immediately = True )
735
+ @has_lock_periodic (
736
+ periodic_run_limit = ovn_const .MAINTENANCE_TASK_RETRY_LIMIT ,
737
+ spacing = ovn_const .MAINTENANCE_ONE_RUN_TASK_SPACING ,
738
+ run_immediately = True )
707
739
def check_redirect_type_router_gateway_ports (self ):
708
740
"""Check OVN router gateway ports
709
741
Check for the option "redirect-type=bridged" value for
@@ -761,7 +793,10 @@ def check_redirect_type_router_gateway_ports(self):
761
793
762
794
# A static spacing value is used here, but this method will only run
763
795
# once per lock due to the use of periodics.NeverAgain().
764
- @has_lock_periodic (spacing = 600 , run_immediately = True )
796
+ @has_lock_periodic (
797
+ periodic_run_limit = ovn_const .MAINTENANCE_TASK_RETRY_LIMIT ,
798
+ spacing = ovn_const .MAINTENANCE_ONE_RUN_TASK_SPACING ,
799
+ run_immediately = True )
765
800
def check_vlan_distributed_ports (self ):
766
801
"""Check VLAN distributed ports
767
802
Check for the option "reside-on-redirect-chassis" value for
@@ -802,7 +837,10 @@ def check_vlan_distributed_ports(self):
802
837
# a gateway (that means, that has "external_ids:OVN_GW_PORT_EXT_ID_KEY").
803
838
# A static spacing value is used here, but this method will only run
804
839
# once per lock due to the use of periodics.NeverAgain().
805
- @has_lock_periodic (spacing = 600 , run_immediately = True )
840
+ @has_lock_periodic (
841
+ periodic_run_limit = ovn_const .MAINTENANCE_TASK_RETRY_LIMIT ,
842
+ spacing = ovn_const .MAINTENANCE_ONE_RUN_TASK_SPACING ,
843
+ run_immediately = True )
806
844
def update_logical_router_with_gateway_network_id (self ):
807
845
"""Update all OVN logical router registers with the GW network ID"""
808
846
cmds = []
@@ -829,7 +867,10 @@ def update_logical_router_with_gateway_network_id(self):
829
867
830
868
# A static spacing value is used here, but this method will only run
831
869
# once per lock due to the use of periodics.NeverAgain().
832
- @has_lock_periodic (spacing = 600 , run_immediately = True )
870
+ @has_lock_periodic (
871
+ periodic_run_limit = ovn_const .MAINTENANCE_TASK_RETRY_LIMIT ,
872
+ spacing = ovn_const .MAINTENANCE_ONE_RUN_TASK_SPACING ,
873
+ run_immediately = True )
833
874
def check_baremetal_ports_dhcp_options (self ):
834
875
"""Update baremetal ports DHCP options
835
876
@@ -912,7 +953,10 @@ def update_port_virtual_type(self):
912
953
raise periodics .NeverAgain ()
913
954
914
955
# TODO(ralonsoh): Remove this in the Antelope+4 cycle
915
- @has_lock_periodic (spacing = 600 , run_immediately = True )
956
+ @has_lock_periodic (
957
+ periodic_run_limit = ovn_const .MAINTENANCE_TASK_RETRY_LIMIT ,
958
+ spacing = ovn_const .MAINTENANCE_ONE_RUN_TASK_SPACING ,
959
+ run_immediately = True )
916
960
def create_router_extra_attributes_registers (self ):
917
961
"""Create missing ``RouterExtraAttributes`` registers.
918
962
@@ -933,7 +977,10 @@ def create_router_extra_attributes_registers(self):
933
977
raise periodics .NeverAgain ()
934
978
935
979
# TODO(slaweq): Remove this in the E cycle (C+2 as it will be next SLURP)
936
- @periodics .periodic (spacing = 600 , run_immediately = True )
980
+ @has_lock_periodic (
981
+ periodic_run_limit = ovn_const .MAINTENANCE_TASK_RETRY_LIMIT ,
982
+ spacing = ovn_const .MAINTENANCE_ONE_RUN_TASK_SPACING ,
983
+ run_immediately = True )
937
984
def add_gw_port_info_to_logical_router_port (self ):
938
985
"""Add info if LRP is connecting internal subnet or ext gateway."""
939
986
cmds = []
@@ -969,7 +1016,10 @@ def add_gw_port_info_to_logical_router_port(self):
969
1016
txn .add (cmd )
970
1017
raise periodics .NeverAgain ()
971
1018
972
- @has_lock_periodic (spacing = 600 , run_immediately = True )
1019
+ @has_lock_periodic (
1020
+ periodic_run_limit = ovn_const .MAINTENANCE_TASK_RETRY_LIMIT ,
1021
+ spacing = ovn_const .MAINTENANCE_ONE_RUN_TASK_SPACING ,
1022
+ run_immediately = True )
973
1023
def check_router_default_route_empty_dst_ip (self ):
974
1024
"""Check routers with default route with empty dst-ip (LP: #2002993).
975
1025
"""
@@ -994,7 +1044,10 @@ def check_router_default_route_empty_dst_ip(self):
994
1044
raise periodics .NeverAgain ()
995
1045
996
1046
# TODO(ralonsoh): Remove this in the Antelope+4 cycle
997
- @has_lock_periodic (spacing = 600 , run_immediately = True )
1047
+ @has_lock_periodic (
1048
+ periodic_run_limit = ovn_const .MAINTENANCE_TASK_RETRY_LIMIT ,
1049
+ spacing = ovn_const .MAINTENANCE_ONE_RUN_TASK_SPACING ,
1050
+ run_immediately = True )
998
1051
def add_vnic_type_and_pb_capabilities_to_lsp (self ):
999
1052
"""Add the port VNIC type and port binding capabilities to the LSP.
1000
1053
@@ -1026,7 +1079,10 @@ def add_vnic_type_and_pb_capabilities_to_lsp(self):
1026
1079
1027
1080
raise periodics .NeverAgain ()
1028
1081
1029
- @has_lock_periodic (spacing = 600 , run_immediately = True )
1082
+ @has_lock_periodic (
1083
+ periodic_run_limit = ovn_const .MAINTENANCE_TASK_RETRY_LIMIT ,
1084
+ spacing = ovn_const .MAINTENANCE_ONE_RUN_TASK_SPACING ,
1085
+ run_immediately = True )
1030
1086
def check_fair_meter_consistency (self ):
1031
1087
"""Update the logging meter after neutron-server reload
1032
1088
@@ -1108,7 +1164,10 @@ def cleanup_old_hash_ring_nodes(self):
1108
1164
context = n_context .get_admin_context ()
1109
1165
hash_ring_db .cleanup_old_nodes (context , days = 5 )
1110
1166
1111
- @periodics .periodic (spacing = 600 , run_immediately = True )
1167
+ @has_lock_periodic (
1168
+ periodic_run_limit = ovn_const .MAINTENANCE_TASK_RETRY_LIMIT ,
1169
+ spacing = ovn_const .MAINTENANCE_ONE_RUN_TASK_SPACING ,
1170
+ run_immediately = True )
1112
1171
def update_nat_floating_ip_with_gateway_port_reference (self ):
1113
1172
"""Set NAT rule gateway_port column to any floating IP without
1114
1173
router gateway port uuid reference - LP#2035281.
0 commit comments