Skip to content

Commit

Permalink
Adds fallback names for plugin checking
Browse files Browse the repository at this point in the history
In pulpcore 3.11, the plugin names changed to fix a bug. This switches
the names of existing plugins to use the new names. It also adds
fallback support to allow pulpcore<3.11 names to continue working.

Fixes pulp#153
  • Loading branch information
bmbouter committed Feb 22, 2021
1 parent a72e518 commit da865ae
Show file tree
Hide file tree
Showing 31 changed files with 63 additions and 43 deletions.
1 change: 1 addition & 0 deletions CHANGES/153.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adds `pulpcore<3.11` plugin name fallback support.
2 changes: 1 addition & 1 deletion pulpcore/cli/ansible/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@main.group()
@pass_pulp_context
def ansible(pulp_ctx: PulpContext) -> None:
pulp_ctx.needs_plugin("pulp_ansible")
pulp_ctx.needs_plugin("ansible")


ansible.add_command(repository)
Expand Down
21 changes: 20 additions & 1 deletion pulpcore/cli/common/context.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections import defaultdict
import datetime
import gettext
import json
Expand Down Expand Up @@ -160,6 +161,20 @@ def wait_for_task(self, task: EntityDefinition, timeout: int = 120) -> Any:
except KeyboardInterrupt:
raise PulpNoWait(f"Task {task_href} sent to background.")

def _get_plugin_name_prior_to_3_11(self, name: str) -> str:
"""The status API names changed in 3.11. Remove me in pulpcore==3.16"""
new_to_old_names_map = defaultdict(lambda: None)
new_to_old_names_map.update(
dict(
ansible="pulp_ansible",
container="pulp_container",
core="pulpcore",
file="pulp_file",
rpm="pulp_rpm",
)
)
return new_to_old_names_map[name]

