From 21dbead3290469201270c40aa6dd5e04f3b31dfd Mon Sep 17 00:00:00 2001 From: Manisha Singhal Date: Fri, 11 Mar 2022 09:15:17 +0100 Subject: [PATCH] Add Support for ULN Remote fixes #470 --- CHANGES/470.feature | 1 + pulpcore/cli/rpm/acs.py | 4 +-- pulpcore/cli/rpm/context.py | 8 ++++++ pulpcore/cli/rpm/remote.py | 34 ++++++++++++++++++++--- pulpcore/cli/rpm/repository.py | 3 +- tests/conftest.py | 1 + tests/scripts/pulp_rpm/test_uln_remote.sh | 24 ++++++++++++++++ 7 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 CHANGES/470.feature create mode 100755 tests/scripts/pulp_rpm/test_uln_remote.sh diff --git a/CHANGES/470.feature b/CHANGES/470.feature new file mode 100644 index 000000000..bf7a940ed --- /dev/null +++ b/CHANGES/470.feature @@ -0,0 +1 @@ +Added support for ULN remotes. diff --git a/pulpcore/cli/rpm/acs.py b/pulpcore/cli/rpm/acs.py index 565b32359..9ca6730ee 100644 --- a/pulpcore/cli/rpm/acs.py +++ b/pulpcore/cli/rpm/acs.py @@ -20,7 +20,7 @@ update_command, ) from pulpcore.cli.common.i18n import get_translation -from pulpcore.cli.rpm.context import PulpRpmACSContext, PulpRpmRemoteContext +from pulpcore.cli.rpm.context import PulpRpmACSContext, PulpRpmRemoteContext, PulpUlnRemoteContext translation = get_translation(__name__) _ = translation.gettext @@ -98,7 +98,7 @@ def remove(acs_ctx: PulpRpmACSContext, paths: Iterable[str]) -> None: "--remote", default_plugin="rpm", default_type="rpm", - context_table={"rpm:rpm": PulpRpmRemoteContext}, + context_table={"rpm:rpm": PulpRpmRemoteContext, "rpm:uln": PulpUlnRemoteContext}, href_pattern=PulpRemoteContext.HREF_PATTERN, help=_("Remote to attach to ACS in the form '[[:]:]' or by href."), ) diff --git a/pulpcore/cli/rpm/context.py b/pulpcore/cli/rpm/context.py index cc4f8809a..31515363c 100644 --- a/pulpcore/cli/rpm/context.py +++ b/pulpcore/cli/rpm/context.py @@ -103,6 +103,14 @@ class PulpRpmRemoteContext(PulpRemoteContext): } +class PulpUlnRemoteContext(PulpRemoteContext): + ENTITY = _("uln remote") + ENTITIES = _("uln remotes") + HREF = "rpm_uln_remote_href" + ID_PREFIX = "remotes_rpm_uln" + NULLABLES = PulpRemoteContext.NULLABLES | {"uln-server-base-url"} + + class PulpRpmRepositoryVersionContext(PulpRepositoryVersionContext): HREF = "rpm_rpm_repository_version_href" ID_PREFIX = "repositories_rpm_rpm_versions" diff --git a/pulpcore/cli/rpm/remote.py b/pulpcore/cli/rpm/remote.py index f7839f5cb..66007f9b8 100644 --- a/pulpcore/cli/rpm/remote.py +++ b/pulpcore/cli/rpm/remote.py @@ -1,6 +1,6 @@ import click -from pulpcore.cli.common.context import PulpContext, pass_pulp_context +from pulpcore.cli.common.context import PluginRequirement, PulpContext, pass_pulp_context from pulpcore.cli.common.generic import ( common_remote_create_options, common_remote_update_options, @@ -11,22 +11,29 @@ label_select_option, list_command, name_option, + pulp_option, show_command, update_command, ) from pulpcore.cli.common.i18n import get_translation -from pulpcore.cli.rpm.context import PulpRpmRemoteContext +from pulpcore.cli.rpm.context import PulpRpmRemoteContext, PulpUlnRemoteContext translation = get_translation(__name__) _ = translation.gettext +def _url_callback(ctx: click.Context, param: click.Parameter, value: str) -> str: + if not value.startswith('uln://'): + raise click.ClickException("Invalid url format. Please enter correct uln channel.") + + return value + @click.group() @click.option( "-t", "--type", "remote_type", - type=click.Choice(["rpm"], case_sensitive=False), + type=click.Choice(["rpm", "uln"], case_sensitive=False), default="rpm", ) @pass_pulp_context @@ -34,6 +41,9 @@ def remote(ctx: click.Context, pulp_ctx: PulpContext, remote_type: str) -> None: if remote_type == "rpm": ctx.obj = PulpRpmRemoteContext(pulp_ctx) + elif remote_type == "uln": + pulp_ctx.needs_plugin(PluginRequirement("rpm", "3.12.0")) + ctx.obj = PulpUlnRemoteContext(pulp_ctx) else: raise NotImplementedError() @@ -43,7 +53,23 @@ def remote(ctx: click.Context, pulp_ctx: PulpContext, remote_type: str) -> None: click.option( "--policy", type=click.Choice(["immediate", "on_demand", "streamed"], case_sensitive=False) ), - click.option("--sles-auth-token"), + pulp_option( + "--sles-auth-token", + allowed_with_contexts=(PulpRpmRemoteContext,), + ), + pulp_option( + "--uln-server-base-url", + default="https://linux-update.oracle.com/", + help=_("ULN Server base URL, default is 'https://linux-update.oracle.com/'"), + allowed_with_contexts=(PulpUlnRemoteContext,), + ), + pulp_option( + "--url", + help=_("Use the ULN channel name starting with uln:// here."), + required=True, + callback=_url_callback, + allowed_with_contexts=(PulpUlnRemoteContext,), + ), ] remote.add_command(list_command(decorators=[label_select_option])) diff --git a/pulpcore/cli/rpm/repository.py b/pulpcore/cli/rpm/repository.py index 5221eb27f..999dd2340 100644 --- a/pulpcore/cli/rpm/repository.py +++ b/pulpcore/cli/rpm/repository.py @@ -39,6 +39,7 @@ PulpRpmPackageContext, PulpRpmRemoteContext, PulpRpmRepositoryContext, + PulpUlnRemoteContext, ) translation = get_translation(__name__) @@ -50,7 +51,7 @@ "--remote", default_plugin="rpm", default_type="rpm", - context_table={"rpm:rpm": PulpRpmRemoteContext}, + context_table={"rpm:rpm": PulpRpmRemoteContext, "rpm:uln": PulpUlnRemoteContext}, href_pattern=PulpRemoteContext.HREF_PATTERN, help=_( "Remote used for synching in the form '[[:]:]' or by href." diff --git a/tests/conftest.py b/tests/conftest.py index 8f951a5c2..09539c6f6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -20,6 +20,7 @@ def pulp_cli_vars(pulp_cli_vars): "ANSIBLE_COLLECTION_REMOTE_URL": "https://galaxy.ansible.com/", "ANSIBLE_ROLE_REMOTE_URL": "https://galaxy.ansible.com/api/v1/roles/?namespace__name=elastic", # noqa "PYTHON_REMOTE_URL": PULP_FIXTURES_URL + "/python-pypi/", + "ULN_REMOTE_URL": "uln://ovm2_2.1.1_i386_patch", } ) return result diff --git a/tests/scripts/pulp_rpm/test_uln_remote.sh b/tests/scripts/pulp_rpm/test_uln_remote.sh new file mode 100755 index 000000000..1af56ca0e --- /dev/null +++ b/tests/scripts/pulp_rpm/test_uln_remote.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# shellcheck source=tests/scripts/config.source +. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source + +pulp debug has-plugin --name "rpm" --min-version "3.12.0" || exit 3 + +# Set USERNAME, USERPASS, and ULN_REMOTE_URL for tests to work. + +USERNAME="user" +USERPASS="changeme" + +cleanup() { + pulp rpm remote --type uln destroy --name "cli_test_uln_remote" || true +} +trap cleanup EXIT + +expect_succ pulp rpm remote --type uln list + +expect_succ pulp rpm remote --type uln create --name "cli_test_uln_remote" --url "$ULN_REMOTE_URL" --username "$USERNAME" --password "$USERPASS" +expect_succ pulp rpm remote --type uln show --name "cli_test_uln_remote" +expect_succ pulp rpm remote --type uln list +expect_succ pulp rpm remote --type uln update --name "cli_test_uln_remote" --uln-server-base-url "https://linux.com/" +expect_succ pulp rpm remote --type uln destroy --name "cli_test_uln_remote"