Add exception states when solum cli cannot connect to endpoint

Added EndpointException, ConnectionError, and ConnectionRefused
errors with proper error messages to provide users with more
information than just "nodename nor servname provided, or not known"

Change-Id: Ib1f64cd8399795375fd701b613010f93013aea3b
This commit is contained in:
dimtruck
2015-04-16 21:08:59 -05:00
parent a2efd95c10
commit aad5eeec2e
2 changed files with 41 additions and 0 deletions

View File

@@ -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

View File

@@ -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")