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 support for autopublish and autodistribute #199

Merged
merged 1 commit into from
Apr 13, 2021
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/155.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for autopublish and autodistribute in pulp_file and pulp_rpm.
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),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

]
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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the default should simply be --no-autopublish.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an update_option. So if not specified, we should def not set (and then update) this option to False.
I think having None here, keeps it from being touched on update calls, and on create calls i'd rather let the server decide on the default.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I believe I misunderstood what it does then

Copy link
Contributor Author

@daviddavis daviddavis Apr 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it should default to --no-autopublish. The dilemma is that this will cause autopublish to always be set in the requests which won't work for older versions of pulp_file/pulp_rpm and we support 5 versions back.

I could either:

  1. Check the version of pulp_file and if it's less than 1.7.0, silently strip out the autopublish key/value from the request.
  2. Keep the default as None which won't set autopublish in requests unless the user explicitly sets --autopublish or --no-autopublish. I could add a comment for us to change the default once we drop support for <1.7.0.

Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welp, ignore my comment. I am too slow.

]
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")
16 changes: 14 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,21 @@
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 +55,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
18 changes: 12 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,17 +56,22 @@ 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),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

click.option("--autopublish/--no-autopublish", default=None),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of completes the repository options, not necessarily related to auto publish.
Do we want to reflect that in the changelog?

]
create_options = update_options + [click.option("--name", required=True)]

repository.add_command(list_command(decorators=[label_select_option]))
repository.add_command(show_command(decorators=lookup_options))
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
5 changes: 5 additions & 0 deletions tests/scripts/pulp_file/test_repository.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ test "$(echo "$OUTPUT" | jq -r '.|length')" != "0"
expect_succ pulp file repository task list --repository "cli_test_file_repo"
test "$(echo "$OUTPUT" | jq -r '.|length')" = "3"

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

if pulp debug has-plugin --name "core" --min-version "3.10.dev"
then
expect_succ pulp repository list
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
16 changes: 16 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,19 @@ 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
if [ "$(pulp debug has-plugin --name "rpm" --min-version "3.11.0.dev")" = "true" ]
then
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/'
fi