Merge "Fix key check in instance actions formatter."

This commit is contained in:
Jenkins 2013-02-20 00:54:27 +00:00 committed by Gerrit Code Review
commit 5fb2d6ef95
2 changed files with 18 additions and 7 deletions

View File

@ -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)

View File

@ -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)