-
Notifications
You must be signed in to change notification settings - Fork 47
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,9 +43,18 @@ def parse_time(time_str): | |
return sage; | ||
} | ||
:return: parsed age in time ticks (or seconds) | ||
0 in case passed in string has negative time | ||
due to setting system clock backwards | ||
""" | ||
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("Incorrect time {}, did you change system time?".format(hour_min_secs)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd change the message to "Invalid time '{}'" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, but I would like to to keep the possible cause of system time modification as that will be a pretty good hint to the debugger. Please suggest There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But I can change "did you change system time?", to "possibly system time changed?" |
||
return 0 | ||
time_delta = datetime.timedelta(days=int(days), hours=struct_time.tm_hour, | ||
minutes=struct_time.tm_min, | ||
seconds=struct_time.tm_sec) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please change this to
0 when invalid string was found in time_str