From b060e3646b3b1e0c5a3cc3d1b632f8ae31a1fe09 Mon Sep 17 00:00:00 2001 From: David Davis Date: Sat, 13 Feb 2021 09:48:34 -0500 Subject: [PATCH] Adding pulp-2to3-migration support fixes #133 --- CHANGES/133.feature | 1 + pulpcore/cli/migration/__init__.py | 14 +++++++ pulpcore/cli/migration/context.py | 33 +++++++++++++++ pulpcore/cli/migration/plan.py | 40 +++++++++++++++++++ pulpcore/cli/migration/pulp2.py | 36 +++++++++++++++++ pulpcore/cli/migration/py.typed | 0 pyproject.toml | 1 + setup.py | 1 + .../scripts/pulp_2to3_migration/test_plan.sh | 21 ++++++++++ .../scripts/pulp_2to3_migration/test_pulp2.sh | 9 +++++ 10 files changed, 156 insertions(+) create mode 100644 CHANGES/133.feature create mode 100644 pulpcore/cli/migration/__init__.py create mode 100644 pulpcore/cli/migration/context.py create mode 100644 pulpcore/cli/migration/plan.py create mode 100644 pulpcore/cli/migration/pulp2.py create mode 100644 pulpcore/cli/migration/py.typed create mode 100755 tests/scripts/pulp_2to3_migration/test_plan.sh create mode 100755 tests/scripts/pulp_2to3_migration/test_pulp2.sh diff --git a/CHANGES/133.feature b/CHANGES/133.feature new file mode 100644 index 000000000..6342ccb3f --- /dev/null +++ b/CHANGES/133.feature @@ -0,0 +1 @@ +Added support for pulp-2to3-migration. diff --git a/pulpcore/cli/migration/__init__.py b/pulpcore/cli/migration/__init__.py new file mode 100644 index 000000000..c31e85bd0 --- /dev/null +++ b/pulpcore/cli/migration/__init__.py @@ -0,0 +1,14 @@ +from pulpcore.cli.common import main +from pulpcore.cli.common.context import PulpContext, pass_pulp_context +from pulpcore.cli.migration.plan import plan +from pulpcore.cli.migration.pulp2 import pulp2 + + +@main.group() +@pass_pulp_context +def migration(pulp_ctx: PulpContext) -> None: + pulp_ctx.needs_plugin("pulp_2to3_migration") + + +migration.add_command(plan) +migration.add_command(pulp2) diff --git a/pulpcore/cli/migration/context.py b/pulpcore/cli/migration/context.py new file mode 100644 index 000000000..56fd505f5 --- /dev/null +++ b/pulpcore/cli/migration/context.py @@ -0,0 +1,33 @@ +from typing import Any + +from pulpcore.cli.common.context import PulpEntityContext + + +class PulpMigrationPlanContext(PulpEntityContext): + ENTITY = "pulp_2to3_migration_migration_plan" + HREF = "pulp_2to3_migration_migration_plan_href" + LIST_ID = "migration_plans_list" + READ_ID = "migration_plans_read" + CREATE_ID = "migration_plans_create" + UPDATE_ID = "migration_plans_partial_update" + DELETE_ID = "migration_plans_delete" + + def run(self, href: str) -> Any: + return self.pulp_ctx.call("migration_plans_run", parameters={self.HREF: href}) + + def reset(self, href: str) -> Any: + return self.pulp_ctx.call("migration_plans_reset", parameters={self.HREF: href}) + + +class PulpMigrationPulp2ContentContext(PulpEntityContext): + ENTITY = "pulp_2to3_migration_pulp2_content" + HREF = "pulp_2to3_migration_pulp2_content_href" + LIST_ID = "pulp2content_list" + READ_ID = "pulp2content_read" + + +class PulpMigrationPulp2RepositoryContext(PulpEntityContext): + ENTITY = "pulp_2to3_migration_pulp2_repository" + HREF = "pulp_2to3_migration_pulp2_repository_href" + LIST_ID = "pulp2repositories_list" + READ_ID = "pulp2repositories_read" diff --git a/pulpcore/cli/migration/plan.py b/pulpcore/cli/migration/plan.py new file mode 100644 index 000000000..0149d421a --- /dev/null +++ b/pulpcore/cli/migration/plan.py @@ -0,0 +1,40 @@ +import click + +from pulpcore.cli.common.context import PulpContext, pass_entity_context, pass_pulp_context +from pulpcore.cli.common.generic import ( + create_command, + destroy_command, + href_option, + list_command, + show_command, +) +from pulpcore.cli.migration.context import PulpMigrationPlanContext + + +@click.group() +@pass_pulp_context +@click.pass_context +def plan(ctx: click.Context, pulp_ctx: PulpContext) -> None: + ctx.obj = PulpMigrationPlanContext(pulp_ctx) + + +plan.add_command(list_command()) +plan.add_command(show_command(decorators=[href_option])) +plan.add_command(destroy_command(decorators=[href_option])) + +create_options = [click.option("--plan", required=True, help="Migration plan in JSON format")] +plan.add_command(create_command(decorators=create_options)) + + +@plan.command(help="Run migration plan") +@click.option("--href", required=True, help="HREF of the plan") +@pass_entity_context +def run(plan_ctx: PulpMigrationPlanContext, href: str) -> None: + plan_ctx.run(href) + + +@plan.command(help="Reset Pulp 3 data for plugins specified in the migration plan") +@click.option("--href", required=True, help="HREF of the plan") +@pass_entity_context +def reset(plan_ctx: PulpMigrationPlanContext, href: str) -> None: + plan_ctx.reset(href) diff --git a/pulpcore/cli/migration/pulp2.py b/pulpcore/cli/migration/pulp2.py new file mode 100644 index 000000000..437b8acaf --- /dev/null +++ b/pulpcore/cli/migration/pulp2.py @@ -0,0 +1,36 @@ +import click + +from pulpcore.cli.common.context import PulpContext, pass_pulp_context +from pulpcore.cli.common.generic import href_option, list_command, show_command +from pulpcore.cli.migration.context import ( + PulpMigrationPulp2ContentContext, + PulpMigrationPulp2RepositoryContext, +) + + +@click.group() +def pulp2() -> None: + pass + + +@pulp2.group() +@pass_pulp_context +@click.pass_context +def content(ctx: click.Context, pulp_ctx: PulpContext) -> None: + ctx.obj = PulpMigrationPulp2ContentContext(pulp_ctx) + + +content.add_command(list_command()) +content.add_command(show_command(decorators=[href_option])) + + +@pulp2.group() +@pass_pulp_context +@click.pass_context +def repository(ctx: click.Context, pulp_ctx: PulpContext) -> None: + ctx.obj = PulpMigrationPulp2RepositoryContext(pulp_ctx) + pass + + +repository.add_command(list_command()) +repository.add_command(show_command(decorators=[href_option])) diff --git a/pulpcore/cli/migration/py.typed b/pulpcore/cli/migration/py.typed new file mode 100644 index 000000000..e69de29bb diff --git a/pyproject.toml b/pyproject.toml index 4e74573d7..f05ff71c4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,6 +17,7 @@ line_length = 100 markers = [ "script: Marks tests provided as shell scripts", "pulpcore: pulpcore tests", + "pulp_2to3_migration: pulp-2to3-migration tests", "pulp_file: pulp_file tests", "pulp_ansible: pulp_ansible tests", "pulp_container: pulp_container tests", diff --git a/setup.py b/setup.py index e0bf0c21c..c4e2ef9a0 100644 --- a/setup.py +++ b/setup.py @@ -35,6 +35,7 @@ "container=pulpcore.cli.container", "core=pulpcore.cli.core", "file=pulpcore.cli.file", + "migration=pulpcore.cli.migration", "rpm=pulpcore.cli.rpm", ], }, diff --git a/tests/scripts/pulp_2to3_migration/test_plan.sh b/tests/scripts/pulp_2to3_migration/test_plan.sh new file mode 100755 index 000000000..fc8f75e1b --- /dev/null +++ b/tests/scripts/pulp_2to3_migration/test_plan.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# shellcheck source=tests/scripts/config.source +. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source + +pulp debug has-plugin --name "pulp_2to3_migration" || exit 3 + +plan_href="" +plan_json='{"plugins": [{"type": "iso"}]}' + +cleanup() { + pulp migration plan destroy --href "$plan_href" || true +} +trap cleanup EXIT + +expect_succ pulp migration plan create --plan "$plan_json" +plan_href=$(echo "$OUTPUT" | jq -r ".pulp_href") +expect_succ pulp migration plan show --href "$plan_href" + +expect_succ pulp migration plan list +expect_succ pulp migration plan destroy --href "$plan_href" diff --git a/tests/scripts/pulp_2to3_migration/test_pulp2.sh b/tests/scripts/pulp_2to3_migration/test_pulp2.sh new file mode 100755 index 000000000..aa52a9f8e --- /dev/null +++ b/tests/scripts/pulp_2to3_migration/test_pulp2.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +# shellcheck source=tests/scripts/config.source +. "$(dirname "$(dirname "$(realpath "$0")")")"/config.source + +pulp debug has-plugin --name "pulp_2to3_migration" || exit 3 + +expect_succ pulp migration pulp2 repository list +expect_succ pulp migration pulp2 content list