summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2014-07-25 00:31:28 +0000
committerGerrit Code Review <review@openstack.org>2014-07-25 00:31:28 +0000
commit14a5aa045a391a900e34a5341b07b71ac973cf77 (patch)
treeee71701a766f86e29e3d295d469004382cbe013f
parentba826fbf3cc9219ad0cce0ff2d529975efc13a8d (diff)
parentfd8aa394580c281f55af31874abb9183aeb469a9 (diff)
downloadpython-cinderclient-14a5aa045a391a900e34a5341b07b71ac973cf77.tar.gz
Merge "Retry when connection to cinder is refused"
-rw-r--r--cinderclient/client.py5
-rw-r--r--cinderclient/tests/test_http.py20
2 files changed, 23 insertions, 2 deletions
diff --git a/cinderclient/client.py b/cinderclient/client.py
index 71d2a42..3145324 100644
--- a/cinderclient/client.py
+++ b/cinderclient/client.py
@@ -317,8 +317,9 @@ class HTTPClient(CinderClientMixin):
except requests.exceptions.ConnectionError as e:
# Catch a connection refused from requests.request
self._logger.debug("Connection refused: %s" % e)
- msg = 'Unable to establish connection: %s' % e
- raise exceptions.ConnectionError(msg)
+ if attempts > self.retries:
+ msg = 'Unable to establish connection: %s' % e
+ raise exceptions.ConnectionError(msg)
self._logger.debug(
"Failed attempt(%s of %s), retrying in %s seconds" %
(attempts, self.retries, backoff))
diff --git a/cinderclient/tests/test_http.py b/cinderclient/tests/test_http.py
index 18eafeb..8d162be 100644
--- a/cinderclient/tests/test_http.py
+++ b/cinderclient/tests/test_http.py
@@ -51,6 +51,9 @@ bad_500_response = utils.TestResponse({
})
bad_500_request = mock.Mock(return_value=(bad_500_response))
+connection_error_request = mock.Mock(
+ side_effect=requests.exceptions.ConnectionError)
+
def get_client(retries=0):
cl = client.HTTPClient("username", "password",
@@ -127,6 +130,23 @@ class ClientTest(utils.TestCase):
test_get_call()
self.assertEqual(self.requests, [])
+ def test_get_retry_connection_error(self):
+ cl = get_authed_client(retries=1)
+
+ self.requests = [connection_error_request, mock_request]
+
+ def request(*args, **kwargs):
+ next_request = self.requests.pop(0)
+ return next_request(*args, **kwargs)
+
+ @mock.patch.object(requests, "request", request)
+ @mock.patch('time.time', mock.Mock(return_value=1234))
+ def test_get_call():
+ resp, body = cl.get("/hi")
+
+ test_get_call()
+ self.assertEqual(self.requests, [])
+
def test_retry_limit(self):
cl = get_authed_client(retries=1)