]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Update volume and snapshot status on delete
authorClay Gerrard <clay.gerrard@gmail.com>
Mon, 22 Oct 2012 21:47:12 +0000 (16:47 -0500)
committerClay Gerrard <clay.gerrard@gmail.com>
Mon, 22 Oct 2012 21:52:15 +0000 (16:52 -0500)
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
cinder/tests/test_volume.py

index be29b30bdbde0890875b93a54ae1a22f86fcada3..14c1bb10639b4e704933ce204ebcfbc3e2194f83 100644 (file)
@@ -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')})
 
index baac8023b402e1feed0a1b66e198481446d46d50..52f980b9511c00b8063c460f3334ecc0147edf3c 100644 (file)
@@ -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,