-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for new pulp_rpm "prune-packages" feature.
closes #979.
- Loading branch information
Showing
5 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Added the "pulp rpm prune-packages" command to support new RPM feature. | ||
|
||
See [2909](https://github.com/pulp/pulp_rpm/issues/2909) for details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import gettext | ||
import typing as t | ||
|
||
import click | ||
from pulp_glue.common.context import PulpException | ||
from pulp_glue.rpm.context import PulpRpmPruneContext, PulpRpmRepositoryContext | ||
|
||
from pulpcore.cli.common.generic import ( | ||
PulpCLIContext, | ||
pass_pulp_context, | ||
pulp_command, | ||
resource_option, | ||
) | ||
|
||
_ = gettext.gettext | ||
|
||
multi_repository_option = resource_option( | ||
"--repository", | ||
"repositories", | ||
default_plugin="rpm", | ||
default_type="rpm", | ||
context_table={"rpm:rpm": PulpRpmRepositoryContext}, | ||
multiple=True, | ||
href_pattern=PulpRpmRepositoryContext.HREF_PATTERN, | ||
help=_( | ||
"RPM Repository to prune, in the form 'rpm:rpm:<name>' or by href." | ||
" Can be called multiple times." | ||
), | ||
) | ||
|
||
|
||
@pulp_command() | ||
@multi_repository_option | ||
@click.option( | ||
"--all-repositories", | ||
type=bool, | ||
is_flag=True, | ||
show_default=True, | ||
default=False, | ||
help=_("Prune *all* repositories accessible to the invoking user."), | ||
) | ||
@click.option( | ||
"--keep-days", | ||
type=int, | ||
default=14, | ||
help=_("Prune packages that were added to the specified repositories more than N days ago."), | ||
) | ||
@click.option( | ||
"--dry-run", | ||
type=bool, | ||
is_flag=True, | ||
show_default=True, | ||
default=False, | ||
help=_("Evaluate the prune-status of the specified repositories but DO NOT make any changes."), | ||
) | ||
@pass_pulp_context | ||
def prune_packages( | ||
pulp_ctx: PulpCLIContext, | ||
repositories: t.Iterable[PulpRpmRepositoryContext], | ||
all_repositories: t.Optional[bool], | ||
keep_days: t.Optional[int], | ||
dry_run: t.Optional[bool], | ||
) -> None: | ||
""" | ||
Prune older Packages from the current-version of a repository/repositories. | ||
Repositories can be specified by repeated --repository arguments. | ||
"All" repositories can be specified by --all-repositories. | ||
At least one repository, or --all-repositories, must be specified. | ||
You may not specify --all-repositories *and* one or more specific repositories. | ||
""" | ||
prune_ctx = PulpRpmPruneContext(pulp_ctx) | ||
if not (all_repositories or repositories): | ||
raise PulpException( | ||
_("at least one --repository, or --all-repositories, must be specified") | ||
) | ||
elif all_repositories and repositories: | ||
raise PulpException( | ||
_("cannot specify --all-repositories and --repository at the same time") | ||
) | ||
|
||
repos_list: t.List[t.Union[str, PulpRpmRepositoryContext]] = ( | ||
["*"] if all_repositories else list(repositories) | ||
) | ||
|
||
result = prune_ctx.prune_packages(repos_list, keep_days, dry_run) | ||
pulp_ctx.output_result(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash | ||
|
||
# shellcheck source=tests/scripts/config.source | ||
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source | ||
|
||
pulp debug has-plugin --name "rpm" --specifier ">=3.27.0.dev" || exit 23 | ||
|
||
cleanup() { | ||
pulp rpm repository destroy --name "cli_test_rpm_prune" || true | ||
pulp rpm repository destroy --name "cli_test_rpm_prune_2" || true | ||
pulp rpm remote destroy --name "cli_test_rpm_prune" || true | ||
} | ||
trap cleanup EXIT | ||
|
||
expect_succ pulp rpm remote create --name "cli_test_rpm_prune" --url "$RPM_REMOTE_URL" --policy on_demand | ||
expect_succ pulp rpm repository create --name "cli_test_rpm_prune" --remote "cli_test_rpm_prune" --no-autopublish | ||
repo_href="$(echo "$OUTPUT" | jq -r '.pulp_href')" | ||
expect_succ pulp rpm repository create --name "cli_test_rpm_prune_2" --remote "cli_test_rpm_prune" --no-autopublish | ||
repo_href_2="$(echo "$OUTPUT" | jq -r '.pulp_href')" | ||
expect_succ pulp rpm repository sync --repository "cli_test_rpm_prune" | ||
expect_succ pulp rpm repository sync --repository "cli_test_rpm_prune_2" | ||
|
||
expect_fail pulp rpm prune-packages | ||
expect_fail pulp rpm prune-packages --repository "rpm:rpm:cli_test_rpm_prune" --all-repositories | ||
expect_fail pulp rpm prune-packages --repository "rpm:rpm:cli_test_rpm_prune" --keep-days foo | ||
expect_fail pulp rpm prune-packages --repository "rpm:rpm:cli_test_rpm_prune" --concurrency bar | ||
|
||
expect_succ pulp rpm prune-packages --repository "rpm:rpm:cli_test_rpm_prune" --keep-days 0 --dry-run | ||
expect_succ pulp rpm prune-packages --repository "${repo_href}" --keep-days 0 --dry-run | ||
expect_succ pulp rpm prune-packages --repository "${repo_href}" --repository "${repo_href_2}" --dry-run | ||
expect_succ pulp rpm prune-packages --repository "rpm:rpm:cli_test_rpm_prune" --repository "rpm:rpm:cli_test_rpm_prune_2" --dry-run | ||
expect_succ pulp rpm prune-packages --repository "rpm:rpm:cli_test_rpm_prune" --repository "${repo_href}" --repository "${repo_href_2}" --dry-run | ||
expect_succ pulp rpm prune-packages --all-repositories --dry-run | ||
expect_succ pulp rpm prune-packages --repository "rpm:rpm:cli_test_rpm_prune" --keep-days 0 | ||
|
||
|
||
|