Show UTC time in swift-recon.
It's not consistent now for example local time in replication part and UTC time at begging of line. Use _ptime in swift-recon for all time printing and this function returns UTC now. Change-Id: I732d9851db157130a08e825e8093b7e244b63e9c
This commit is contained in:
parent
0db4fa0a21
commit
edc823e803
@ -181,12 +181,12 @@ class SwiftRecon(object):
|
||||
def _ptime(self, timev=None):
|
||||
"""
|
||||
:param timev: a unix timestamp or None
|
||||
:returns: a pretty string of the current time or provided time
|
||||
:returns: a pretty string of the current time or provided time in UTC
|
||||
"""
|
||||
if timev:
|
||||
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timev))
|
||||
return time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(timev))
|
||||
else:
|
||||
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
||||
return time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())
|
||||
|
||||
def _md5_file(self, path):
|
||||
"""
|
||||
@ -495,16 +495,14 @@ class SwiftRecon(object):
|
||||
elapsed = time.time() - least_recent_time
|
||||
elapsed, elapsed_unit = seconds2timeunit(elapsed)
|
||||
print('Oldest completion was %s (%d %s ago) by %s.' % (
|
||||
time.strftime('%Y-%m-%d %H:%M:%S',
|
||||
time.gmtime(least_recent_time)),
|
||||
self._ptime(least_recent_time),
|
||||
elapsed, elapsed_unit, host))
|
||||
if most_recent_url is not None:
|
||||
host = urlparse(most_recent_url).netloc
|
||||
elapsed = time.time() - most_recent_time
|
||||
elapsed, elapsed_unit = seconds2timeunit(elapsed)
|
||||
print('Most recent completion was %s (%d %s ago) by %s.' % (
|
||||
time.strftime('%Y-%m-%d %H:%M:%S',
|
||||
time.gmtime(most_recent_time)),
|
||||
self._ptime(most_recent_time),
|
||||
elapsed, elapsed_unit, host))
|
||||
print("=" * 79)
|
||||
|
||||
@ -899,12 +897,8 @@ class SwiftRecon(object):
|
||||
continue
|
||||
if (ts_remote < ts_start or ts_remote > ts_end):
|
||||
diff = abs(ts_end - ts_remote)
|
||||
ts_end_f = time.strftime(
|
||||
"%Y-%m-%d %H:%M:%S",
|
||||
time.localtime(ts_end))
|
||||
ts_remote_f = time.strftime(
|
||||
"%Y-%m-%d %H:%M:%S",
|
||||
time.localtime(ts_remote))
|
||||
ts_end_f = self._ptime(ts_end)
|
||||
ts_remote_f = self._ptime(ts_remote)
|
||||
|
||||
print("!! %s current time is %s, but remote is %s, "
|
||||
"differs by %.2f sec" % (
|
||||
|
@ -164,17 +164,17 @@ class TestRecon(unittest.TestCase):
|
||||
self.assertEqual(stats.get('perc_none'), 25.0)
|
||||
|
||||
def test_ptime(self):
|
||||
with mock.patch('time.localtime') as mock_localtime:
|
||||
mock_localtime.return_value = time.struct_time(
|
||||
with mock.patch('time.gmtime') as mock_gmtime:
|
||||
mock_gmtime.return_value = time.struct_time(
|
||||
(2013, 12, 17, 10, 0, 0, 1, 351, 0))
|
||||
|
||||
timestamp = self.recon_instance._ptime(1387274400)
|
||||
self.assertEqual(timestamp, "2013-12-17 10:00:00")
|
||||
mock_localtime.assert_called_with(1387274400)
|
||||
mock_gmtime.assert_called_with(1387274400)
|
||||
|
||||
timestamp2 = self.recon_instance._ptime()
|
||||
self.assertEqual(timestamp2, "2013-12-17 10:00:00")
|
||||
mock_localtime.assert_called_with()
|
||||
mock_gmtime.assert_called_with()
|
||||
|
||||
def test_get_devices(self):
|
||||
ringbuilder = builder.RingBuilder(2, 3, 1)
|
||||
@ -750,11 +750,7 @@ class TestReconCommands(unittest.TestCase):
|
||||
mock.call('1/2 hosts matched, 0 error[s] while checking hosts.'),
|
||||
]
|
||||
|
||||
def mock_localtime(*args, **kwargs):
|
||||
return time.gmtime(*args, **kwargs)
|
||||
|
||||
with mock.patch("time.localtime", mock_localtime):
|
||||
cli.time_check([('127.0.0.1', 6010), ('127.0.0.1', 6020)])
|
||||
cli.time_check([('127.0.0.1', 6010), ('127.0.0.1', 6020)])
|
||||
|
||||
# We need any_order=True because the order of calls depends on the dict
|
||||
# that is returned from the recon middleware, thus can't rely on it
|
||||
|
Loading…
Reference in New Issue
Block a user