Files
glance/glance/tests/stubs.py
T
Takashi Kajinami 205ca3336a Remove sendfile support
pysendfile[1] was added as an optional dependency but the library
hasn't been maintained and has got no release since 2014.

What is worse, the sendfile implementation is not actually working
since The SendFileIterator class was removed[2]. (Follow-up[3] removed
the remaining reference to the class). The broken implementation has
not been detected because the client is not currently used to upload
contents.

Remove the incomplete implementation to get rid of the dependency on
the unmaintained library.

[1] https://pypi.org/project/pysendfile/
[2] 76c3620c7e
[3] 0c151d7d7e

Closes-Bug: #2062573
Change-Id: Ia4784f59d16660e8d40c0e409f092ac4e46870b4
2024-05-02 09:20:59 +00:00

93 lines
2.8 KiB
Python

# Copyright 2010-2011 OpenStack Foundation
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""Stubouts, mocks and fixtures for the test suite"""
import routes
import webob
from glance.api.middleware import context
from glance.api.v2 import router
def stub_out_store_server(stubs, base_dir, **kwargs):
"""Mocks calls to 127.0.0.1 on 9292 for testing.
Done so that a real Glance server does not need to be up and
running
"""
class FakeSocket(object):
def __init__(self, *args, **kwargs):
pass
def fileno(self):
return 42
class FakeGlanceConnection(object):
def __init__(self, *args, **kwargs):
self.sock = FakeSocket()
def connect(self):
return True
def close(self):
return True
def putrequest(self, method, url):
self.req = webob.Request.blank(url)
self.req.method = method
def putheader(self, key, value):
self.req.headers[key] = value
def endheaders(self):
hl = [i.lower() for i in self.req.headers.keys()]
assert not ('content-length' in hl and
'transfer-encoding' in hl), (
'Content-Length and Transfer-Encoding are mutually exclusive')
def send(self, data):
# send() is called during chunked-transfer encoding, and
# data is of the form %x\r\n%s\r\n. Strip off the %x and
# only write the actual data in tests.
self.req.body += data.split("\r\n")[1]
def request(self, method, url, body=None, headers=None):
self.req = webob.Request.blank(url)
self.req.method = method
if headers:
self.req.headers = headers
if body:
self.req.body = body
def getresponse(self):
mapper = routes.Mapper()
api = context.UnauthenticatedContextMiddleware(router.API(mapper))
res = self.req.get_response(api)
# httplib.Response has a read() method...fake it out
def fake_reader():
return res.body
setattr(res, 'read', fake_reader)
return res
def fake_image_iter(self):
for i in self.source.app_iter:
yield i