'Test create volume with ImageCopyFailure
We\'ll raise an exception inside _connect_device after volume has
already been attached to confirm that it detaches the volume.'

@mock.patch('cinder.utils.brick_get_connector_properties')
@mock.patch('cinder.utils.brick_get_connector')
@mock.patch('cinder.volume.driver.BaseVD.secure_file_operations_enabled')
@mock.patch('cinder.volume.driver.BaseVD._detach_volume')
@mock.patch('cinder.image.image_utils.qemu_img_info')
def test_create_volume_from_image_unavailable(self, mock_qemu_info, mock_detach, mock_secure, *args):

    mock_secure.side_effect = NameError
    image_info = imageutils.QemuImgInfo()
    image_info.virtual_size = '1073741824'
    mock_qemu_info.return_value = image_info
    unbound_copy_method = cinder.volume.driver.BaseVD.copy_image_to_volume
    bound_copy_method = unbound_copy_method.__get__(self.volume.driver)
    with mock.patch.object(self.volume.driver, 'copy_image_to_volume', side_effect=bound_copy_method):
        self.assertRaises(exception.ImageCopyFailure, self._create_volume_from_image, fakeout_copy_image_to_volume=False)
    self.assertEqual(1, mock_detach.call_count)
