summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--swiftclient/client.py10
-rw-r--r--swiftclient/service.py3
-rw-r--r--test/unit/test_swiftclient.py53
3 files changed, 38 insertions, 28 deletions
diff --git a/swiftclient/client.py b/swiftclient/client.py
index 168bfed..e42ac70 100644
--- a/swiftclient/client.py
+++ b/swiftclient/client.py
@@ -1646,7 +1646,7 @@ class Connection:
starting_backoff=1, max_backoff=64, tenant_name=None,
os_options=None, auth_version="1", cacert=None,
insecure=False, cert=None, cert_key=None,
- ssl_compression=True, retry_on_ratelimit=False,
+ ssl_compression=True, retry_on_ratelimit=True,
timeout=None, session=None, force_auth_retry=False):
"""
:param authurl: authentication URL
@@ -1678,9 +1678,9 @@ class Connection:
will be made. This may provide a performance
increase for https upload/download operations.
:param retry_on_ratelimit: by default, a ratelimited connection will
- raise an exception to the caller. Setting
- this parameter to True will cause a retry
- after a backoff.
+ retry after a backoff. Setting this
+ parameter to False will cause an exception
+ to be raised to the caller.
:param timeout: The connect timeout for the HTTP connection.
:param session: A keystoneauth session object.
:param force_auth_retry: reset auth info even if client got unexpected
@@ -1825,7 +1825,7 @@ class Connection:
self.http_conn = None
elif 500 <= err.http_status <= 599:
pass
- elif self.retry_on_ratelimit and err.http_status == 498:
+ elif self.retry_on_ratelimit and err.http_status in (498, 429):
pass
else:
raise
diff --git a/swiftclient/service.py b/swiftclient/service.py
index ed0f40a..440271b 100644
--- a/swiftclient/service.py
+++ b/swiftclient/service.py
@@ -155,6 +155,7 @@ def _build_default_global_options():
"user": environ.get('ST_USER'),
"key": environ.get('ST_KEY'),
"retries": 5,
+ "retry_on_ratelimit": True,
"force_auth_retry": False,
"os_username": environ.get('OS_USERNAME'),
"os_user_id": environ.get('OS_USER_ID'),
@@ -270,10 +271,12 @@ def get_conn(options):
"""
Return a connection building it from the options.
"""
+ options = dict(_default_global_options, **options)
return Connection(options['auth'],
options['user'],
options['key'],
timeout=options.get('timeout'),
+ retry_on_ratelimit=options['retry_on_ratelimit'],
retries=options['retries'],
auth_version=options['auth_version'],
os_options=options['os_options'],
diff --git a/test/unit/test_swiftclient.py b/test/unit/test_swiftclient.py
index ad2af50..ae3e76f 100644
--- a/test/unit/test_swiftclient.py
+++ b/test/unit/test_swiftclient.py
@@ -2130,30 +2130,37 @@ class TestConnection(MockHttpTest):
pass
c.sleep = quick_sleep
- # test retries
- conn = c.Connection('http://www.test.com/auth/v1.0', 'asdf', 'asdf',
- retry_on_ratelimit=True)
- code_iter = [200] + [498] * (conn.retries + 1)
- auth_resp_headers = {
- 'x-auth-token': 'asdf',
- 'x-storage-url': 'http://storage/v1/test',
- }
- c.http_connection = self.fake_http_connection(
- *code_iter, headers=auth_resp_headers)
- with self.assertRaises(c.ClientException) as exc_context:
- conn.head_account()
- self.assertIn('Account HEAD failed', str(exc_context.exception))
- self.assertEqual(conn.attempts, conn.retries + 1)
+ def test_status_code(code):
+ # test retries
+ conn = c.Connection('http://www.test.com/auth/v1.0',
+ 'asdf', 'asdf', retry_on_ratelimit=True)
+ code_iter = [200] + [code] * (conn.retries + 1)
+ auth_resp_headers = {
+ 'x-auth-token': 'asdf',
+ 'x-storage-url': 'http://storage/v1/test',
+ }
+ c.http_connection = self.fake_http_connection(
+ *code_iter, headers=auth_resp_headers)
+ with self.assertRaises(c.ClientException) as exc_context:
+ conn.head_account()
+ self.assertIn('Account HEAD failed', str(exc_context.exception))
+ self.assertEqual(code, exc_context.exception.http_status)
+ self.assertEqual(conn.attempts, conn.retries + 1)
- # test default no-retry
- c.http_connection = self.fake_http_connection(
- 200, 498,
- headers=auth_resp_headers)
- conn = c.Connection('http://www.test.com/auth/v1.0', 'asdf', 'asdf')
- with self.assertRaises(c.ClientException) as exc_context:
- conn.head_account()
- self.assertIn('Account HEAD failed', str(exc_context.exception))
- self.assertEqual(conn.attempts, 1)
+ # test default no-retry
+ c.http_connection = self.fake_http_connection(
+ 200, code,
+ headers=auth_resp_headers)
+ conn = c.Connection('http://www.test.com/auth/v1.0',
+ 'asdf', 'asdf', retry_on_ratelimit=False)
+ with self.assertRaises(c.ClientException) as exc_context:
+ conn.head_account()
+ self.assertIn('Account HEAD failed', str(exc_context.exception))
+ self.assertEqual(code, exc_context.exception.http_status)
+ self.assertEqual(conn.attempts, 1)
+
+ test_status_code(498)
+ test_status_code(429)
def test_retry_with_socket_error(self):
def quick_sleep(*args):