diff --git a/solumclient/openstack/common/apiclient/client.py b/solumclient/openstack/common/apiclient/client.py index 33e151b..82d56b6 100644 --- a/solumclient/openstack/common/apiclient/client.py +++ b/solumclient/openstack/common/apiclient/client.py @@ -242,6 +242,20 @@ class HTTPClient(object): try: return self.request( method, self.concat_url(endpoint, url), **kwargs) + except exceptions.ConnectionRefused as refused_ex: + print('ERROR: Cannot connect to %s. Make sure it ' + + 'is valid: %s.' % endpoint) + raise refused_ex + except exceptions.EndpointException as endpoint_ex: + print('ERROR: Service catalog endpoint is invalid. ' + + 'Please check your ' + + 'endpoint is valid: %s.' % endpoint) + raise endpoint_ex + except requests.ConnectionError as conn_err: + print('ERROR: Unable to connect to endpoint. ' + + 'Make sure that ' + + 'your endpoint (%s) is valid.' % endpoint) + raise conn_err except exceptions.Unauthorized as unauth_ex: if just_authenticated: raise diff --git a/solumclient/tests/common/test_client.py b/solumclient/tests/common/test_client.py index ddf73fb..e6f6a25 100644 --- a/solumclient/tests/common/test_client.py +++ b/solumclient/tests/common/test_client.py @@ -67,3 +67,30 @@ class ClientTest(base.TestCase): self.assertRaises( exceptions.HttpError, http_client.client_request, TestClient(http_client), "GET", "/resource") + + def test_client_with_invalid_endpoint(self): + http_client = client.HTTPClient(FakeAuthPlugin()) + mock_request = mock.Mock() + mock_request.side_effect = requests.ConnectionError + with mock.patch("requests.Session.request", mock_request): + self.assertRaises( + requests.ConnectionError, http_client.client_request, + TestClient(http_client), "GET", "/resource") + + def test_client_with_invalid_service_catalog(self): + http_client = client.HTTPClient(FakeAuthPlugin()) + mock_request = mock.Mock() + mock_request.side_effect = exceptions.EndpointException + with mock.patch("requests.Session.request", mock_request): + self.assertRaises( + exceptions.EndpointException, http_client.client_request, + TestClient(http_client), "GET", "/resource") + + def test_client_with_connection_refused(self): + http_client = client.HTTPClient(FakeAuthPlugin()) + mock_request = mock.Mock() + mock_request.side_effect = exceptions.ConnectionRefused + with mock.patch("requests.Session.request", mock_request): + self.assertRaises( + exceptions.ConnectionRefused, http_client.client_request, + TestClient(http_client), "GET", "/resource")