From ad0eab8bb2cb7ef50600d3a08a2c201f374304c8 Mon Sep 17 00:00:00 2001 From: Ildiko Vancsa Date: Wed, 21 Jan 2015 17:55:02 +0100 Subject: [PATCH] Fix policy validation in JSONSchema Fix the JSONSchema for server_group to include the validation of conflicting policies. The check in the create function in v3 was removed. Change-Id: I258f76adb6e5b85838bb2daae0ac25057ea8e650 Closes-Bug: #1413281 --- nova/api/openstack/compute/plugins/v3/server_groups.py | 6 ------ nova/api/openstack/compute/schemas/v3/server_groups.py | 6 ++---- .../openstack/compute/contrib/test_server_groups.py | 10 +++++++--- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/nova/api/openstack/compute/plugins/v3/server_groups.py b/nova/api/openstack/compute/plugins/v3/server_groups.py index 1389b05254e2..50b0c49cef02 100644 --- a/nova/api/openstack/compute/plugins/v3/server_groups.py +++ b/nova/api/openstack/compute/plugins/v3/server_groups.py @@ -131,12 +131,6 @@ class ServerGroupController(wsgi.Controller): """Creates a new server group.""" context = _authorize_context(req) - policies = body['server_group']['policies'] - if ('anti-affinity' in policies and - 'affinity' in policies): - msg = _("Conflicting policies configured!") - raise exc.HTTPBadRequest(explanation=msg) - quotas = objects.Quotas() try: quotas.reserve(context, project_id=context.project_id, diff --git a/nova/api/openstack/compute/schemas/v3/server_groups.py b/nova/api/openstack/compute/schemas/v3/server_groups.py index 56449d2f5393..9a2b16dbb2ae 100644 --- a/nova/api/openstack/compute/schemas/v3/server_groups.py +++ b/nova/api/openstack/compute/schemas/v3/server_groups.py @@ -29,11 +29,9 @@ create = { 'name': parameter_types.name, 'policies': { 'type': 'array', - 'items': { - 'type': 'string', 'enum': SUPPORTED_POLICIES - }, + 'items': [{'enum': SUPPORTED_POLICIES}], 'uniqueItems': True, - 'minItems': 1 + 'additionalItems': False, } }, 'required': ['name', 'policies'], diff --git a/nova/tests/unit/api/openstack/compute/contrib/test_server_groups.py b/nova/tests/unit/api/openstack/compute/contrib/test_server_groups.py index 6c48e82f2213..696421191062 100644 --- a/nova/tests/unit/api/openstack/compute/contrib/test_server_groups.py +++ b/nova/tests/unit/api/openstack/compute/contrib/test_server_groups.py @@ -93,9 +93,8 @@ class ServerGroupTestV21(test.TestCase): self.assertRaises(self.validation_error, self.controller.create, self.req, body={'server_group': sgroup}) - def test_create_server_group_normal(self): + def _create_server_group_normal(self, policies): sgroup = server_group_template() - policies = ['anti-affinity'] sgroup['policies'] = policies res_dict = self.controller.create(self.req, body={'server_group': sgroup}) @@ -103,6 +102,11 @@ class ServerGroupTestV21(test.TestCase): self.assertTrue(uuidutils.is_uuid_like(res_dict['server_group']['id'])) self.assertEqual(res_dict['server_group']['policies'], policies) + def test_create_server_group(self): + policies = ['affinity', 'anti-affinity'] + for policy in policies: + self._create_server_group_normal([policy]) + def _create_instance(self, context): instance = objects.Instance(context=context, image_ref=1, node='node1', reservation_id='a', host='host1', project_id='fake', @@ -208,7 +212,7 @@ class ServerGroupTestV21(test.TestCase): sgroup = server_group_template() policies = ['anti-affinity', 'affinity'] sgroup['policies'] = policies - self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create, + self.assertRaises(self.validation_error, self.controller.create, self.req, body={'server_group': sgroup}) def test_create_server_group_with_duplicate_policies(self):