From 74da7dbb8451ae0d85c8f2f9ae0f6619297b227d Mon Sep 17 00:00:00 2001 From: Andrew Laski Date: Fri, 15 Feb 2013 15:07:32 -0500 Subject: Push 'Error' result from event to instance action. Currently a failed event stores an 'Error' result but in order to see which actions have failed it would require grabbing each one through the api to see the events. This patch adds 'Error' to the message field of the instance action so that any actions with failures can be seen from the initial listing of actions on an instance. Change-Id: Ieeb798c47211ab00fe5b767dc1f18a665549ba01 --- nova/db/sqlalchemy/api.py | 4 ++++ nova/tests/test_db_api.py | 44 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index eb9181fce..3057a9414 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -4654,6 +4654,10 @@ def action_event_finish(context, values): raise exception.InstanceActionEventNotFound(action_id=action['id'], event=values['event']) event_ref.update(values) + + if values['result'].lower() == 'error': + action.update({'message': 'Error'}) + return event_ref diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py index 835527219..b16fdae9e 100644 --- a/nova/tests/test_db_api.py +++ b/nova/tests/test_db_api.py @@ -724,7 +724,7 @@ class DbApiTestCase(test.TestCase): self.assertEqual('schedule', events[0]['event']) self.assertEqual(start_time, events[0]['start_time']) - def test_instance_action_event_finish(self): + def test_instance_action_event_finish_success(self): """Finish an instance action event.""" ctxt = context.get_admin_context() uuid = str(stdlib_uuid.uuid4()) @@ -748,15 +748,55 @@ class DbApiTestCase(test.TestCase): event_finish_values = {'event': 'schedule', 'request_id': ctxt.request_id, 'instance_uuid': uuid, - 'finish_time': finish_time} + 'finish_time': finish_time, + 'result': 'Success'} + db.action_event_finish(ctxt, event_finish_values) + + # Retrieve the event to ensure it was successfully added + events = db.action_events_get(ctxt, action['id']) + action = db.action_get_by_request_id(ctxt, uuid, ctxt.request_id) + self.assertEqual(1, len(events)) + self.assertEqual('schedule', events[0]['event']) + self.assertEqual(start_time, events[0]['start_time']) + self.assertEqual(finish_time, events[0]['finish_time']) + self.assertNotEqual(action['message'], 'Error') + + def test_instance_action_event_finish_error(self): + """Finish an instance action event with an error.""" + ctxt = context.get_admin_context() + uuid = str(stdlib_uuid.uuid4()) + + start_time = timeutils.utcnow() + action_values = {'action': 'run_instance', + 'instance_uuid': uuid, + 'request_id': ctxt.request_id, + 'user_id': ctxt.user_id, + 'project_id': ctxt.project_id, + 'start_time': start_time} + action = db.action_start(ctxt, action_values) + + event_values = {'event': 'schedule', + 'request_id': ctxt.request_id, + 'instance_uuid': uuid, + 'start_time': start_time} + db.action_event_start(ctxt, event_values) + + finish_time = timeutils.utcnow() + datetime.timedelta(seconds=5) + event_finish_values = {'event': 'schedule', + 'request_id': ctxt.request_id, + 'instance_uuid': uuid, + 'finish_time': finish_time, + 'result': 'Error'} db.action_event_finish(ctxt, event_finish_values) # Retrieve the event to ensure it was successfully added events = db.action_events_get(ctxt, action['id']) + action = db.action_get_by_request_id(ctxt, uuid, ctxt.request_id) self.assertEqual(1, len(events)) self.assertEqual('schedule', events[0]['event']) self.assertEqual(start_time, events[0]['start_time']) self.assertEqual(finish_time, events[0]['finish_time']) + self.assertEqual(action['message'], 'Error') def test_instance_action_and_event_start_string_time(self): """Create an instance action and event with a string start_time.""" -- cgit