From 479254f368ecfb78bf6913dc26230e378999436e Mon Sep 17 00:00:00 2001 From: Andrew Laski Date: Fri, 15 Feb 2013 15:20:23 -0500 Subject: [PATCH] Fix key check in instance actions formatter. The 'key in object' check doesn't work for sqlalchemy models so nothing was getting copied over during the format. This patch switches to using get() to retrieve a value. Bug 1126593 Change-Id: I726c2a624928247de41a077c23fe80742cbf9044 --- .../compute/contrib/instance_actions.py | 6 ++---- .../compute/contrib/test_instance_actions.py | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/nova/api/openstack/compute/contrib/instance_actions.py b/nova/api/openstack/compute/contrib/instance_actions.py index 4ab32ad4cfd9..ecacde7bf0a5 100644 --- a/nova/api/openstack/compute/contrib/instance_actions.py +++ b/nova/api/openstack/compute/contrib/instance_actions.py @@ -71,15 +71,13 @@ class InstanceActionsController(wsgi.Controller): def _format_action(self, action_raw): action = {} for key in ACTION_KEYS: - if key in action_raw: - action[key] = action_raw[key] + action[key] = action_raw.get(key) return action def _format_event(self, event_raw): event = {} for key in EVENT_KEYS: - if key in event_raw: - event[key] = event_raw[key] + event[key] = event_raw.get(key) return event @wsgi.serializers(xml=InstanceActionsTemplate) diff --git a/nova/tests/api/openstack/compute/contrib/test_instance_actions.py b/nova/tests/api/openstack/compute/contrib/test_instance_actions.py index b4db5daba1b8..8650275a7f5c 100644 --- a/nova/tests/api/openstack/compute/contrib/test_instance_actions.py +++ b/nova/tests/api/openstack/compute/contrib/test_instance_actions.py @@ -21,6 +21,7 @@ from webob import exc from nova.api.openstack.compute.contrib import instance_actions from nova import db +from nova.db.sqlalchemy import models from nova import exception from nova.openstack.common import policy from nova import test @@ -98,7 +99,12 @@ class InstanceActionsTest(test.TestCase): def test_list_actions(self): def fake_get_actions(context, uuid): - return self.fake_actions[uuid].values() + actions = [] + for act in self.fake_actions[uuid].itervalues(): + action = models.InstanceAction() + action.update(act) + actions.append(action) + return actions self.stubs.Set(db, 'actions_get', fake_get_actions) req = fakes.HTTPRequest.blank('/v2/123/servers/12/os-instance-actions') @@ -110,10 +116,17 @@ class InstanceActionsTest(test.TestCase): def test_get_action_with_events_allowed(self): def fake_get_action(context, uuid, request_id): - return self.fake_actions[uuid][request_id] + action = models.InstanceAction() + action.update(self.fake_actions[uuid][request_id]) + return action def fake_get_events(context, action_id): - return self.fake_events[action_id] + events = [] + for evt in self.fake_events[action_id]: + event = models.InstanceActionEvent() + event.update(evt) + events.append(event) + return events self.stubs.Set(db, 'action_get_by_request_id', fake_get_action) self.stubs.Set(db, 'action_events_get', fake_get_events)