summaryrefslogtreecommitdiff
path: root/glance/tests/stubs.py
diff options
context:
space:
mode:
authorMike Lundy <mike@pistoncloud.com>2012-04-13 19:53:16 -0700
committerMike Lundy <mike@pistoncloud.com>2012-04-24 09:55:13 -0700
commit223fbee49a55691504623fa691bbb3e48048d5f3 (patch)
tree22d98f424e1c9743f4cd278183e55b43c7ddf206 /glance/tests/stubs.py
parenta9fb22483d9ebc08320dcf9019861ecd2e1feb63 (diff)
downloadglance-223fbee49a55691504623fa691bbb3e48048d5f3.tar.gz
Omit Content-Length on chunked transfer
Content-Length and Transfer-Encoding conflict according to the HTTP spec. This fixes bug 981332. This also adds the ability to test both the sendfile-present and sendfile-absent codepaths; the sendfile-present test will be skipped on sendfile-absent platforms. Change-Id: Ibb017b4a43d89ffdb6b868648296603cfec7780d
Diffstat (limited to 'glance/tests/stubs.py')
-rw-r--r--glance/tests/stubs.py28
1 files changed, 23 insertions, 5 deletions
diff --git a/glance/tests/stubs.py b/glance/tests/stubs.py
index 246ba9385..deb09cdc2 100644
--- a/glance/tests/stubs.py
+++ b/glance/tests/stubs.py
@@ -56,7 +56,7 @@ def stub_out_registry_and_store_server(stubs, base_dir):
def close(self):
return True
- def request(self, method, url, body=None, headers={}):
+ def request(self, method, url, body=None, headers=None):
self.req = webob.Request.blank("/" + url.lstrip("/"))
self.req.method = method
if headers:
@@ -107,6 +107,8 @@ def stub_out_registry_and_store_server(stubs, base_dir):
def __init__(self, *args, **kwargs):
self.sock = FakeSocket()
+ self.stub_force_sendfile = kwargs.get('stub_force_sendfile',
+ SENDFILE_SUPPORTED)
def connect(self):
return True
@@ -120,7 +122,7 @@ def stub_out_registry_and_store_server(stubs, base_dir):
def putrequest(self, method, url):
self.req = webob.Request.blank(self._clean_url(url))
- if SENDFILE_SUPPORTED:
+ if self.stub_force_sendfile:
fake_sendfile = FakeSendFile(self.req)
stubs.Set(sendfile, 'sendfile', fake_sendfile.sendfile)
self.req.method = method
@@ -129,7 +131,10 @@ def stub_out_registry_and_store_server(stubs, base_dir):
self.req.headers[key] = value
def endheaders(self):
- pass
+ 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
@@ -137,7 +142,7 @@ def stub_out_registry_and_store_server(stubs, base_dir):
# only write the actual data in tests.
self.req.body += data.split("\r\n")[1]
- def request(self, method, url, body=None, headers={}):
+ def request(self, method, url, body=None, headers=None):
self.req = webob.Request.blank(self._clean_url(url))
self.req.method = method
if headers:
@@ -185,8 +190,21 @@ def stub_out_registry_and_store_server(stubs, base_dir):
for i in self.source.app_iter:
yield i
+ def fake_sendable(self, body):
+ force = getattr(self, 'stub_force_sendfile', None)
+ if force is None:
+ return self._stub_orig_sendable(body)
+ else:
+ if force:
+ assert glance.common.client.SENDFILE_SUPPORTED
+ return force
+
stubs.Set(glance.common.client.BaseClient, 'get_connection_type',
fake_get_connection_type)
+ setattr(glance.common.client.BaseClient, '_stub_orig_sendable',
+ glance.common.client.BaseClient._sendable)
+ stubs.Set(glance.common.client.BaseClient, '_sendable',
+ fake_sendable)
stubs.Set(glance.common.client.ImageBodyIterator, '__iter__',
fake_image_iter)
@@ -209,7 +227,7 @@ def stub_out_registry_server(stubs, **kwargs):
def close(self):
return True
- def request(self, method, url, body=None, headers={}):
+ def request(self, method, url, body=None, headers=None):
self.req = webob.Request.blank("/" + url.lstrip("/"))
self.req.method = method
if headers: