]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Use model_query() in db.*****_destroy
authorling-yun <zengyunling@huawei.com>
Sat, 30 Nov 2013 09:09:28 +0000 (17:09 +0800)
committerling-yun <zengyunling@huawei.com>
Tue, 3 Dec 2013 07:34:17 +0000 (15:34 +0800)
Use model_query() instead of session.query in db.volume_destroy,
db.volume_type_destroy, db.transfer_destroy and db.snapshot_destroy as
other methods use.
model_query function is the query helper which is used in most part of
cinder/db/sqlalchemy/api.py.

Change-Id: I97be252df9d40bb97231e3341d5cedec26af2d93
Closes-Bug: #1256483

cinder/db/sqlalchemy/api.py

index 866bca042d679eea6c0b976716adc801fbe687c7..6eb217d28d652292d4f2923b619c4b660f3a4826 100644 (file)
@@ -1080,21 +1080,21 @@ def volume_destroy(context, volume_id):
     session = get_session()
     now = timeutils.utcnow()
     with session.begin():
-        session.query(models.Volume).\
+        model_query(context, models.Volume, session=session).\
             filter_by(id=volume_id).\
             update({'status': 'deleted',
                     'deleted': True,
                     'deleted_at': now,
                     'updated_at': literal_column('updated_at')})
-        session.query(models.IscsiTarget).\
+        model_query(context, models.IscsiTarget, session=session).\
             filter_by(volume_id=volume_id).\
             update({'volume_id': None})
-        session.query(models.VolumeMetadata).\
+        model_query(context, models.VolumeMetadata, session=session).\
             filter_by(volume_id=volume_id).\
             update({'deleted': True,
                     'deleted_at': now,
                     'updated_at': literal_column('updated_at')})
-        session.query(models.VolumeAdminMetadata).\
+        model_query(context, models.VolumeAdminMetadata, session=session).\
             filter_by(volume_id=volume_id).\
             update({'deleted': True,
                     'deleted_at': now,
@@ -1447,13 +1447,13 @@ def snapshot_create(context, values):
 def snapshot_destroy(context, snapshot_id):
     session = get_session()
     with session.begin():
-        session.query(models.Snapshot).\
+        model_query(context, models.Snapshot, session=session).\
             filter_by(id=snapshot_id).\
             update({'status': 'deleted',
                     'deleted': True,
                     'deleted_at': timeutils.utcnow(),
                     'updated_at': literal_column('updated_at')})
-        session.query(models.SnapshotMetadata).\
+        model_query(context, models.SnapshotMetadata, session=session).\
             filter_by(snapshot_id=snapshot_id).\
             update({'deleted': True,
                     'deleted_at': timeutils.utcnow(),
@@ -1839,12 +1839,12 @@ def volume_type_destroy(context, id):
             msg = _('VolumeType %s deletion failed, VolumeType in use.') % id
             LOG.error(msg)
             raise exception.VolumeTypeInUse(volume_type_id=id)
-        session.query(models.VolumeTypes).\
+        model_query(context, models.VolumeTypes, session=session).\
             filter_by(id=id).\
             update({'deleted': True,
                     'deleted_at': timeutils.utcnow(),
                     'updated_at': literal_column('updated_at')})
-        session.query(models.VolumeTypeExtraSpecs).\
+        model_query(context, models.VolumeTypeExtraSpecs, session=session).\
             filter_by(volume_type_id=id).\
             update({'deleted': True,
                     'deleted_at': timeutils.utcnow(),
@@ -2641,7 +2641,7 @@ def transfer_destroy(context, transfer_id):
             volume_ref['status'] = 'available'
         volume_ref.update(volume_ref)
         volume_ref.save(session=session)
-        session.query(models.Transfer).\
+        model_query(context, models.Transfer, session=session).\
             filter_by(id=transfer_id).\
             update({'deleted': True,
                     'deleted_at': timeutils.utcnow(),