@@ -355,8 +355,11 @@ def vip_port_update_handler(self, vip_lp, fip, action):
355
355
if port :
356
356
request_info ['vip_related' ] = [
357
357
ip ['ip_address' ] for ip in port .fixed_ips ]
358
- self .add_request ({'type' : ovn_const .REQ_TYPE_HANDLE_VIP_FIP ,
359
- 'info' : request_info })
358
+ if action != ovn_const .REQ_INFO_ACTION_SYNC :
359
+ self .add_request ({'type' : ovn_const .REQ_TYPE_HANDLE_VIP_FIP ,
360
+ 'info' : request_info })
361
+ else :
362
+ self .handle_vip_fip (request_info )
360
363
361
364
def _find_lb_in_ls (self , network ):
362
365
"""Find LB associated to a Network using Network information
@@ -2966,8 +2969,13 @@ def handle_vip_fip(self, fip_info):
2966
2969
additional_vip_fip = fip_info .get ('additional_vip_fip' , False )
2967
2970
external_ids = copy .deepcopy (ovn_lb .external_ids )
2968
2971
commands = []
2972
+ need_ext_set = True
2973
+ need_hc_set = True
2969
2974
2970
- if fip_info ['action' ] == ovn_const .REQ_INFO_ACTION_ASSOCIATE :
2975
+ if fip_info ['action' ] in (
2976
+ ovn_const .REQ_INFO_ACTION_ASSOCIATE ,
2977
+ ovn_const .REQ_INFO_ACTION_SYNC
2978
+ ):
2971
2979
if additional_vip_fip :
2972
2980
existing_addi_vip_fip = external_ids .get (
2973
2981
ovn_const .LB_EXT_IDS_ADDIT_VIP_FIP_KEY , [])
@@ -2984,31 +2992,51 @@ def handle_vip_fip(self, fip_info):
2984
2992
fip_info ['vip_fip' ])
2985
2993
vip_fip_info = {
2986
2994
ovn_const .LB_EXT_IDS_VIP_FIP_KEY : fip_info ['vip_fip' ]}
2987
- commands .append (
2988
- self .ovn_nbdb_api .db_set ('Load_Balancer' , ovn_lb .uuid ,
2989
- ('external_ids' , vip_fip_info )))
2990
- for lb_hc in ovn_lb .health_check :
2991
- if self ._get_vip_lbhc (lb_hc ) in fip_info ['vip_related' ]:
2992
- vip = fip_info ['vip_fip' ]
2993
- lb_hc_external_ids = copy .deepcopy (lb_hc .external_ids )
2994
- lb_hc_external_ids [ovn_const .LB_EXT_IDS_HM_VIP ] = vip
2995
- if self ._check_lbhc_vip_format (lb_hc .vip ):
2996
- port = lb_hc .vip .rsplit (':' )[- 1 ]
2997
- vip += ':' + port
2998
- else :
2999
- vip = ''
3000
- kwargs = {
3001
- 'vip' : vip ,
3002
- 'options' : lb_hc .options ,
3003
- 'external_ids' : lb_hc_external_ids }
3004
- with self .ovn_nbdb_api .transaction (
3005
- check_error = True ) as txn :
3006
- fip_lbhc = txn .add (self .ovn_nbdb_api .db_create (
3007
- 'Load_Balancer_Health_Check' , ** kwargs ))
3008
- txn .add (self .ovn_nbdb_api .db_add (
3009
- 'Load_Balancer' , ovn_lb .uuid ,
3010
- 'health_check' , fip_lbhc ))
2995
+ if fip_info ['action' ] == ovn_const .REQ_INFO_ACTION_SYNC :
2996
+ # Don't need to trigger OVN DB set if external_ids not changed
2997
+ need_ext_set = not all (
2998
+ ovn_lb .external_ids .get (k ) ==
2999
+ v for k , v in vip_fip_info .items ()
3000
+ )
3001
+ # For sync scenario, check if FIP VIP already in health_check
3002
+ for lb_hc in ovn_lb .health_check :
3003
+ # All lbhc in health_check are already checked
3004
+ # at this stage of sync workflow in hm_purge.
3005
+ # So we should be able to just check health_check.
3006
+ if self ._get_vip_lbhc (lb_hc ) == fip_info ['vip_fip' ]:
3007
+ need_hc_set = False
3008
+ break
3009
+
3010
+ if need_ext_set :
3011
+ commands .append (
3012
+ self .ovn_nbdb_api .db_set (
3013
+ 'Load_Balancer' , ovn_lb .uuid , (
3014
+ 'external_ids' , vip_fip_info )))
3015
+
3016
+ if need_hc_set :
3017
+ for lb_hc in ovn_lb .health_check :
3018
+ if self ._get_vip_lbhc (lb_hc ) in fip_info ['vip_related' ]:
3019
+ vip = fip_info ['vip_fip' ]
3020
+ lb_hc_external_ids = copy .deepcopy (lb_hc .external_ids )
3021
+ lb_hc_external_ids [ovn_const .LB_EXT_IDS_HM_VIP ] = vip
3022
+ if self ._check_lbhc_vip_format (lb_hc .vip ):
3023
+ port = lb_hc .vip .rsplit (':' )[- 1 ]
3024
+ vip += ':' + port
3025
+ else :
3026
+ vip = ''
3027
+ kwargs = {
3028
+ 'vip' : vip ,
3029
+ 'options' : lb_hc .options ,
3030
+ 'external_ids' : lb_hc_external_ids }
3031
+ with self .ovn_nbdb_api .transaction (
3032
+ check_error = True ) as txn :
3033
+ fip_lbhc = txn .add (self .ovn_nbdb_api .db_create (
3034
+ 'Load_Balancer_Health_Check' , ** kwargs ))
3035
+ txn .add (self .ovn_nbdb_api .db_add (
3036
+ 'Load_Balancer' , ovn_lb .uuid ,
3037
+ 'health_check' , fip_lbhc ))
3011
3038
else :
3039
+ # For disassociate case
3012
3040
existing_addi_vip_fip_need_updated = False
3013
3041
existing_addi_vip_fip = external_ids .get (
3014
3042
ovn_const .LB_EXT_IDS_ADDIT_VIP_FIP_KEY , [])
@@ -3052,8 +3080,14 @@ def handle_vip_fip(self, fip_info):
3052
3080
commands .append (self .ovn_nbdb_api .db_destroy (
3053
3081
'Load_Balancer_Health_Check' , lb_hc .uuid ))
3054
3082
break
3055
-
3056
- commands .extend (self ._refresh_lb_vips (ovn_lb , external_ids ))
3083
+ commands .extend (
3084
+ self ._refresh_lb_vips (
3085
+ ovn_lb ,
3086
+ external_ids ,
3087
+ is_sync = (
3088
+ fip_info ['action' ] == ovn_const .REQ_INFO_ACTION_SYNC )
3089
+ )
3090
+ )
3057
3091
self ._execute_commands (commands )
3058
3092
3059
3093
def handle_member_dvr (self , info ):
@@ -3140,6 +3174,18 @@ def handle_member_dvr(self, info):
3140
3174
{'member' : info ['id' ],
3141
3175
'fip' : fip .external_ip })
3142
3176
3177
+ def get_lsp (self , port_id , network_id ):
3178
+ ls_name = utils .ovn_name (network_id )
3179
+ try :
3180
+ ls = self .ovn_nbdb_api .lookup ('Logical_Switch' , ls_name )
3181
+ except idlutils .RowNotFound :
3182
+ LOG .warn (f"Logical Switch { ls_name } not found." )
3183
+ return
3184
+ for port in ls .ports :
3185
+ if port_id in port .name :
3186
+ # We found particular port
3187
+ return port
3188
+
3143
3189
def _get_member_lsp (self , member_ip , member_subnet_id ):
3144
3190
neutron_client = clients .get_neutron_client ()
3145
3191
try :
@@ -3160,6 +3206,15 @@ def _get_member_lsp(self, member_ip, member_subnet_id):
3160
3206
# We found particular port
3161
3207
return port
3162
3208
3209
+ def get_fip_from_vip (self , lb ):
3210
+ neutron_client = clients .get_neutron_client ()
3211
+ try :
3212
+ return list (neutron_client .ips (port_id = lb .vip_port_id ))
3213
+ except openstack .exceptions .HttpException as e :
3214
+ LOG .warn ("Error on fetch fip for "
3215
+ f"{ lb .loadbalancer_id } "
3216
+ f"Error: { str (e )} " )
3217
+
3163
3218
def _add_lbhc (self , ovn_lb , pool_key , info ):
3164
3219
hm_id = info [constants .ID ]
3165
3220
status = {constants .ID : hm_id ,
@@ -3586,7 +3641,7 @@ def _lookup_lbhcs_by_hm_id(self, hm_id):
3586
3641
raise idlutils .RowNotFound (table = 'Load_Balancer_Health_Check' ,
3587
3642
col = 'external_ids' , match = hm_id )
3588
3643
3589
- def _find_ovn_lb_from_hm_id (self , hm_id ):
3644
+ def _find_ovn_lb_from_hm_id (self , hm_id , lbhc_vip = None ):
3590
3645
lbs = self .ovn_nbdb_api .db_list_rows (
3591
3646
'Load_Balancer' ).execute (check_error = True )
3592
3647
ovn_lb = None
@@ -3597,7 +3652,14 @@ def _find_ovn_lb_from_hm_id(self, hm_id):
3597
3652
break
3598
3653
3599
3654
try :
3600
- lbhcs = self ._lookup_lbhcs_by_hm_id (hm_id )
3655
+ lbhcs_by_hm_id = self ._lookup_lbhcs_by_hm_id (hm_id )
3656
+ if lbhc_vip :
3657
+ lbhcs = []
3658
+ for lbhc in lbhcs_by_hm_id :
3659
+ if lbhc .vip == lbhc_vip :
3660
+ lbhcs .append (lbhc )
3661
+ else :
3662
+ lbhcs = lbhcs_by_hm_id
3601
3663
except idlutils .RowNotFound :
3602
3664
LOG .debug ("Loadbalancer health check %s not found!" , hm_id )
3603
3665
return [], ovn_lb
@@ -4112,17 +4174,17 @@ def hm_purge(self, lb_id):
4112
4174
continue
4113
4175
fetch_hc_ids .extend ([str (lbhc .uuid ) for lbhc in lbhcs ])
4114
4176
4115
- for hc_id in ovn_lb .health_check :
4116
- if str (hc_id .uuid ) not in fetch_hc_ids :
4177
+ for lbhc in ovn_lb .health_check :
4178
+ if str (lbhc .uuid ) not in fetch_hc_ids :
4117
4179
commands = []
4118
4180
commands .append (
4119
4181
self .ovn_nbdb_api .db_remove (
4120
4182
'Load_Balancer' , ovn_lb .uuid ,
4121
- 'health_check' , hc_id .uuid ))
4183
+ 'health_check' , lbhc .uuid ))
4122
4184
commands .append (
4123
4185
self .ovn_nbdb_api .db_destroy (
4124
4186
'Load_Balancer_Health_Check' ,
4125
- hc_id .uuid ))
4187
+ lbhc .uuid ))
4126
4188
try :
4127
4189
self ._execute_commands (commands )
4128
4190
except idlutils .RowNotFound :
0 commit comments