Skip to content

Commit

Permalink
Adding pulp-2to3-migration support
Browse files Browse the repository at this point in the history
fixes #133
  • Loading branch information
David Davis committed Feb 13, 2021
1 parent c1f1774 commit 09d51a0
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 2 deletions.
12 changes: 12 additions & 0 deletions pulpcore/cli/migration/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from pulpcore.cli.common import main
from pulpcore.cli.common.context import PulpContext, pass_pulp_context
from pulpcore.cli.migration.plan import plan


@main.group()
@pass_pulp_context
def migration(pulp_ctx: PulpContext) -> None:
pulp_ctx.needs_plugin("pulp_2to3_migration")


migration.add_command(plan)
19 changes: 19 additions & 0 deletions pulpcore/cli/migration/context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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})
40 changes: 40 additions & 0 deletions pulpcore/cli/migration/plan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import click

from pulpcore.cli.common.context import (
PulpContext,
PulpEntityContext,
pass_entity_context,
pass_pulp_context,
)
from pulpcore.cli.common.generic import create_command, destroy_by_href, list_entities, show_by_href
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)
pass


plan.add_command(list_entities)
plan.add_command(show_by_href)
plan.add_command(destroy_by_href)

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)
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ line_length = 100
markers = [
"script: Marks tests provided as shell scripts",
"pulpcore: pulpcore tests.",
"pulp_file: pulp_file tests.",
"pulp_2to3_migration: pulp-2to3-migration tests.",
"pulp_ansible: pulp_ansible tests.",
"pulp_container: pulp_container tests."
"pulp_container: pulp_container tests.",
"pulp_file: pulp_file tests.",
]
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"container=pulpcore.cli.container",
"core=pulpcore.cli.core",
"file=pulpcore.cli.file",
"migration=pulpcore.cli.migration",
"rpm=pulpcore.cli.rpm",
],
},
Expand Down
21 changes: 21 additions & 0 deletions tests/scripts/pulp_2to3_migration/test_plan.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 09d51a0

Please sign in to comment.