async def pre_migrate_all_content(plan):
    """
    Pre-migrate all content for the specified plugins.

    Args:
        plan (MigrationPlan): Migration Plan to use for migration.
    """
    plugins_to_migrate = plan.get_plugins()
    pre_migrators = []

    # get all the content models for the migrating plugins
    for plugin, plugin_migrator in PLUGIN_MIGRATORS.items():
        if plugin not in plugins_to_migrate:
            continue
        for content_type in plugin_migrator.pulp2_content_models:
            # mongodb model
            pulp2_content_model = plugin_migrator.pulp2_content_models[content_type]

            # postgresql model
            pulp_2to3_detail_model = plugin_migrator.content_models[content_type]

            content_model = ContentModel(pulp2=pulp2_content_model,
                                         pulp_2to3_detail=pulp_2to3_detail_model)
            pre_migrators.append(pre_migrate_content(content_model))

    _logger.debug('Pre-migrating Pulp 2 content')
    await asyncio.wait(pre_migrators)
Ejemplo n.º 2
0
async def migrate_importers(plan):
    """
    A coroutine to migrate pre-migrated importers.

    Args:
        plan (MigrationPlan): Migration Plan to use.
    """
    # gather all needed plugin importer migrators
    importer_migrators = {}
    plugins_to_migrate = plan.get_plugins()

    for plugin, plugin_migrator in PLUGIN_MIGRATORS.items():
        if plugin not in plugins_to_migrate:
            continue
        importer_migrators.update(**plugin_migrator.importer_migrators)

    progress_data = dict(message='Migrating importers to Pulp 3',
                         code='migrating.importers',
                         total=0)
    with ProgressReport(**progress_data) as pb:
        # Temp fix until https://pulp.plan.io/issues/5485 is done
        pulp2importers_qs = Pulp2Importer.objects.filter(
            pulp2_type_id__in=importer_migrators.keys(), pulp3_remote=None)
        pb.total += pulp2importers_qs.count()
        pb.save()

        for pulp2importer in pulp2importers_qs:
            importer_migrator = importer_migrators.get(
                pulp2importer.pulp2_type_id)
            remote, created = await importer_migrator.migrate_to_pulp3(
                pulp2importer)
            pulp2importer.pulp3_remote = remote
            pulp2importer.is_migrated = True
            pulp2importer.save()
            if created:
                pb.increment()
            else:
                pb.total -= 1
                pb.save()