From 30cc8aa5eb86dea36d6475907ad5b95ff3ed3ba7 Mon Sep 17 00:00:00 2001 From: Andrew Laski Date: Tue, 15 Jan 2013 17:24:49 -0500 Subject: [PATCH] Record instance actions and events Record when an action is initiated on an instance, and the underlying events related to completing that action. Actions will typically occur at the API level and should match what a user intended to do with an instance. Events will typically track what happens behind the scenes and may include things that would be unclear for a user if exposed, but should be beneficial to an admin/deployer. Adds a new wrapper to the compute manager. The wrapper will record when an event begins and finishes from the point of view of the compute manager. It will also record errors if they occur. Blueprint instance-actions Change-Id: I801f3e796d091e146413f84c2ccfab95ad2e1af4 --- nova/tests/test_db_api.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py index 684f9fde..4bec5503 100644 --- a/nova/tests/test_db_api.py +++ b/nova/tests/test_db_api.py @@ -721,6 +721,34 @@ class DbApiTestCase(test.TestCase): self.assertEqual(start_time, events[0]['start_time']) self.assertEqual(finish_time, events[0]['finish_time']) + def test_instance_action_and_event_start_string_time(self): + """Create an instance action and event with a string start_time.""" + ctxt = context.get_admin_context() + uuid = str(stdlib_uuid.uuid4()) + + start_time = timeutils.utcnow() + start_time_str = timeutils.strtime(start_time) + 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_str} + action = db.action_start(ctxt, action_values) + + event_values = {'event': 'schedule', + 'instance_uuid': uuid, + 'request_id': ctxt.request_id, + 'start_time': start_time_str} + db.action_event_start(ctxt, event_values) + + # Retrieve the event to ensure it was successfully added + events = db.action_events_get(ctxt, action['id']) + self.assertEqual(1, len(events)) + self.assertEqual('schedule', events[0]['event']) + # db api still returns models with datetime, not str, values + self.assertEqual(start_time, events[0]['start_time']) + def test_instance_action_event_get_by_id(self): """Get a specific instance action event.""" ctxt1 = context.get_admin_context()