Skip to content

Commit 8654fbd

Browse files
committed
Support python distributions
pointing to a specific repository version is not supported by pulp.squeezer so is not supported here either
1 parent 7810047 commit 8654fbd

5 files changed

Lines changed: 232 additions & 0 deletions

File tree

roles/pulp_distribution/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Role variables
1212
* `pulp_validate_certs`: Whether to validate Pulp server certificate. Default is `true`
1313
* `pulp_distribution_container`: List of distributions for container repositories. Default is an empty list
1414
* `pulp_distribution_deb`: List of distributions for Deb repositories. Default is an empty list
15+
* `pulp_distribution_python`: List of distributions for Python repositories. Default is an empty list
1516
* `pulp_distribution_rpm`: List of distributions for RPM repositories. Default is an empty list
1617
* `pulp_distribution_deb_skip_existing`: Whether to skip existing Deb
1718
distributions. If true, new distributions will not be created for a
@@ -67,6 +68,18 @@ Example playbook
6768
distribution: ubuntu-focal
6869
content_guard: secure-content-guard
6970
state: present
71+
pulp_distribution_python:
72+
# specify a remote to make a pull-through cache
73+
- name: pull_through_distribution
74+
base_path: pullthrough
75+
repository: test_python_repo
76+
remote: test_python_repo-remote
77+
state: present
78+
# without remote it automatically serves the latest version of the repository
79+
- name: latest_version_distribution
80+
base_path: latest
81+
repository: test_python_repo
82+
state: present
7083
pulp_distribution_rpm:
7184
# Distribute the latest version of the centos-baseos repository.
7285
- name: centos-baseos

roles/pulp_distribution/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pulp_validate_certs: true
66

77
pulp_distribution_container: []
88
pulp_distribution_deb: []
9+
pulp_distribution_python: []
910
pulp_distribution_rpm: []
1011

1112
# Whether to skip existing distributions. If true, new distributions will

roles/pulp_distribution/tasks/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
tags: deb
1010
when: pulp_distribution_deb | length > 0
1111

12+
- include_tasks: python.yml
13+
tags: python
14+
when: pulp_distribution_python | length > 0
15+
1216
- include_tasks: rpm.yml
1317
tags: rpm
1418
when: pulp_distribution_rpm | length > 0
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
- name: Ensure Python distributions are defined
3+
pulp.squeezer.python_distribution:
4+
pulp_url: "{{ pulp_url }}"
5+
username: "{{ pulp_username }}"
6+
password: "{{ pulp_password }}"
7+
validate_certs: "{{ pulp_validate_certs | bool }}"
8+
name: "{{ item.name }}"
9+
base_path: "{{ item.base_path | default(omit) }}"
10+
content_guard: "{{ item.content_guard | default(omit) }}"
11+
remote: "{{ (item.remote | default(omit)) if item.state == 'present' else omit }}"
12+
repository: "{{ item.repository if item.state == 'present' else omit }}"
13+
state: "{{ item.state }}"
14+
with_items: "{{ pulp_distribution_python }}"

