Skip to content
Merged
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
14 changes: 10 additions & 4 deletions plugins/modules/pulp_container_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
choices:
- present
- absent
- read
tags:
description:
- List of tags to add or remove
Expand Down Expand Up @@ -137,7 +138,7 @@ def get_content_units(self, repo):
offset += PAGE_LIMIT

tag_names = [tag["name"] for tag in tags]
if (self.module.params["state"] == "present" and
if (self.module.params["state"] in ["present", "read"] and
not self.module.params["allow_missing"] and
len(tag_names) != len(self.module.params["tags"])):
missing = ", ".join(set(self.module.params["tags"]) - set(tag_names))
Expand Down Expand Up @@ -176,13 +177,18 @@ def add(self):
def remove(self):
self.add_or_remove(self._remove_id, self.get_content_units(self))

def read(self):
self.get_content_units(self)

def process(self):
# Populate self.entity.
self.find(failsafe=False)
if self.module.params["state"] == "present":
response = self.add()
self.add()
elif self.module.params["state"] == "absent":
response = self.remove()
self.remove()
elif self.module.params["state"] == "read":
self.read()
else:
raise SqueezerException("Unexpected state")
self.module.set_result(self._name_singular, self.presentation(self.entity))
Expand All @@ -195,7 +201,7 @@ def main():
repository={"required": True},
src_repo={},
src_is_push={"type": "bool", "default": False},
state={"default": "present", "choices": ["present", "absent"]},
state={"default": "present", "choices": ["present", "absent", "read"]},
tags={"type": "list", "elements": "str", "required": True},
wait={"type": "bool", "default": True},
),
Expand Down
23 changes: 23 additions & 0 deletions tests/test_container_content.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,29 @@
assert:
that:
- failed_task.name == "Add or remove content units"
- set_fact:
failed_task:

# Repeat the above test with state=read
- block:
- include_role:
name: pulp_container_content
vars:
pulp_container_content:
- repository: test_container_repo
tags:
- not-a-valid-tag
state: read
rescue:
- set_fact:
failed_task: "{{ ansible_failed_task }}"
always:
- name: Assert that querying a missing tag failed
assert:
that:
- failed_task.name == "Add or remove content units"
- set_fact:
failed_task:

- include_role:
name: pulp_repository
Expand Down