Skip to content

Commit

Permalink
Add support for autopublish and autodistribute
Browse files Browse the repository at this point in the history
fixes pulp#155
  • Loading branch information
David Davis committed Apr 12, 2021
1 parent 1fcecc1 commit b346bf2
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 20 deletions.
1 change: 1 addition & 0 deletions CHANGES/155.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for autopublish and autodistribute.
24 changes: 17 additions & 7 deletions pulpcore/cli/file/distribution.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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",
Expand All @@ -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))
Expand Down
10 changes: 5 additions & 5 deletions pulpcore/cli/file/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down
1 change: 1 addition & 0 deletions pulpcore/cli/rpm/common.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CHECKSUM_CHOICES = ("unknown", "md5", "sha1", "sha224", "sha256", "sha384", "sha512")
14 changes: 12 additions & 2 deletions pulpcore/cli/rpm/distribution.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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",
Expand All @@ -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"),
Expand Down
16 changes: 10 additions & 6 deletions pulpcore/cli/rpm/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]))
Expand Down
6 changes: 6 additions & 0 deletions tests/scripts/pulp_file/test_distribution.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/scripts/pulp_file/test_repository.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 13 additions & 0 deletions tests/scripts/pulp_file/test_sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
13 changes: 13 additions & 0 deletions tests/scripts/pulp_rpm/test_rpm_sync_publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/'

0 comments on commit b346bf2

Please sign in to comment.