Skip to content

Commit

Permalink
Added --optimize and --sync-policy options to rpm repo sync.
Browse files Browse the repository at this point in the history
fixes pulp#462.

Co-authored by: Grant Gainey <ggainey@redhat.com>
  • Loading branch information
Aran Cox authored and ggainey committed Aug 3, 2022
1 parent 3bd71ab commit 99ee12d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGES/462.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added --optimize and --sync_options to the "rpm repository sync" subcommand.
42 changes: 40 additions & 2 deletions pulpcore/cli/rpm/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@


SKIP_TYPES = ["srpm"]
SYNC_TYPES = ["additive", "mirror_complete", "mirror_content_only"]
remote_option = resource_option(
"--remote",
default_plugin="rpm",
Expand Down Expand Up @@ -165,16 +166,49 @@ def repository(ctx: click.Context, pulp_ctx: PulpContext, repo_type: str) -> Non
@name_option
@href_option
@remote_option
@click.option("--mirror/--no-mirror", default=None)
@click.option(
"--skip-type", "skip_types", multiple=True, type=click.Choice(SKIP_TYPES, case_sensitive=False)
"--mirror/--no-mirror",
default=None,
help="""
DEPRECATED: If True, sync_policy will default to 'mirror_complete' instead
of 'additive'.
""",
)
@pulp_option(
"--optimize/--no-optimize",
default=None,
help="Whether or not to optimize sync.",
needs_plugins=[PluginRequirement("rpm", "3.3.0")],
)
@click.option(
"--skip-type",
"skip_types",
multiple=True,
type=click.Choice(SKIP_TYPES, case_sensitive=False),
help="List of content types to skip during sync.",
)
@pulp_option(
"--sync-policy",
"sync_policy",
type=click.Choice(SYNC_TYPES, case_sensitive=False),
help="""
Modifies how the sync is performed. 'mirror_complete' will clone the original metadata
and create an automatic publication from it, but comes with some limitations and does
not work for certain repositories. 'mirror_content_only' will change the repository
contents to match the remote but the metadata will be regenerated and will not be
bit-for-bit identical. 'additive' will retain the existing contents of the repository
and add the contents of the repository being synced.
""",
needs_plugins=[PluginRequirement("rpm", "3.16.0")],
)
@pass_repository_context
def sync(
repository_ctx: PulpRepositoryContext,
remote: EntityFieldDefinition,
mirror: Optional[bool],
optimize: Optional[bool],
skip_types: Iterable[str],
sync_policy: Optional[str],
) -> None:
repository = repository_ctx.entity
repository_href = repository_ctx.pulp_href
Expand All @@ -183,8 +217,12 @@ def sync(

if mirror:
body["mirror"] = mirror
if optimize:
body["optimize"] = optimize
if skip_types:
body["skip_types"] = skip_types
if sync_policy:
body["sync_policy"] = sync_policy

if isinstance(remote, PulpEntityContext):
body["remote"] = remote.pulp_href
Expand Down
27 changes: 21 additions & 6 deletions tests/scripts/pulp_rpm/test_rpm_sync_publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ expect_succ pulp rpm repository show --name "cli_test_rpm_repository"
test "$(echo "$OUTPUT" | jq -r '.description')" = "null"

# skip-types is broken in 3.12.0
if pulp debug has-plugin --name "rpm" --min-version "3.12.0" --max-version "3.12.1"
then
expect_succ pulp rpm repository sync --name "cli_test_rpm_repository"
else
expect_succ pulp rpm repository sync --name "cli_test_rpm_repository" --skip-type srpm
fi
#if pulp debug has-plugin --name "rpm" --min-version "3.12.0" --max-version "3.12.1"
#then
# expect_succ pulp rpm repository sync --name "cli_test_rpm_repository"
#else
# expect_succ pulp rpm repository sync --name "cli_test_rpm_repository" --skip-type srpm
#fi
expect_succ pulp rpm repository sync --name "cli_test_rpm_repository"

expect_succ pulp rpm publication create --repository "cli_test_rpm_repository"
PUBLICATION_HREF=$(echo "$OUTPUT" | jq -r .pulp_href)
Expand All @@ -52,6 +53,20 @@ expect_succ pulp rpm repository update --name "cli_test_rpm_repository" --retain
expect_succ pulp rpm repository show --name "cli_test_rpm_repository"
test "$(echo "$OUTPUT" | jq -r '.retain_package_versions')" = "2"

if pulp debug has-plugin --name "rpm" --min-version "3.3.0"
then
expect_succ pulp rpm repository sync --name "cli_test_rpm_repository" --optimize
expect_succ pulp rpm repository sync --name "cli_test_rpm_repository" --no-optimize
fi

if pulp debug has-plugin --name "rpm" --min-version "3.16.0"
then
expect_succ pulp rpm repository sync --name "cli_test_rpm_repository" --sync-policy additive
expect_succ pulp rpm repository sync --name "cli_test_rpm_repository" --sync-policy mirror_complete
expect_succ pulp rpm repository sync --name "cli_test_rpm_repository" --sync-policy mirror_content_only
expect_fail pulp rpm repository sync --name "cli_test_rpm_repository" --sync-policy foobar
fi

expect_succ pulp rpm distribution destroy --name "cli_test_rpm_distro"
expect_succ pulp rpm publication destroy --href "$PUBLICATION_HREF"
expect_succ pulp rpm publication destroy --href "$PUBLICATION_VER_HREF"
Expand Down

0 comments on commit 99ee12d

Please sign in to comment.