Cascade deletes of RP aggregate associations

Currently when we delete a resource provider, the associations it has to
aggregates are not also deleted. This patch adds the deletion of all
ResourceProviderAggregate associations for that RP.

Closes-Bug: #1647697

Change-Id: I47ebd1464256f2fbc7505a5c1b3c74a4ba89ccf0
This commit is contained in:
EdLeafe 2016-12-06 21:02:32 +00:00
parent bea29e6d58
commit 693a535c0c
2 changed files with 22 additions and 0 deletions

View File

@ -419,6 +419,12 @@ class ResourceProvider(base.NovaObject):
# Delete any inventory associated with the resource provider
context.session.query(models.Inventory).\
filter(models.Inventory.resource_provider_id == _id).delete()
# Delete any aggregate associations for the resource provider
# The name substitution on the next line is needed to satisfy pep8
RPA_model = models.ResourceProviderAggregate
context.session.query(RPA_model).\
filter(RPA_model.resource_provider_id == _id).delete()
# Now delete the RP records
result = context.session.query(models.ResourceProvider).\
filter(models.ResourceProvider.id == _id).delete()
if not result:

View File

@ -691,6 +691,22 @@ class TestResourceProviderAggregates(test.NoDBTestCase):
read_aggregate_uuids = rp.get_aggregates()
self.assertEqual([], read_aggregate_uuids)
def test_delete_rp_clears_aggs(self):
rp = objects.ResourceProvider(
context=self.context,
uuid=uuidsentinel.rp_uuid,
name=uuidsentinel.rp_name
)
rp.create()
rp_id = rp.id
start_aggregate_uuids = [uuidsentinel.agg_a, uuidsentinel.agg_b]
rp.set_aggregates(start_aggregate_uuids)
aggs = objects.ResourceProvider._get_aggregates(self.context, rp_id)
self.assertEqual(2, len(aggs))
rp.destroy()
aggs = objects.ResourceProvider._get_aggregates(self.context, rp_id)
self.assertEqual(0, len(aggs))
class TestAllocation(ResourceProviderBaseCase):