py3 object-server follow-ups

Change-Id: Ief7d85af8d3e1d5e03a6484a889c9146d69f1377
Related-Change: I203a54fddddbd4352be0e6ea476a628e3f747dc1
This commit is contained in:
Tim Burke
2019-01-14 22:32:31 +00:00
parent 5b5ed29ab4
commit 2bd7b7a109
3 changed files with 22 additions and 27 deletions

View File

@@ -95,24 +95,17 @@ def _make_backend_fragments_header(fragments):
return None return None
if six.PY2: class EventletPlungerString(bytes):
class EventletPlungerString(str): """
""" Eventlet won't send headers until it's accumulated at least
Eventlet won't send headers until it's accumulated at least eventlet.wsgi.MINIMUM_CHUNK_SIZE bytes or the app iter is exhausted.
eventlet.wsgi.MINIMUM_CHUNK_SIZE bytes or the app iter is exhausted. If we want to send the response body behind Eventlet's back, perhaps
If we want to send the response body behind Eventlet's back, perhaps with some zero-copy wizardry, then we have to unclog the plumbing in
with some zero-copy wizardry, then we have to unclog the plumbing in eventlet.wsgi to force the headers out, so we use an
eventlet.wsgi to force the headers out, so we use an EventletPlungerString to empty out all of Eventlet's buffers.
EventletPlungerString to empty out all of Eventlet's buffers. """
""" def __len__(self):
def __len__(self): return wsgi.MINIMUM_CHUNK_SIZE + 1
return wsgi.MINIMUM_CHUNK_SIZE + 1
else:
# Eventlet of 0.23.0 does encode('ascii') and strips our __len__.
# Avoid it by inheriting from bytes.
class EventletPlungerString(bytes):
def __len__(self):
return wsgi.MINIMUM_CHUNK_SIZE + 1
class ObjectController(BaseStorageServer): class ObjectController(BaseStorageServer):

View File

@@ -48,7 +48,6 @@ from swift.obj import server
from hashlib import md5 from hashlib import md5
import logging.handlers import logging.handlers
import six
from six.moves import range from six.moves import range
from six import BytesIO from six import BytesIO
from six.moves.http_client import HTTPException from six.moves.http_client import HTTPException
@@ -924,7 +923,7 @@ def fake_http_connect(*code_iter, **kwargs):
def getheaders(self): def getheaders(self):
etag = self.etag etag = self.etag
if not etag: if not etag:
if isinstance(self.body, six.binary_type): if isinstance(self.body, bytes):
etag = '"' + md5(self.body).hexdigest() + '"' etag = '"' + md5(self.body).hexdigest() + '"'
else: else:
etag = '"68b329da9893e34099c7d8ad5cb9c940"' etag = '"68b329da9893e34099c7d8ad5cb9c940"'

View File

@@ -6863,7 +6863,10 @@ class TestObjectController(unittest.TestCase):
}) })
resp = req.get_response(self.object_controller) resp = req.get_response(self.object_controller)
self.assertEqual(resp.status_int, 200) self.assertEqual(resp.status_int, 200)
suffix = list(pickle.loads(resp.body).keys())[0] suffixes = list(pickle.loads(resp.body).keys())
self.assertEqual(1, len(suffixes),
'Expected just one suffix; got %r' % (suffixes,))
suffix = suffixes[0]
self.assertEqual(suffix, os.path.basename( self.assertEqual(suffix, os.path.basename(
os.path.dirname(objfile._datadir))) os.path.dirname(objfile._datadir)))
# tombstone still exists # tombstone still exists
@@ -7619,7 +7622,7 @@ class TestObjectServer(unittest.TestCase):
if six.PY2: if six.PY2:
conn.sock.fd._sock.close() conn.sock.fd._sock.close()
else: else:
conn.sock.fd.close() conn.sock.fd._real_close()
for i in range(2): for i in range(2):
sleep(0) sleep(0)
self.assertFalse(self.logger.get_lines_for_level('error')) self.assertFalse(self.logger.get_lines_for_level('error'))
@@ -7722,7 +7725,7 @@ class TestObjectServer(unittest.TestCase):
# give the object server a little time to trampoline enough to # give the object server a little time to trampoline enough to
# recognize request has finished, or socket has closed or whatever # recognize request has finished, or socket has closed or whatever
sleep(0.1) sleep(0.01)
def test_multiphase_put_client_disconnect_right_before_commit(self): def test_multiphase_put_client_disconnect_right_before_commit(self):
with self._check_multiphase_put_commit_handling() as context: with self._check_multiphase_put_commit_handling() as context:
@@ -7731,7 +7734,7 @@ class TestObjectServer(unittest.TestCase):
if six.PY2: if six.PY2:
conn.sock.fd._sock.close() conn.sock.fd._sock.close()
else: else:
conn.sock.fd.close() conn.sock.fd._real_close()
sleep(0) sleep(0)
put_timestamp = context['put_timestamp'] put_timestamp = context['put_timestamp']
@@ -7775,7 +7778,7 @@ class TestObjectServer(unittest.TestCase):
if six.PY2: if six.PY2:
conn.sock.fd._sock.close() conn.sock.fd._sock.close()
else: else:
conn.sock.fd.close() conn.sock.fd._real_close()
sleep(0) sleep(0)
put_timestamp = context['put_timestamp'] put_timestamp = context['put_timestamp']
@@ -7957,7 +7960,7 @@ class TestObjectServer(unittest.TestCase):
if six.PY2: if six.PY2:
conn.sock.fd._sock.close() conn.sock.fd._sock.close()
else: else:
conn.sock.fd.close() conn.sock.fd._real_close()
sleep(0) sleep(0)
# and make sure it demonstrates the client disconnect # and make sure it demonstrates the client disconnect
@@ -8155,7 +8158,7 @@ class TestObjectServer(unittest.TestCase):
if six.PY2: if six.PY2:
conn.sock.fd._sock.close() conn.sock.fd._sock.close()
else: else:
conn.sock.fd.close() conn.sock.fd._real_close()
sleep(0) sleep(0)
# and make sure it demonstrates the client disconnect # and make sure it demonstrates the client disconnect