From e7d275c174f4c12a6ec6775a344fbd55e0a52100 Mon Sep 17 00:00:00 2001 From: Stefan Joosten Date: Thu, 13 Jun 2024 11:13:50 +0200 Subject: [PATCH 1/2] Fix spelling of plural of (Python) distributions --- plugins/modules/python_distribution.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/python_distribution.py b/plugins/modules/python_distribution.py index 5883449..978a666 100644 --- a/plugins/modules/python_distribution.py +++ b/plugins/modules/python_distribution.py @@ -128,7 +128,7 @@ def main(): with PulpEntityAnsibleModule( context_class=PulpPythonDistributionContext, entity_singular="distribution", - entity_plural="distribuions", + entity_plural="distributions", import_errors=[("pulp-glue", PULP_CLI_IMPORT_ERR)], argument_spec=dict( name=dict(), From 1f8bb15446f91fd375c805c8b4345c36e19619fa Mon Sep 17 00:00:00 2001 From: Stefan Joosten Date: Thu, 13 Jun 2024 14:07:45 +0200 Subject: [PATCH 2/2] Add 'repository' keyword to "python_distribution" Pulp Python plugin supports setting up a distribution to track the latest RepositoryVersion of a Pulp Python repository. --- plugins/modules/python_distribution.py | 32 ++++++++++++++++- tests/playbooks/python_distribution.yaml | 46 ++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/plugins/modules/python_distribution.py b/plugins/modules/python_distribution.py index 978a666..49be950 100644 --- a/plugins/modules/python_distribution.py +++ b/plugins/modules/python_distribution.py @@ -43,6 +43,11 @@ - Or the empty string to remove the remote type: str required: false + repository: + description: + - Name of the repository of which the latest RepositoryVersion will be served + type: str + required: false extends_documentation_fragment: - pulp.squeezer.pulp.entity_state - pulp.squeezer.pulp.glue @@ -73,6 +78,16 @@ publication: /pub/api/v3/publications/python/python/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa/ state: present +- name: Create a python distribution that serves the latest repository version + pulp.squeezer.python_distribution: + pulp_url: https://pulp.example.org + username: admin + password: password + name: new_python_distribution + base_path: new/python/dist + repository: my_python_repository + state: present + - name: Create a python destribution with remote for pull-through caching pulp.squeezer.python_distribution: pulp_url: https://pulp.example.org @@ -110,7 +125,11 @@ try: from pulp_glue.core.context import PulpContentGuardContext - from pulp_glue.python.context import PulpPythonDistributionContext, PulpPythonRemoteContext + from pulp_glue.python.context import ( + PulpPythonDistributionContext, + PulpPythonRemoteContext, + PulpPythonRepositoryContext, + ) # Fix this in pulp-glue if "content_guard" not in PulpPythonDistributionContext.NULLABLES: @@ -136,6 +155,7 @@ def main(): publication=dict(), content_guard=dict(), remote=dict(), + repository=dict(), ), required_if=[ ("state", "present", ["name", "base_path"]), @@ -144,6 +164,7 @@ def main(): ) as module: content_guard_name = module.params["content_guard"] remote_name = module.params["remote"] + repository_name = module.params["repository"] natural_key = { "name": module.params["name"], @@ -170,6 +191,15 @@ def main(): else: desired_attributes["remote"] = "" + if repository_name is not None: + if repository_name: + repository_ctx = PulpPythonRepositoryContext( + module.pulp_ctx, entity={"name": repository_name} + ) + desired_attributes["repository"] = repository_ctx.pulp_href + else: + desired_attributes["repository"] = "" + module.process(natural_key, desired_attributes) diff --git a/tests/playbooks/python_distribution.yaml b/tests/playbooks/python_distribution.yaml index 3cfa6c1..8618da9 100644 --- a/tests/playbooks/python_distribution.yaml +++ b/tests/playbooks/python_distribution.yaml @@ -224,6 +224,52 @@ - ansible_check_mode or result.distribution.base_url is regex(".*/pypi/pull_through_mirror") - result.distribution.remote == "" + - name: Retrieve repository + pulp.squeezer.python_repository: + name: test_python_repository + register: repository_result + + - name: Distribute latest version of repository + pulp.squeezer.python_distribution: + name: test_python_distribution + base_path: test_python_base_path + repository: test_python_repository + state: present + register: result + - name: Verify distribute latest version of repository + ansible.builtin.assert: + that: + - result.changed == true + - result.distribution.name == "test_python_distribution" + - result.distribution.base_path == "test_python_base_path" + - ansible_check_mode or result.distribution.base_url is regex(".*/pypi/test_python_base_path") + - result.distribution.repository == repository_result.repository.pulp_href + + - name: Distribute publication of repository (2nd try) + pulp.squeezer.python_distribution: + name: test_python_distribution + base_path: test_python_base_path + repository: test_python_repository + state: present + register: result + - name: Verify distribute publication of repository (2nd try) + ansible.builtin.assert: + that: + - result.changed == false + + - name: Read distribution + pulp.squeezer.python_distribution: + name: test_python_distribution + register: result + - name: Verify read distribution + ansible.builtin.assert: + that: + - result.changed == false + - result.distribution.name == "test_python_distribution" + - result.distribution.base_path == "test_python_base_path" + - result.distribution.base_url is regex(".*/pypi/test_python_base_path") + - result.distribution.repository == repository_result.repository.pulp_href + - hosts: localhost gather_facts: false vars_files: