From: Clay Gerrard Date: Mon, 22 Oct 2012 21:47:12 +0000 (-0500) Subject: Update volume and snapshot status on delete X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=71994f45f51bde72b3323fb84a2461ae452b6949;p=openstack-build%2Fcinder-build.git Update volume and snapshot status on delete Change the status of "deleting" resources at the same time we update boolean flag for deleted. Makes dumb queries looking for stuck statuses a little easier. Change-Id: Iaf3386526a369f9bf281eb4be42eb11277038c92 --- diff --git a/cinder/db/sqlalchemy/api.py b/cinder/db/sqlalchemy/api.py index be29b30bd..14c1bb106 100644 --- a/cinder/db/sqlalchemy/api.py +++ b/cinder/db/sqlalchemy/api.py @@ -971,7 +971,8 @@ def volume_destroy(context, volume_id): with session.begin(): session.query(models.Volume).\ filter_by(id=volume_id).\ - update({'deleted': True, + update({'status': 'deleted', + 'deleted': True, 'deleted_at': timeutils.utcnow(), 'updated_at': literal_column('updated_at')}) session.query(models.IscsiTarget).\ @@ -1173,7 +1174,8 @@ def snapshot_destroy(context, snapshot_id): with session.begin(): session.query(models.Snapshot).\ filter_by(id=snapshot_id).\ - update({'deleted': True, + update({'status': 'deleted', + 'deleted': True, 'deleted_at': timeutils.utcnow(), 'updated_at': literal_column('updated_at')}) diff --git a/cinder/tests/test_volume.py b/cinder/tests/test_volume.py index baac8023b..52f980b95 100644 --- a/cinder/tests/test_volume.py +++ b/cinder/tests/test_volume.py @@ -113,6 +113,9 @@ class VolumeTestCase(test.TestCase): volume_id).id) self.volume.delete_volume(self.context, volume_id) + vol = db.volume_get(context.get_admin_context(read_deleted='yes'), + volume_id) + self.assertEquals(vol['status'], 'deleted') self.assertEquals(len(test_notifier.NOTIFICATIONS), 4) self.assertRaises(exception.NotFound, db.volume_get, @@ -263,6 +266,9 @@ class VolumeTestCase(test.TestCase): snapshot_id).id) self.volume.delete_snapshot(self.context, snapshot_id) + snap = db.snapshot_get(context.get_admin_context(read_deleted='yes'), + snapshot_id) + self.assertEquals(snap['status'], 'deleted') self.assertRaises(exception.NotFound, db.snapshot_get, self.context,