Merge "Fix bug in db.instance_type_destroy"

This commit is contained in:
Jenkins 2013-04-25 18:55:37 +00:00 committed by Gerrit Code Review
commit 13c085bc96
2 changed files with 26 additions and 1 deletions

View File

@ -3761,6 +3761,10 @@ def instance_type_destroy(context, name):
session.query(models.InstanceTypeExtraSpecs).\
filter_by(instance_type_id=instance_type_id).\
soft_delete()
model_query(context, models.InstanceTypeProjects,
session=session, read_deleted="no").\
filter_by(instance_type_id=instance_type_id).\
soft_delete()
@require_context
@ -3775,7 +3779,8 @@ def instance_type_access_get_by_flavor_id(context, flavor_id):
instance_type_ref = _instance_type_get_query(context).\
filter_by(flavorid=flavor_id).\
first()
if not instance_type_ref:
return []
return [r for r in instance_type_ref.projects]

View File

@ -2307,6 +2307,26 @@ class InstanceTypeAccessTestCase(BaseInstanceTypeTestCase):
db.instance_type_access_remove,
self.ctxt, inst_type['flavorid'], 'p2')
def test_instance_type_access_removed_after_instance_type_destroy(self):
inst_type1 = self._create_inst_type({'flavorid': 'f1', 'name': 'n1'})
inst_type2 = self._create_inst_type({'flavorid': 'f2', 'name': 'n2'})
values = [
(inst_type1['flavorid'], 'p1'),
(inst_type1['flavorid'], 'p2'),
(inst_type2['flavorid'], 'p3')
]
for v in values:
self._create_inst_type_access(*v)
db.instance_type_destroy(self.ctxt, inst_type1['name'])
p = (self.ctxt, inst_type1['flavorid'])
self.assertEqual(0, len(db.instance_type_access_get_by_flavor_id(*p)))
p = (self.ctxt, inst_type2['flavorid'])
self.assertEqual(1, len(db.instance_type_access_get_by_flavor_id(*p)))
db.instance_type_destroy(self.ctxt, inst_type2['name'])
self.assertEqual(0, len(db.instance_type_access_get_by_flavor_id(*p)))
class FixedIPTestCase(BaseInstanceTypeTestCase):
def _timeout_test(self, ctxt, timeout, multi_host):