Skip to content

Commit 10b9b9e

Browse files
authored
Merge pull request #67 from stackhpc/pulp-container-content-read
pulp_container_content: Add state=read, allowing for checking presence of tags
2 parents 6b589c6 + 53453c0 commit 10b9b9e

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

plugins/modules/pulp_container_content.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
choices:
4343
- present
4444
- absent
45+
- read
4546
tags:
4647
description:
4748
- List of tags to add or remove
@@ -137,7 +138,7 @@ def get_content_units(self, repo):
137138
offset += PAGE_LIMIT
138139

139140
tag_names = [tag["name"] for tag in tags]
140-
if (self.module.params["state"] == "present" and
141+
if (self.module.params["state"] in ["present", "read"] and
141142
not self.module.params["allow_missing"] and
142143
len(tag_names) != len(self.module.params["tags"])):
143144
missing = ", ".join(set(self.module.params["tags"]) - set(tag_names))
@@ -176,13 +177,18 @@ def add(self):
176177
def remove(self):
177178
self.add_or_remove(self._remove_id, self.get_content_units(self))
178179

180+
def read(self):
181+
self.get_content_units(self)
182+
179183
def process(self):
180184
# Populate self.entity.
181185
self.find(failsafe=False)
182186
if self.module.params["state"] == "present":
183-
response = self.add()
187+
self.add()
184188
elif self.module.params["state"] == "absent":
185-
response = self.remove()
189+
self.remove()
190+
elif self.module.params["state"] == "read":
191+
self.read()
186192
else:
187193
raise SqueezerException("Unexpected state")
188194
self.module.set_result(self._name_singular, self.presentation(self.entity))
@@ -195,7 +201,7 @@ def main():
195201
repository={"required": True},
196202
src_repo={},
197203
src_is_push={"type": "bool", "default": False},
198-
state={"default": "present", "choices": ["present", "absent"]},
204+
state={"default": "present", "choices": ["present", "absent", "read"]},
199205
tags={"type": "list", "elements": "str", "required": True},
200206
wait={"type": "bool", "default": True},
201207
),

tests/test_container_content.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,29 @@
188188
assert:
189189
that:
190190
- failed_task.name == "Add or remove content units"
191+
- set_fact:
192+
failed_task:
193+
194+
# Repeat the above test with state=read
195+
- block:
196+
- include_role:
197+
name: pulp_container_content
198+
vars:
199+
pulp_container_content:
200+
- repository: test_container_repo
201+
tags:
202+
- not-a-valid-tag
203+
state: read
204+
rescue:
205+
- set_fact:
206+
failed_task: "{{ ansible_failed_task }}"
207+
always:
208+
- name: Assert that querying a missing tag failed
209+
assert:
210+
that:
211+
- failed_task.name == "Add or remove content units"
212+
- set_fact:
213+
failed_task:
191214

192215
- include_role:
193216
name: pulp_repository

0 commit comments

Comments
 (0)