diff options
author | Andrew Laski <andrew.laski@rackspace.com> | 2013-02-15 15:20:23 -0500 |
---|---|---|
committer | Andrew Laski <andrew.laski@rackspace.com> | 2013-02-19 10:06:01 -0500 |
commit | 479254f368ecfb78bf6913dc26230e378999436e (patch) | |
tree | c14cb1ade51529257bc92868e8840e123c8f1ab0 | |
parent | 6cab9c3d1c5b31284c3da5f531ab879bd27e3496 (diff) | |
download | nova-479254f368ecfb78bf6913dc26230e378999436e.tar.gz nova-479254f368ecfb78bf6913dc26230e378999436e.tar.xz nova-479254f368ecfb78bf6913dc26230e378999436e.zip |
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
-rw-r--r-- | nova/api/openstack/compute/contrib/instance_actions.py | 6 | ||||
-rw-r--r-- | nova/tests/api/openstack/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 4ab32ad4c..ecacde7bf 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 b4db5daba..8650275a7 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) |