From b346bf2ab18f69624799351afcb5fb342c5d14c1 Mon Sep 17 00:00:00 2001 From: David Davis Date: Thu, 8 Apr 2021 07:43:06 -0400 Subject: [PATCH] Add support for autopublish and autodistribute fixes #155 --- CHANGES/155.feature | 1 + pulpcore/cli/file/distribution.py | 24 +++++++++++++------ pulpcore/cli/file/repository.py | 10 ++++---- pulpcore/cli/rpm/common.py | 1 + pulpcore/cli/rpm/distribution.py | 14 +++++++++-- pulpcore/cli/rpm/repository.py | 16 ++++++++----- tests/scripts/pulp_file/test_distribution.sh | 6 +++++ tests/scripts/pulp_file/test_repository.sh | 4 ++++ tests/scripts/pulp_file/test_sync.sh | 13 ++++++++++ .../scripts/pulp_rpm/test_rpm_sync_publish.sh | 13 ++++++++++ 10 files changed, 82 insertions(+), 20 deletions(-) create mode 100644 CHANGES/155.feature create mode 100644 pulpcore/cli/rpm/common.py diff --git a/CHANGES/155.feature b/CHANGES/155.feature new file mode 100644 index 000000000..e13d2afd9 --- /dev/null +++ b/CHANGES/155.feature @@ -0,0 +1 @@ +Added support for autopublish and autodistribute. diff --git a/pulpcore/cli/file/distribution.py b/pulpcore/cli/file/distribution.py index 411d7174a..e0654f821 100644 --- a/pulpcore/cli/file/distribution.py +++ b/pulpcore/cli/file/distribution.py @@ -1,8 +1,9 @@ import gettext +from typing import Optional, Union import click -from pulpcore.cli.common.context import PulpContext, pass_pulp_context +from pulpcore.cli.common.context import PulpContext, PulpEntityContext, pass_pulp_context from pulpcore.cli.common.generic import ( base_path_contains_option, base_path_option, @@ -16,11 +17,21 @@ show_command, update_command, ) -from pulpcore.cli.file.context import PulpFileDistributionContext +from pulpcore.cli.file.context import PulpFileDistributionContext, PulpFileRepositoryContext _ = gettext.gettext +def _repository_callback( + ctx: click.Context, param: click.Parameter, value: Optional[str] +) -> Union[str, PulpEntityContext, None]: + # Pass None and "" verbatim + if value: + pulp_ctx: PulpContext = ctx.find_object(PulpContext) + return PulpFileRepositoryContext(pulp_ctx, entity={"name": value}) + return value + + @click.group() @click.option( "-t", @@ -40,14 +51,13 @@ def distribution(ctx: click.Context, pulp_ctx: PulpContext, distribution_type: s filter_options = [label_select_option, base_path_option, base_path_contains_option] lookup_options = [href_option, name_option] -create_options = [ - click.option("--name", required=True), - click.option("--base-path", required=True), - click.option("--publication"), -] update_options = [ click.option("--base-path"), click.option("--publication"), + click.option("--repository", callback=_repository_callback), +] +create_options = update_options + [ + click.option("--name", required=True), ] distribution.add_command(list_command(decorators=filter_options)) diff --git a/pulpcore/cli/file/repository.py b/pulpcore/cli/file/repository.py index d13825334..15aabe48e 100644 --- a/pulpcore/cli/file/repository.py +++ b/pulpcore/cli/file/repository.py @@ -64,14 +64,14 @@ def repository(ctx: click.Context, pulp_ctx: PulpContext, repo_type: str) -> Non lookup_options = [href_option, name_option] nested_lookup_options = [repository_href_option, repository_option] -create_options = [ - click.option("--name", required=True), - click.option("--description"), - click.option("--remote", callback=_remote_callback), -] update_options = [ click.option("--description"), click.option("--remote", callback=_remote_callback), + click.option("--manifest"), + click.option("--autopublish/--no-autopublish", default=None), +] +create_options = update_options + [ + click.option("--name", required=True), ] repository.add_command(list_command(decorators=[label_select_option])) diff --git a/pulpcore/cli/rpm/common.py b/pulpcore/cli/rpm/common.py new file mode 100644 index 000000000..a2aac56f2 --- /dev/null +++ b/pulpcore/cli/rpm/common.py @@ -0,0 +1 @@ +CHECKSUM_CHOICES = ("unknown", "md5", "sha1", "sha224", "sha256", "sha384", "sha512") diff --git a/pulpcore/cli/rpm/distribution.py b/pulpcore/cli/rpm/distribution.py index 3e249d72d..bec84b7ac 100644 --- a/pulpcore/cli/rpm/distribution.py +++ b/pulpcore/cli/rpm/distribution.py @@ -1,8 +1,9 @@ import gettext +from typing import Optional, Union import click -from pulpcore.cli.common.context import PulpContext, pass_pulp_context +from pulpcore.cli.common.context import PulpContext, PulpEntityContext, pass_pulp_context from pulpcore.cli.common.generic import ( base_path_contains_option, base_path_option, @@ -16,11 +17,19 @@ show_command, update_command, ) -from pulpcore.cli.rpm.context import PulpRpmDistributionContext +from pulpcore.cli.rpm.context import PulpRpmDistributionContext, PulpRpmRepositoryContext _ = gettext.gettext +def _repository_callback(ctx: click.Context, param: click.Parameter, value: Optional[str]) -> Union[str, PulpEntityContext, None]: + # Pass None and "" verbatim + if value: + pulp_ctx: PulpContext = ctx.find_object(PulpContext) + return PulpRpmRepositoryContext(pulp_ctx, entity={"name": value}) + return value + + @click.group() @click.option( "-t", @@ -44,6 +53,7 @@ def distribution(ctx: click.Context, pulp_ctx: PulpContext, distribution_type: s click.option("--name", required=True), click.option("--base-path", required=True), click.option("--publication"), + click.option("--repository", callback=_repository_callback), ] update_options = [ click.option("--base-path"), diff --git a/pulpcore/cli/rpm/repository.py b/pulpcore/cli/rpm/repository.py index 813131d9c..a97d50f16 100644 --- a/pulpcore/cli/rpm/repository.py +++ b/pulpcore/cli/rpm/repository.py @@ -22,6 +22,7 @@ update_command, version_command, ) +from pulpcore.cli.rpm.common import CHECKSUM_CHOICES from pulpcore.cli.rpm.context import PulpRpmRemoteContext, PulpRpmRepositoryContext _ = gettext.gettext @@ -55,16 +56,19 @@ def repository(ctx: click.Context, pulp_ctx: PulpContext, repo_type: str) -> Non lookup_options = [href_option, name_option] -create_options = [ - click.option("--name", required=True), - click.option("--description"), - click.option("--retain-package-versions", type=int), - click.option("--remote", callback=_remote_callback), -] update_options = [ click.option("--description"), click.option("--retain-package-versions", type=int), click.option("--remote", callback=_remote_callback), + click.option("--metadata-checksum-type", type=click.Choice(CHECKSUM_CHOICES, case_sensitive=False)), + click.option("--package-checksum-type", type=click.Choice(CHECKSUM_CHOICES, case_sensitive=False)), + click.option("--gpgcheck", type=click.Choice((0, 1))), + click.option("--repo-gpgcheck", type=click.Choice((0, 1))), + click.option("--sqlite-metadata/--no-sqlite-metadata", default=None), + click.option("--autopublish/--no-autopublish", default=None), +] +create_options = update_options + [ + click.option("--name", required=True) ] repository.add_command(list_command(decorators=[label_select_option])) diff --git a/tests/scripts/pulp_file/test_distribution.sh b/tests/scripts/pulp_file/test_distribution.sh index 3b1edc8e3..c2ffeaba9 100755 --- a/tests/scripts/pulp_file/test_distribution.sh +++ b/tests/scripts/pulp_file/test_distribution.sh @@ -37,6 +37,12 @@ expect_succ pulp file distribution update \ --base-path "cli_test_file_distro" \ --publication "$PUBLICATION_HREF" +if [ "$(pulp debug has-plugin --name "file" --min-version "1.7.0.dev")" = "true" ] +then + expect_succ pulp file distribution update \ + --name "cli_test_file_distro" \ + --repository "cli_test_file_repository" +fi expect_succ pulp file distribution list --base-path "cli_test_file_distro" test "$(echo "$OUTPUT" | jq -r length)" -eq 1 diff --git a/tests/scripts/pulp_file/test_repository.sh b/tests/scripts/pulp_file/test_repository.sh index 954a99deb..69a08495e 100755 --- a/tests/scripts/pulp_file/test_repository.sh +++ b/tests/scripts/pulp_file/test_repository.sh @@ -19,6 +19,10 @@ expect_succ pulp file repository list expect_succ pulp file repository create --name "cli_test_file_repo" --description "Test repository for CLI tests" expect_succ pulp file repository update --name "cli_test_file_repo" --description "" --remote "cli_test_file_remote1" +if [ "$(pulp debug has-plugin --name "file" --min-version "1.7.0.dev")" = "true" ] +then + expect_succ pulp file repository update --name "cli_test_file_repo" --manifest "manifest.csv" +fi expect_succ pulp file repository show --name "cli_test_file_repo" expect_succ test "$(echo "$OUTPUT" | jq -r '.remote')" = "$REMOTE1_HREF" expect_succ pulp file repository update --name "cli_test_file_repo" --remote "cli_test_file_remote2" diff --git a/tests/scripts/pulp_file/test_sync.sh b/tests/scripts/pulp_file/test_sync.sh index fa0eeda97..1d2f09e83 100755 --- a/tests/scripts/pulp_file/test_sync.sh +++ b/tests/scripts/pulp_file/test_sync.sh @@ -5,9 +5,12 @@ pulp debug has-plugin --name "file" || exit 3 +autopublish_repo="cli_test_file_repository_autopublish" + cleanup() { pulp file remote destroy --name "cli_test_file_remote" || true pulp file repository destroy --name "cli_test_file_repository" || true + pulp file repository destroy --name "$autopublish_repo" || true } trap cleanup EXIT @@ -42,3 +45,13 @@ test "$(echo "$OUTPUT" | jq -r '.state')" = "completed" # Delete version again expect_succ pulp file repository version destroy --repository "cli_test_file_repository" --version 1 + +# Test autopublish +if [ "$(pulp debug has-plugin --name "file" --min-version "1.7.0.dev")" = "true" ] +then + expect_succ pulp file repository create --name "$autopublish_repo" --remote "cli_test_file_remote" --autopublish + expect_succ pulp file repository sync --name "$autopublish_repo" + task=$(echo "$ERROUTPUT" | grep -E -o "/pulp/api/v3/tasks/[-[:xdigit:]]*/") + created_resources=$(pulp show --href "$task" | jq -r ".created_resources") + echo "$created_resources" | grep -q '/pulp/api/v3/publications/file/file/' +fi diff --git a/tests/scripts/pulp_rpm/test_rpm_sync_publish.sh b/tests/scripts/pulp_rpm/test_rpm_sync_publish.sh index 7915814dc..23b116304 100755 --- a/tests/scripts/pulp_rpm/test_rpm_sync_publish.sh +++ b/tests/scripts/pulp_rpm/test_rpm_sync_publish.sh @@ -49,3 +49,16 @@ expect_succ pulp rpm publication destroy --href "$PUBLICATION_HREF" expect_succ pulp rpm publication destroy --href "$PUBLICATION_VER_HREF" expect_succ pulp rpm repository destroy --name "cli_test_rpm_repository" expect_succ pulp rpm remote destroy --name "cli_test_rpm_remote" + +# auto-publish +expect_succ pulp rpm remote create --name "cli_test_rpm_remote" --url "$RPM_REMOTE_URL" +expect_succ pulp rpm repository create --name "cli_test_rpm_repository" --remote "cli_test_rpm_remote" --autopublish + +expect_succ pulp rpm distribution create --name "cli_test_rpm_distro" \ + --base-path "cli_test_rpm_distro" \ + --repository "cli_test_rpm_repository" + +expect_succ pulp rpm repository sync --name "cli_test_rpm_repository" + +expect_succ pulp rpm distribution show --name "cli_test_rpm_distro" +echo $OUTPUT | jq -r ".publication" | grep -q '/pulp/api/v3/publications/rpm/rpm/'