Merge "Clean uploading volume when c-vol restarts"

This commit is contained in:
Jenkins 2016-02-07 05:51:52 +00:00 committed by Gerrit Code Review
commit d5ccbf9c28
2 changed files with 25 additions and 0 deletions

View File

@ -285,6 +285,27 @@ class VolumeTestCase(BaseVolumeTestCase):
self.assertEqual("error", volume['status']) self.assertEqual("error", volume['status'])
self.volume.delete_volume(self.context, volume_id) 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): def test_init_host_resumes_deletes(self):
"""init_host will resume deleting volume in deleting status.""" """init_host will resume deleting volume in deleting status."""
volume = tests_utils.create_volume(self.context, status='deleting', volume = tests_utils.create_volume(self.context, status='deleting',

View File

@ -424,6 +424,10 @@ class VolumeManager(manager.SchedulerDependentManager):
self.driver.clear_download(ctxt, volume) self.driver.clear_download(ctxt, volume)
volume.status = 'error' volume.status = 'error'
volume.save() 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: else:
pass pass
snapshots = objects.SnapshotList.get_by_host( snapshots = objects.SnapshotList.get_by_host(