diff --git a/CHANGES/462.feature b/CHANGES/462.feature new file mode 100644 index 000000000..91c81bd6b --- /dev/null +++ b/CHANGES/462.feature @@ -0,0 +1 @@ +Added --optimize and --sync_options to the "rpm repository sync" subcommand. diff --git a/pulpcore/cli/rpm/repository.py b/pulpcore/cli/rpm/repository.py index fd060de9b..0164e130c 100644 --- a/pulpcore/cli/rpm/repository.py +++ b/pulpcore/cli/rpm/repository.py @@ -48,6 +48,7 @@ SKIP_TYPES = ["srpm"] +SYNC_TYPES = ["additive", "mirror_complete", "mirror_content_only"] remote_option = resource_option( "--remote", default_plugin="rpm", @@ -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 @@ -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 diff --git a/tests/scripts/pulp_rpm/test_rpm_sync_publish.sh b/tests/scripts/pulp_rpm/test_rpm_sync_publish.sh index 21b7a0ee5..c33a7754d 100755 --- a/tests/scripts/pulp_rpm/test_rpm_sync_publish.sh +++ b/tests/scripts/pulp_rpm/test_rpm_sync_publish.sh @@ -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) @@ -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"