From 71994f45f51bde72b3323fb84a2461ae452b6949 Mon Sep 17 00:00:00 2001 From: Clay Gerrard Date: Mon, 22 Oct 2012 16:47:12 -0500 Subject: [PATCH] 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 --- cinder/db/sqlalchemy/api.py | 6 ++++-- cinder/tests/test_volume.py | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) 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, -- 2.45.2