diff options
| author | Stanislaw Pitucha <stanislaw.pitucha@hp.com> | 2013-02-19 15:40:16 +0000 |
|---|---|---|
| committer | Stanislaw Pitucha <stanislaw.pitucha@hp.com> | 2013-02-19 17:22:55 +0000 |
| commit | 7f7c9a1d8596cff87f576cf45318cf96c5d33262 (patch) | |
| tree | af64147dd81d3dd714d0d143858bcdab85cdf81c /tests/test_http.py | |
| parent | d831b5eb278a2e6830601044cea00cf1e2ffdde5 (diff) | |
| download | python-glanceclient-7f7c9a1d8596cff87f576cf45318cf96c5d33262.tar.gz | |
Report name resolution errors properly
Errors in name resolution have been logged previously with the url path
rather than the hostname. That resulted in incorrect errors like:
InvalidEndpoint: Error finding address for
/v1/images/detail?is_public=none&limit=20: [Errno -2]
Name or service not known
rather than one mentioning hostname itself. This patch changes the log
message to fit the situation.
Change-Id: I1eecbcb22d41b1341c214937b9cbfd046fd301a0
Diffstat (limited to 'tests/test_http.py')
| -rw-r--r-- | tests/test_http.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/test_http.py b/tests/test_http.py index cabcf8d..3d87444 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -83,6 +83,48 @@ class TestClient(testtools.TestCase): self.assertEqual(resp, fake) +class TestHostResolutionError(testtools.TestCase): + + def setUp(self): + super(TestHostResolutionError, self).setUp() + self.mock = mox.Mox() + self.invalid_host = "example.com.incorrect_top_level_domain" + + def test_incorrect_domain_error(self): + """ + Make sure that using a domain which does not resolve causes an + exception which mentions that specific hostname as a reason for + failure. + """ + class FailingConnectionClass(object): + def __init__(self, *args, **kwargs): + pass + + def putrequest(self, *args, **kwargs): + raise socket.gaierror(-2, "Name or service not known") + + def request(self, *args, **kwargs): + raise socket.gaierror(-2, "Name or service not known") + + self.endpoint = 'http://%s:9292' % (self.invalid_host,) + self.client = http.HTTPClient(self.endpoint, token=u'abc123') + + self.mock.StubOutWithMock(self.client, 'get_connection') + self.client.get_connection().AndReturn(FailingConnectionClass()) + self.mock.ReplayAll() + + try: + self.client.raw_request('GET', '/example/path') + self.fail("gaierror should be raised") + except exc.InvalidEndpoint as e: + self.assertTrue(self.invalid_host in str(e), + "exception should contain the hostname") + + def tearDown(self): + super(TestHostResolutionError, self).tearDown() + self.mock.UnsetStubs() + + class TestResponseBodyIterator(testtools.TestCase): def test_iter_default_chunk_size_64k(self): resp = utils.FakeResponse({}, StringIO.StringIO('X' * 98304)) |
