Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry prepare environment three times before failing #1517

Merged
merged 1 commit into from Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Expand Up @@ -88,6 +88,7 @@ repos:
- flaky
- pytest
- ruamel.yaml
- tenacity
- types-PyYAML
- wcmatch
- yamllint
Expand All @@ -111,5 +112,6 @@ repos:
- pyyaml
- rich
- ruamel.yaml
- tenacity
- sphinx
- wcmatch
2 changes: 2 additions & 0 deletions docs/requirements.txt
Expand Up @@ -35,6 +35,7 @@ requests==2.25.1
rich==10.1.0
ruamel.yaml.clib==0.2.2
ruamel.yaml==0.17.2 ; python_version >= "3.7"
six==1.15.0
snowballstemmer==2.1.0
sphinx-ansible-theme==0.3.2
sphinx-notfound-page==0.6
Expand All @@ -47,6 +48,7 @@ sphinxcontrib-jsmath==1.0.1
sphinxcontrib-programoutput2==2.0a1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.4
tenacity==7.0.0
typing-extensions==3.7.4.3
urllib3==1.26.4
wcmatch==8.1.2
Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Expand Up @@ -78,6 +78,7 @@ install_requires =
ruamel.yaml >= 0.15.34,<1; python_version < "3.7"
ruamel.yaml >= 0.15.37,<1; python_version >= "3.7"
# NOTE: per issue #509 0.15.34 included in debian backports
tenacity
typing-extensions; python_version < "3.8"
wcmatch>=7.0 # MIT

Expand Down
9 changes: 8 additions & 1 deletion src/ansiblelint/prerun.py
Expand Up @@ -8,6 +8,7 @@
from functools import lru_cache
from typing import List, Optional, Tuple

import tenacity
from packaging import version

from ansiblelint.config import (
Expand Down Expand Up @@ -94,6 +95,12 @@ def _get_ver_err() -> Tuple[str, str]:
return ver, err


@tenacity.retry( # Retry up to 3 times as galaxy server can return errors
reraise=True,
wait=tenacity.wait_fixed(30), # type: ignore
stop=tenacity.stop_after_attempt(3), # type: ignore
before_sleep=tenacity.after_log(_logger, logging.WARNING), # type: ignore
)
def prepare_environment() -> None:
"""Make dependencies available if needed."""
if not options.configured:
Expand Down Expand Up @@ -151,7 +158,7 @@ def prepare_environment() -> None:
)
if run.returncode != 0:
_logger.error(run.stdout)
sys.exit(run.returncode)
raise RuntimeError(run.returncode)

_install_galaxy_role()
_perform_mockings()
Expand Down
2 changes: 2 additions & 0 deletions test-requirements.txt
Expand Up @@ -27,6 +27,8 @@ pyyaml==5.4.1
rich==10.1.0
ruamel.yaml.clib==0.2.2
ruamel.yaml==0.17.2 ; python_version >= "3.7"
six==1.15.0
tenacity==7.0.0
toml==0.10.2
typing-extensions==3.7.4.3
wcmatch==8.1.2
Expand Down