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

A 'repository' keyword to python_distribution module #162

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
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
34 changes: 32 additions & 2 deletions plugins/modules/python_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -128,14 +147,15 @@ def main():
with PulpEntityAnsibleModule(
context_class=PulpPythonDistributionContext,
entity_singular="distribution",
entity_plural="distribuions",
entity_plural="distributions",
Comment on lines -131 to +150
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

import_errors=[("pulp-glue", PULP_CLI_IMPORT_ERR)],
argument_spec=dict(
name=dict(),
base_path=dict(),
publication=dict(),
content_guard=dict(),
remote=dict(),
repository=dict(),
),
required_if=[
("state", "present", ["name", "base_path"]),
Expand All @@ -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"],
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind trying if this worked too?

Suggested change
desired_attributes["repository"] = repository_ctx.pulp_href
desired_attributes["repository"] = repository_ctx

I think glue should be able to resolve that.

else:
desired_attributes["repository"] = ""

module.process(natural_key, desired_attributes)


Expand Down
46 changes: 46 additions & 0 deletions tests/playbooks/python_distribution.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading