Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add container content add/remove commands #496

Merged
merged 1 commit into from
Apr 14, 2022
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
1 change: 1 addition & 0 deletions CHANGES/422.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added pulp_container repository list/add/remove content commands.
16 changes: 15 additions & 1 deletion pulpcore/cli/container/context.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any
from typing import Any, List, Optional

from pulpcore.cli.common.context import (
EntityDefinition,
Expand Down Expand Up @@ -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"
Expand Down
22 changes: 19 additions & 3 deletions pulpcore/cli/container/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
list_command,
name_option,
pulp_group,
repository_content_command,
repository_href_option,
repository_option,
resource_option,
Expand All @@ -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

Expand All @@ -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 '[[<plugin>:]<resource_type>:]<name>' or by href."
),
help=_("Remote used for syncing in the form '[[<plugin>:]<resource_type>:]<name>' or by href."),
)


Expand All @@ -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]))
Expand All @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions tests/scripts/pulp_container/test_content.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"