From fe2f9c2950b283f6fa0018b2b6c85c1928e88276 Mon Sep 17 00:00:00 2001 From: Jay Faulkner Date: Thu, 13 Jun 2024 07:44:20 -0700 Subject: [PATCH] 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 --- proliantutils/redfish/connector.py | 36 +++++++++++++++---- proliantutils/tests/redfish/test_connector.py | 8 ++++- requirements.txt | 2 +- tox.ini | 11 +++--- 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/proliantutils/redfish/connector.py b/proliantutils/redfish/connector.py index 9088d00a..c146fb7c 100644 --- a/proliantutils/redfish/connector.py +++ b/proliantutils/redfish/connector.py @@ -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, - headers=headers, - blocking=blocking, - timeout=timeout, - allow_redirects=False) + 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, + 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 diff --git a/proliantutils/tests/redfish/test_connector.py b/proliantutils/tests/redfish/test_connector.py index 292f85fb..fe279e64 100644 --- a/proliantutils/tests/redfish/test_connector.py +++ b/proliantutils/tests/redfish/test_connector.py @@ -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) diff --git a/requirements.txt b/requirements.txt index edfed25b..c459b4a2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/tox.ini b/tox.ini index ae15e190..e644320b 100644 --- a/tox.ini +++ b/tox.ini @@ -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