Skip to content

Commit 7b572e8

Browse files
authored
Merge pull request #559 from stackhpc/fix-missing-dist-sync
Try creating dist if it doesn't exist
2 parents c69cdb3 + 443126c commit 7b572e8

1 file changed

Lines changed: 94 additions & 11 deletions

File tree

ansible/test-pulp-repo-version-query.yml

Lines changed: 94 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,48 @@
6464
register: pulp_rpm_dists_list
6565

6666
- vars:
67-
repo: "{{ pulp_deb_repos_list.repositories | selectattr('name', 'equalto', item.repository) | first }}"
68-
pub: "{{ (pulp_deb_pubs_list.publications + pulp_deb_verbatim_pubs_list.publications) | selectattr('repository', 'equalto', repo.pulp_href) | stackhpc.pulp.sort_publications
69-
| first }}"
70-
dist: "{{ pulp_deb_dists_list.distributions | selectattr('publication', 'equalto', pub.pulp_href) | first }}"
67+
repo_list: >-
68+
{{ pulp_deb_repos_list.repositories
69+
| selectattr('name', 'equalto', item.repository)
70+
| list }}
71+
repo: "{{ repo_list[0] if (repo_list | length > 0) else {} }}"
72+
pubs: >-
73+
{{ (pulp_deb_pubs_list.publications + pulp_deb_verbatim_pubs_list.publications)
74+
| selectattr('repository', 'equalto', repo.get('pulp_href', ''))
75+
| stackhpc.pulp.sort_publications | list }}
76+
pub: "{{ pubs[0] if (pubs | length > 0) else {} }}"
77+
base_name: "{{ item.name | regex_replace('-[0-9]{8}T[0-9]{6}$', '') }}"
78+
safe_pattern: "^{{ base_name | regex_escape }}(-[0-9]{8}T[0-9]{6})?$"
79+
existing_dists: >-
80+
{{ pulp_deb_dists_list.distributions
81+
| selectattr('publication', 'equalto', pub.get('pulp_href', ''))
82+
| selectattr('name', 'match', safe_pattern)
83+
| list }}
84+
dist: "{{ existing_dists[0] if (existing_dists | length > 0) else {} }}"
7185

7286
block:
87+
- name: Ensure Deb distributions exist for latest publication
88+
pulp.squeezer.deb_distribution:
89+
pulp_url: "{{ pulp_url }}"
90+
username: "{{ pulp_username }}"
91+
password: "{{ pulp_password }}"
92+
name: "{{ item.name }}"
93+
base_path: "{{ item.base_path }}"
94+
publication: "{{ pub.get('pulp_href') }}"
95+
content_guard: "{{ item.content_guard | default(omit) }}"
96+
state: present
97+
loop: "{{ dev_pulp_distribution_deb }}"
98+
loop_control:
99+
label: "{{ item.repository }}"
100+
when: (pub | length > 0) and (existing_dists | length == 0)
101+
102+
- name: Re-query Deb distributions (to capture newly created ones)
103+
pulp.squeezer.deb_distribution:
104+
pulp_url: "{{ pulp_url }}"
105+
username: "{{ pulp_username }}"
106+
password: "{{ pulp_password }}"
107+
register: pulp_deb_dists_list
108+
73109
- name: Display latest Deb distributions
74110
vars:
75111
info:
@@ -81,23 +117,66 @@
81117
loop: "{{ dev_pulp_distribution_deb }}"
82118
loop_control:
83119
label: "{{ item.repository }}"
120+
when: pub | length > 0
84121

85122
- name: Set a fact about latest Deb versions
86123
ansible.builtin.set_fact:
87-
test_pulp_repository_deb_repo_versions: "{{ test_pulp_repository_deb_repo_versions | default({}) | combine({item.short_name: dist.base_path | basename})
88-
}}"
124+
test_pulp_repository_deb_repo_versions: >-
125+
{{ test_pulp_repository_deb_repo_versions
126+
| default({})
127+
| combine({item.short_name: dist.base_path | basename}) }}
89128
loop: "{{ dev_pulp_distribution_deb }}"
90129
loop_control:
91130
label: "{{ item.repository }}"
131+
when: dist | length > 0
92132

