Skip to content

Commit

Permalink
Fixes the issue where 'now' in time string does not get converted int…
Browse files Browse the repository at this point in the history
…o UTC formet if 'last' argument is provided to the contrail-logs.

Change-Id: Ibf38f1d8ae1873540a5b2967a70a03f8354b1d18
closes-bug: #1686164
  • Loading branch information
mkheni committed Apr 26, 2017
1 parent a8117f1 commit 7b7f345
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
24 changes: 13 additions & 11 deletions src/opserver/opserver_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,6 @@ def parse_start_end_time(start_time, end_time, last):
'now' in end_time:
ostart_time = start_time
oend_time = end_time
now = OpServerUtils.utc_timestamp_usec()
td = OpServerUtils.convert_to_time_delta(ostart_time[len('now'):])
if td == None:
ostart_time = now
else:
ostart_time = now + (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10 ** 6)
td = OpServerUtils.convert_to_time_delta(oend_time[len('now'):])
if td == None:
oend_time = now
else:
oend_time = now + (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10 ** 6)
elif start_time.isdigit() and \
end_time.isdigit():
ostart_time = int(start_time)
Expand All @@ -243,6 +232,19 @@ def parse_start_end_time(start_time, end_time, last):
elif ostart_time is not None and oend_time is None:
oend_time = ostart_time + OpServerUtils.DEFAULT_TIME_DELTA

if 'now' in str(ostart_time) and 'now' in str(oend_time):
now = OpServerUtils.utc_timestamp_usec()
td = OpServerUtils.convert_to_time_delta(ostart_time[len('now'):])
if td == None:
ostart_time = now
else:
ostart_time = now + (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10 ** 6)
td = OpServerUtils.convert_to_time_delta(oend_time[len('now'):])
if td == None:
oend_time = now
else:
oend_time = now + (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10 ** 6)

return ostart_time, oend_time
# end parse_start_end_time

Expand Down
4 changes: 2 additions & 2 deletions src/opserver/test/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def test_6_long_query(self):
test_num = 6

argv = sys.argv
sys.argv = "contrail-logs --start-time now-30m --end-time now".split()
sys.argv = "contrail-logs --last 25m".split()
self._querier.run()
sys.argv = argv

Expand All @@ -210,7 +210,7 @@ def test_6_long_query(self):
del query_list[i]['start_time']
del query_list[i]['end_time']
self.assertEqual(expected_result_dict, query_list[i])
self.assertEqual(int(query_list[2]['end_time']) - int(query_list[2]['start_time']),10*60*pow(10,6) - 2)
self.assertEqual(int(query_list[2]['end_time']) - int(query_list[2]['start_time']),5*60*pow(10,6) - 2)
del query_list[2]['start_time']
del query_list[2]['end_time']
self.assertEqual(expected_result_dict, query_list[2])
Expand Down

0 comments on commit 7b7f345

Please sign in to comment.