summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2017-12-12 21:39:36 +0000
committerGerrit Code Review <review@openstack.org>2017-12-12 21:39:36 +0000
commit4d4930c59af32d717088b3af28047ee1fcf09d4a (patch)
treebd15458e8d9fab734edee06a840610c809669ad7
parent11e856a53cdfab945947a1b08f9963b600f47b50 (diff)
parentfc225f16a12471bfde9d5d0d378e69fba201e58a (diff)
Merge "[placement] Fix foreign key constraint error" into stable/pike16.0.4
-rw-r--r--nova/objects/resource_provider.py4
-rw-r--r--nova/tests/unit/objects/test_resource_provider.py29
2 files changed, 33 insertions, 0 deletions
diff --git a/nova/objects/resource_provider.py b/nova/objects/resource_provider.py
index 5d621d1..abb8166 100644
--- a/nova/objects/resource_provider.py
+++ b/nova/objects/resource_provider.py
@@ -505,6 +505,10 @@ class ResourceProvider(base.NovaObject):
505 RPA_model = models.ResourceProviderAggregate 505 RPA_model = models.ResourceProviderAggregate
506 context.session.query(RPA_model).\ 506 context.session.query(RPA_model).\
507 filter(RPA_model.resource_provider_id == _id).delete() 507 filter(RPA_model.resource_provider_id == _id).delete()
508 # delete any trait associations for the resource provider
509 RPT_model = models.ResourceProviderTrait
510 context.session.query(RPT_model).\
511 filter(RPT_model.resource_provider_id == _id).delete()
508 # Now delete the RP records 512 # Now delete the RP records
509 result = context.session.query(models.ResourceProvider).\ 513 result = context.session.query(models.ResourceProvider).\
510 filter(models.ResourceProvider.id == _id).delete() 514 filter(models.ResourceProvider.id == _id).delete()
diff --git a/nova/tests/unit/objects/test_resource_provider.py b/nova/tests/unit/objects/test_resource_provider.py
index 746a925..f0a43be 100644
--- a/nova/tests/unit/objects/test_resource_provider.py
+++ b/nova/tests/unit/objects/test_resource_provider.py
@@ -140,6 +140,35 @@ class TestResourceProvider(test_objects._LocalTest):
140 objects.ResourceProvider.get_by_uuid, 140 objects.ResourceProvider.get_by_uuid,
141 self.context, uuids.missing) 141 self.context, uuids.missing)
142 142
143 def test_destroy_with_traits(self):
144 """Test deleting a resource provider that has a trait successfully.
145 """
146 rp = resource_provider.ResourceProvider(self.context,
147 uuid=uuids.rp,
148 name='fake_rp1')
149 rp.create()
150 custom_trait = resource_provider.Trait(self.context,
151 uuid=uuids.trait,
152 name='CUSTOM_TRAIT_1')
153 custom_trait.create()
154 rp.set_traits([custom_trait])
155
156 trl = rp.get_traits()
157 self.assertEqual(1, len(trl))
158
159 # Delete a resource provider that has a trait assosiation.
160 rp.destroy()
161
162 # Assert the record has been deleted
163 # in 'resource_provider_traits' table
164 # after Resource Provider object has been destroyed.
165 trl = rp.get_traits()
166 self.assertEqual(0, len(trl))
167 # Assert that NotFound exception is raised.
168 self.assertRaises(exception.NotFound,
169 resource_provider.ResourceProvider.get_by_uuid,
170 self.context, uuids.rp)
171
143 172
144class TestInventoryNoDB(test_objects._LocalTest): 173class TestInventoryNoDB(test_objects._LocalTest):
145 USES_DB = False 174 USES_DB = False