'Test create image from volume if create image fails.
In this case API will rollback to previous status.'

@mock.patch.object(volume_api.API, 'get_volume_image_metadata')
@mock.patch.object(glance.GlanceImageService, 'create')
@mock.patch.object(volume_rpcapi.VolumeAPI, 'copy_volume_to_image')
def test_copy_volume_to_image_fail_image_create(self, mock_copy_to_image, mock_create, mock_get_image_metadata):

    volume = utils.create_volume(self.context)
    mock_get_image_metadata.return_value = {}
    mock_create.side_effect = Exception()
    req = fakes.HTTPRequest.blank(('/v2/fakeproject/volumes/%s/action' % volume.id))
    body = self._get_os_volume_upload_image()
    self.assertRaises(webob.exc.HTTPBadRequest, self.controller._volume_upload_image, req, volume.id, body)
    self.assertFalse(mock_copy_to_image.called)
    vol_db = objects.Volume.get_by_id(self.context, volume.id)
    self.assertEqual('available', vol_db.status)
    self.assertIsNone(vol_db.previous_status)
    db.volume_destroy(context.get_admin_context(), volume.id)
