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 Apr 5, 2022
1 parent 750376b commit 4fb0fe6
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 11 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
106 changes: 98 additions & 8 deletions pulpcore/cli/rpm/remote.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,50 @@
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,
create_command,
destroy_command,
href_option,
label_command,
label_select_option,
list_command,
load_file_or_string_callback,
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 _uln_url_callback(ctx: click.Context, param: click.Parameter, value: str) -> str:
if type(ctx.obj) == PulpUlnRemoteContext and 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,14 +54,93 @@ 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,),
),
click.option(
"--url",
help=_(
"For remote_type:uln, Use the ULN channel name starting with uln://. For remote_type:rpm, use url with http/https."
),
required=True,
callback=_uln_url_callback,
),
]

remote_create_options = [
click.option("--name", required=True),
click.option(
"--ca-cert",
help=_("a PEM encoded CA certificate or @file containing same"),
callback=load_file_or_string_callback,
),
click.option(
"--client-cert",
help=_("a PEM encoded client certificate or @file containing same"),
callback=load_file_or_string_callback,
),
click.option(
"--client-key",
help=_("a PEM encode private key or @file containing same"),
callback=load_file_or_string_callback,
),
click.option("--connect-timeout", type=float),
click.option(
"--download-concurrency", type=int, help=_("total number of simultaneous connections")
),
click.option("--password"),
click.option("--proxy-url"),
click.option("--proxy-username"),
click.option("--proxy-password"),
click.option("--rate-limit", type=int, help=_("limit download rate in requests per second")),
click.option("--sock-connect-timeout", type=float),
click.option("--sock-read-timeout", type=float),
click.option("--tls-validation", type=bool),
click.option("--total-timeout", type=float),
click.option("--username"),
]

remote_update_options = [
click.option(
"--ca-cert",
help=_("a PEM encoded CA certificate or @file containing same"),
callback=load_file_or_string_callback,
),
click.option(
"--client-cert",
help=_("a PEM encoded client certificate or @file containing same"),
callback=load_file_or_string_callback,
),
click.option(
"--client-key",
help=_("a PEM encode private key or @file containing same"),
callback=load_file_or_string_callback,
),
click.option("--connect-timeout", type=float),
click.option(
"--download-concurrency", type=int, help=_("total number of simultaneous connections")
),
click.option("--password"),
click.option("--proxy-url"),
click.option("--proxy-username"),
click.option("--proxy-password"),
click.option("--rate-limit", type=int, help=_("limit download rate in requests per second")),
click.option("--sock-connect-timeout", type=float),
click.option("--sock-read-timeout", type=float),
click.option("--tls-validation", type=bool),
click.option("--total-timeout", type=float),
click.option("--username"),
]

remote.add_command(list_command(decorators=[label_select_option]))
remote.add_command(show_command(decorators=lookup_options))
remote.add_command(create_command(decorators=common_remote_create_options + rpm_remote_options))
remote.add_command(create_command(decorators=remote_create_options + rpm_remote_options))
remote.add_command(
update_command(decorators=lookup_options + common_remote_update_options + rpm_remote_options)
update_command(decorators=lookup_options + remote_update_options + rpm_remote_options)
)
remote.add_command(destroy_command(decorators=lookup_options))
remote.add_command(label_command())
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 4fb0fe6

Please sign in to comment.