]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Allow CG without snapshot to be deleted
authorXing Yang <xing.yang@emc.com>
Mon, 10 Aug 2015 21:15:50 +0000 (17:15 -0400)
committerXing Yang <xing.yang@emc.com>
Sat, 15 Aug 2015 08:31:40 +0000 (04:31 -0400)
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

cinder/db/sqlalchemy/api.py
cinder/tests/unit/test_db_api.py

index 5906fbd426306f570005874b22a0ae782f5dd055..72a26a7122ec26842943a7b0b36f3903cd97f3b5 100644 (file)
@@ -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()
 
index 06d68d5eda5ac448a59798dd228b1ff4a76d54c1..9cd95385a326e33cf830985b495cb690253908bd 100644 (file)
@@ -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,