Skip to content

Commit 22a068b

Browse files
authored
Merge pull request #60 from stackhpc/container-content-wait
pulp_container_content: Allow not waiting for content changes
2 parents 7e28e54 + de6b8f2 commit 22a068b

File tree

6 files changed

+39
-8
lines changed

6 files changed

+39
-8
lines changed

galaxy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace: "stackhpc"
22
name: "pulp"
3-
version: "0.5.0"
3+
version: "0.5.1"
44
readme: "README.md"
55
authors:
66
- "Piotr Parczewski"

plugins/modules/pulp_container_content.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,17 @@ def add_or_remove(self, add_or_remove_id, content_units):
137137
add_or_remove_id, body=body, uploads=self.uploads, parameters=parameters
138138
)
139139
if response and "task" in response:
140-
task = PulpTask(self.module, {"pulp_href": response["task"]}).wait_for()
141-
# Adding or removing content results in creation of a new repository version
142-
if task["created_resources"]:
143-
self.entity = {"pulp_href": task["created_resources"][0]}
144-
self.module.set_changed()
140+
if self.module.params["wait"]:
141+
task = PulpTask(self.module, {"pulp_href": response["task"]}).wait_for()
142+
# Adding or removing content results in creation of a new repository version
143+
if task["created_resources"]:
144+
self.entity = {"pulp_href": task["created_resources"][0]}
145+
self.module.set_changed()
146+
else:
147+
self.entity = None
145148
else:
146-
self.entity = None
149+
self._name_singular = "task"
150+
self.entity = {"pulp_href": response["task"]}
147151
else:
148152
self.entity = response
149153
else:
@@ -178,6 +182,7 @@ def main():
178182
src_is_push={"type": "bool", "default": False},
179183
state={"default": "present"},
180184
tags={"type": "list", "item": "str", "required": True},
185+
wait={"type": "bool", "default": True},
181186
),
182187
required_if=[("state", "present", ["src_repo"])],
183188
) as module:

roles/pulp_container_content/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Role variables
2323
* `state`: Whether to add (`present`) or remove (`absent`) content.
2424
* `tags`: List of names of tags to add or remove.
2525

26+
* `pulp_container_content_wait`: Whether to wait for content addition to complete in order. Default is `true`.
27+
2628
Example playbook
2729
----------------
2830

roles/pulp_container_content/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ pulp_password:
55
pulp_validate_certs: true
66

77
pulp_container_content: []
8+
pulp_container_content_wait: true

roles/pulp_container_content/tasks/main.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,25 @@
1111
repository: "{{ item.repository }}"
1212
tags: "{{ item.tags }}"
1313
state: "{{ item.state | default(omit) }}"
14+
wait: "{{ pulp_container_content_wait | bool }}"
1415
loop: "{{ pulp_container_content }}"
16+
register: pulp_container_content_result
17+
18+
- name: Wait for tasks to complete
19+
pulp.squeezer.task:
20+
pulp_url: "{{ pulp_url }}"
21+
username: "{{ pulp_username }}"
22+
password: "{{ pulp_password }}"
23+
validate_certs: "{{ pulp_validate_certs | bool }}"
24+
pulp_href: "{{ content_result.task.pulp_href }}"
25+
state: "completed"
26+
loop: "{{ pulp_container_content }}"
27+
when:
28+
- not pulp_container_content_wait | bool
29+
- "'task' in content_result"
30+
changed_when: pulp_container_content_wait_result.task.created_resources | default([]) | length > 0
31+
register: pulp_container_content_wait_result
32+
loop_control:
33+
index_var: result_index
34+
vars:
35+
content_result: "{{ pulp_container_content_result.results[result_index] }}"

tests/test_container_content.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
that:
5757
- tags.json.results | map(attribute='name') | sort | list == ['manifest_a', 'manifest_b']
5858

59-
# Test idempotence
59+
# Test idempotence and not waiting
6060
- include_role:
6161
name: pulp_container_content
6262
vars:
@@ -67,6 +67,7 @@
6767
- manifest_a
6868
- manifest_b
6969
state: present
70+
pulp_container_content_wait: false
7071

7172
- include_role:
7273
name: pulp_container_content
@@ -111,6 +112,7 @@
111112
tags:
112113
- manifest_b
113114
state: absent
115+
pulp_container_content_wait: false
114116

115117
- include_role:
116118
name: pulp_container_content

0 commit comments

Comments
 (0)