Skip to content

Commit

Permalink
Merge pull request #151 from mdellweg/bump-glue-version
Browse files Browse the repository at this point in the history
Bump glue version
  • Loading branch information
mdellweg authored Mar 17, 2024
2 parents f3b4552 + e997a75 commit 30b9ed0
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 49 deletions.
22 changes: 22 additions & 0 deletions .ci/scripts/update_action_groups.py
Original file line number Diff line number Diff line change
@@ -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()
64 changes: 64 additions & 0 deletions .ci/scripts/update_requirements.py
Original file line number Diff line number Diff line change
@@ -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)
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 🙈"
Expand Down Expand Up @@ -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
82 changes: 41 additions & 41 deletions meta/runtime.yml
Original file line number Diff line number Diff line change
@@ -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'
...
18 changes: 15 additions & 3 deletions plugins/module_utils/pulp_glue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}'."
Expand Down Expand Up @@ -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"],
Expand Down
5 changes: 4 additions & 1 deletion plugins/modules/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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'
Expand Down

0 comments on commit 30b9ed0

Please sign in to comment.