From cd881ac3e9e52b260b09bb369548591c52522576 Mon Sep 17 00:00:00 2001 From: Brian Scholer <1260690+briantist@users.noreply.github.com> Date: Sat, 18 Feb 2023 17:20:49 -0500 Subject: [PATCH] fix new sanity test requirements and CI docker version hang (#347) * remove unused import * disrespect retry-after header * show warning on retry * more import shenanigans * wheres my pep pep * sigh 2.11 --- .github/actions/docker-image-versions/versions.py | 11 +++++++++-- plugins/lookup/vault_login.py | 6 +++--- plugins/lookup/vault_token_create.py | 6 +++--- plugins/modules/vault_login.py | 6 +++--- tests/unit/compat/builtins.py | 2 +- tests/unit/compat/mock.py | 2 -- tests/unit/plugins/lookup/conftest.py | 2 -- .../module_utils/authentication/test_auth_none.py | 7 ++----- .../module_utils/authentication/test_auth_token.py | 8 +++----- .../authentication/test_hashi_vault_authenticator.py | 4 +--- .../plugins/module_utils/test_hashi_vault_helper.py | 5 ++--- 11 files changed, 27 insertions(+), 32 deletions(-) diff --git a/.github/actions/docker-image-versions/versions.py b/.github/actions/docker-image-versions/versions.py index 71ba9ce73..9d7fcea2d 100755 --- a/.github/actions/docker-image-versions/versions.py +++ b/.github/actions/docker-image-versions/versions.py @@ -17,13 +17,20 @@ import requests from urllib3.util.retry import Retry from requests.adapters import HTTPAdapter - +from warnings import warn from packaging import version TAG_URI = 'https://registry.hub.docker.com/v2/repositories/library/%s/tags?page_size=1024' +class WarningRetry(Retry): + def new(self, **kwargs): + if self.total > 0: + warn('Error on request. Retries remaining: %i' % (self.total,)) + return super().new(**kwargs) + + def main(argv): image = None include_prerelease = include_postrelease = False @@ -60,7 +67,7 @@ def main(argv): tag_url = TAG_URI % image sess = requests.Session() - retry = Retry(total=5, backoff_factor=0.2) + retry = WarningRetry(total=5, backoff_factor=0.2, respect_retry_after_header=False) adapter = HTTPAdapter(max_retries=retry) sess.mount('https://', adapter) diff --git a/plugins/lookup/vault_login.py b/plugins/lookup/vault_login.py index ebb49e4a3..27d497965 100644 --- a/plugins/lookup/vault_login.py +++ b/plugins/lookup/vault_login.py @@ -94,13 +94,13 @@ from ansible.module_utils.six import raise_from -from ansible_collections.community.hashi_vault.plugins.plugin_utils._hashi_vault_lookup_base import HashiVaultLookupBase -from ansible_collections.community.hashi_vault.plugins.module_utils._hashi_vault_common import HashiVaultValueError +from ...plugins.plugin_utils._hashi_vault_lookup_base import HashiVaultLookupBase +from ...plugins.module_utils._hashi_vault_common import HashiVaultValueError display = Display() try: - import hvac + import hvac # pylint: disable=unused-import except ImportError as imp_exc: HVAC_IMPORT_ERROR = imp_exc else: diff --git a/plugins/lookup/vault_token_create.py b/plugins/lookup/vault_token_create.py index 9b19ae290..520288897 100644 --- a/plugins/lookup/vault_token_create.py +++ b/plugins/lookup/vault_token_create.py @@ -102,13 +102,13 @@ from ansible.module_utils.six import raise_from -from ansible_collections.community.hashi_vault.plugins.plugin_utils._hashi_vault_lookup_base import HashiVaultLookupBase -from ansible_collections.community.hashi_vault.plugins.module_utils._hashi_vault_common import HashiVaultValueError +from ...plugins.plugin_utils._hashi_vault_lookup_base import HashiVaultLookupBase +from ...plugins.module_utils._hashi_vault_common import HashiVaultValueError display = Display() try: - import hvac + import hvac # pylint: disable=unused-import except ImportError as imp_exc: HVAC_IMPORT_ERROR = imp_exc else: diff --git a/plugins/modules/vault_login.py b/plugins/modules/vault_login.py index c52e969e0..fe0408da2 100644 --- a/plugins/modules/vault_login.py +++ b/plugins/modules/vault_login.py @@ -102,14 +102,14 @@ from ansible.module_utils._text import to_native from ansible.module_utils.basic import missing_required_lib -from ansible_collections.community.hashi_vault.plugins.module_utils._hashi_vault_module import HashiVaultModule -from ansible_collections.community.hashi_vault.plugins.module_utils._hashi_vault_common import HashiVaultValueError +from ...plugins.module_utils._hashi_vault_module import HashiVaultModule +from ...plugins.module_utils._hashi_vault_common import HashiVaultValueError # we don't actually need to import hvac directly in this module # because all of the hvac calls happen in module utils, but # we would like to control the error message here for consistency. try: - import hvac + import hvac # pylint: disable=unused-import except ImportError: HAS_HVAC = False HVAC_IMPORT_ERROR = traceback.format_exc() diff --git a/tests/unit/compat/builtins.py b/tests/unit/compat/builtins.py index f60ee6782..349d310e8 100644 --- a/tests/unit/compat/builtins.py +++ b/tests/unit/compat/builtins.py @@ -26,7 +26,7 @@ # One unittest needs to import builtins via __import__() so we need to have # the string that represents it try: - import __builtin__ + import __builtin__ # pylint: disable=unused-import except ImportError: BUILTINS = 'builtins' else: diff --git a/tests/unit/compat/mock.py b/tests/unit/compat/mock.py index 515b94a3c..c98b26312 100644 --- a/tests/unit/compat/mock.py +++ b/tests/unit/compat/mock.py @@ -9,8 +9,6 @@ ''' Compat module for Python3.x's unittest.mock module ''' -import sys - # Python 2.7 # Note: Could use the pypi mock library on python3.x as well as python2.x. It diff --git a/tests/unit/plugins/lookup/conftest.py b/tests/unit/plugins/lookup/conftest.py index 244cb4c5e..ba4da9291 100644 --- a/tests/unit/plugins/lookup/conftest.py +++ b/tests/unit/plugins/lookup/conftest.py @@ -7,8 +7,6 @@ import pytest -from ...compat import mock - @pytest.fixture def minimal_vars(): diff --git a/tests/unit/plugins/module_utils/authentication/test_auth_none.py b/tests/unit/plugins/module_utils/authentication/test_auth_none.py index 87cfe91fb..1e3024f11 100644 --- a/tests/unit/plugins/module_utils/authentication/test_auth_none.py +++ b/tests/unit/plugins/module_utils/authentication/test_auth_none.py @@ -8,11 +8,8 @@ import pytest -from ansible_collections.community.hashi_vault.tests.unit.compat import mock - -from ansible_collections.community.hashi_vault.plugins.module_utils._auth_method_none import HashiVaultAuthMethodNone - -from ansible_collections.community.hashi_vault.plugins.module_utils._hashi_vault_common import HashiVaultAuthMethodBase +from ......plugins.module_utils._auth_method_none import HashiVaultAuthMethodNone +from ......plugins.module_utils._hashi_vault_common import HashiVaultAuthMethodBase @pytest.fixture diff --git a/tests/unit/plugins/module_utils/authentication/test_auth_token.py b/tests/unit/plugins/module_utils/authentication/test_auth_token.py index 7f5d12802..d8a13435b 100644 --- a/tests/unit/plugins/module_utils/authentication/test_auth_token.py +++ b/tests/unit/plugins/module_utils/authentication/test_auth_token.py @@ -4,14 +4,12 @@ # SPDX-License-Identifier: GPL-3.0-or-later from __future__ import (absolute_import, division, print_function) -from _pytest.fixtures import fixture -from _pytest.python_api import raises __metaclass__ = type import os import pytest -from ansible_collections.community.hashi_vault.tests.unit.compat import mock +from ......tests.unit.compat import mock try: import hvac @@ -19,11 +17,11 @@ # python 2.6, which isn't supported anyway hvac = mock.MagicMock() -from ansible_collections.community.hashi_vault.plugins.module_utils._auth_method_token import ( +from ......plugins.module_utils._auth_method_token import ( HashiVaultAuthMethodToken, ) -from ansible_collections.community.hashi_vault.plugins.module_utils._hashi_vault_common import ( +from ......plugins.module_utils._hashi_vault_common import ( HashiVaultAuthMethodBase, HashiVaultValueError, ) diff --git a/tests/unit/plugins/module_utils/authentication/test_hashi_vault_authenticator.py b/tests/unit/plugins/module_utils/authentication/test_hashi_vault_authenticator.py index 439dd7f15..4853d2c76 100644 --- a/tests/unit/plugins/module_utils/authentication/test_hashi_vault_authenticator.py +++ b/tests/unit/plugins/module_utils/authentication/test_hashi_vault_authenticator.py @@ -8,9 +8,7 @@ import pytest -from ansible_collections.community.hashi_vault.tests.unit.compat import mock - -from ansible_collections.community.hashi_vault.plugins.module_utils._authenticator import HashiVaultAuthenticator +from ......plugins.module_utils._authenticator import HashiVaultAuthenticator @pytest.fixture diff --git a/tests/unit/plugins/module_utils/test_hashi_vault_helper.py b/tests/unit/plugins/module_utils/test_hashi_vault_helper.py index 1993a8598..6a5c6002b 100644 --- a/tests/unit/plugins/module_utils/test_hashi_vault_helper.py +++ b/tests/unit/plugins/module_utils/test_hashi_vault_helper.py @@ -6,12 +6,11 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import sys import os import pytest -from ansible_collections.community.hashi_vault.tests.unit.compat import mock -from ansible_collections.community.hashi_vault.plugins.module_utils._hashi_vault_common import ( +from .....tests.unit.compat import mock +from .....plugins.module_utils._hashi_vault_common import ( HashiVaultHelper, _stringify, )