Properly create and delete Aggregates

* If deleted aggregate with same name exists, ignore it
* When delete aggregate, delete metadata as well
* Removes aggregates.name unique constraint

Fix bug 1052479

Change-Id: I430e69367bdedbf65049a5142d137ab788763ae3
This commit is contained in:
Joe Gordon
2012-09-18 23:41:44 +00:00
committed by Vishvananda Ishaya
parent c84de5b8f1
commit 888dc933df
2 changed files with 34 additions and 0 deletions

View File

@@ -605,6 +605,17 @@ class AggregateDBApiTestCase(test.TestCase):
expected_metadata = db.aggregate_metadata_get(ctxt, result['id'])
self.assertDictMatch(expected_metadata, _get_fake_aggr_metadata())
def test_aggregate_create_delete_create_with_metadata(self):
"""Ensure aggregate metadata is deleted bug 1052479."""
ctxt = context.get_admin_context()
result = _create_aggregate(context=ctxt)
expected_metadata = db.aggregate_metadata_get(ctxt, result['id'])
self.assertDictMatch(expected_metadata, _get_fake_aggr_metadata())
db.aggregate_delete(ctxt, result['id'])
result = _create_aggregate(metadata=None)
expected_metadata = db.aggregate_metadata_get(ctxt, result['id'])
self.assertEqual(expected_metadata, {})
def test_aggregate_create_low_privi_context(self):
"""Ensure right context is applied when creating aggregate."""
self.assertRaises(exception.AdminRequired,

View File

@@ -480,3 +480,26 @@ class TestMigrations(test.TestCase):
migration_api.downgrade(engine, TestMigrations.REPOSITORY, 111)
agg = sqlalchemy.select([aggregate_hosts.c.host]).execute().first()
self.assertEqual(host, agg.host)
def test_migration_133(self):
for key, engine in self.engines.items():
migration_api.version_control(engine, TestMigrations.REPOSITORY,
migration.INIT_VERSION)
migration_api.upgrade(engine, TestMigrations.REPOSITORY, 132)
# Set up a single volume, values don't matter
metadata = sqlalchemy.schema.MetaData()
metadata.bind = engine
aggregates = sqlalchemy.Table('aggregates', metadata,
autoload=True)
name = 'name'
aggregates.insert().values(id=1, availability_zone='nova',
aggregate_name=1, name=name).execute()
migration_api.upgrade(engine, TestMigrations.REPOSITORY, 133)
aggregates.insert().values(id=2, availability_zone='nova',
aggregate_name=2, name=name).execute()
migration_api.downgrade(engine, TestMigrations.REPOSITORY, 132)
agg = sqlalchemy.select([aggregates.c.name]).execute().first()
self.assertEqual(name, agg.name)