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
Changes from 1 commit
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
11 changes: 10 additions & 1 deletion src/lldp_syncd/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

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

"""
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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd change the message to "Invalid time '{}'"

Copy link
Author

Choose a reason for hiding this comment

The 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

Copy link
Author

@vasant17 vasant17 Sep 11, 2020

Choose a reason for hiding this comment

The 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)
Expand Down