diff --git a/.ci/scripts/update_action_groups.py b/.ci/scripts/update_action_groups.py new file mode 100644 index 00000000..c4fd1894 --- /dev/null +++ b/.ci/scripts/update_action_groups.py @@ -0,0 +1,22 @@ +import os +from pathlib import Path + +import yaml + + +def main() -> None: + modules_path = Path("plugins/modules") + runtime_path = Path("meta/runtime.yml") + modules = sorted([module.stem for module in modules_path.glob("*.py")]) + action_groups = {"squeezer": modules} + runtime = yaml.safe_load(runtime_path.read_text()) + if runtime.get("action_groups") != action_groups: + print("Updating action groups. 🌓") + runtime["action_groups"] = action_groups + runtime_path.write_text(yaml.safe_dump(runtime, explicit_start=True, explicit_end=True)) + else: + print("Action groups are up to date. 🎬") + + +if __name__ == "__main__": + main() diff --git a/.ci/scripts/update_requirements.py b/.ci/scripts/update_requirements.py new file mode 100644 index 00000000..10bc117d --- /dev/null +++ b/.ci/scripts/update_requirements.py @@ -0,0 +1,64 @@ +import re +import sys +from pathlib import Path + +from packaging.requirements import Requirement +from packaging.specifiers import Specifier, SpecifierSet +from packaging.version import Version + + +def fix_requirements_file(path: Path, check: bool, name: str, specifier: SpecifierSet) -> None: + lines = path.read_text().split("\n") + for num, line in enumerate(lines): + try: + requirement = Requirement(line) + except: + pass + else: + if requirement.name == name: + if requirement.specifier == specifier: + print(f"{path} is up to date.") + break + elif check: + print(f"{path} has unmatched pulp-glue requirement.") + sys.exit(1) + else: + print(f"Update {path}.") + requirement.specifier = specifier + lines[num] = str(requirement) + path.write_text("\n".join(lines)) + break + else: + print(f"{name} requirement missing from {path}.") + sys.exit(1) + + +def main(check: bool) -> None: + pulp_glue_path = Path("plugins/module_utils/pulp_glue.py") + requirements_path = Path("requirements.txt") + lower_bounds_path = Path("lower_bounds_constraints.lock") + + with pulp_glue_path.open("r") as fp: + for line in fp.readlines(): + if match := re.search(r"GLUE_VERSION_SPEC\s*=\s*\"(.*)\"", line): + GLUE_VERSION_SPEC = SpecifierSet(match.group(1)) + break + else: + print("GLUE_VERSION_SPEC not found!") + sys.exit(1) + try: + min_version = min( + [Version(spec.version) for spec in GLUE_VERSION_SPEC if spec.operator == ">="] + ) + except ValueError: + print("No lower bound requirement specified for pulp-glue.") + sys.exit(1) + lower_bounds_spec = Specifier(f"=={min_version}") + + fix_requirements_file(requirements_path, check, "pulp-glue", GLUE_VERSION_SPEC) + fix_requirements_file(lower_bounds_path, check, "pulp-glue", lower_bounds_spec) + + +if __name__ == "__main__": + check = len(sys.argv) == 2 and sys.argv[1] == "--check" + main(check) diff --git a/Makefile b/Makefile index 69115259..58aa7b14 100644 --- a/Makefile +++ b/Makefile @@ -39,17 +39,22 @@ info: @echo " roles:\n $(foreach ROLE,$(notdir $(ROLES)), - $(ROLE)\n)" @echo " $(foreach PLUGIN_TYPE,$(PLUGIN_TYPES), $(PLUGIN_TYPE):\n $(foreach PLUGIN,$(basename $(notdir $(_$(PLUGIN_TYPE)))), - $(PLUGIN)\n)\n)" -black: +format: + python .ci/scripts/update_action_groups.py + python .ci/scripts/update_requirements.py isort . black . lint: $(MANIFEST) | tests/playbooks/vars/server.yaml + python .ci/scripts/update_requirements.py --check yamllint -f parsable tests/playbooks ansible-playbook --syntax-check tests/playbooks/*.yaml | grep -v '^$$' black --check --diff . isort -c --diff . ifneq ($(ACTION_GROUPS), $(MODULES)) - @echo 'plugins/modules/ and meta/runtime.yml action_groups are not in sync' && exit 1 + @echo "plugins/modules/ and meta/runtime.yml action_groups are not in sync 🌓" && exit 1 +else + @echo "Action groups are fine! 🎬" endif GALAXY_IMPORTER_CONFIG=tests/galaxy-importer.cfg python -m galaxy_importer.main $(NAMESPACE)-$(NAME)-$(VERSION).tar.gz @echo "🙊 Code 🙉 LGTM 🙈" @@ -110,4 +115,4 @@ clean: FORCE: -.PHONY: help dist install black lint sanity test livetest test-setup publish FORCE +.PHONY: help dist install format lint sanity test livetest test-setup publish FORCE diff --git a/meta/runtime.yml b/meta/runtime.yml index a3efc286..301fdc06 100644 --- a/meta/runtime.yml +++ b/meta/runtime.yml @@ -1,45 +1,45 @@ --- -requires_ansible: ">=2.8" action_groups: squeezer: - - access_policy - - ansible_distribution - - ansible_remote - - ansible_repository - - ansible_role - - ansible_sync - - api_call - - artifact - - container_distribution - - container_remote - - container_repository - - container_sync - - deb_distribution - - deb_publication - - deb_remote - - deb_repository - - deb_sync - - delete_orphans - - file_content - - file_distribution - - file_publication - - file_remote - - file_repository - - file_repository_content - - file_sync - - purge_tasks - - python_distribution - - python_publication - - python_remote - - python_repository - - python_sync - - repair - - rpm_distribution - - rpm_publication - - rpm_remote - - rpm_repository - - rpm_sync - - status - - task - - x509_cert_guard + - access_policy + - ansible_distribution + - ansible_remote + - ansible_repository + - ansible_role + - ansible_sync + - api_call + - artifact + - container_distribution + - container_remote + - container_repository + - container_sync + - deb_distribution + - deb_publication + - deb_remote + - deb_repository + - deb_sync + - delete_orphans + - file_content + - file_distribution + - file_publication + - file_remote + - file_repository + - file_repository_content + - file_sync + - purge_tasks + - python_distribution + - python_publication + - python_remote + - python_repository + - python_sync + - repair + - rpm_distribution + - rpm_publication + - rpm_remote + - rpm_repository + - rpm_sync + - status + - task + - x509_cert_guard +requires_ansible: '>=2.8' ... diff --git a/plugins/module_utils/pulp_glue.py b/plugins/module_utils/pulp_glue.py index 3c975407..562aff1c 100644 --- a/plugins/module_utils/pulp_glue.py +++ b/plugins/module_utils/pulp_glue.py @@ -15,7 +15,7 @@ from pulp_glue.common import __version__ as pulp_glue_version from pulp_glue.common.context import PulpContext, PulpException, PulpNoWait - GLUE_VERSION_SPEC = ">=0.20.0,<=0.23.2" + GLUE_VERSION_SPEC = ">=0.20.0,<0.25" if not SpecifierSet(GLUE_VERSION_SPEC).contains(pulp_glue_version): raise ImportError( f"Installed 'pulp-glue' version '{pulp_glue_version}' is not in '{GLUE_VERSION_SPEC}'." @@ -85,18 +85,30 @@ def __init__(self, **kwargs): if import_error[1] is not None: self.fail_json(msg=missing_required_lib(import_error[0]), exception=import_error[1]) + auth_args = {} + if SpecifierSet(">=0.24.0").contains(pulp_glue_version): + if self.params["username"]: + from pulp_glue.common.openapi import BasicAuthProvider + + auth_args["auth_provider"] = BasicAuthProvider( + username=self.params["username"], + password=self.params["password"], + ) + else: + auth_args["username"] = self.params["username"] + auth_args["password"] = self.params["password"] + self.pulp_ctx = PulpSqueezerContext( api_root="/pulp/", api_kwargs=dict( base_url=self.params["pulp_url"], - username=self.params["username"], - password=self.params["password"], cert=self.params["user_cert"], key=self.params["user_key"], validate_certs=self.params["validate_certs"], refresh_cache=self.params["refresh_api_cache"], safe_calls_only=self.check_mode, user_agent=f"Squeezer/{__VERSION__}", + **auth_args, ), background_tasks=False, timeout=self.params["timeout"], diff --git a/plugins/modules/status.py b/plugins/modules/status.py index 61b5eb6d..3224838f 100644 --- a/plugins/modules/status.py +++ b/plugins/modules/status.py @@ -53,7 +53,10 @@ def main(): component_versions = { item["component"]: item["version"] for item in result.get("versions", []) } - if component_versions != module.pulp_ctx.component_versions: + if ( + not module.params["refresh_api_cache"] + and component_versions != module.pulp_ctx.component_versions + ): module.warn("Notice: Cached api is outdated. Refreshing...") module.pulp_ctx.api.load_api(refresh_cache=True) result = module.pulp_ctx.call("status_read") diff --git a/requirements.txt b/requirements.txt index e554e265..d3a5a38d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -pulp-glue>=0.20.0,<=0.23.2 # Keep this in sync with plugins/module_utils/pulp_glue.py +pulp-glue<0.25,>=0.20.0 ansible_runner<2.3; python_version < '3.7' ansible_runner; python_version >= '3.7'