Merge "Allow aggregate create to have None as the az"

This commit is contained in:
Jenkins 2013-02-14 06:03:28 +00:00 committed by Gerrit Code Review
commit 4ffddcfa63
2 changed files with 14 additions and 1 deletions

View File

@ -2513,8 +2513,11 @@ class AggregateAPI(base.Base):
"""Creates the model for the aggregate."""
values = {"name": aggregate_name}
metadata = None
if availability_zone:
metadata = {'availability_zone': availability_zone}
aggregate = self.db.aggregate_create(context, values,
metadata={'availability_zone': availability_zone})
metadata=metadata)
aggregate = self._get_aggregate_info(context, aggregate)
# To maintain the same API result as before.
del aggregate['hosts']

View File

@ -6190,6 +6190,16 @@ class ComputeAPIAggrTestCase(BaseTestCase):
self.stubs.Set(rpc, 'call', fake_rpc_method)
self.stubs.Set(rpc, 'cast', fake_rpc_method)
def test_aggregate_no_zone(self):
# Ensure we can create an aggregate without an availability zone
aggr = self.api.create_aggregate(self.context, 'fake_aggregate',
None)
self.api.delete_aggregate(self.context, aggr['id'])
db.aggregate_get(self.context.elevated(read_deleted='yes'),
aggr['id'])
self.assertRaises(exception.AggregateNotFound,
self.api.delete_aggregate, self.context, aggr['id'])
def test_update_aggregate_metadata(self):
# Ensure metadata can be updated.
aggr = self.api.create_aggregate(self.context, 'fake_aggregate',