]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Replace soft_delete in volume_type_access_remove
authorMichal Dulko <michal.dulko@intel.com>
Mon, 21 Sep 2015 13:58:01 +0000 (15:58 +0200)
committerMichal Dulko <michal.dulko@intel.com>
Mon, 21 Sep 2015 14:09:01 +0000 (16:09 +0200)
This commit replaces oslo.db's soft_delete used in
volume_type_access_remove in db.api with a simple update setting
deleted column to True.

As deleted column is boolean it is represented in the DB by TINYINT,
which max value is 127. This introduces problems when removing records
with id higher than that, because soft_delete sets deleted column to the
value of id. This commit fixes the issue and adds unit tests for such
case.

Change-Id: I484e66125b5a29f490c070696b336be4a2693b3e
Closes-Bug: 1496747

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

index 622b7eb0d320f22109dd98131a0338f394c01c7d..a6aa6ffe48e8ea4d0897dd94c773b166e39a6a0a 100644 (file)
@@ -2770,10 +2770,12 @@ def volume_type_access_remove(context, type_id, project_id):
     """Remove given tenant from the volume type access list."""
     volume_type_id = _volume_type_get_id_from_volume_type(context, type_id)
 
-    count = _volume_type_access_query(context).\
-        filter_by(volume_type_id=volume_type_id).\
-        filter_by(project_id=project_id).\
-        soft_delete(synchronize_session=False)
+    count = (_volume_type_access_query(context).
+             filter_by(volume_type_id=volume_type_id).
+             filter_by(project_id=project_id).
+             update({'deleted': True,
+                     'deleted_at': timeutils.utcnow(),
+                     'updated_at': literal_column('updated_at')}))
     if count == 0:
         raise exception.VolumeTypeAccessNotFound(
             volume_type_id=type_id, project_id=project_id)
index d732f61ee5c180e0d5fd7a302f239c365b1accfa..ab944e339bf9f13c630df0bfb6c353cfb33771d6 100644 (file)
@@ -1351,6 +1351,34 @@ class DBAPIVolumeTypeTestCase(BaseTest):
                           self.ctxt,
                           {'name': 'n2', 'id': vt['id']})
 
+    def test_volume_type_access_remove(self):
+        vt = db.volume_type_create(self.ctxt, {'name': 'n1'})
+        db.volume_type_access_add(self.ctxt, vt['id'], 'fake_project')
+        vtas = db.volume_type_access_get_all(self.ctxt, vt['id'])
+        self.assertEqual(1, len(vtas))
+        db.volume_type_access_remove(self.ctxt, vt['id'], 'fake_project')
+        vtas = db.volume_type_access_get_all(self.ctxt, vt['id'])
+        self.assertEqual(0, len(vtas))
+
+    def test_volume_type_access_remove_high_id(self):
+        vt = db.volume_type_create(self.ctxt, {'name': 'n1'})
+        vta = db.volume_type_access_add(self.ctxt, vt['id'], 'fake_project')
+        vtas = db.volume_type_access_get_all(self.ctxt, vt['id'])
+        self.assertEqual(1, len(vtas))
+
+        # NOTE(dulek): Bug 1496747 uncovered problems when deleting accesses
+        # with id column higher than 128. This is regression test for that
+        # case.
+
+        session = sqlalchemy_api.get_session()
+        vta.id = 150
+        vta.save(session=session)
+        session.close()
+
+        db.volume_type_access_remove(self.ctxt, vt['id'], 'fake_project')
+        vtas = db.volume_type_access_get_all(self.ctxt, vt['id'])
+        self.assertEqual(0, len(vtas))
+
     def test_get_volume_type_extra_specs(self):
         # Ensure that volume type extra specs can be accessed after
         # the DB session is closed.