Skip to content

Commit

Permalink
Adding pulp-2to3-migration support
Browse files Browse the repository at this point in the history
fixes pulp#133
  • Loading branch information
David Davis committed Feb 15, 2021
1 parent e701ec2 commit b060e36
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES/133.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for pulp-2to3-migration.
14 changes: 14 additions & 0 deletions pulpcore/cli/migration/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
33 changes: 33 additions & 0 deletions pulpcore/cli/migration/context.py
Original file line number Diff line number Diff line change
@@ -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"
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, 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)
36 changes: 36 additions & 0 deletions pulpcore/cli/migration/pulp2.py
Original file line number Diff line number Diff line change
@@ -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]))
Empty file added pulpcore/cli/migration/py.typed
Empty file.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
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"
9 changes: 9 additions & 0 deletions tests/scripts/pulp_2to3_migration/test_pulp2.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b060e36

Please sign in to comment.