Skip to content

Commit

Permalink
Add Support for ULN Remote
Browse files Browse the repository at this point in the history
fixes pulp#470
  • Loading branch information
Manisha15 committed Mar 24, 2022
1 parent 750376b commit 21dbead
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGES/470.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for ULN remotes.
4 changes: 2 additions & 2 deletions pulpcore/cli/rpm/acs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 '[[<plugin>:]<resource_type>:]<name>' or by href."),
)
Expand Down
8 changes: 8 additions & 0 deletions pulpcore/cli/rpm/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
34 changes: 30 additions & 4 deletions pulpcore/cli/rpm/remote.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -11,29 +11,39 @@
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
@click.pass_context
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()

Expand All @@ -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]))
Expand Down
3 changes: 2 additions & 1 deletion pulpcore/cli/rpm/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
PulpRpmPackageContext,
PulpRpmRemoteContext,
PulpRpmRepositoryContext,
PulpUlnRemoteContext,
)

translation = get_translation(__name__)
Expand All @@ -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 '[[<plugin>:]<resource_type>:]<name>' or by href."
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 24 additions & 0 deletions tests/scripts/pulp_rpm/test_uln_remote.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 21dbead

Please sign in to comment.