From 788001fcaf20600b8d50a86cf86884b5946710f9 Mon Sep 17 00:00:00 2001 From: drngsl Date: Wed, 15 Feb 2017 03:24:42 -0500 Subject: [PATCH] Raise TypeError in manilaclient/common/httpclient.py object 'HTTPClient' property 'retries' is None for default, when code 'if attempts > self.retries:' is executed at some time, TypeError will raise. Change-Id: I37c6235d30edc3afc5c5e2c88d710b6c60f49311 Closes-Bug: #1664877 --- manilaclient/common/httpclient.py | 2 +- manilaclient/tests/unit/common/test_httpclient.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/manilaclient/common/httpclient.py b/manilaclient/common/httpclient.py index 3cc8bd4..f309bf8 100644 --- a/manilaclient/common/httpclient.py +++ b/manilaclient/common/httpclient.py @@ -48,7 +48,7 @@ class HTTPClient(object): http_log_debug=False): self.endpoint_url = endpoint_url self.base_url = self._get_base_url(self.endpoint_url) - self.retries = retries + self.retries = int(retries or 0) self.http_log_debug = http_log_debug self.request_options = self._set_request_options( diff --git a/manilaclient/tests/unit/common/test_httpclient.py b/manilaclient/tests/unit/common/test_httpclient.py index 5fca734..4d48c76 100644 --- a/manilaclient/tests/unit/common/test_httpclient.py +++ b/manilaclient/tests/unit/common/test_httpclient.py @@ -176,6 +176,15 @@ class ClientTest(utils.TestCase): test_get_call() self.assertEqual(self.requests, []) + def test_get_with_retries_none(self): + cl = get_authed_client(retries=None) + + @mock.patch.object(requests, "request", bad_401_request) + def test_get_call(): + resp, body = cl.get("/hi") + + self.assertRaises(exceptions.Unauthorized, test_get_call) + def test_post(self): cl = get_authed_client()