Merge "Use a helper to create aggregate"

This commit is contained in:
Jenkins 2017-05-06 09:36:54 +00:00 committed by Gerrit Code Review
commit 2b4deb3b09

View File

@ -59,15 +59,20 @@ class AggregatesAdminTestJSON(base.BaseV2ComputeAdminTest):
msg += " for hypervisor_type %s" % CONF.compute.hypervisor_type
raise testtools.TestCase.failureException(msg)
def _create_test_aggregate(self, **kwargs):
if 'name' not in kwargs:
kwargs['name'] = data_utils.rand_name(self.aggregate_name_prefix)
aggregate = self.client.create_aggregate(**kwargs)['aggregate']
self.addCleanup(test_utils.call_and_ignore_notfound_exc,
self.client.delete_aggregate, aggregate['id'])
self.assertEqual(kwargs['name'], aggregate['name'])
return aggregate
@decorators.idempotent_id('0d148aa3-d54c-4317-aa8d-42040a475e20')
def test_aggregate_create_delete(self):
# Create and delete an aggregate.
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
aggregate = (self.client.create_aggregate(name=aggregate_name)
['aggregate'])
self.addCleanup(test_utils.call_and_ignore_notfound_exc,
self.client.delete_aggregate, aggregate['id'])
self.assertEqual(aggregate_name, aggregate['name'])
aggregate = self._create_test_aggregate()
self.assertIsNone(aggregate['availability_zone'])
self.client.delete_aggregate(aggregate['id'])
@ -76,13 +81,8 @@ class AggregatesAdminTestJSON(base.BaseV2ComputeAdminTest):
@decorators.idempotent_id('5873a6f8-671a-43ff-8838-7ce430bb6d0b')
def test_aggregate_create_delete_with_az(self):
# Create and delete an aggregate.
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
az_name = data_utils.rand_name(self.az_name_prefix)
aggregate = self.client.create_aggregate(
name=aggregate_name, availability_zone=az_name)['aggregate']
self.addCleanup(test_utils.call_and_ignore_notfound_exc,
self.client.delete_aggregate, aggregate['id'])
self.assertEqual(aggregate_name, aggregate['name'])
aggregate = self._create_test_aggregate(availability_zone=az_name)
self.assertEqual(az_name, aggregate['availability_zone'])
self.client.delete_aggregate(aggregate['id'])
@ -91,11 +91,7 @@ class AggregatesAdminTestJSON(base.BaseV2ComputeAdminTest):
@decorators.idempotent_id('68089c38-04b1-4758-bdf0-cf0daec4defd')
def test_aggregate_create_verify_entry_in_list(self):
# Create an aggregate and ensure it is listed.
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
aggregate = (self.client.create_aggregate(name=aggregate_name)
['aggregate'])
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
aggregate = self._create_test_aggregate()
aggregates = self.client.list_aggregates()['aggregates']
self.assertIn((aggregate['id'], aggregate['availability_zone']),
map(lambda x: (x['id'], x['availability_zone']),
@ -104,11 +100,7 @@ class AggregatesAdminTestJSON(base.BaseV2ComputeAdminTest):
@decorators.idempotent_id('36ec92ca-7a73-43bc-b920-7531809e8540')
def test_aggregate_create_update_metadata_get_details(self):
# Create an aggregate and ensure its details are returned.
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
aggregate = (self.client.create_aggregate(name=aggregate_name)
['aggregate'])
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
aggregate = self._create_test_aggregate()
body = self.client.show_aggregate(aggregate['id'])['aggregate']
self.assertEqual(aggregate['name'], body['name'])
self.assertEqual(aggregate['availability_zone'],
@ -129,11 +121,9 @@ class AggregatesAdminTestJSON(base.BaseV2ComputeAdminTest):
# Update an aggregate and ensure properties are updated correctly
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
az_name = data_utils.rand_name(self.az_name_prefix)
aggregate = self.client.create_aggregate(
name=aggregate_name, availability_zone=az_name)['aggregate']
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
aggregate = self._create_test_aggregate(
name=aggregate_name, availability_zone=az_name)
self.assertEqual(aggregate_name, aggregate['name'])
self.assertEqual(az_name, aggregate['availability_zone'])
self.assertIsNotNone(aggregate['id'])
@ -159,9 +149,7 @@ class AggregatesAdminTestJSON(base.BaseV2ComputeAdminTest):
# Add a host to the given aggregate and remove.
self.useFixture(fixtures.LockFixture('availability_zone'))
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
aggregate = (self.client.create_aggregate(name=aggregate_name)
['aggregate'])
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
aggregate = self._create_test_aggregate(name=aggregate_name)
body = (self.client.add_host(aggregate['id'], host=self.host)
['aggregate'])
@ -182,9 +170,8 @@ class AggregatesAdminTestJSON(base.BaseV2ComputeAdminTest):
# Add a host to the given aggregate and list.
self.useFixture(fixtures.LockFixture('availability_zone'))
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
aggregate = (self.client.create_aggregate(name=aggregate_name)
['aggregate'])
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
aggregate = self._create_test_aggregate(name=aggregate_name)
self.client.add_host(aggregate['id'], host=self.host)
self.addCleanup(self.client.remove_host, aggregate['id'],
host=self.host)
@ -202,9 +189,8 @@ class AggregatesAdminTestJSON(base.BaseV2ComputeAdminTest):
# Add a host to the given aggregate and get details.
self.useFixture(fixtures.LockFixture('availability_zone'))
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
aggregate = (self.client.create_aggregate(name=aggregate_name)
['aggregate'])
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
aggregate = self._create_test_aggregate(name=aggregate_name)
self.client.add_host(aggregate['id'], host=self.host)
self.addCleanup(self.client.remove_host, aggregate['id'],
host=self.host)
@ -218,11 +204,9 @@ class AggregatesAdminTestJSON(base.BaseV2ComputeAdminTest):
def test_aggregate_add_host_create_server_with_az(self):
# Add a host to the given aggregate and create a server.
self.useFixture(fixtures.LockFixture('availability_zone'))
aggregate_name = data_utils.rand_name(self.aggregate_name_prefix)
az_name = data_utils.rand_name(self.az_name_prefix)
aggregate = self.client.create_aggregate(
name=aggregate_name, availability_zone=az_name)['aggregate']
self.addCleanup(self.client.delete_aggregate, aggregate['id'])
aggregate = self._create_test_aggregate(availability_zone=az_name)
self.client.add_host(aggregate['id'], host=self.host)
self.addCleanup(self.client.remove_host, aggregate['id'],
host=self.host)