def has_plugin(
self, name: str, min_version: Optional[str] = None, max_version: Optional[str] = None
) -> bool:
Expand All @@ -169,7 +184,11 @@ def has_plugin(
return (min_version is None) and (max_version is None)
version: Optional[str] = self.component_versions.get(name)
if version is None:
return False
pre_3_11_version: Optional[str] = self._get_plugin_name_prior_to_3_11(name)
if pre_3_11_version is None:
return False
else:
version = pre_3_11_version
if min_version is not None:
if parse_version(version) < parse_version(min_version):
return False
Expand Down
2 changes: 1 addition & 1 deletion pulpcore/cli/container/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@main.group()
@pass_pulp_context
def container(pulp_ctx: PulpContext) -> None:
pulp_ctx.needs_plugin("pulp_container")
pulp_ctx.needs_plugin("container")


container.add_command(repository)
Expand Down
26 changes: 13 additions & 13 deletions pulpcore/cli/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PulpAccessPolicyContext(PulpEntityContext):
def find(self, **kwargs: Any) -> Any:
"""Workaroud for the missing ability to filter"""
# https://pulp.plan.io/issues/8189
if self.pulp_ctx.has_plugin("pulpcore", min_version="3.10.dev0"):
if self.pulp_ctx.has_plugin("core", min_version="3.10.dev"):
# Workaround not needed anymore
return super().find(**kwargs)
search_result = self.list(limit=sys.maxsize, offset=0, parameters={})
Expand Down Expand Up @@ -106,7 +106,7 @@ class PulpExportContext(PulpEntityContext):
exporter: EntityDefinition

def list(self, limit: int, offset: int, parameters: Dict[str, Any]) -> List[Any]:
if not self.pulp_ctx.has_plugin("pulpcore", min_version="3.10.dev0"):
if not self.pulp_ctx.has_plugin("core", min_version="3.10.dev"):
# Workaround for improperly rendered nested resource paths and weird HREF names
# https://github.com/pulp/pulpcore/pull/1066
parameters[PulpExporterContext.HREF] = self.exporter["pulp_href"]
Expand All @@ -118,7 +118,7 @@ def create(
parameters: Optional[Dict[str, Any]] = None,
non_blocking: bool = False,
) -> Any:
if not self.pulp_ctx.has_plugin("pulpcore", min_version="3.10.dev0"):
if not self.pulp_ctx.has_plugin("core", min_version="3.10.dev"):
# Workaround for improperly rendered nested resource paths and weird HREF names
# https://github.com/pulp/pulpcore/pull/1066
if parameters is None:
Expand All @@ -128,15 +128,15 @@ def create(

@property
def HREF(self) -> str: # type: ignore
if not self.pulp_ctx.has_plugin("pulpcore", min_version="3.10.dev0"):
if not self.pulp_ctx.has_plugin("core", min_version="3.10.dev"):
# Workaround for improperly rendered nested resource paths and weird HREF names
# https://github.com/pulp/pulpcore/pull/1066
return "core_pulp_pulp_export_href"
return "pulp_pulp_export_href"

@property
def scope(self) -> Dict[str, Any]:
if not self.pulp_ctx.has_plugin("pulpcore", min_version="3.10.dev0"):
if not self.pulp_ctx.has_plugin("core", min_version="3.10.dev"):
# Workaround for improperly rendered nested resource paths and weird HREF names
# https://github.com/pulp/pulpcore/pull/1066
return {}
Expand All @@ -154,7 +154,7 @@ class PulpGroupContext(PulpEntityContext):

def find(self, **kwargs: Any) -> Any:
"""Workaroud for the missing ability to filter"""
if self.pulp_ctx.has_plugin("pulpcore", min_version="3.10.dev0"):
if self.pulp_ctx.has_plugin("core", min_version="3.10.dev"):
# Workaround not needed anymore
return super().find(**kwargs)
# See https://pulp.plan.io/issues/7975
Expand All @@ -172,15 +172,15 @@ class PulpGroupPermissionContext(PulpEntityContext):
group_ctx: PulpGroupContext

def __init__(self, pulp_ctx: PulpContext, group_ctx: PulpGroupContext) -> None:
pulp_ctx.needs_plugin("pulpcore", min_version="3.10.dev0")
pulp_ctx.needs_plugin("core", min_version="3.10.dev")
super().__init__(pulp_ctx)
self.group_ctx = group_ctx

def find(self, **kwargs: Any) -> Any:
"""Workaroud for the missing ability to filter"""
# # TODO fix upstream and adjust to guard for the proper version
# # https://pulp.plan.io/issues/8241
# if self.pulp_ctx.has_plugin("pulpcore", min_version="3.99.dev0"):
# if self.pulp_ctx.has_plugin("core", min_version="3.99.dev"):
# # Workaround not needed anymore
# return super().find(**kwargs)
search_result = self.list(limit=sys.maxsize, offset=0, parameters={})
Expand Down Expand Up @@ -229,7 +229,7 @@ def __init__(self, pulp_ctx: PulpContext, group_ctx: PulpGroupContext) -> None:
self.group_ctx = group_ctx

def list(self, limit: int, offset: int, parameters: Dict[str, Any]) -> List[Any]:
if not self.pulp_ctx.has_plugin("pulpcore", min_version="3.10.dev0"):
if not self.pulp_ctx.has_plugin("core", min_version="3.10.dev"):
# Workaround for improperly rendered nested resource paths and weird HREF names
# https://github.com/pulp/pulpcore/pull/1066
parameters[PulpGroupContext.HREF] = self.group_ctx.pulp_href
Expand All @@ -241,7 +241,7 @@ def create(
parameters: Optional[Dict[str, Any]] = None,
non_blocking: bool = False,
) -> Any:
if not self.pulp_ctx.has_plugin("pulpcore", min_version="3.10.dev0"):
if not self.pulp_ctx.has_plugin("core", min_version="3.10.dev"):
# Workaround for improperly rendered nested resource paths and weird HREF names
# https://github.com/pulp/pulpcore/pull/1066
if parameters is None:
Expand All @@ -251,15 +251,15 @@ def create(

@property
def HREF(self) -> str: # type: ignore
if not self.pulp_ctx.has_plugin("pulpcore", min_version="3.10.dev0"):
if not self.pulp_ctx.has_plugin("core", min_version="3.10.dev"):
# Workaround for improperly rendered nested resource paths and weird HREF names
# https://github.com/pulp/pulpcore/pull/1066
return "auth_auth_groups_user_href"
return "auth_groups_user_href"

@property
def scope(self) -> Dict[str, Any]:
if not self.pulp_ctx.has_plugin("pulpcore", min_version="3.10.dev0"):
if not self.pulp_ctx.has_plugin("core", min_version="3.10.dev"):
# Workaround for improperly rendered nested resource paths and weird HREF names
# https://github.com/pulp/pulpcore/pull/1066
return {}
Expand Down Expand Up @@ -317,7 +317,7 @@ class PulpUserContext(PulpEntityContext):

def find(self, **kwargs: Any) -> Any:
"""Workaroud for the missing ability to filter"""
if self.pulp_ctx.has_plugin("pulpcore", min_version="3.10.dev0"):
if self.pulp_ctx.has_plugin("core", min_version="3.10.dev"):
# Workaround not needed anymore
return super().find(**kwargs)
# See https://pulp.plan.io/issues/7975
Expand Down
2 changes: 1 addition & 1 deletion pulpcore/cli/core/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def repository(ctx: click.Context, pulp_ctx: PulpContext) -> None:
Please look for the plugin specific repository commands for more detailed actions.
i.e. 'pulp file repository <...>'
"""
pulp_ctx.needs_plugin("pulpcore", min_version="3.10.dev")
pulp_ctx.needs_plugin("core", min_version="3.10.dev")
ctx.obj = PulpRepositoryContext(pulp_ctx)


Expand Down
2 changes: 1 addition & 1 deletion pulpcore/cli/file/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@main.group(name="file")
@pass_pulp_context
def file_group(pulp_ctx: PulpContext) -> None:
pulp_ctx.needs_plugin("pulp_file")
pulp_ctx.needs_plugin("file")


file_group.add_command(repository)
Expand Down
2 changes: 1 addition & 1 deletion pulpcore/cli/rpm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@main.group()
@pass_pulp_context
def rpm(pulp_ctx: PulpContext) -> None:
pulp_ctx.needs_plugin("pulp_rpm")
pulp_ctx.needs_plugin("rpm")


rpm.add_command(repository)
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/pulp_ansible/test_distribution.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# shellcheck source=tests/scripts/config.source
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source

pulp debug has-plugin --name "pulp_ansible" || exit 3
pulp debug has-plugin --name "ansible" || exit 3

cleanup() {
pulp ansible repository destroy --name "cli_test_ansible_repository" || true
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/pulp_ansible/test_remote.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# shellcheck source=tests/scripts/config.source
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source

pulp debug has-plugin --name "pulp_ansible" || exit 3
pulp debug has-plugin --name "ansible" || exit 3

cleanup() {
pulp ansible remote -t "role" destroy --name "cli_test_ansible_role_remote" || true
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/pulp_ansible/test_repository.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# shellcheck source=tests/scripts/config.source
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source

pulp debug has-plugin --name "pulp_ansible" || exit 3
pulp debug has-plugin --name "ansible" || exit 3

cleanup() {
pulp ansible repository destroy --name "cli_test_ansible_repo" || true
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/pulp_ansible/test_sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# shellcheck source=tests/scripts/config.source
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source

pulp debug has-plugin --name "pulp_ansible" || exit 3
pulp debug has-plugin --name "ansible" || exit 3

cleanup() {
pulp ansible remote -t "role" destroy --name "cli_test_ansible_remote" || true
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/pulp_container/test_distribution.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# shellcheck source=tests/scripts/config.source
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source

pulp debug has-plugin --name "pulp_container" || exit 3
pulp debug has-plugin --name "container" || exit 3

cleanup() {
pulp container repository destroy --name "cli_test_container_repository" || true
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/pulp_container/test_remote.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# shellcheck source=tests/scripts/config.source
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source

pulp debug has-plugin --name "pulp_container" || exit 3
pulp debug has-plugin --name "container" || exit 3

cleanup() {
pulp container remote destroy --name "cli_test_container_remote" || true
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/pulp_container/test_repository.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# shellcheck source=tests/scripts/config.source
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source

pulp debug has-plugin --name "pulp_container" || exit 3
pulp debug has-plugin --name "container" || exit 3

cleanup() {
pulp container repository destroy --name "cli_test_container_repo" || true
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/pulp_container/test_sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# shellcheck source=tests/scripts/config.source
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source

pulp debug has-plugin --name "pulp_container" || exit 3
pulp debug has-plugin --name "container" || exit 3

cleanup() {
pulp container remote destroy --name "cli_test_container_remote" || true
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/pulp_file/test_content.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# shellcheck source=tests/scripts/config.source
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source

pulp debug has-plugin --name "pulp_file" || exit 3
pulp debug has-plugin --name "file" || exit 3

cleanup() {
pulp file repository destroy --name "cli_test_file_repository" || true
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/pulp_file/test_content_bulk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# shellcheck source=tests/scripts/config.source
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source

pulp debug has-plugin --name "pulp_file" || exit 3
pulp debug has-plugin --name "file" || exit 3

cleanup() {
pulp file repository destroy --name "cli_test_file_repository" || true
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/pulp_file/test_distribution.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# shellcheck source=tests/scripts/config.source
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source

pulp debug has-plugin --name "pulp_file" || exit 3
pulp debug has-plugin --name "file" || exit 3

cleanup() {
pulp file remote destroy --name "cli_test_file_remote" || true
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/pulp_file/test_label.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# shellcheck source=tests/scripts/config.source
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source

pulp debug has-plugin --name "pulpcore" --min-version "3.10.0" || exit 3
pulp debug has-plugin --name "core" --min-version "3.10.0" || exit 3

cleanup() {
pulp file repository destroy --name "cli_test_file_repo" || true
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/pulp_file/test_publication.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# shellcheck source=tests/scripts/config.source
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source

pulp debug has-plugin --name "pulp_file" || exit 3
pulp debug has-plugin --name "file" || exit 3

cleanup() {
pulp file remote destroy --name "cli_test_file_remote" || true
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/pulp_file/test_remote.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# shellcheck source=tests/scripts/config.source
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source

pulp debug has-plugin --name "pulp_file" || exit 3
pulp debug has-plugin --name "file" || exit 3

cleanup() {
pulp file remote destroy --name "cli_test_file_remote" || true
Expand Down
4 changes: 2 additions & 2 deletions tests/scripts/pulp_file/test_repository.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# shellcheck source=tests/scripts/config.source
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source

pulp debug has-plugin --name "pulp_file" || exit 3
pulp debug has-plugin --name "file" || exit 3

cleanup() {
pulp file repository destroy --name "cli_test_file_repo" || true
Expand All @@ -30,7 +30,7 @@ expect_succ test "$(echo "$OUTPUT" | jq -r '.description')" = "null"
expect_succ test "$(echo "$OUTPUT" | jq -r '.remote')" = ""
expect_succ pulp file repository list
test "$(echo "$OUTPUT" | jq -r '.|length')" != "0"
if pulp debug has-plugin --name "pulpcore" --min-version "3.10.dev"
if pulp debug has-plugin --name "core" --min-version "3.10.dev"
then
expect_succ pulp repository list
test "$(echo "$OUTPUT" | jq -r '.|length')" != "0"
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/pulp_file/test_sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# shellcheck source=tests/scripts/config.source
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source

pulp debug has-plugin --name "pulp_file" || exit 3
pulp debug has-plugin --name "file" || exit 3

cleanup() {
pulp file remote destroy --name "cli_test_file_remote" || true
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/pulp_rpm/test_rpm_sync_publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# shellcheck source=tests/scripts/config.source
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source

pulp debug has-plugin --name "pulp_rpm" || exit 3
pulp debug has-plugin --name "rpm" || exit 3

cleanup() {
pulp rpm remote destroy --name "cli_test_rpm_remote" || true
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/pulpcore/test_group_permissions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# shellcheck source=tests/scripts/config.source
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source

pulp debug has-plugin --name "pulpcore" --min-version "3.10.dev" || exit 3
pulp debug has-plugin --name "core" --min-version "3.10.dev" || exit 3

cleanup() {
pulp group destroy --name "cli_test_group" || true
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/pulpcore/test_pulpexporter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# shellcheck source=tests/scripts/config.source
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source

pulp debug has-plugin --name "pulp_file" || exit 3
pulp debug has-plugin --name "file" || exit 3

RMOTE="cli_test_file_remote"
REPO1="cli_test_pulpexporter_repository_1"
Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/pulpcore/test_pulpimporter.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# shellcheck source=tests/scripts/config.source
. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source

pulp debug has-plugin --name "pulp_file" || exit 3
pulp debug has-plugin --name "file" || exit 3

cleanup() {
pulp importer pulp destroy --name "cli_test_importer" || true
Expand Down
Loading

0 comments on commit da865ae

Please sign in to comment.