From 47f089fbcac5a587c3eef7dc7f83f6d476ababf9 Mon Sep 17 00:00:00 2001 From: Alistair Coles Date: Mon, 23 Feb 2015 11:09:39 +0000 Subject: [PATCH] Include unsupported url scheme with ClientException This was an attempt to reveal some more info about failing jenkins jobs such as here [1] where glance_store is receiving a swiftclient exception because of 'unsupported scheme in url'. It seems worth merging the more helpful exception message. [1] http://logs.openstack.org/91/155291/7/check/gate-tempest-dsvm-neutron-src-python-swiftclient/4adac1e/ Change-Id: I0f3411efd42d045b07d6d1000f59a06865d8034b --- swiftclient/client.py | 3 ++- tests/unit/test_swiftclient.py | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/swiftclient/client.py b/swiftclient/client.py index d0ff52ea..2a19ae4e 100644 --- a/swiftclient/client.py +++ b/swiftclient/client.py @@ -170,7 +170,8 @@ class HTTPConnection(object): self.requests_args = {} self.request_session = requests.Session() if self.parsed_url.scheme not in ('http', 'https'): - raise ClientException("Unsupported scheme") + raise ClientException('Unsupported scheme "%s" in url "%s"' + % (self.parsed_url.scheme, url)) self.requests_args['verify'] = not insecure if cacert and not insecure: # verify requests parameter is used to pass the CA_BUNDLE file diff --git a/tests/unit/test_swiftclient.py b/tests/unit/test_swiftclient.py index 03600163..931a2165 100644 --- a/tests/unit/test_swiftclient.py +++ b/tests/unit/test_swiftclient.py @@ -975,6 +975,29 @@ class TestGetCapabilities(MockHttpTest): class TestHTTPConnection(MockHttpTest): + def test_bad_url_scheme(self): + url = u'www.test.com' + exc = self.assertRaises(c.ClientException, c.http_connection, url) + expected = u'Unsupported scheme "" in url "www.test.com"' + self.assertEqual(expected, str(exc)) + + url = u'://www.test.com' + exc = self.assertRaises(c.ClientException, c.http_connection, url) + expected = u'Unsupported scheme "" in url "://www.test.com"' + self.assertEqual(expected, str(exc)) + + url = u'blah://www.test.com' + exc = self.assertRaises(c.ClientException, c.http_connection, url) + expected = u'Unsupported scheme "blah" in url "blah://www.test.com"' + self.assertEqual(expected, str(exc)) + + def test_ok_url_scheme(self): + for scheme in ('http', 'https', 'HTTP', 'HTTPS'): + url = u'%s://www.test.com' % scheme + parsed_url, conn = c.http_connection(url) + self.assertEqual(scheme.lower(), parsed_url.scheme) + self.assertEqual(u'%s://www.test.com' % scheme, conn.url) + def test_ok_proxy(self): conn = c.http_connection(u'http://www.test.com/', proxy='http://localhost:8080')