Skip to content

Commit

Permalink
fix new sanity test requirements and CI docker version hang (#347)
Browse files Browse the repository at this point in the history
* remove unused import

* disrespect retry-after header

* show warning on retry

* more import shenanigans

* wheres my pep pep

* sigh 2.11
  • Loading branch information
briantist authored Feb 18, 2023
1 parent fa44d9c commit cd881ac
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 32 deletions.
11 changes: 9 additions & 2 deletions .github/actions/docker-image-versions/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions plugins/lookup/vault_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions plugins/lookup/vault_token_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions plugins/modules/vault_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/compat/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/compat/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/plugins/lookup/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

import pytest

from ...compat import mock


@pytest.fixture
def minimal_vars():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,24 @@
# 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
except ImportError:
# 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,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions tests/unit/plugins/module_utils/test_hashi_vault_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down

0 comments on commit cd881ac

Please sign in to comment.