Skip to content

Commit

Permalink
Add content list to container push repositories
Browse files Browse the repository at this point in the history
fixes pulp#600
  • Loading branch information
mdellweg committed Mar 15, 2024
1 parent 8437376 commit 0fd7071
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES/600.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added the content list commands to container push repositories.
12 changes: 8 additions & 4 deletions pulpcore/cli/common/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1530,6 +1530,10 @@ def repository_content_command(**kwargs: t.Any) -> click.Group:
"""A factory that creates a repository content command group."""

content_contexts = kwargs.pop("contexts", {})
list_kwargs = kwargs.pop("list_kwargs", {})
add_kwargs = kwargs.pop("add_kwargs", {})
remove_kwargs = kwargs.pop("remove_kwargs", {})
modify_kwargs = kwargs.pop("modify_kwargs", {})

def version_callback(
ctx: click.Context, param: click.Parameter, value: t.Optional[int]
Expand All @@ -1540,7 +1544,7 @@ def version_callback(

# This is a mypy bug getting confused with positional args
# https://github.com/python/mypy/issues/15037
@pulp_command("list") # type: ignore [arg-type]
@pulp_command("list", **list_kwargs) # type: ignore [arg-type]
@click.option("--all-types", is_flag=True)
@limit_option
@offset_option
Expand All @@ -1563,7 +1567,7 @@ def content_list(
result = content_ctx.list(limit=limit, offset=offset, parameters=parameters)
pulp_ctx.output_result(result)

@pulp_command("add")
@pulp_command("add", **add_kwargs)
@repository_option
@click.option("--base-version", type=int, callback=version_callback)
@pass_content_context
Expand All @@ -1574,7 +1578,7 @@ def content_add(
repo_ctx = base_version.repository_ctx
repo_ctx.modify(add_content=[content_ctx.pulp_href], base_version=base_version.pulp_href)

@pulp_command("remove")
@pulp_command("remove", **remove_kwargs)
@click.option("--all", is_flag=True, help=_("Remove all content from repository version"))
@repository_option
@click.option("--base-version", type=int, callback=version_callback)
Expand All @@ -1588,7 +1592,7 @@ def content_remove(
remove_content = ["*" if all else content_ctx.pulp_href]
repo_ctx.modify(remove_content=remove_content, base_version=base_version.pulp_href)

@pulp_command("modify")
@pulp_command("modify", **modify_kwargs)
@repository_option
@click.option("--base-version", type=int, callback=version_callback)
def content_modify(
Expand Down
4 changes: 3 additions & 1 deletion pulpcore/cli/container/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ def repository() -> None:
contexts=contexts,
add_decorators=show_options,
remove_decorators=show_options,
allowed_with_contexts=container_context,
add_kwargs={"allowed_with_contexts": container_context},
remove_kwargs={"allowed_with_contexts": container_context},
modify_kwargs={"allowed_with_contexts": container_context},
)
)

Expand Down
7 changes: 7 additions & 0 deletions tests/scripts/pulp_container/test_content.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pulp debug has-plugin --name "container" || exit 23

cleanup() {
pulp container repository destroy --name "cli_test_container_repository" || true
pulp container repository destroy --name "cli_test_container_push_repository" || true
pulp container remote destroy --name "cli_test_container_remote" || true
pulp orphan cleanup || true
}
Expand All @@ -16,6 +17,7 @@ trap cleanup EXIT
pulp container remote create --name "cli_test_container_remote" --url "$CONTAINER_REMOTE_URL" --upstream-name "$CONTAINER_IMAGE"
pulp container repository create --name "cli_test_container_repository"
pulp container repository sync --name "cli_test_container_repository" --remote "cli_test_container_remote"
pulp container repository create --name "cli_test_container_push_repository"

# Check each content list
expect_succ pulp container content -t blob list
Expand Down Expand Up @@ -59,3 +61,8 @@ expect_succ pulp container repository content --type "tag" remove --repository "
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"

expect_succ pulp container repository -t push content list --repository "cli_test_container_push_repository" --all-types
expect_succ pulp container repository -t push content --type "tag" list --repository "cli_test_container_push_repository"
expect_succ pulp container repository -t push content --type "manifest" list --repository "cli_test_container_push_repository"
expect_succ pulp container repository -t push content --type "blob" list --repository "cli_test_container_push_repository"

0 comments on commit 0fd7071

Please sign in to comment.