Merge "Fix full_listing in internal_client"

This commit is contained in:
Jenkins 2016-03-24 20:19:28 +00:00 committed by Gerrit Code Review
commit 9c014e855c
2 changed files with 41 additions and 1 deletions

View File

@ -741,11 +741,25 @@ class SimpleClient(object):
def base_request(self, method, container=None, name=None, prefix=None,
headers=None, proxy=None, contents=None,
full_listing=None, logger=None, additional_info=None,
timeout=None):
timeout=None, marker=None):
# Common request method
trans_start = time()
url = self.url
if full_listing:
body_data = self.base_request(method, container, name, prefix,
headers, proxy, timeout=timeout,
marker=marker)
listing = body_data[1]
while listing:
marker = listing[-1]['name']
listing = self.base_request(method, container, name, prefix,
headers, proxy, timeout=timeout,
marker=marker)[1]
if listing:
body_data[1].extend(listing)
return body_data
if headers is None:
headers = {}
@ -762,6 +776,9 @@ class SimpleClient(object):
if prefix:
url += '&prefix=%s' % prefix
if marker:
url += '&marker=%s' % quote(marker)
req = urllib2.Request(url, headers=headers, data=contents)
if proxy:
proxy = urllib.parse.urlparse(proxy)

View File

@ -356,6 +356,29 @@ class TestInternalClient(unittest.TestCase):
# sanity check
self.assertEqual(body, resp_body)
def test_base_full_listing(self):
body1 = [{'name': 'a'}, {'name': "b"}, {'name': "c"}]
body2 = [{'name': 'd'}]
body3 = []
class FakeConn(object):
def __init__(self, body):
self.body = body
def read(self):
return json.dumps(self.body)
def info(self):
return {}
mocked_func = 'swift.common.internal_client.urllib2.urlopen'
with mock.patch(mocked_func) as mock_urlopen:
mock_urlopen.side_effect = [
FakeConn(body1), FakeConn(body2), FakeConn(body3)]
sc = internal_client.SimpleClient('http://0.0.0.0/')
_, resp_body = sc.base_request('GET', full_listing=True)
self.assertEqual(body1 + body2, resp_body)
def test_make_request_method_path_headers(self):
class InternalClient(internal_client.InternalClient):
def __init__(self):