Delete type access list when deleting types

Currently we're in a foobar situation with two database
models ShareTypeProjects and ShareGroupTypeProjects
where we keep stuff around even when the concerned
ShareType or ShareGroupType objects are deleted.

So, delete type access rules when types are being deleted.

Change-Id: Id135a96f2d1b7306156bab0ddedcb1b838a74f0a
Closes-Bug: #1870751
Signed-off-by: Goutham Pacha Ravi <gouthampravi@gmail.com>
(cherry picked from commit 5f80a24ff2)
This commit is contained in:
Goutham Pacha Ravi 2020-04-06 08:52:22 -07:00
parent 18430ceafe
commit da38cf6194
3 changed files with 51 additions and 6 deletions

View File

@ -4226,10 +4226,22 @@ def share_type_destroy(context, id):
'gtypes': share_group_types_count}
LOG.error(msg, msg_args)
raise exception.ShareTypeInUse(share_type_id=id)
(model_query(context, models.ShareTypeExtraSpecs, session=session).
filter_by(share_type_id=id).soft_delete())
(model_query(context, models.ShareTypes, session=session).
filter_by(id=id).soft_delete())
model_query(
context, models.ShareTypeExtraSpecs, session=session
).filter_by(
share_type_id=id
).soft_delete()
model_query(
context, models.ShareTypeProjects, session=session
).filter_by(
share_type_id=id,
).soft_delete()
model_query(
context, models.ShareTypes, session=session
).filter_by(
id=id
).soft_delete()
# Destroy any quotas, usages and reservations for the share type:
quota_destroy_all_by_share_type(context, id)
@ -5093,6 +5105,11 @@ def share_group_type_destroy(context, type_id):
).filter_by(
share_group_type_id=type_id,
).soft_delete()
model_query(
context, models.ShareGroupTypeProjects, session=session
).filter_by(
share_group_type_id=type_id,
).soft_delete()
model_query(
context, models.ShareGroupTypes, session=session
).filter_by(

View File

@ -1210,6 +1210,12 @@ class ShareGroupTypeAPITestCase(test.TestCase):
name='orange', is_public=False, share_types=[share_type_1['id']],
group_specs={'dabo': 'allin', 'cadence': 'count'},
override_defaults=True)
db_api.share_group_type_access_add(self.ctxt,
share_group_type_1['id'],
"2018ndaetfigovnsaslcahfavmrpions")
db_api.share_group_type_access_add(self.ctxt,
share_group_type_1['id'],
"2016ndaetfigovnsaslcahfavmrpions")
share_group_type_2 = db_utils.create_share_group_type(
name='regalia', share_types=[share_type_2['id']])
if used_by_groups:
@ -1235,6 +1241,9 @@ class ShareGroupTypeAPITestCase(test.TestCase):
self.assertDictMatch(
{}, db_api.share_group_type_specs_get(
self.ctxt, share_group_type_1['id']))
self.assertRaises(exception.ShareGroupTypeNotFound,
db_api.share_group_type_access_get_all,
self.ctxt, share_group_type_1['id'])
self.assertRaises(exception.ShareGroupTypeNotFound,
db_api.share_group_type_get,
self.ctxt, share_group_type_1['id'])
@ -3391,8 +3400,16 @@ class ShareTypeAPITestCase(test.TestCase):
def test_share_type_destroy_in_use(self, used_by_shares,
used_by_group_types):
share_type_1 = db_utils.create_share_type(
name='orange', extra_specs={'somekey': 'someval'})
share_type_2 = db_utils.create_share_type(name='regalia')
name='orange', extra_specs={'somekey': 'someval'},
is_public=False, override_defaults=True)
share_type_2 = db_utils.create_share_type(
name='regalia', override_defaults=True)
db_api.share_type_access_add(self.ctxt,
share_type_1['id'],
"2018ndaetfigovnsaslcahfavmrpions")
db_api.share_type_access_add(self.ctxt,
share_type_1['id'],
"2016ndaetfigovnsaslcahfavmrpions")
if used_by_shares:
share_1 = db_utils.create_share(share_type_id=share_type_1['id'])
db_utils.create_share(share_type_id=share_type_2['id'])
@ -3425,6 +3442,9 @@ class ShareTypeAPITestCase(test.TestCase):
self.assertDictMatch(
{}, db_api.share_type_extra_specs_get(
self.ctxt, share_type_1['id']))
self.assertRaises(exception.ShareTypeNotFound,
db_api.share_type_access_get_all,
self.ctxt, share_type_1['id'])
self.assertRaises(exception.ShareTypeNotFound,
db_api.share_type_get,
self.ctxt, share_type_1['id'])

View File

@ -0,0 +1,8 @@
---
fixes:
- |
Fixed the cleanup for private share types and share group types to include
clearing out the database entries recording project specific access
rules to these types. See
`Launchpad bug 1870751 <https://launchpad.net/bugs/1870751>`_ for more
details.