From afa1d139adea8315d0d8188d7e233fecbdc21c72 Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Jun 02 2023 21:06:51 +0000 Subject: [PATCH 1/5] tox.ini: switch to allowlist_externals the other directive is deprecated since 3.18.0 in 2020 and has been removed in 4.x. Signed-off-by: Adam Williamson --- diff --git a/docs/dev-guide.rst b/docs/dev-guide.rst index c845a88..6b8a0e4 100644 --- a/docs/dev-guide.rst +++ b/docs/dev-guide.rst @@ -85,6 +85,8 @@ the tests: vagrant +Alternatively, you can use `tox`. You will need version 3.18.0 or higher. + You should run smoke test after deploying on stage: .. code-block:: console diff --git a/tox.ini b/tox.ini index a1e2b9e..95ab7c3 100644 --- a/tox.ini +++ b/tox.ini @@ -7,7 +7,7 @@ skip_missing_interpreters = True deps = -rrequirements.txt -rdev-requirements.txt -whitelist_externals = +allowlist_externals = rm setenv = GREENWAVE_CONFIG={toxinidir}/conf/settings.py.example @@ -28,7 +28,7 @@ commands = [testenv:docs] changedir = docs -whitelist_externals = +allowlist_externals = mkdir rm commands= From 33d98780ce5ab73cd637c00e57a9a2f2042b9e42 Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Jun 02 2023 21:16:48 +0000 Subject: [PATCH 2/5] Handle urllib3 removing deprecated alias for allowed_methods The old names here were deprecated in 1.26.0 and removed in 2.0. Let's still support them for now as dropping support for versions before 1.26.0 seems a bit aggressive. Signed-off-by: Adam Williamson --- diff --git a/greenwave/request_session.py b/greenwave/request_session.py index 6cd823a..ca5e816 100644 --- a/greenwave/request_session.py +++ b/greenwave/request_session.py @@ -54,14 +54,25 @@ def get_requests_session(): """ Get http(s) session for request processing. """ session = RequestsSession() - retry = Retry( - total=3, - read=3, - connect=3, - backoff_factor=1, - status_forcelist=(500, 502, 503, 504), - method_whitelist=Retry.DEFAULT_METHOD_WHITELIST.union(('POST',)), - ) + try: + retry = Retry( + total=3, + read=3, + connect=3, + backoff_factor=1, + status_forcelist=(500, 502, 503, 504), + allowed_methods=Retry.DEFAULT_ALLOWED_METHODS.union(('POST',)), + ) + except AttributeError: + # for urllib3 < 1.26.0, remove when no longer needed + retry = Retry( + total=3, + read=3, + connect=3, + backoff_factor=1, + status_forcelist=(500, 502, 503, 504), + method_whitelist=Retry.DEFAULT_METHOD_WHITELIST.union(('POST',)), + ) adapter = HTTPAdapter(max_retries=retry) session.mount('http://', adapter) session.mount('https://', adapter) From 30a3db3d9547b6e62501548c69b3c41631cd3169 Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Jun 02 2023 21:27:37 +0000 Subject: [PATCH 3/5] Mark _make_request with 'nosec' due to false positive Current Bandit flags these for not specifying a timeout. However, we actually set a default timeout for all requests made through `requests_session` - see request_session.py. Bandit obviously isn't able to work that out. Signed-off-by: Adam Williamson --- diff --git a/greenwave/resources.py b/greenwave/resources.py index 0e9265a..e75f42c 100644 --- a/greenwave/resources.py +++ b/greenwave/resources.py @@ -111,7 +111,7 @@ class ResultsRetriever(BaseRetriever): return requests_session.get( self.url + '/results/latest', params=params, - **request_args) + **request_args) # nosec B113 def _results_match_time(self, results): if not self.since: @@ -143,7 +143,7 @@ class WaiversRetriever(BaseRetriever): return requests_session.post( self.url + '/waivers/+filtered', json={'filters': params}, - **request_args) + **request_args) # nosec B113 class NoSourceException(RuntimeError): From e2f1bf3dd79f20df2c3869bcf44c70d6a4b9ff63 Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Jun 02 2023 21:29:08 +0000 Subject: [PATCH 4/5] del is a keyword not a function This makes current flake8 happy. Signed-off-by: Adam Williamson --- diff --git a/functional-tests/test_api_v1.py b/functional-tests/test_api_v1.py index c114682..8bf1d1b 100644 --- a/functional-tests/test_api_v1.py +++ b/functional-tests/test_api_v1.py @@ -774,7 +774,7 @@ def test_ignore_result(requests_session, greenwave_server, testdatabuilder): # repeating the test for "when" parameter instead of "ignore_result" # ...we should get the same behaviour. - del(data['ignore_result']) + del data['ignore_result'] data['when'] = right_before_this_time(result['submit_time']) r = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r.status_code == 200 @@ -916,7 +916,7 @@ def test_ignore_waiver(requests_session, greenwave_server, testdatabuilder): # repeating the test for "when" parameter instead of "ignore_waiver" # ...we should get the same behaviour. - del(data['ignore_waiver']) + del data['ignore_waiver'] data['when'] = right_before_this_time(waiver['timestamp']) r_ = requests_session.post(greenwave_server + 'api/v1.0/decision', json=data) assert r_.status_code == 200 From 37f27c166017910063a77a8054ba688442bb5e5e Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Jun 02 2023 21:38:30 +0000 Subject: [PATCH 5/5] Update sphinx config to current standards The intersphinx config format we use is documented as being from "before Sphinx 1.0" and "Deprecated since [Sphinx] 6.2" - https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html#confval-intersphinx_mapping so, switch to the current one. This means we can drop the inventory file and just get the one from the Python docs site. Also, setting `language = None` gives a warning with current Sphinx, and because we run with `-W`, the warning is treated as an error and doc generation fails. Set it to "en", since our docs are indeed in English. Signed-off-by: Adam Williamson --- diff --git a/docs/conf.py b/docs/conf.py index 02de2e2..efbb12c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -69,7 +69,7 @@ release = greenwave.__version__ # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = None +language = "en" # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. @@ -182,5 +182,4 @@ epub_exclude_files = ['search.html'] # Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = {'https://docs.python.org/3/': 'python-intersphinx.inv'} - +intersphinx_mapping = {'python': ('https://docs.python.org/3', None)} diff --git a/docs/python-intersphinx.inv b/docs/python-intersphinx.inv deleted file mode 100644 index 839c38f..0000000 Binary files a/docs/python-intersphinx.inv and /dev/null differ