From 53453c02a3d2ef0837a7d1c93d2670949450cb87 Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Wed, 25 Oct 2023 14:04:02 +0100 Subject: [PATCH] pulp_container_content: Add state=read, allowing for checking presence of tags --- plugins/modules/pulp_container_content.py | 14 ++++++++++---- tests/test_container_content.yml | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/plugins/modules/pulp_container_content.py b/plugins/modules/pulp_container_content.py index 0447c20..c5aeef3 100644 --- a/plugins/modules/pulp_container_content.py +++ b/plugins/modules/pulp_container_content.py @@ -42,6 +42,7 @@ choices: - present - absent + - read tags: description: - List of tags to add or remove @@ -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)) @@ -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)) @@ -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}, ), diff --git a/tests/test_container_content.yml b/tests/test_container_content.yml index 9dfb9ef..47ed5fe 100644 --- a/tests/test_container_content.yml +++ b/tests/test_container_content.yml @@ -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