Skip to content

Commit

Permalink
Added label command to ansible distribution
Browse files Browse the repository at this point in the history
fixes: #185
  • Loading branch information
gerrod3 committed Mar 25, 2021
1 parent f9a6726 commit 2c62fe6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGES/185.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added label command to ansible distribution group
2 changes: 2 additions & 0 deletions pulpcore/cli/ansible/distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
create_command,
destroy_command,
href_option,
label_command,
label_select_option,
list_command,
name_option,
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions pulpcore/cli/common/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions pulpcore/cli/common/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
9 changes: 9 additions & 0 deletions tests/scripts/pulp_ansible/test_distribution.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 2c62fe6

Please sign in to comment.