@@ -44,12 +44,16 @@ def parse_time(time_str):
44
44
}
45
45
:return: parsed age in time ticks (or seconds)
46
46
"""
47
- days , hour_min_secs = re .split (LLDPD_UPTIME_RE_SPLIT_PATTERN , time_str )
48
- struct_time = time .strptime (hour_min_secs , LLDPD_TIME_FORMAT )
49
- time_delta = datetime .timedelta (days = int (days ), hours = struct_time .tm_hour ,
50
- minutes = struct_time .tm_min ,
51
- seconds = struct_time .tm_sec )
52
- return int (time_delta .total_seconds ())
47
+ try :
48
+ days , hour_min_secs = re .split (LLDPD_UPTIME_RE_SPLIT_PATTERN , time_str )
49
+ struct_time = time .strptime (hour_min_secs , LLDPD_TIME_FORMAT )
50
+ time_delta = datetime .timedelta (days = int (days ), hours = struct_time .tm_hour ,
51
+ minutes = struct_time .tm_min ,
52
+ seconds = struct_time .tm_sec )
53
+ return int (time_delta .total_seconds ())
54
+ except ValueError :
55
+ logger .exception ("Failed to parse lldp age {} -- " .format (time_str ))
56
+ return 0
53
57
54
58
55
59
class LldpSyncDaemon (SonicSyncDaemon ):
@@ -264,7 +268,7 @@ def parse_update(self, lldp_json):
264
268
parsed_interfaces [if_name ].update ({'lldp_rem_sys_cap_enabled' :
265
269
self .parse_sys_capabilities (
266
270
capability_list , enabled = True )})
267
- if lldp_json [ 'lldp_loc_chassis' ] :
271
+ if lldp_json . get ( 'lldp_loc_chassis' ) :
268
272
loc_chassis_keys = ('lldp_loc_chassis_id_subtype' ,
269
273
'lldp_loc_chassis_id' ,
270
274
'lldp_loc_sys_name' ,
0 commit comments