diff --git a/nova/api/openstack/compute/schemas/aggregates.py b/nova/api/openstack/compute/schemas/aggregates.py index 52f0a6878..5283429e7 100644 --- a/nova/api/openstack/compute/schemas/aggregates.py +++ b/nova/api/openstack/compute/schemas/aggregates.py @@ -16,11 +16,11 @@ import copy from nova.api.validation import parameter_types -availability_zone = copy.deepcopy(parameter_types.name) -availability_zone['type'] = ['string', 'null'] -availability_zone_with_leading_trailing_spaces = copy.deepcopy(parameter_types. - name_with_leading_trailing_spaces) -availability_zone_with_leading_trailing_spaces['type'] = ['string', 'null'] +availability_zone = {'oneOf': [parameter_types.name, {'type': 'null'}]} +availability_zone_with_leading_trailing_spaces = { + 'oneOf': [parameter_types.name_with_leading_trailing_spaces, + {'type': 'null'}] +} create = { diff --git a/nova/tests/unit/api/openstack/compute/test_aggregates.py b/nova/tests/unit/api/openstack/compute/test_aggregates.py index f0a738777..76ce73d98 100644 --- a/nova/tests/unit/api/openstack/compute/test_aggregates.py +++ b/nova/tests/unit/api/openstack/compute/test_aggregates.py @@ -16,6 +16,7 @@ """Tests for the aggregates admin api.""" import mock +import uuid from webob import exc from nova.api.openstack.compute import aggregates as aggregates_v21 @@ -264,6 +265,19 @@ class AggregateTestCaseV21(test.NoDBTestCase): {"name": "test", "availability_zone": ""}}) + @mock.patch('nova.compute.api.AggregateAPI.create_aggregate') + def test_create_with_none_availability_zone(self, mock_create_agg): + mock_create_agg.return_value = objects.Aggregate(self.context, + name='test', + uuid=uuid.uuid4(), + hosts=[], + metadata={}) + body = {"aggregate": {"name": "test", + "availability_zone": None}} + result = self.controller.create(self.req, body=body) + mock_create_agg.assert_called_once_with(self.context, 'test', None) + self.assertEqual(result['aggregate']['name'], 'test') + def test_create_with_extra_invalid_arg(self): self.assertRaises(self.bad_request, self.controller.create, self.req, body={"name": "test", @@ -381,6 +395,21 @@ class AggregateTestCaseV21(test.NoDBTestCase): self.assertRaises(self.bad_request, self.controller.update, self.req, "2", body=test_metadata) + @mock.patch('nova.compute.api.AggregateAPI.update_aggregate') + def test_update_with_none_availability_zone(self, mock_update_agg): + agg_id = uuid.uuid4() + mock_update_agg.return_value = objects.Aggregate(self.context, + name='test', + uuid=agg_id, + hosts=[], + metadata={}) + body = {"aggregate": {"name": "test", + "availability_zone": None}} + result = self.controller.update(self.req, agg_id, body=body) + mock_update_agg.assert_called_once_with(self.context, agg_id, + body['aggregate']) + self.assertEqual(result['aggregate']['name'], 'test') + def test_update_with_bad_aggregate(self): test_metadata = {"aggregate": {"name": "test_name"}}