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] 7d8b87c37f
Change-Id: I6a2cf4c6d041b67d3509153b4cef18b459263648
Closes-Bug: #1692085
This commit is contained in:
parent
a0edf0c2bf
commit
7df87fd4a2
|
@ -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})
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue