From 0d41b2326009c470f41f365c508e473ebdacb11c Mon Sep 17 00:00:00 2001 From: Matthew Oliver Date: Tue, 7 Jun 2016 14:52:28 +1000 Subject: [PATCH] Add end_marker and reverse options to direct_client Currently the direct_get_container and direct_get_account methods of the direct client don't support passing in the 'end_marker' and 'reverse' params. This change adds support for these params in direct client. Change-Id: I846fc70ff3abdb1674152a8d9e0521c709f254c4 --- swift/common/direct_client.py | 22 ++++++++++++++++++---- test/unit/common/test_direct_client.py | 9 +++++++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/swift/common/direct_client.py b/swift/common/direct_client.py index 94be486d74..cfc25d6eb8 100644 --- a/swift/common/direct_client.py +++ b/swift/common/direct_client.py @@ -79,8 +79,9 @@ def _make_req(node, part, method, path, _headers, stype, def _get_direct_account_container(path, stype, node, part, marker=None, limit=None, - prefix=None, delimiter=None, conn_timeout=5, - response_timeout=15): + prefix=None, delimiter=None, + conn_timeout=5, response_timeout=15, + end_marker=None, reverse=None): """Base class for get direct account and container. Do not use directly use the get_direct_account or @@ -95,6 +96,10 @@ def _get_direct_account_container(path, stype, node, part, qs += '&prefix=%s' % quote(prefix) if delimiter: qs += '&delimiter=%s' % quote(delimiter) + if end_marker: + qs += '&end_marker=%s' % quote(end_marker) + if reverse: + qs += '&reverse=%s' % quote(reverse) with Timeout(conn_timeout): conn = http_connect(node['ip'], node['port'], node['device'], part, 'GET', path, query_string=qs, @@ -124,7 +129,7 @@ def gen_headers(hdrs_in=None, add_ts=False): def direct_get_account(node, part, account, marker=None, limit=None, prefix=None, delimiter=None, conn_timeout=5, - response_timeout=15): + response_timeout=15, end_marker=None, reverse=None): """ Get listings directly from the account server. @@ -137,6 +142,8 @@ def direct_get_account(node, part, account, marker=None, limit=None, :param delimiter: delimiter for the query :param conn_timeout: timeout in seconds for establishing the connection :param response_timeout: timeout in seconds for getting the response + :param end_marker: end_marker query + :param reverse: reverse the returned listing :returns: a tuple of (response headers, a list of containers) The response headers will HeaderKeyDict. """ @@ -145,6 +152,8 @@ def direct_get_account(node, part, account, marker=None, limit=None, marker=marker, limit=limit, prefix=prefix, delimiter=delimiter, + end_marker=end_marker, + reverse=reverse, conn_timeout=conn_timeout, response_timeout=response_timeout) @@ -185,7 +194,8 @@ def direct_head_container(node, part, account, container, conn_timeout=5, def direct_get_container(node, part, account, container, marker=None, limit=None, prefix=None, delimiter=None, - conn_timeout=5, response_timeout=15): + conn_timeout=5, response_timeout=15, end_marker=None, + reverse=None): """ Get container listings directly from the container server. @@ -199,6 +209,8 @@ def direct_get_container(node, part, account, container, marker=None, :param delimiter: delimiter for the query :param conn_timeout: timeout in seconds for establishing the connection :param response_timeout: timeout in seconds for getting the response + :param end_marker: end_marker query + :param reverse: reverse the returned listing :returns: a tuple of (response headers, a list of objects) The response headers will be a HeaderKeyDict. """ @@ -207,6 +219,8 @@ def direct_get_container(node, part, account, container, marker=None, part, marker=marker, limit=limit, prefix=prefix, delimiter=delimiter, + end_marker=end_marker, + reverse=reverse, conn_timeout=conn_timeout, response_timeout=response_timeout) diff --git a/test/unit/common/test_direct_client.py b/test/unit/common/test_direct_client.py index aae8129340..1426f28406 100644 --- a/test/unit/common/test_direct_client.py +++ b/test/unit/common/test_direct_client.py @@ -172,7 +172,8 @@ class TestDirectClient(unittest.TestCase): with mocked_http_conn(200, stub_headers, body) as conn: resp_headers, resp = direct_client.direct_get_account( self.node, self.part, self.account, marker='marker', - prefix='prefix', delimiter='delimiter', limit=1000) + prefix='prefix', delimiter='delimiter', limit=1000, + end_marker='endmarker', reverse='on') self.assertEqual(conn.method, 'GET') self.assertEqual(conn.path, self.account_path) @@ -184,6 +185,8 @@ class TestDirectClient(unittest.TestCase): self.assertTrue('limit=1000' in conn.query_string) self.assertTrue('prefix=prefix' in conn.query_string) self.assertTrue('format=json' in conn.query_string) + self.assertTrue('end_marker=endmarker' in conn.query_string) + self.assertTrue('reverse=on' in conn.query_string) def test_direct_client_exception(self): stub_headers = {'X-Trans-Id': 'txb5f59485c578460f8be9e-0053478d09'} @@ -335,7 +338,7 @@ class TestDirectClient(unittest.TestCase): resp_headers, resp = direct_client.direct_get_container( self.node, self.part, self.account, self.container, marker='marker', prefix='prefix', delimiter='delimiter', - limit=1000) + limit=1000, end_marker='endmarker', reverse='on') self.assertEqual(conn.req_headers['user-agent'], 'direct-client %s' % os.getpid()) @@ -346,6 +349,8 @@ class TestDirectClient(unittest.TestCase): self.assertTrue('limit=1000' in conn.query_string) self.assertTrue('prefix=prefix' in conn.query_string) self.assertTrue('format=json' in conn.query_string) + self.assertTrue('end_marker=endmarker' in conn.query_string) + self.assertTrue('reverse=on' in conn.query_string) def test_direct_get_container_no_content_does_not_decode_body(self): headers = {}