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

always force galaxy to install collections #164

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions src/tox_lsr/test_scripts/runqemu.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,29 @@ def is_ansible_env_var_supported(env_var_name):
return False


def is_ansible_cmd_line_option_supported(cmd, option):
"""See if ansible or galaxy supports the given option --option."""
# cmd is a list e.g. ["ansible-galaxy", "collection", "install"]
result = subprocess.check_output( # nosec
cmd + ["--help"], stderr=subprocess.STDOUT, encoding="utf-8"
)
# look for name: ENV_VAR_NAME in output
match = re.search(r" {} ".format(option), result)
if match:
return True
return False


def get_galaxy_force_flag():
"""Get flag to use to force collection reinstall."""
cmd = ["ansible-galaxy", "collection", "install"]
if is_ansible_cmd_line_option_supported(cmd, "--force-with-deps"):
return "--force-with-deps"
if is_ansible_cmd_line_option_supported(cmd, "--force"):
return "--force"
return ""


if is_ansible_env_var_supported("ANSIBLE_COLLECTIONS_PATH"):
COLL_PATH_ENV_VAR = "ANSIBLE_COLLECTIONS_PATH"
else:
Expand Down Expand Up @@ -1165,7 +1188,6 @@ def run_ansible_playbooks( # noqa: C901
def install_requirements(sourcedir, collection_path, test_env, collection):
"""Install reqs from {meta,tests}/collection-requirements.yml, if any."""
collection_save_file = None
force_flag = None
if collection:
save_collection = os.path.join(
collection_path,
Expand All @@ -1188,7 +1210,6 @@ def install_requirements(sourcedir, collection_path, test_env, collection):
save_collection,
]
)
force_flag = "--force"
coll_rqf = os.path.join(sourcedir, "meta", "collection-requirements.yml")
tests_rqf = os.path.join(sourcedir, "tests", "collection-requirements.yml")
galaxy_env = {COLL_PATH_ENV_VAR: collection_path}
Expand All @@ -1198,14 +1219,13 @@ def install_requirements(sourcedir, collection_path, test_env, collection):
"ansible-galaxy",
"collection",
"install",
get_galaxy_force_flag(),
"-p",
collection_path,
"-vv",
"-r",
reqfile,
]
if force_flag:
ag_cmd.append(force_flag)
subprocess.check_call( # nosec
ag_cmd,
stdout=sys.stdout,
Expand Down Expand Up @@ -1254,6 +1274,7 @@ def setup_callback_plugins(pretty, profile, profile_task_limit, test_env):
"-p",
os.environ["LSR_TOX_ENV_TMP_DIR"],
"-vv",
get_galaxy_force_flag(),
"ansible.posix",
],
stdout=sys.stdout,
Expand Down
Loading