]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Clean uploading volume when c-vol restarts
authorLisaLi <xiaoyan.li@intel.com>
Wed, 3 Feb 2016 03:10:39 +0000 (11:10 +0800)
committerLisaLi <xiaoyan.li@intel.com>
Thu, 4 Feb 2016 02:14:48 +0000 (10:14 +0800)
This patch is to clean up the state of uploading volumes to
original status when volume service restarts.

Change-Id: I0f49261f11efff835fa2e173bab5c823ca8d7d6e
Closes-bug: #1541175

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

index d3a5a230cad38b8d8fdefdca7208c044f48983f2..0f69c21a266744251bde94dc76a7d75f3f285908 100644 (file)
@@ -285,6 +285,27 @@ class VolumeTestCase(BaseVolumeTestCase):
         self.assertEqual("error", volume['status'])
         self.volume.delete_volume(self.context, volume_id)
 
+    def test_init_host_clears_uploads_available_volume(self):
+        """init_host will clean an available volume stuck in uploading."""
+        volume = tests_utils.create_volume(self.context, status='uploading',
+                                           size=0, host=CONF.host)
+        self.volume.init_host()
+        volume = objects.Volume.get_by_id(context.get_admin_context(),
+                                          volume.id)
+        self.assertEqual("available", volume.status)
+
+    def test_init_host_clears_uploads_in_use_volume(self):
+        """init_host will clean an in-use volume stuck in uploading."""
+        volume = tests_utils.create_volume(self.context, status='uploading',
+                                           size=0, host=CONF.host)
+        fake_uuid = fakes.get_fake_uuid()
+        tests_utils.attach_volume(self.context, volume.id, fake_uuid,
+                                  'fake_host', '/dev/vda')
+        self.volume.init_host()
+        volume = objects.Volume.get_by_id(context.get_admin_context(),
+                                          volume.id)
+        self.assertEqual("in-use", volume.status)
+
     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',
index c93f0ee74cb49a85a508b020cb1f16e954dbb78c..cfd466dfc0a3b8f336f693e00919fe6727f0677e 100644 (file)
@@ -424,6 +424,10 @@ class VolumeManager(manager.SchedulerDependentManager):
                         self.driver.clear_download(ctxt, volume)
                     volume.status = 'error'
                     volume.save()
+                elif volume.status == 'uploading':
+                        # Set volume status to available or in-use.
+                        self.db.volume_update_status_based_on_attachment(
+                            ctxt, volume.id)
                 else:
                     pass
             snapshots = objects.SnapshotList.get_by_host(