From cf966b950a4ace91f4fa4b6cf01b0cebdb5e6b5a Mon Sep 17 00:00:00 2001 From: Chmouel Boudjnah Date: Wed, 21 Aug 2013 09:36:27 +0200 Subject: [PATCH] Allow configure the number of http retries Allow setting the maximum number of times we want to retry to http_connect when communicating with the Identity service. Closes-Bug: 1209194 Change-Id: I56bff55dc808a1188d42f1643a8018a8d49012c6 --- keystoneclient/middleware/auth_token.py | 7 ++++++- tests/test_auth_token_middleware.py | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/keystoneclient/middleware/auth_token.py b/keystoneclient/middleware/auth_token.py index f2a0991ef..f58de4b60 100644 --- a/keystoneclient/middleware/auth_token.py +++ b/keystoneclient/middleware/auth_token.py @@ -228,6 +228,10 @@ opts = [ default=None, help='Request timeout value for communicating with Identity' ' API server.'), + cfg.IntOpt('http_request_max_retries', + default=3, + help='How many times are we trying to reconnect when' + ' communicating with Identity API Server.'), cfg.StrOpt('http_handler', default=None, help='Allows to pass in the name of a fake http_handler' @@ -428,7 +432,8 @@ class AuthProtocol(object): self.http_connect_timeout = (http_connect_timeout_cfg and int(http_connect_timeout_cfg)) self.auth_version = None - self.http_request_max_retries = 3 + self.http_request_max_retries = \ + self._conf_get('http_request_max_retries') def _assert_valid_memcache_protection_config(self): if self._memcache_security_strategy: diff --git a/tests/test_auth_token_middleware.py b/tests/test_auth_token_middleware.py index 172acf751..eac659c3c 100644 --- a/tests/test_auth_token_middleware.py +++ b/tests/test_auth_token_middleware.py @@ -26,6 +26,7 @@ import testtools import uuid import fixtures +import mock import webob from keystoneclient.common import cms @@ -1282,6 +1283,21 @@ class AuthTokenMiddlewareTest(BaseAuthTokenMiddlewareTest): self.middleware(req.environ, self.start_fake_response) self.assertEqual(self._get_cached_token(token), None) + def test_http_request_max_retries(self): + times_retry = 10 + + req = webob.Request.blank('/') + token = self.token_dict['uuid_token_default'] + req.headers['X-Auth-Token'] = token + + self.set_middleware(conf=dict(http_request_max_retries=times_retry)) + + with mock.patch('time.sleep') as mock_obj: + self.set_fake_http(RaisingHTTPNetworkError) + self.middleware(req.environ, self.start_fake_response) + + self.assertEqual(mock_obj.call_count, times_retry) + class CertDownloadMiddlewareTest(BaseAuthTokenMiddlewareTest): def setUp(self):