Fix the bug when showing event in log format

The event time displayed in log format is truncated, because the event
log formater of heatclient resolves the event_time string incorrectly.
Exchange the date and time fields splitted from event_time attribute,
and don't truncate the last character of time_date[1].

Closes-Bug: #1498283
Change-Id: If94093e2b0531a78c26ba9baeceafc19b61df5f8
This commit is contained in:
zengyingzhe 2015-09-28 18:40:25 +08:00
parent 36864381c5
commit 35dd0f21df
4 changed files with 41 additions and 12 deletions

View File

@ -102,8 +102,8 @@ def event_log_formatter(events):
event_time = getattr(event, 'event_time', '')
time_date = event_time.split('T')
try:
event_time = time_date[0]
event_date = time_date[1][:-1]
event_date = time_date[0]
event_time = time_date[1]
except IndexError:
event_time = event_date = ''

View File

@ -100,7 +100,7 @@ def mock_script_event_list(
action="CREATE", final_state="COMPLETE", fakehttp=True):
resp_dict = {"events": [
{"event_time": "2013-12-05T14:14:31Z",
{"event_time": "2013-12-05T14:14:31",
"id": rsrc_eventid1,
"links": [{"href": "http://heat.example.com:8004/foo",
"rel": "self"},
@ -113,7 +113,7 @@ def mock_script_event_list(
"resource_name": resource_name if resource_name else "testresource",
"resource_status": "%s_IN_PROGRESS" % action,
"resource_status_reason": "state changed"},
{"event_time": "2013-12-05T14:14:32Z",
{"event_time": "2013-12-05T14:14:32",
"id": rsrc_eventid2,
"links": [{"href": "http://heat.example.com:8004/foo",
"rel": "self"},
@ -133,7 +133,7 @@ def mock_script_event_list(
stack_event1 = "0159dccd-65e1-46e8-a094-697d20b009e5"
stack_event2 = "8f591a36-7190-4adb-80da-00191fe22388"
resp_dict["events"].insert(
0, {"event_time": "2013-12-05T14:14:30Z",
0, {"event_time": "2013-12-05T14:14:30",
"id": stack_event1,
"links": [{"href": "http://heat.example.com:8004/foo",
"rel": "self"},
@ -147,7 +147,7 @@ def mock_script_event_list(
"resource_status": "%s_IN_PROGRESS" % action,
"resource_status_reason": "state changed"})
resp_dict["events"].append(
{"event_time": "2013-12-05T14:14:33Z",
{"event_time": "2013-12-05T14:14:33",
"id": stack_event2,
"links": [{"href": "http://heat.example.com:8004/foo",
"rel": "self"},

View File

@ -425,8 +425,8 @@ class ShellTestNoMox(TestCase):
eventid2,
'state changed',
'CREATE_IN_PROGRESS',
'2013-12-05T14:14:31Z',
'2013-12-05T14:14:32Z',
'2013-12-05T14:14:31',
'2013-12-05T14:14:32',
]
for r in required:
@ -2923,8 +2923,8 @@ class ShellTestEvents(ShellBase):
'state changed',
'CREATE_IN_PROGRESS',
'CREATE_COMPLETE',
'2013-12-05T14:14:31Z',
'2013-12-05T14:14:32Z',
'2013-12-05T14:14:31',
'2013-12-05T14:14:32',
]
for r in required:
self.assertRegexpMatches(event_list_text, r)
@ -2953,9 +2953,9 @@ class ShellTestEvents(ShellBase):
event_list_text = self.shell('event-list {0} --format log'.format(
stack_id))
expected = '14:14:31 2013-12-05 %s [aResource]: ' \
expected = '2013-12-05 14:14:31 %s [aResource]: ' \
'CREATE_IN_PROGRESS state changed\n' \
'14:14:32 2013-12-05 %s [aResource]: CREATE_COMPLETE ' \
'2013-12-05 14:14:32 %s [aResource]: CREATE_COMPLETE ' \
'state changed\n' % (self.event_id_one, self.event_id_two)
self.assertEqual(expected, event_list_text)

View File

@ -161,6 +161,35 @@ class ShellTest(testtools.TestCase):
self.assertEqual('one\ntwo',
utils.newline_list_formatter(['one', 'two']))
def test_event_log_formatter(self):
event1 = {'event_time': '2015-09-28T12:12:12',
'id': '123456789',
'resource_name': 'res_name',
'resource_status': 'CREATE_IN_PROGRESS',
'resource_status_reason': 'CREATE started'}
event2 = {'event_time': '2015-09-28T12:12:22',
'id': '123456789',
'resource_name': 'res_name',
'resource_status': 'CREATE_COMPLETE',
'resource_status_reason': 'CREATE completed'}
events_list = [hc_res.Resource(manager=None, info=event1),
hc_res.Resource(manager=None, info=event2)]
expected = ('2015-09-28 12:12:12 123456789 [res_name]: '
'CREATE_IN_PROGRESS CREATE started\n'
'2015-09-28 12:12:22 123456789 [res_name]: '
'CREATE_COMPLETE CREATE completed')
self.assertEqual(expected, utils.event_log_formatter(events_list))
self.assertEqual('', utils.event_log_formatter([]))
notime_event = {'id': '123',
'resource_name': 'resname',
'resource_status': 'CREATE_COMPLETE',
'resource_status_reason': 'state changed'}
notime_event_list = [hc_res.Resource(manager=None, info=notime_event)]
self.assertEqual(' 123 [resname]: CREATE_COMPLETE state changed',
utils.event_log_formatter(notime_event_list))
class ShellTestParameterFiles(testtools.TestCase):