Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/lldp_syncd/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ def parse_time(time_str):
}
:return: parsed age in time ticks (or seconds)
"""
days, hour_min_secs = re.split(LLDPD_UPTIME_RE_SPLIT_PATTERN, time_str)
struct_time = time.strptime(hour_min_secs, LLDPD_TIME_FORMAT)
time_delta = datetime.timedelta(days=int(days), hours=struct_time.tm_hour,
minutes=struct_time.tm_min,
seconds=struct_time.tm_sec)
return int(time_delta.total_seconds())
try:
days, hour_min_secs = re.split(LLDPD_UPTIME_RE_SPLIT_PATTERN, time_str)
struct_time = time.strptime(hour_min_secs, LLDPD_TIME_FORMAT)
time_delta = datetime.timedelta(days=int(days), hours=struct_time.tm_hour,
minutes=struct_time.tm_min,
seconds=struct_time.tm_sec)
return int(time_delta.total_seconds())
except ValueError:
logger.exception("Failed to parse lldp age {} -- ".format(time_str))
return 0


class LldpSyncDaemon(SonicSyncDaemon):
Expand Down Expand Up @@ -264,7 +268,7 @@ def parse_update(self, lldp_json):
parsed_interfaces[if_name].update({'lldp_rem_sys_cap_enabled':
self.parse_sys_capabilities(
capability_list, enabled=True)})
if lldp_json['lldp_loc_chassis']:
if lldp_json.get('lldp_loc_chassis'):
loc_chassis_keys = ('lldp_loc_chassis_id_subtype',
'lldp_loc_chassis_id',
'lldp_loc_sys_name',
Expand Down
1 change: 1 addition & 0 deletions tests/test_lldpSyncDaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def test_sync_roundtrip(self):
def test_timeparse(self):
self.assertEqual(lldp_syncd.daemon.parse_time("0 day, 05:09:02"), make_seconds(0, 5, 9, 2))
self.assertEqual(lldp_syncd.daemon.parse_time("2 days, 05:59:02"), make_seconds(2, 5, 59, 2))
self.assertEqual(lldp_syncd.daemon.parse_time("-2 days, -23:-55:-02"), make_seconds(0, 0, 0, 0))

def parse_mgmt_ip(self, json_file):
parsed_update = self.daemon.parse_update(json_file)
Expand Down