Skip to content

Commit 3ec2f0c

Browse files
committed
fix(client): improve timeout logging
Signed-off-by: Chris Snow <[email protected]>
1 parent 7de8c3a commit 3ec2f0c

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

hpecp/client.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828

2929
import requests
3030
from six import raise_from
31+
from urllib3.exceptions import (
32+
NewConnectionError,
33+
ConnectTimeoutError,
34+
MaxRetryError,
35+
)
3136

3237
from .catalog import CatalogController
3338
from .config import ConfigController
@@ -477,20 +482,26 @@ def create_session(self):
477482
response = None
478483
try:
479484
self.log.debug("REQ: {} : {} {}".format("Login", "post", url))
480-
response = requests.post(url, json=auth, verify=self.verify_ssl)
485+
response = requests.post(
486+
url, json=auth, verify=self.verify_ssl, timeout=10
487+
)
481488
response.raise_for_status()
482489

483-
except requests.exceptions.ConnectionError as e:
490+
except (
491+
requests.exceptions.ConnectionError,
492+
NewConnectionError,
493+
MaxRetryError,
494+
ConnectTimeoutError,
495+
) as e:
484496
self.log.debug(
485497
"RES: {} : {} {} {}".format("Login", "post", url, str(e))
486498
)
487499
if self.log.level == 10: # "DEBUG"
488-
msg = "Could not connect to controller."
500+
# The error is already output to the log, so this message
501+
# can be brief.
502+
msg = "Could not connect to the controller."
489503
else:
490-
msg = (
491-
"Could not connect to controller - set LOG_LEVEL=DEBUG to "
492-
"see more detail."
493-
)
504+
msg = "Could not connect to the controller.\n" + str(e)
494505
raise_from(
495506
APIException(
496507
message=msg, request_method="post", request_url=url,

tests/library/cli_test.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,15 @@ def test_get_failed_login(self, mock_get, mock_post):
337337

338338
self.assertEqual(cm.exception.code, 1)
339339

340-
self.assertEqual(self.out.getvalue(), "")
340+
self.assertEqual(self.out.getvalue().strip(), "")
341+
342+
actual_err = self.err.getvalue().strip()
343+
expected_err = "Could not connect to the controller."
341344

342345
# coverage seems to populate standard error (issues 93)
343346
self.assertTrue(
344-
self.err.getvalue().endswith(
345-
"Could not connect to controller - set LOG_LEVEL=DEBUG to see more detail.\n"
346-
)
347+
self.err.getvalue().strip().endswith(expected_err),
348+
"Expected: `{}` Actual: `{}`".format(expected_err, actual_err),
347349
)
348350

349351
@patch("requests.get", side_effect=mocked_requests_get)

0 commit comments

Comments
 (0)