py3: port object controller in proxy

When looking at the tuple thing, remember that tuples are comparable
with ints in py2, but they do not compare like (100)[0]. Instead, they
are always greater, acting almost like MAX_INT. No wonder py3 banned
that practice.

We had a much of other noncomparables, but we dealt with them in
obvious ways, like adding key= to sorted().

Change-Id: I52e96406c3c1f39b98c1d81bdc057805cd1a6278
This commit is contained in:
Pete Zaitcev 2019-01-30 17:35:37 -06:00
parent 1d4249ee9d
commit 988e719232
6 changed files with 205 additions and 161 deletions

View File

@ -1694,7 +1694,7 @@ class Controller(object):
response.append(resp)
statuses.append(resp[0])
while len(response) < node_number:
response.append((HTTP_SERVICE_UNAVAILABLE, '', '', ''))
response.append((HTTP_SERVICE_UNAVAILABLE, '', '', b''))
statuses, reasons, resp_headers, bodies = zip(*response)
return self.best_response(req, statuses, reasons, bodies,
'%s %s' % (self.server_type, req.method),

View File

@ -1563,7 +1563,7 @@ def segment_range_to_fragment_range(segment_start, segment_end, segment_size,
# the index of the first byte of the first fragment
fragment_start = ((
segment_start / segment_size * fragment_size)
segment_start // segment_size * fragment_size)
if segment_start is not None else None)
# the index of the last byte of the last fragment
fragment_end = (
@ -1572,13 +1572,13 @@ def segment_range_to_fragment_range(segment_start, segment_end, segment_size,
# range unbounded on the left; no -1 since we're
# asking for the last N bytes, not to have a
# particular byte be the last one
((segment_end + 1) / segment_size
((segment_end + 1) // segment_size
* fragment_size) if segment_start is None else
# range bounded on both sides; the -1 is because the
# rest of the expression computes the length of the
# fragment, and a range of N bytes starts at index M
# and ends at M + N - 1.
((segment_end + 1) / segment_size * fragment_size) - 1)
((segment_end + 1) // segment_size * fragment_size) - 1)
return (fragment_start, fragment_end)

View File

@ -443,7 +443,7 @@ class Application(object):
except (Exception, Timeout):
start_response('500 Server Error',
[('Content-Type', 'text/plain')])
return ['Internal server error.\n']
return [b'Internal server error.\n']
def update_request(self, req):
if 'x-storage-token' in req.headers and \

View File

@ -1045,10 +1045,10 @@ def fake_http_connect(*code_iter, **kwargs):
expect_headers = next(expect_headers_iter)
timestamp = next(timestamps_iter)
if status <= 0:
if isinstance(status, int) and status <= 0:
raise HTTPException()
if body_iter is None:
body = static_body or ''
body = static_body or b''
else:
body = next(body_iter)
return FakeConn(status, etag, body=body, timestamp=timestamp,
@ -1133,7 +1133,7 @@ def requires_o_tmpfile_support_in_tmp(func):
class StubResponse(object):
def __init__(self, status, body='', headers=None, frag_index=None):
def __init__(self, status, body=b'', headers=None, frag_index=None):
self.status = status
self.body = body
self.readable = BytesIO(body)
@ -1188,7 +1188,7 @@ def encode_frag_archive_bodies(policy, body):
def make_ec_object_stub(test_body, policy, timestamp):
segment_size = policy.ec_segment_size
test_body = test_body or (
'test' * segment_size)[:-random.randint(1, 1000)]
b'test' * segment_size)[:-random.randint(1, 1000)]
timestamp = timestamp or utils.Timestamp.now()
etag = md5(test_body).hexdigest()
ec_archive_bodies = encode_frag_archive_bodies(policy, test_body)

File diff suppressed because it is too large Load Diff

View File

@ -86,7 +86,8 @@ commands =
test/unit/container/test_replicator.py \
test/unit/container/test_sync_store.py \
test/unit/obj/test_server.py \
test/unit/proxy/controllers/test_info.py}
test/unit/proxy/controllers/test_info.py \
test/unit/proxy/controllers/test_obj.py}
[testenv:py36]
commands = {[testenv:py35]commands}