Skip to content

Commit

Permalink
Add container content add/remove commands
Browse files Browse the repository at this point in the history
[noissue]
  • Loading branch information
gerrod3 committed Apr 13, 2022
1 parent 9cee6bd commit e060d51
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
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"

0 comments on commit e060d51

Please sign in to comment.