From ded22fae59c0eda0a3a4f52e65c345d5289e27df Mon Sep 17 00:00:00 2001 From: Gerrod Ubben Date: Wed, 13 Apr 2022 18:30:33 -0400 Subject: [PATCH] Add container content add/remove commands fixes: #422 --- CHANGES/422.feature | 1 + pulpcore/cli/container/context.py | 16 +++++++++++++- pulpcore/cli/container/repository.py | 22 +++++++++++++++++--- tests/scripts/pulp_container/test_content.sh | 14 +++++++++++++ 4 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 CHANGES/422.feature diff --git a/CHANGES/422.feature b/CHANGES/422.feature new file mode 100644 index 000000000..d0dfa891f --- /dev/null +++ b/CHANGES/422.feature @@ -0,0 +1 @@ +Added pulp_container repository list/add/remove content commands. diff --git a/pulpcore/cli/container/context.py b/pulpcore/cli/container/context.py index 5a7100566..999c55e31 100644 --- a/pulpcore/cli/container/context.py +++ b/pulpcore/cli/container/context.py @@ -1,4 +1,4 @@ -from typing import Any +from typing import Any, List, Optional from pulpcore.cli.common.context import ( EntityDefinition, @@ -110,6 +110,20 @@ class PulpContainerRepositoryContext(PulpContainerBaseRepositoryContext): "roles": [PluginRequirement("container", "2.11.0.dev")], } + def modify( + self, + href: str, + add_content: Optional[List[str]] = None, + remove_content: Optional[List[str]] = None, + base_version: Optional[str] = None, + ) -> Any: + if remove_content: + self.call( + "remove", parameters={self.HREF: href}, body={"content_units": remove_content} + ) + if add_content: + self.call("add", parameters={self.HREF: href}, body={"content_units": add_content}) + class PulpContainerPushRepositoryContext(PulpContainerBaseRepositoryContext): HREF = "container_container_push_repository_href" diff --git a/pulpcore/cli/container/repository.py b/pulpcore/cli/container/repository.py index 0e9343f3a..c65140e83 100644 --- a/pulpcore/cli/container/repository.py +++ b/pulpcore/cli/container/repository.py @@ -19,6 +19,7 @@ list_command, name_option, pulp_group, + repository_content_command, repository_href_option, repository_option, resource_option, @@ -30,11 +31,15 @@ version_command, ) from pulpcore.cli.common.i18n import get_translation +from pulpcore.cli.container.content import show_options from pulpcore.cli.container.context import ( PulpContainerBaseRepositoryContext, + PulpContainerBlobContext, + PulpContainerManifestContext, PulpContainerPushRepositoryContext, PulpContainerRemoteContext, PulpContainerRepositoryContext, + PulpContainerTagContext, ) from pulpcore.cli.core.generic import task_command @@ -58,9 +63,7 @@ def _tag_callback(ctx: click.Context, param: click.Parameter, value: str) -> str default_type="container", context_table={"container:container": PulpContainerRemoteContext}, href_pattern=PulpRemoteContext.HREF_PATTERN, - help=_( - "Remote used for synching in the form '[[:]:]' or by href." - ), + help=_("Remote used for syncing in the form '[[:]:]' or by href."), ) @@ -84,6 +87,11 @@ def repository() -> None: retained_versions_option, ] create_options = update_options + [click.option("--name", required=True)] +contexts = { + "tag": PulpContainerTagContext, + "manifest": PulpContainerManifestContext, + "blob": PulpContainerBlobContext, +} container_context = (PulpContainerRepositoryContext,) repository.add_command(list_command(decorators=[label_select_option])) @@ -103,6 +111,14 @@ def repository() -> None: repository.add_command(version_command(decorators=nested_lookup_options)) repository.add_command(role_command(decorators=lookup_options)) repository.add_command(label_command(decorators=nested_lookup_options)) +repository.add_command( + repository_content_command( + contexts=contexts, + add_decorators=show_options, + remove_decorators=show_options, + allowed_with_contexts=container_context, + ) +) @repository.command(allowed_with_contexts=container_context) diff --git a/tests/scripts/pulp_container/test_content.sh b/tests/scripts/pulp_container/test_content.sh index e947601b2..cc441125f 100755 --- a/tests/scripts/pulp_container/test_content.sh +++ b/tests/scripts/pulp_container/test_content.sh @@ -45,3 +45,17 @@ tag_digest="$(echo "$OUTPUT" | jq -r .digest)" expect_succ pulp container content -t tag show --name "$tag_name" --digest "$tag_digest" test "$(echo "$OUTPUT" | jq -r .pulp_href)" = "$tag_href" + +# Test repository content commands +expect_succ pulp container repository content list --repository "cli_test_container_repository" --all-types +expect_succ pulp container repository content --type "tag" list --repository "cli_test_container_repository" +expect_succ pulp container repository content --type "manifest" list --repository "cli_test_container_repository" +expect_succ pulp container repository content --type "blob" list --repository "cli_test_container_repository" + +expect_succ pulp container repository content --type "blob" remove --repository "cli_test_container_repository" --digest "$blob_digest" +expect_succ pulp container repository content --type "manifest" remove --repository "cli_test_container_repository" --digest "$manifest_digest" +expect_succ pulp container repository content --type "tag" remove --repository "cli_test_container_repository" --name "$tag_name" --digest "$tag_digest" + +expect_succ pulp container repository content add --repository "cli_test_container_repository" --href "$blob_href" +expect_succ pulp container repository content add --repository "cli_test_container_repository" --href "$manifest_href" +expect_succ pulp container repository content add --repository "cli_test_container_repository" --href "$tag_href"