Skip to content

Commit

Permalink
Add offline option to prepare_environment (#138)
Browse files Browse the repository at this point in the history
Fixes: #137
  • Loading branch information
ssbarnea authored May 9, 2022
1 parent 07e827d commit a46916d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/ansible_compat/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,14 @@ def prepare_environment(
required_collections: Optional[Dict[str, str]] = None,
retry: bool = False,
install_local: bool = False,
offline: bool = False,
) -> None:
"""Make dependencies available if needed."""
if required_collections is None:
required_collections = {}

self.install_requirements("requirements.yml", retry=retry)
if not offline:
self.install_requirements("requirements.yml", retry=retry)

destination = f"{self.cache_dir}/collections" if self.cache_dir else None
for name, min_version in required_collections.items():
Expand Down
8 changes: 8 additions & 0 deletions test/roles/acme.missing_deps/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
galaxy_info:
name: missing_deps
namespace: acme
description: foo
license: GPL
min_ansible_version: "2.10"
platforms: []
2 changes: 2 additions & 0 deletions test/roles/acme.missing_deps/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
collections:
- foo.bar # collection that does not exist, so we can test offline mode
7 changes: 7 additions & 0 deletions test/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,13 @@ def test_install_collection_from_disk_fail() -> None:
runtime.prepare_environment(install_local=True)


def test_prepare_environment_offline_role() -> None:
"""Ensure that we can make use of offline roles."""
with remember_cwd("test/roles/acme.missing_deps"):
runtime = Runtime(isolated=True)
runtime.prepare_environment(install_local=True, offline=True)


def test_runtime_run(runtime: Runtime) -> None:
"""Check if tee and non tee mode return same kind of results."""
result1 = runtime.exec(["seq", "10"])
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ setenv =
PIP_DISABLE_PIP_VERSION_CHECK = 1
PIP_CONSTRAINT = {toxinidir}/constraints.txt
PRE_COMMIT_COLOR = always
PYTEST_REQPASS = 74
PYTEST_REQPASS = 75
FORCE_COLOR = 1
allowlist_externals =
ansible
Expand Down

0 comments on commit a46916d

Please sign in to comment.