From 2c62fe61747719fbeb7d287d6e61eb900877845e Mon Sep 17 00:00:00 2001 From: Gerrod Ubben Date: Tue, 23 Mar 2021 19:14:42 -0400 Subject: [PATCH] Added label command to ansible distribution fixes: #185 --- CHANGES/185.feature | 1 + pulpcore/cli/ansible/distribution.py | 2 ++ pulpcore/cli/common/context.py | 12 ++++++------ pulpcore/cli/common/generic.py | 9 +++++++-- tests/scripts/pulp_ansible/test_distribution.sh | 9 +++++++++ 5 files changed, 25 insertions(+), 8 deletions(-) create mode 100644 CHANGES/185.feature diff --git a/CHANGES/185.feature b/CHANGES/185.feature new file mode 100644 index 000000000..5a94171fc --- /dev/null +++ b/CHANGES/185.feature @@ -0,0 +1 @@ +Added label command to ansible distribution group diff --git a/pulpcore/cli/ansible/distribution.py b/pulpcore/cli/ansible/distribution.py index 73d1c198e..58a4d31e1 100644 --- a/pulpcore/cli/ansible/distribution.py +++ b/pulpcore/cli/ansible/distribution.py @@ -20,6 +20,7 @@ create_command, destroy_command, href_option, + label_command, label_select_option, list_command, name_option, @@ -79,6 +80,7 @@ def distribution(ctx: click.Context, pulp_ctx: PulpContext, distribution_type: s distribution.add_command(show_command(decorators=lookup_options)) distribution.add_command(destroy_command(decorators=lookup_options)) distribution.add_command(create_command(decorators=create_options)) +distribution.add_command(label_command(needs=[("core", "3.10.0"), ("ansible", "0.8.0.dev")])) # TODO Add content_guard option diff --git a/pulpcore/cli/common/context.py b/pulpcore/cli/common/context.py index 06484a06a..ef9e63838 100644 --- a/pulpcore/cli/common/context.py +++ b/pulpcore/cli/common/context.py @@ -392,14 +392,14 @@ def delete(self, href: str, non_blocking: bool = False) -> Any: ) def set_label(self, href: str, key: str, value: str, non_blocking: bool = False) -> Any: - entity = self.show(href) - entity["pulp_labels"][key] = value - return self.update(href, body=entity, non_blocking=non_blocking) + labels = self.show(href)["pulp_labels"] + labels[key] = value + return self.update(href, body={"pulp_labels": labels}, non_blocking=non_blocking) def unset_label(self, href: str, key: str, non_blocking: bool = False) -> Any: - entity = self.show(href) - entity["pulp_labels"].pop(key) - return self.update(href, body=entity, non_blocking=non_blocking) + labels = self.show(href)["pulp_labels"] + labels.pop(key) + return self.update(href, body={"pulp_labels": labels}, non_blocking=non_blocking) def show_label(self, href: str, key: str) -> Any: entity = self.show(href) diff --git a/pulpcore/cli/common/generic.py b/pulpcore/cli/common/generic.py index 8b556a044..7072ae7ba 100644 --- a/pulpcore/cli/common/generic.py +++ b/pulpcore/cli/common/generic.py @@ -390,10 +390,15 @@ def label_command(**kwargs: Any) -> click.Command: if "name" not in kwargs: kwargs["name"] = "label" decorators = kwargs.pop("decorators", [name_option, href_option]) + needs = kwargs.pop("needs", [("core", "3.10.0")]) @click.group(**kwargs) - def label_group() -> None: - pass + @pass_pulp_context + def label_group(pulp_ctx: PulpContext) -> None: + for plugin in needs: + min_ver = plugin[1] if len(plugin) >= 2 else None + max_ver = plugin[2] if len(plugin) == 3 else None + pulp_ctx.needs_plugin(plugin[0], min_ver, max_ver) @click.command(name="set", help=_("Add or update a label")) @click.option("--key", required=True, help=_("Key of the label")) diff --git a/tests/scripts/pulp_ansible/test_distribution.sh b/tests/scripts/pulp_ansible/test_distribution.sh index 93eb4cdd2..5b173957e 100755 --- a/tests/scripts/pulp_ansible/test_distribution.sh +++ b/tests/scripts/pulp_ansible/test_distribution.sh @@ -27,4 +27,13 @@ expect_succ pulp ansible distribution list expect_succ pulp ansible distribution show --name "cli_test_ansible_distro" expect_succ pulp ansible distribution update --name "cli_test_ansible_distro" --repository "" +if [ "$(pulp debug has-plugin --name "core" --min-version "3.10.0")" = "true" ] +then + if [ "$(pulp debug has-plugin --name "ansible" --min-version "0.8.0.dev")" = "true" ] + then + expect_succ pulp ansible distribution label set --name "cli_test_ansible_distro" --key "test" --value "success" + else + expect_fail pulp ansible distribution label set --name "cli_test_ansible_distro" --key "test" --value "fail" + fi +fi expect_succ pulp ansible distribution destroy --name "cli_test_ansible_distro"