Do not break on sushy.connector.Connector sig change

Right now, retries break in ilo driver due to server_side_retries being
an accepted kwarg in sushy.connector.Connector._op, but not this
version.

We should accept any set of args, but only pass on known-good args, as
sushy.connector.Connector._op() will pass on any unknown kwargs to
requests, which means we should not blindly pass on all kwargs.

Additionally, fixed related unit tests and some basic configuration
fixes to get linting to pass.

Change-Id: I80796cc4280a194735e6e4034d37cca4fdc97f97
This commit is contained in:
Jay Faulkner 2024-06-13 07:44:20 -07:00
parent f655e23cef
commit fe2f9c2950
4 changed files with 43 additions and 14 deletions

View File

@ -36,7 +36,8 @@ class HPEConnector(connector.Connector):
stop_max_attempt_number=MAX_RETRY_ATTEMPTS,
wait_fixed=MAX_TIME_BEFORE_RETRY)
def _op(self, method, path='', data=None, headers=None,
blocking=False, timeout=60):
blocking=False, timeout=60, server_side_retries_left=None,
allow_reauth=True, **kwargs):
"""Overrides the base method to support retrying the operation.
:param method: The HTTP method to be used, e.g: GET, POST,
@ -46,16 +47,37 @@ class HPEConnector(connector.Connector):
:param headers: Optional dictionary of headers.
:param blocking: Whether to block for asynchronous operations.
:param timeout: Max time in seconds to wait for blocking async call.
:param server_side_retries_left: Remaining retries. If not provided
will use limit provided by instance's server_side_retries
:param allow_reauth: Whether to allow refreshing the authentication
token.
:param **kwargs: Catchall to improve compatability if parent class
changes -- unsued.
:returns: The response from the connector.Connector's _op method.
"""
resp = super(HPEConnector, self)._op(method, path, data=data,
resp = super(HPEConnector, self)._op(
method=method,
path=path,
data=data,
headers=headers,
blocking=blocking,
timeout=timeout,
allow_redirects=False)
server_side_retries_left=server_side_retries_left,
allow_reauth=allow_reauth,
allow_redirects=False
)
# With IPv6, Gen10 server gives redirection response with new path with
# a prefix of '/' so this check is required
if resp.status_code == 308:
path = urlparse(resp.headers['Location']).path
resp = super(HPEConnector, self)._op(method, path, data, headers)
resp = super(HPEConnector, self)._op(
method=method,
path=path,
data=data,
headers=headers,
blocking=blocking,
timeout=timeout,
server_side_retries_left=server_side_retries_left,
allow_reauth=allow_reauth
)
return resp

View File

@ -40,6 +40,8 @@ class HPEConnectorTestCase(testtools.TestCase):
conn_mock.assert_called_once_with(hpe_conn, 'GET', path='fake/path',
data=None, headers=headers,
blocking=False, timeout=60,
server_side_retries_left=None,
allow_reauth=True,
allow_redirects=False)
self.assertEqual(1, conn_mock.call_count)
@ -91,8 +93,12 @@ class HPEConnectorTestCase(testtools.TestCase):
data=None, headers=headers)
calls = [mock.call(hpe_conn, 'GET', path='fake/path', data=None,
headers=headers, blocking=False, timeout=60,
server_side_retries_left=None,
allow_reauth=True,
allow_redirects=False),
mock.call(hpe_conn, 'GET', path='/new/path', data=None,
headers=headers)]
headers=headers, blocking=False, timeout=60,
server_side_retries_left=None,
allow_reauth=True)]
conn_mock.assert_has_calls(calls)
self.assertEqual(res.status_code, 200)

View File

@ -11,5 +11,5 @@ pyasn1>=0.5.1 # BSD
pyasn1-modules>=0.3.0 # BSD
# Redfish communication uses the Sushy library
sushy>=4.5.0
sushy>=4.5.2
pyOpenSSL>=19.1.0

11
tox.ini
View File

@ -28,10 +28,10 @@ passenv =
[testenv:pep8]
deps =
hacking>=4.1.0,<5.0.0 # Apache-2.0
flake8-import-order>=0.17.1 # LGPLv3
pycodestyle>=2.0.0,<3.0.0 # MIT
Pygments>=2.2.0 # BSD
hacking # Apache-2.0
flake8-import-order # LGPLv3
pycodestyle # MIT
Pygments # BSD
commands = flake8 {posargs}
[testenv:cover]
@ -51,9 +51,10 @@ commands =
[flake8]
show-source = True
# [C901] function is too complex.
# [E275] missing whitespace after keyword
# [E731] do not assign a lambda expression, use a def
# [W503] Line break occurred before a binary operator. Conflicts with W504.
ignore = C901,E731,W503
ignore = C901,E275,E731,W503
exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build,*cpqdisk_mibs
max-complexity=15
import-order-style = pep8