From 7df87fd4a26ebee3899fbc42d21757bf880a10d4 Mon Sep 17 00:00:00 2001 From: Eric Fried Date: Fri, 19 May 2017 14:53:34 -0400 Subject: [PATCH] Convert IOError from requests This requests commit [1] changed the behavior when a nonexistent cacert file is passed in: now it raises IOError. This is getting through glanceclient.common.http.HTTPClient._request, which used to raise CommunicationError in this scenario. Even though there is arguably a better exception than CommunicationError to represent this condition (like maybe IOError), for backward compatibility this change set converts IOError to CommunicationError. We also improve the unit test to raise the original exception if the expected conditions aren't met; this improves debugability. [1] https://github.com/kennethreitz/requests/commit/7d8b87c37f3a5fb993fd83eda6888ac217cd108e Change-Id: I6a2cf4c6d041b67d3509153b4cef18b459263648 Closes-Bug: #1692085 --- glanceclient/common/http.py | 2 +- glanceclient/tests/unit/test_ssl.py | 12 ++---------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/glanceclient/common/http.py b/glanceclient/common/http.py index bb9c4b5..f65da68 100644 --- a/glanceclient/common/http.py +++ b/glanceclient/common/http.py @@ -257,7 +257,7 @@ class HTTPClient(_BaseHTTPClient): message = "Error finding address for %s: %s" % ( self.endpoint_hostname, e) raise exc.InvalidEndpoint(message=message) - except (socket.error, socket.timeout) as e: + except (socket.error, socket.timeout, IOError) as e: endpoint = self.endpoint message = ("Error communicating with %(endpoint)s %(e)s" % {'endpoint': endpoint, 'e': e}) diff --git a/glanceclient/tests/unit/test_ssl.py b/glanceclient/tests/unit/test_ssl.py index 69dd399..9bca2ec 100644 --- a/glanceclient/tests/unit/test_ssl.py +++ b/glanceclient/tests/unit/test_ssl.py @@ -252,13 +252,5 @@ class TestHTTPSVerifyCert(testtools.TestCase): cacert=cacert) gc.images.get('image123') except exc.CommunicationError as e: - # NOTE(dsariel) - # starting from python 2.7.8 the way of handling x509 certificates - # was changed (github.com/python/peps/blob/master/pep-0476.txt#L28) - # and error message become similar to the one in 3.X - if (six.PY2 and 'certificate' not in e.message and - 'No such file' not in e.message or - six.PY3 and 'No such file' not in e.message): - self.fail('No appropriate failure message is received') - except Exception as e: - self.fail('Unexpected exception has been raised') + if 'invalid path' not in e.message: + raise