-
Notifications
You must be signed in to change notification settings - Fork 57
Add connection timeout #341
Add connection timeout #341
Conversation
3c85cf1
to
c97dc75
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes suggested do seem to add value, and allowing for a custom timeout is something that does make sense.
I've made a few requests for changes, but overall the PR looks good.
tests/unit/test_connection.py
Outdated
@@ -858,6 +872,18 @@ def test_do_http_with_bad_status_line(self, mock_get_connection): | |||
|
|||
mock_conn.close.assert_has_calls([call(), call()]) | |||
|
|||
@patch.object(connection, 'get_connection') | |||
def test_do_http_with_io_error(self, mock_get_connection): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest swapping out the more generic term io in this test title for the more specific timeout, which is being targeted in this test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
tests/unit/test_connection.py
Outdated
@@ -604,6 +604,20 @@ def test_download_to_stream_when_error_status_with_empty_body(self, mock_get_con | |||
else: | |||
self.fail() | |||
|
|||
@patch.object(connection, 'get_connection') | |||
def test_download_to_stream_with_io_error(self, mock_get_connection): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest swapping out the more generic term io in this test title for the more specific timeout, which is being targeted in this test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
hpOneView/oneview_client.py
Outdated
|
||
config = dict(ip=ip, | ||
image_streamer_ip=image_streamer_ip, | ||
api_version=api_version, | ||
ssl_certificate=ssl_certificate, | ||
credentials=dict(userName=username, authLoginDomain=auth_login_domain, password=password, sessionID=sessionID), | ||
proxy=proxy) | ||
proxy=proxy, | ||
timeout=timeout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be added in line 242 after proxy=proxy,
, no need to add a new line only for this field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
hpOneView/oneview_client.py
Outdated
@@ -116,7 +116,8 @@ class OneViewClient(object): | |||
DEFAULT_API_VERSION = 300 | |||
|
|||
def __init__(self, config): | |||
self.__connection = connection(config["ip"], config.get('api_version', self.DEFAULT_API_VERSION), config.get('ssl_certificate', False)) | |||
self.__connection = connection(config["ip"], config.get('api_version', self.DEFAULT_API_VERSION), | |||
config.get('ssl_certificate', False), config.get('timeout')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason to move config.get('ssl_certificate', False),
? Otherwise it should remain in line 119.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
hpOneView/connection.py
Outdated
@@ -148,6 +149,9 @@ def do_http(self, method, path, body, custom_headers=None): | |||
conn.close() | |||
time.sleep(1) | |||
continue | |||
except http.client.HTTPException as e: | |||
raise HPOneViewException(str(e)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps its worth using traceback.format_exc()
here instead of str(e)
, in a similar way to this line, to make sure we get the same behavior in py2/3 and a full stack trace in case of hitting an issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line appears to still be using str(e)
though, perhaps it was missed in the commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed that one, fixed
CHANGELOG.md
Outdated
@@ -1,3 +1,8 @@ | |||
# 4.5.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps 4.4.1
instead of 4.5.0
for the proposed version number?
Since no new resources are being added, timeout seems like a small enhancement.
I'd also suggest adding (Unreleased)
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
c97dc75
to
8a91a71
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See next patch-set for updates
620f5dd
to
adf82aa
Compare
We've had situations where we've hit against a system time-out when connecting to OneView. That timeout was over 2 minutes long. To avoid this we've added a timeout field to the config json, and if present the value is used as a timeout in http.client.HTTPSConnection.
adf82aa
to
0341436
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed that line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, is the PR ready to be merged?
Yes, it can be merged. |
We've had situations where we've hit against a system time-out when
connecting to OneView. That timeout was over 2 minutes long. To avoid
this we've added a timeout field to the config json, and if present the
value is used as a timeout in http.client.HTTPSConnection.
Description
Adds a connection time-out
Issues Resolved
[List any issues this PR will resolve. e.g., Fixes #1]
Check List
$ tox
).