@@ -16,10 +16,12 @@ import syslog
16
16
import traceback
17
17
import subprocess
18
18
import time
19
+ import warnings
19
20
import sonic_device_util
20
21
from swsssdk import ConfigDBConnector
21
22
from swsssdk import SonicV2Connector
22
23
from netaddr import IPAddress , IPNetwork
24
+ from requests .exceptions import ConnectTimeout
23
25
24
26
25
27
#
@@ -263,7 +265,7 @@ def get_vlan_addresses(vlan_interface):
263
265
ipv6_addr .append (keys [1 ].split ('/' )[0 ])
264
266
elif keys [0 ] == 'link/ether' :
265
267
mac_addr = keys [1 ]
266
- except Exception as e :
268
+ except Exception :
267
269
log_error ('failed to get %s addresses from o.s.' % vlan_interface )
268
270
pass
269
271
@@ -338,17 +340,41 @@ def construct_neighbor_advertiser_slice():
338
340
339
341
return slice_obj
340
342
343
+ def wrapped_ferret_request (request_slice , https_endpoint , http_endpoint ):
344
+ """
345
+ Attempts to reach ferret by first trying HTTPS, failing over to HTTP in
346
+ case of failure (e.g. timeout, endpoint not found, etc.).
347
+ """
348
+ response = None
349
+
350
+ # NOTE: While we transition to HTTPS we're disabling the verify field. We
351
+ # need to add a way to fetch certificates in this script ASAP.
352
+ try :
353
+ with warnings .catch_warnings ():
354
+ warnings .simplefilter ("ignore" )
355
+ response = requests .post (https_endpoint ,
356
+ json = request_slice ,
357
+ timeout = DEFAULT_REQUEST_TIMEOUT ,
358
+ verify = False )
359
+ except ConnectTimeout :
360
+ log_info ("HTTPS Ferret endpoint not found, trying HTTP..." )
361
+ response = requests .post (http_endpoint ,
362
+ json = request_slice ,
363
+ timeout = DEFAULT_REQUEST_TIMEOUT )
364
+
365
+ return response
341
366
342
367
def post_neighbor_advertiser_slice (ferret_service_vip ):
343
368
request_slice = construct_neighbor_advertiser_slice ()
344
369
save_as_json (request_slice , NEIGHBOR_ADVERTISER_REQUEST_SLICE_PATH )
345
370
346
- url = 'http://{}:85{}{}' .format (ferret_service_vip , FERRET_NEIGHBOR_ADVERTISER_API_PREFIX , get_switch_name ())
371
+ https_endpoint = 'https://{}:448{}{}' .format (ferret_service_vip , FERRET_NEIGHBOR_ADVERTISER_API_PREFIX , get_switch_name ())
372
+ http_endpoint = 'http://{}:85{}{}' .format (ferret_service_vip , FERRET_NEIGHBOR_ADVERTISER_API_PREFIX , get_switch_name ())
347
373
response = None
348
374
349
375
for retry in range (DEFAULT_FERRET_QUERY_RETRIES ):
350
376
try :
351
- response = requests . post ( url , json = request_slice , timeout = DEFAULT_REQUEST_TIMEOUT )
377
+ response = wrapped_ferret_request ( request_slice , https_endpoint , http_endpoint )
352
378
except Exception as e :
353
379
log_error ('The request failed, vip: {}, error: {}' .format (ferret_service_vip , e ))
354
380
return None
@@ -514,7 +540,7 @@ def remove_vxlan_tunnel():
514
540
515
541
516
542
def remove_vxlan_tunnel_map ():
517
- for (index , vlan_intf_name ) in enumerate (get_vlan_interfaces (), 1 ):
543
+ for (index , _ ) in enumerate (get_vlan_interfaces (), 1 ):
518
544
config_db .set_entry ('VXLAN_TUNNEL_MAP' , (VXLAN_TUNNEL_NAME , VXLAN_TUNNEL_MAP_PREFIX + str (index )), None )
519
545
520
546
0 commit comments