Merge "Check unknown event name when create external server event"

This commit is contained in:
Jenkins 2015-09-16 11:03:10 +00:00 committed by Gerrit Code Review
commit ed637dead2
3 changed files with 14 additions and 2 deletions

View File

@ -60,6 +60,10 @@ class ServerExternalEventsController(wsgi.Controller):
raise webob.exc.HTTPBadRequest(
_('Invalid event status `%s\'') % status)
if client_event.get('name') not in external_event_obj.EVENT_NAMES:
raise webob.exc.HTTPBadRequest(
_('Invalid event name %s') % client_event.get('name'))
try:
event.instance_uuid = client_event.pop('server_uuid')
event.name = client_event.pop('name')

View File

@ -12,7 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
from nova.api.validation import parameter_types
from nova.objects import external_event as external_event_obj
create = {
@ -26,7 +25,10 @@ create = {
'server_uuid': {
'type': 'string', 'format': 'uuid'
},
'name': parameter_types.name,
'name': {
'type': 'string',
'enum': external_event_obj.EVENT_NAMES
},
'status': {
'type': 'string',
'enum': external_event_obj.EVENT_STATUSES,

View File

@ -147,6 +147,12 @@ class ServerExternalEventsTestV21(test.NoDBTestCase):
self.assertRaises(self.invalid_error,
self.api.create, self.req, body=body)
def test_create_unkown_events(self):
self.event_1['name'] = 'unkown_event'
body = {'events': self.event_1}
self.assertRaises(self.invalid_error,
self.api.create, self.req, body=body)
@mock.patch('nova.objects.instance.Instance.get_by_uuid', fake_get_by_uuid)
class ServerExternalEventsTestV2(ServerExternalEventsTestV21):