Merge "py3: port proxy container controller"

This commit is contained in:
Zuul 2019-03-05 01:01:04 +00:00 committed by Gerrit Code Review
commit 65f2fd8c95
4 changed files with 15 additions and 10 deletions

View File

@ -17,6 +17,7 @@ from swift import gettext_ as _
import json
from six.moves.urllib.parse import unquote
from swift.common.utils import public, csv_append, Timestamp, \
config_true_value, ShardRange
from swift.common.constraints import check_metadata, CONTAINER_LISTING_LIMIT
@ -26,7 +27,7 @@ from swift.proxy.controllers.base import Controller, delay_denial, \
cors_validation, set_info_cache, clear_info_cache
from swift.common.storage_policy import POLICIES
from swift.common.swob import HTTPBadRequest, HTTPForbidden, \
HTTPNotFound, HTTPServiceUnavailable
HTTPNotFound, HTTPServiceUnavailable, str_to_wsgi, wsgi_to_bytes
class ContainerController(Controller):
@ -187,9 +188,9 @@ class ContainerController(Controller):
if end_marker and end_marker in shard_range:
params['end_marker'] = end_marker
elif reverse:
params['end_marker'] = shard_range.lower_str
params['end_marker'] = str_to_wsgi(shard_range.lower_str)
else:
params['end_marker'] = shard_range.end_marker
params['end_marker'] = str_to_wsgi(shard_range.end_marker)
if (shard_range.account == self.account_name and
shard_range.container == self.container_name):
@ -212,11 +213,13 @@ class ContainerController(Controller):
if limit <= 0:
break
elif (end_marker and reverse and
end_marker >= objects[-1]['name'].encode('utf-8')):
if (end_marker and reverse and
(wsgi_to_bytes(end_marker) >=
objects[-1]['name'].encode('utf-8'))):
break
elif (end_marker and not reverse and
end_marker <= objects[-1]['name'].encode('utf-8')):
if (end_marker and not reverse and
(wsgi_to_bytes(end_marker) <=
objects[-1]['name'].encode('utf-8'))):
break
resp.body = json.dumps(objects).encode('ascii')

View File

@ -47,7 +47,7 @@ class FakeResponse(object):
base_headers = {}
def __init__(self, status_int=200, headers=None, body=''):
def __init__(self, status_int=200, headers=None, body=b''):
self.status_int = status_int
self._headers = headers or {}
self.body = body

View File

@ -450,7 +450,8 @@ class TestContainerController(TestRingBase):
self.assertLess(name(prev), name(next_))
container_path = '/v1/a/c' + query_string
codes = (resp[0] for resp in mock_responses)
bodies = iter([json.dumps(resp[1]) for resp in mock_responses])
bodies = iter([json.dumps(resp[1]).encode('ascii')
for resp in mock_responses])
exp_headers = [resp[2] for resp in mock_responses]
request = Request.blank(container_path)
with mocked_http_conn(
@ -1010,7 +1011,7 @@ class TestContainerController(TestRingBase):
'X-Backend-Sharding-State': 'unsharded',
'X-Container-Object-Count': 0,
'X-Container-Bytes-Used': 0,
'X-Container-Meta-Flavour': 'flavour%d' % i,
'X-Container-Meta-Flavour': 'flavour',
'X-Backend-Storage-Policy-Index': 0}
# empty first shard range

View File

@ -88,6 +88,7 @@ commands =
test/unit/obj/test_server.py \
test/unit/obj/test_updater.py \
test/unit/proxy/controllers/test_base.py \
test/unit/proxy/controllers/test_container.py \
test/unit/proxy/controllers/test_info.py \
test/unit/proxy/controllers/test_obj.py}