Browse Source

Allow CG without snapshot to be deleted

If a CG is created from CG Snapshot, it cannot be deleted until
the CG Snapshot is deleted. This is wrong. This is because the query
to find CG who are parents of CG Snapshot didn't filter out the
CG uuid and as a result, it is not possible to delete any CG if
there are any existing CG Snanpshot.

This patch fixes the problem by fixing the function in db API
that finds all CGs that have CG Snapshot depending on them.
* CGs with any CG Snapshot depending on them still cannot be deleted
  until the CG Snapshot is deleted first.
* CGs without any CG Snapshot depending on them should be allowed
  to be deleted.

Change-Id: I1380b26c4a957946c7dc27285557966f558cf03d
Closes-Bug: #1485783
changes/92/213892/4
Xing Yang 6 years ago
parent
commit
62a682d20b
  1. 4
      cinder/db/sqlalchemy/api.py
  2. 26
      cinder/tests/unit/test_db_api.py

4
cinder/db/sqlalchemy/api.py

@ -3765,10 +3765,10 @@ def _cgsnapshot_get_all(context, project_id=None, group_id=None, filters=None):
query = query.filter_by(**filters)
if project_id:
query.filter_by(project_id=project_id)
query = query.filter_by(project_id=project_id)
if group_id:
query.filter_by(consistencygroup_id=group_id)
query = query.filter_by(consistencygroup_id=group_id)
return query.all()

26
cinder/tests/unit/test_db_api.py

@ -1215,6 +1215,32 @@ class DBAPICgsnapshotTestCase(BaseTest):
self.ctxt,
filters))
def test_cgsnapshot_get_all_by_group(self):
cgsnapshot1 = db.cgsnapshot_create(self.ctxt, {'id': 1,
'consistencygroup_id': 'g1'})
cgsnapshot2 = db.cgsnapshot_create(self.ctxt, {'id': 2,
'consistencygroup_id': 'g1'})
db.cgsnapshot_create(self.ctxt, {'id': 3,
'consistencygroup_id': 'g2'})
tests = [
({'consistencygroup_id': 'g1'}, [cgsnapshot1, cgsnapshot2]),
({'id': 3}, []),
({'fake_key': 'fake'}, []),
({'consistencygroup_id': 'g2'}, []),
(None, [cgsnapshot1, cgsnapshot2]),
]
for filters, expected in tests:
self._assertEqualListsOfObjects(expected,
db.cgsnapshot_get_all_by_group(
self.ctxt,
'g1',
filters))
db.cgsnapshot_destroy(self.ctxt, '1')
db.cgsnapshot_destroy(self.ctxt, '2')
db.cgsnapshot_destroy(self.ctxt, '3')
def test_cgsnapshot_get_all_by_project(self):
cgsnapshot1 = db.cgsnapshot_create(self.ctxt,
{'id': 1,

Loading…
Cancel
Save