93133
- name: Display latest versions fact
94134
ansible.builtin.debug:
95135
var: test_pulp_repository_deb_repo_versions
136+
96137
- vars:
97-
repo: "{{ pulp_rpm_repos_list.repositories | selectattr('name', 'equalto', item.repository) | first }}"
98-
pub: "{{ pulp_rpm_pubs_list.publications | selectattr('repository', 'equalto', repo.pulp_href) | stackhpc.pulp.sort_publications | first }}"
99-
dist: "{{ pulp_rpm_dists_list.distributions | selectattr('publication', 'equalto', pub.pulp_href) | first }}"
138+
repo_list: >-
139+
{{ pulp_rpm_repos_list.repositories
140+
| selectattr('name', 'equalto', item.repository)
141+
| list }}
142+
repo: "{{ repo_list[0] if (repo_list | length > 0) else {} }}"
143+
pubs: >-
144+
{{ pulp_rpm_pubs_list.publications
145+
| selectattr('repository', 'equalto', repo.get('pulp_href', ''))
146+
| stackhpc.pulp.sort_publications | list }}
147+
pub: "{{ pubs[0] if (pubs | length > 0) else {} }}"
148+
base_name: "{{ item.name | regex_replace('-[0-9]{8}T[0-9]{6}$', '') }}"
149+
safe_pattern: "^{{ base_name | regex_escape }}(-[0-9]{8}T[0-9]{6})?$"
150+
existing_dists: >-
151+
{{ pulp_rpm_dists_list.distributions
152+
| selectattr('publication', 'equalto', pub.get('pulp_href', ''))
153+
| selectattr('name', 'match', safe_pattern)
154+
| list }}
155+
dist: "{{ existing_dists[0] if (existing_dists | length > 0) else {} }}"
156+
100157
block:
158+
- name: Ensure RPM distributions exist for latest publication
159+
pulp.squeezer.rpm_distribution:
160+
pulp_url: "{{ pulp_url }}"
161+
username: "{{ pulp_username }}"
162+
password: "{{ pulp_password }}"
163+
name: "{{ item.name }}"
164+
base_path: "{{ item.base_path }}"
165+
publication: "{{ pub.get('pulp_href') }}"
166+
content_guard: "{{ item.content_guard | default(omit) }}"
167+
state: present
168+
loop: "{{ dev_pulp_distribution_rpm }}"
169+
loop_control:
170+
label: "{{ item.repository }}"
171+
when: (pub | length > 0) and (existing_dists | length == 0)
172+
173+
- name: Re-query RPM distributions (to capture newly created ones)
174+
pulp.squeezer.rpm_distribution:
175+
pulp_url: "{{ pulp_url }}"
176+
username: "{{ pulp_username }}"
177+
password: "{{ pulp_password }}"
178+
register: pulp_rpm_dists_list
179+
101180
- name: Display latest RPM distributions
102181
vars:
103182
info:
@@ -109,14 +188,18 @@
109188
loop: "{{ dev_pulp_distribution_rpm }}"
110189
loop_control:
111190
label: "{{ item.repository }}"
191+
when: pub | length > 0
112192

113193
- name: Set a fact about latest RPM versions
114194
ansible.builtin.set_fact:
115-
test_pulp_repository_rpm_repo_versions: "{{ test_pulp_repository_rpm_repo_versions | default({}) | combine({item.short_name: dist.base_path | basename})
116-
}}"
195+
test_pulp_repository_rpm_repo_versions: >-
196+
{{ test_pulp_repository_rpm_repo_versions
197+
| default({})
198+
| combine({item.short_name: dist.base_path | basename}) }}
117199
loop: "{{ dev_pulp_distribution_rpm }}"
118200
loop_control:
119201
label: "{{ item.repository }}"
202+
when: dist | length > 0
120203

121204
- name: Display latest versions fact
122205
ansible.builtin.debug:

0 commit comments

Comments
 (0)