Skip to content
Open
Changes from 1 commit
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
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@vasant17 vasant17 Sep 11, 2020

Copy link
Copy Markdown
Author

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