Skip to content
This repository was archived by the owner on Nov 29, 2023. It is now read-only.

Commit 6c7fb0e

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Report name resolution errors properly"
2 parents 51bbf74 + 7f7c9a1 commit 6c7fb0e

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

glanceclient/common/http.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ def _http_request(self, url, method, **kwargs):
183183
conn.request(method, conn_url, **kwargs)
184184
resp = conn.getresponse()
185185
except socket.gaierror as e:
186-
message = "Error finding address for %(url)s: %(e)s" % locals()
186+
message = "Error finding address for %s: %s" % (
187+
self.endpoint_hostname, e)
187188
raise exc.InvalidEndpoint(message=message)
188189
except (socket.error, socket.timeout) as e:
189190
endpoint = self.endpoint

tests/test_http.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,48 @@ def test_http_encoding(self):
8383
self.assertEqual(resp, fake)
8484

8585

86+
class TestHostResolutionError(testtools.TestCase):
87+
88+
def setUp(self):
89+
super(TestHostResolutionError, self).setUp()
90+
self.mock = mox.Mox()
91+
self.invalid_host = "example.com.incorrect_top_level_domain"
92+
93+
def test_incorrect_domain_error(self):
94+
"""
95+
Make sure that using a domain which does not resolve causes an
96+
exception which mentions that specific hostname as a reason for
97+
failure.
98+
"""
99+
class FailingConnectionClass(object):
100+
def __init__(self, *args, **kwargs):
101+
pass
102+
103+
def putrequest(self, *args, **kwargs):
104+
raise socket.gaierror(-2, "Name or service not known")
105+
106+
def request(self, *args, **kwargs):
107+
raise socket.gaierror(-2, "Name or service not known")
108+
109+
self.endpoint = 'http://%s:9292' % (self.invalid_host,)
110+
self.client = http.HTTPClient(self.endpoint, token=u'abc123')
111+
112+
self.mock.StubOutWithMock(self.client, 'get_connection')
113+
self.client.get_connection().AndReturn(FailingConnectionClass())
114+
self.mock.ReplayAll()
115+
116+
try:
117+
self.client.raw_request('GET', '/example/path')
118+
self.fail("gaierror should be raised")
119+
except exc.InvalidEndpoint as e:
120+
self.assertTrue(self.invalid_host in str(e),
121+
"exception should contain the hostname")
122+
123+
def tearDown(self):
124+
super(TestHostResolutionError, self).tearDown()
125+
self.mock.UnsetStubs()
126+
127+
86128
class TestResponseBodyIterator(testtools.TestCase):
87129
def test_iter_default_chunk_size_64k(self):
88130
resp = utils.FakeResponse({}, StringIO.StringIO('X' * 98304))

0 commit comments

Comments
 (0)