Fix bulk heartbeating when emitting XML

Previously, we would set eventlet.minimum_write_chunk_size *after* we
emit the XML declaration. As a result, eventlet thinks it should buffer
the entire response, rendering our attempts at heartbeating useless.

Change-Id: Idb58c6cc982cc221fed5fc837afd06aa958d9ad4
This commit is contained in:
Tim Burke 2017-10-10 00:27:13 +00:00
parent 047d8d12fd
commit 88c9ba4396
2 changed files with 12 additions and 7 deletions

View File

@ -379,6 +379,7 @@ class Bulk(object):
'Response Body': '',
'Number Deleted': 0,
'Number Not Found': 0}
req.environ['eventlet.minimum_write_chunk_size'] = 0
try:
if not out_content_type:
raise HTTPNotAcceptable(request=req)
@ -399,7 +400,6 @@ class Bulk(object):
if objs_to_delete is None:
objs_to_delete = self.get_objs_to_delete(req)
failed_file_response = {'type': HTTPBadRequest}
req.environ['eventlet.minimum_write_chunk_size'] = 0
def delete_filter(predicate, objs_to_delete):
for obj_to_delete in objs_to_delete:
@ -507,6 +507,7 @@ class Bulk(object):
last_yield = time()
separator = ''
containers_accessed = set()
req.environ['eventlet.minimum_write_chunk_size'] = 0
try:
if not out_content_type:
raise HTTPNotAcceptable(request=req)
@ -526,7 +527,6 @@ class Bulk(object):
tar = tarfile.open(mode='r|' + compress_type,
fileobj=req.body_file)
failed_response_type = HTTPBadRequest
req.environ['eventlet.minimum_write_chunk_size'] = 0
containers_created = 0
while True:
if last_yield + self.yield_frequency < time():

View File

@ -243,9 +243,11 @@ class TestUntar(unittest.TestCase):
def handle_extract_and_iter(self, req, compress_format,
out_content_type='application/json'):
resp_body = ''.join(
self.bulk.handle_extract_iter(req, compress_format,
out_content_type=out_content_type))
iter = self.bulk.handle_extract_iter(
req, compress_format, out_content_type=out_content_type)
first_chunk = next(iter)
self.assertEqual(req.environ['eventlet.minimum_write_chunk_size'], 0)
resp_body = first_chunk + ''.join(iter)
return resp_body
def test_create_container_for_path(self):
@ -623,8 +625,11 @@ class TestDelete(unittest.TestCase):
self.app.delete_paths = []
def handle_delete_and_iter(self, req, out_content_type='application/json'):
resp_body = ''.join(self.bulk.handle_delete_iter(
req, out_content_type=out_content_type))
iter = self.bulk.handle_delete_iter(
req, out_content_type=out_content_type)
first_chunk = next(iter)
self.assertEqual(req.environ['eventlet.minimum_write_chunk_size'], 0)
resp_body = first_chunk + ''.join(iter)
return resp_body
def test_bulk_delete_uses_predefined_object_errors(self):