'Test that init_host will unwedge a volume stuck in downloading.'

@mock.patch('cinder.image.image_utils.cleanup_temporary_file')
def test_init_host_clears_downloads(self, mock_cleanup_tmp_file):

    volume = tests_utils.create_volume(self.context, status='downloading', size=0, host=CONF.host)
    db.worker_create(self.context, resource_type='Volume', resource_id=volume.id, status=volume.status, service_id=self.service_id)
    mock_clear = self.mock_object(self.volume.driver, 'clear_download')
    self.volume.init_host(service_id=service.Service.service_id)
    self.assertEqual(1, mock_clear.call_count)
    self.assertEqual(volume.id, mock_clear.call_args[0][1].id)
    volume.refresh()
    self.assertEqual('error', volume['status'])
    mock_cleanup_tmp_file.assert_called_once_with(CONF.host)
    self.volume.delete_volume(self.context, volume=volume)
    self._assert_workers_are_removed()
