From: LisaLi Date: Wed, 3 Feb 2016 03:10:39 +0000 (+0800) Subject: Clean uploading volume when c-vol restarts X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=0dc1a273cf14f51b07c32d466dd738ed6e0673fc;p=openstack-build%2Fcinder-build.git Clean uploading volume when c-vol restarts This patch is to clean up the state of uploading volumes to original status when volume service restarts. Change-Id: I0f49261f11efff835fa2e173bab5c823ca8d7d6e Closes-bug: #1541175 --- diff --git a/cinder/tests/unit/test_volume.py b/cinder/tests/unit/test_volume.py index d3a5a230c..0f69c21a2 100644 --- a/cinder/tests/unit/test_volume.py +++ b/cinder/tests/unit/test_volume.py @@ -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', diff --git a/cinder/volume/manager.py b/cinder/volume/manager.py index c93f0ee74..cfd466dfc 100644 --- a/cinder/volume/manager.py +++ b/cinder/volume/manager.py @@ -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(