]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Handle volumes no longer existing in resume delete
authorMike Perez <thingee@gmail.com>
Thu, 22 May 2014 21:29:06 +0000 (14:29 -0700)
committerMike Perez <thingee@gmail.com>
Tue, 27 May 2014 20:45:43 +0000 (13:45 -0700)
init_host resumes deletes for volumes with a status of 'deleting'. It
does these sequentially, and sometimes a volume could be deleted under
it, causing a bad stacktrace. This will gracefully handle those
situations and move on. Added coverage for resume volume delete being
successful as well.

Change-Id: I5b30265609b65804f2da77d9daa84b640de7939c
Closes-Bug: #1322340

cinder/tests/test_volume.py
cinder/volume/manager.py

index a0016af73ecc9f61a9301c2f1825664822ad869a..f8fd46ea4e9d763f5b66ef2bae725b3bedbdb1e5 100644 (file)
@@ -154,6 +154,15 @@ class VolumeTestCase(BaseVolumeTestCase):
         self.assertEqual(volume['status'], "error")
         self.volume.delete_volume(self.context, volume_id)
 
+    def test_init_host_resumes_deletes(self):
+        """init_host will resume deleting volume in deleting status."""
+        volume = tests_utils.create_volume(self.context, status='deleting',
+                                           size=0, host=CONF.host)
+        volume_id = volume['id']
+        self.volume.init_host()
+        self.assertRaises(exception.VolumeNotFound, db.volume_get,
+                          context.get_admin_context(), volume_id)
+
     @mock.patch.object(QUOTAS, 'reserve')
     @mock.patch.object(QUOTAS, 'commit')
     @mock.patch.object(QUOTAS, 'rollback')
@@ -521,6 +530,14 @@ class VolumeTestCase(BaseVolumeTestCase):
         self.assertRaises(exception.NotFound, db.volume_get,
                           self.context, volume['id'])
 
+    @mock.patch.object(db, 'volume_get', side_effect=exception.VolumeNotFound(
+                       volume_id='12345678-1234-5678-1234-567812345678'))
+    def test_delete_volume_not_found(self, mock_get_volume):
+        """"Test delete volume moves on if the volume does not exist."""
+        volume_id = '12345678-1234-5678-1234-567812345678'
+        self.assertTrue(self.volume.delete_volume(self.context, volume_id))
+        self.assertTrue(mock_get_volume.called)
+
     def test_create_volume_from_snapshot(self):
         """Test volume can be created from a snapshot."""
         volume_src = tests_utils.create_volume(self.context,
index 32fbfa51765565cb7c2a8887daddc9608cf02247..049f83a36cc290bec666699f5bd609e0764ddcda 100644 (file)
@@ -346,7 +346,15 @@ class VolumeManager(manager.SchedulerDependentManager):
     def delete_volume(self, context, volume_id, unmanage_only=False):
         """Deletes and unexports volume."""
         context = context.elevated()
-        volume_ref = self.db.volume_get(context, volume_id)
+
+        try:
+            volume_ref = self.db.volume_get(context, volume_id)
+        except exception.VolumeNotFound:
+            # NOTE(thingee): It could be possible for a volume to
+            # be deleted when resuming deletes from init_host().
+            LOG.info(_("Tried to delete volume %s, but it no longer exists, "
+                       "moving on") % (volume_id))
+            return True
 
         if context.project_id != volume_ref['project_id']:
             project_id = volume_ref['project_id']