diff --git a/nova/api/openstack/compute/legacy_v2/contrib/server_external_events.py b/nova/api/openstack/compute/legacy_v2/contrib/server_external_events.py index 7a015759e94d..65ba052ad73d 100644 --- a/nova/api/openstack/compute/legacy_v2/contrib/server_external_events.py +++ b/nova/api/openstack/compute/legacy_v2/contrib/server_external_events.py @@ -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') diff --git a/nova/api/openstack/compute/schemas/server_external_events.py b/nova/api/openstack/compute/schemas/server_external_events.py index 792720c4c1ee..c8c7ebdc238b 100644 --- a/nova/api/openstack/compute/schemas/server_external_events.py +++ b/nova/api/openstack/compute/schemas/server_external_events.py @@ -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, diff --git a/nova/tests/unit/api/openstack/compute/test_server_external_events.py b/nova/tests/unit/api/openstack/compute/test_server_external_events.py index 7b35c094993b..f2dddbfd3b93 100644 --- a/nova/tests/unit/api/openstack/compute/test_server_external_events.py +++ b/nova/tests/unit/api/openstack/compute/test_server_external_events.py @@ -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):