Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative LLDP time #29

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/lldp_syncd/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,17 @@ def parse_time(time_str):
return sage;
}
:return: parsed age in time ticks (or seconds)
0 on invalid time_str
"""
if '-' in time_str:
return 0

days, hour_min_secs = re.split(LLDPD_UPTIME_RE_SPLIT_PATTERN, time_str)
struct_time = time.strptime(hour_min_secs, LLDPD_TIME_FORMAT)
try:
struct_time = time.strptime(hour_min_secs, LLDPD_TIME_FORMAT)
except ValueError:
logger.warning("Invalid time {}, possibly system time changed?".format(hour_min_secs))
return 0
time_delta = datetime.timedelta(days=int(days), hours=struct_time.tm_hour,
minutes=struct_time.tm_min,
seconds=struct_time.tm_sec)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_lldpSyncDaemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ def test_sync_roundtrip(self):
def test_timeparse(self):
self.assertEquals(lldp_syncd.daemon.parse_time("0 day, 05:09:02"), make_seconds(0, 5, 9, 2))
self.assertEquals(lldp_syncd.daemon.parse_time("2 days, 05:59:02"), make_seconds(2, 5, 59, 2))
self.assertEquals(lldp_syncd.daemon.parse_time("2 days, -05:-59:-02"), make_seconds(0, 0, 0, 0))
self.assertEquals(lldp_syncd.daemon.parse_time("-2 days, 05:59:02"), make_seconds(0, 0, 0, 0))
self.assertEquals(lldp_syncd.daemon.parse_time("0 days, 00:00:-02"), make_seconds(0, 0, 0, 0))
self.assertEquals(lldp_syncd.daemon.parse_time("0 days, 00:-10:00"), make_seconds(0, 0, 0, 0))

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