tests/test_python_distribution.yml

Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
---
2+
- name: Test pulp_distribution python
3+
gather_facts: false
4+
hosts: localhost
5+
vars:
6+
pulp_url: http://localhost:8080
7+
pulp_username: admin
8+
pulp_password: password
9+
pulp_validate_certs: true
10+
tasks:
11+
- include_role:
12+
name: pulp_repository
13+
vars:
14+
pulp_repository_python_repos:
15+
- name: test_python_repo
16+
url: "https://fixtures.pulpproject.org/python-pypi/"
17+
policy: immediate
18+
state: present
19+
sync: false
20+
21+
- include_role:
22+
name: pulp_distribution
23+
vars:
24+
pulp_distribution_python:
25+
- name: test_python_distribution
26+
base_path: test_python_distribution
27+
repository: test_python_repo
28+
remote: test_python_repo-remote
29+
state: present
30+
31+
- name: Query repository
32+
pulp.squeezer.python_repository:
33+
pulp_url: "{{ pulp_url }}"
34+
username: "{{ pulp_username }}"
35+
password: "{{ pulp_password }}"
36+
validate_certs: "{{ pulp_validate_certs }}"
37+
name: test_python_repo
38+
register: repo_result
39+
40+
- name: Query distribution
41+
pulp.squeezer.python_distribution:
42+
pulp_url: "{{ pulp_url }}"
43+
username: "{{ pulp_username }}"
44+
password: "{{ pulp_password }}"
45+
validate_certs: "{{ pulp_validate_certs }}"
46+
name: test_python_distribution
47+
register: dist_result
48+
49+
- debug:
50+
var: dist_result
51+
52+
- name: Verify distribution creation
53+
assert:
54+
that:
55+
- dist_result.distribution.name == "test_python_distribution"
56+
- dist_result.distribution.base_path == "test_python_distribution"
57+
58+
- name: Query distribution package index
59+
ansible.builtin.uri:
60+
url: "{{ pulp_url }}{{ dist_result.distribution.base_url | ansible.builtin.urlsplit('path') }}simple/"
61+
return_content: true
62+
register: package_index
63+
64+
- debug:
65+
var: package_index
66+
67+
- name: Verify package index
68+
ansible.builtin.assert:
69+
that:
70+
- package_index.status == 200
71+
- "'Simple Index' in package_index.content"
72+
- "'shelf-reader' not in package_index.content" # gets pulled-through later on
73+
74+
- name: Query shelf-reader from distribution
75+
ansible.builtin.uri:
76+
url: "{{ pulp_url }}{{ dist_result.distribution.base_url | ansible.builtin.urlsplit('path') }}simple/shelf-reader/"
77+
return_content: true
78+
register: package_index
79+
80+
- name: Verify package index
81+
ansible.builtin.assert:
82+
that:
83+
- package_index.status == 200
84+
- "'shelf-reader-0.1.tar.gz' in package_index.content"
85+
- "'shelf_reader-0.1-py2-none-any.whl' in package_index.content"
86+
87+
- include_role:
88+
name: pulp_distribution
89+
vars:
90+
pulp_distribution_python:
91+
- name: test_python_distribution
92+
state: absent
93+
94+
- include_role:
95+
name: pulp_repository
96+
vars:
97+
pulp_repository_python_repos:
98+
- name: test_python_repo
99+
state: absent
100+
101+
- name: Query distributions
102+
pulp.squeezer.python_distribution:
103+
pulp_url: "{{ pulp_url }}"
104+
username: "{{ pulp_username }}"
105+
password: "{{ pulp_password }}"
106+
validate_certs: "{{ pulp_validate_certs }}"
107+
register: python_distributions
108+
109+
- name: Verify distribution deletion
110+
assert:
111+
that: python_distributions.distributions | length == 0
112+
113+
# ---- test distribution serving latest version
114+
- include_role:
115+
name: pulp_repository
116+
vars:
117+
pulp_repository_python_repos:
118+
- name: test_python_repo
119+
url: "https://fixtures.pulpproject.org/python-pypi/"
120+
policy: immediate
121+
state: present
122+
includes: ["shelf-reader"]
123+
124+
- include_role:
125+
name: pulp_distribution
126+
vars:
127+
pulp_distribution_python:
128+
- name: test_python_distribution
129+
base_path: test_python_distribution
130+
repository: test_python_repo
131+
state: present
132+
133+
- name: Query repository
134+
pulp.squeezer.python_repository:
135+
pulp_url: "{{ pulp_url }}"
136+
username: "{{ pulp_username }}"
137+
password: "{{ pulp_password }}"
138+
validate_certs: "{{ pulp_validate_certs }}"
139+
name: test_python_repo
140+
register: repo_result
141+
142+
- name: Query distribution
143+
pulp.squeezer.python_distribution:
144+
pulp_url: "{{ pulp_url }}"
145+
username: "{{ pulp_username }}"
146+
password: "{{ pulp_password }}"
147+
validate_certs: "{{ pulp_validate_certs }}"
148+
name: test_python_distribution
149+
register: dist_result
150+
151+
- debug:
152+
var: dist_result
153+
154+
- name: Verify distribution creation
155+
assert:
156+
that:
157+
- dist_result.distribution.name == "test_python_distribution"
158+
- dist_result.distribution.base_path == "test_python_distribution"
159+
160+
- name: Query distribution package index
161+
ansible.builtin.uri:
162+
url: "{{ pulp_url }}{{ dist_result.distribution.base_url | ansible.builtin.urlsplit('path') }}simple/"
163+
return_content: true
164+
register: package_index
165+
166+
- debug:
167+
var: package_index
168+
169+
- name: Verify package index
170+
ansible.builtin.assert:
171+
that:
172+
- package_index.status == 200
173+
- "'Simple Index' in package_index.content"
174+
- "'shelf-reader' in package_index.content" # already there because the repository is synced
175+
176+
- include_role:
177+
name: pulp_distribution
178+
vars:
179+
pulp_distribution_python:
180+
- name: test_python_distribution
181+
state: absent
182+
183+
- include_role:
184+
name: pulp_repository
185+
vars:
186+
pulp_repository_python_repos:
187+
- name: test_python_repo
188+
state: absent
189+
190+
- name: Query distributions
191+
pulp.squeezer.python_distribution:
192+
pulp_url: "{{ pulp_url }}"
193+
username: "{{ pulp_username }}"
194+
password: "{{ pulp_password }}"
195+
validate_certs: "{{ pulp_validate_certs }}"
196+
register: python_distributions
197+
198+
- name: Verify distribution deletion
199+
assert:
200+
that: python_distributions.distributions | length == 0

0 commit comments

Comments
 (0)