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
This commit is contained in:
parent
6cab9c3d1c
commit
479254f368
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user