Ejemplo n.º 1
0
def import_and_move_to_staging(artifact_pk, **kwargs):
    """Import collection version and move to staging repository.

    Custom task to call pulp_ansible's import_collection() task then
    enqueue two tasks to add to staging repo and remove from inbound repo.

    This task will not wait for the enqueued tasks to finish.
    """
    inbound_repository_pk = kwargs.get('repository_pk')
    import_collection(artifact_pk=artifact_pk, repository_pk=inbound_repository_pk)

    content_artifact = ContentArtifact.objects.get(artifact_id=artifact_pk)
    collection_version = content_artifact.content.ansible_collectionversion

    # enqueue task to add collection_version to staging repo
    try:
        staging_repo = AnsibleRepository.objects.get(name=STAGING_NAME)
    except AnsibleRepository.DoesNotExist:
        raise RuntimeError(f'Could not find staging repository: "{STAGING_NAME}"')
    locks = [staging_repo]
    task_args = (collection_version.pk, staging_repo.pk)
    enqueue_with_reservation(add_content_to_repository, locks, args=task_args)

    # enqueue task to remove collection_verion from inbound repo
    inbound_repo = AnsibleRepository.objects.get(pk=inbound_repository_pk)
    locks = [inbound_repo]
    task_args = (collection_version.pk, inbound_repository_pk)
    enqueue_with_reservation(remove_content_from_repository, locks, args=task_args)
Ejemplo n.º 2
0
def import_and_auto_approve(artifact_pk, **kwargs):
    """Import collection version and automatically approve.

    Custom task to call pulp_ansible's import_collection() task
    then automatically approve collection version so no
    manual approval action needs to occur.
    """
    inbound_repository_pk = kwargs.get('repository_pk')
    import_collection(artifact_pk=artifact_pk, repository_pk=inbound_repository_pk)
    content_artifact = ContentArtifact.objects.get(artifact_id=artifact_pk)
    collection_version = content_artifact.content.ansible_collectionversion

    # FIXME: remove when no longer using certification flag
    collection_version.certification = VERSION_CERTIFIED
    collection_version.save()

    # enqueue task to add collection_version to golden repo
    try:
        golden_repo = AnsibleRepository.objects.get(name=GOLDEN_NAME)
    except AnsibleRepository.DoesNotExist:
        raise RuntimeError(f'Could not find golden repository: "{GOLDEN_NAME}"')
    locks = [golden_repo]
    task_args = (collection_version.pk, golden_repo.pk)
    enqueue_with_reservation(add_content_to_repository, locks, args=task_args)

    # enqueue task to remove collection_verion from inbound repo
    inbound_repo = AnsibleRepository.objects.get(pk=inbound_repository_pk)
    locks = [inbound_repo]
    task_args = (collection_version.pk, inbound_repository_pk)
    enqueue_with_reservation(remove_content_from_repository, locks, args=task_args)
Ejemplo n.º 3
0
def import_and_auto_approve(temp_file_pk, **kwargs):
    """Import collection version and automatically approve.

    Custom task to call pulp_ansible's import_collection() task
    then automatically approve collection version so no
    manual approval action needs to occur.
    """
    inbound_repository_pk = kwargs.get('repository_pk')
    import_collection(
        temp_file_pk=temp_file_pk,
        repository_pk=inbound_repository_pk,
        expected_namespace=kwargs['expected_namespace'],
        expected_name=kwargs['expected_name'],
        expected_version=kwargs['expected_version'],
    )

    try:
        golden_repo = AnsibleDistribution.objects.get(
            name=GOLDEN_NAME).repository
    except AnsibleRepository.DoesNotExist:
        raise RuntimeError(
            f'Could not find staging repository: "{GOLDEN_NAME}"')

    inbound_repo = AnsibleRepository.objects.get(pk=inbound_repository_pk)

    created_collection_versions = get_created_collection_versions()

    for collection_version in created_collection_versions:
        call_copy_task(collection_version, inbound_repo, golden_repo)
        call_remove_task(collection_version, inbound_repo)

        log.info(
            'Imported and auto approved collection artifact %s to repository %s',
            collection_version.relative_path, golden_repo.latest_version())
Ejemplo n.º 4
0
def import_and_move_to_staging(temp_file_pk, **kwargs):
    """Import collection version and move to staging repository.

    Custom task to call pulp_ansible's import_collection() task then
    enqueue two tasks to add to staging repo and remove from inbound repo.

    This task will not wait for the enqueued tasks to finish.
    """
    inbound_repository_pk = kwargs.get('repository_pk')
    import_collection(
        temp_file_pk=temp_file_pk,
        repository_pk=inbound_repository_pk,
        expected_namespace=kwargs['expected_namespace'],
        expected_name=kwargs['expected_name'],
        expected_version=kwargs['expected_version'],
    )

    try:
        staging_repo = AnsibleDistribution.objects.get(
            name=STAGING_NAME).repository
    except AnsibleRepository.DoesNotExist:
        raise RuntimeError(
            f'Could not find staging repository: "{STAGING_NAME}"')

    inbound_repo = AnsibleRepository.objects.get(pk=inbound_repository_pk)

    created_collection_versions = get_created_collection_versions()

    for collection_version in created_collection_versions:
        call_copy_task(collection_version, inbound_repo, staging_repo)
        call_remove_task(collection_version, inbound_repo)
Ejemplo n.º 5
0
def import_and_auto_approve(artifact_pk, **kwargs):
    """Import collection version and automatically approve.

    Custom task to call pulp_ansible's import_collection() task
    then automatically approve collection version so no
    manual approval action needs to occur.

    Approval currently is a collection version certification flag
    Approval later will be moving from a staging to an approved repo
    """
    import_collection(artifact_pk=artifact_pk, repository_pk=kwargs.get('repository_pk', None))
    content_artifact = ContentArtifact.objects.get(artifact_id=artifact_pk)
    collection_version = content_artifact.content.ansible_collectionversion
    collection_version.certification = VERSION_CERTIFIED
    collection_version.save()
Ejemplo n.º 6
0
def import_collection_from_path(path):
    """
    Import a single collection by path.

    This method will not fail if the Artifact already exists.

    Args:
        path: The path to the tarball to import.

    """
    artifact = Artifact.init_and_validate(path)

    try:
        artifact.save()
    except IntegrityError:
        artifact = Artifact.objects.get(sha256=artifact.sha256)

    import_collection(artifact.pk)
Ejemplo n.º 7
0
def import_and_auto_approve(temp_file_pk, **kwargs):
    """Import collection version and automatically approve.

    Custom task to call pulp_ansible's import_collection() task
    then automatically approve collection version so no
    manual approval action needs to occur.
    """
    inbound_repository_pk = kwargs.get('repository_pk')
    import_collection(temp_file_pk=temp_file_pk,
                      repository_pk=inbound_repository_pk)

    try:
        golden_repo = AnsibleDistribution.objects.get(
            name=GOLDEN_NAME).repository
    except AnsibleRepository.DoesNotExist:
        raise RuntimeError(
            f'Could not find staging repository: "{GOLDEN_NAME}"')

    inbound_repo = AnsibleRepository.objects.get(pk=inbound_repository_pk)

    remove_locks = [inbound_repo]
    add_locks = [golden_repo]

    created_collection_versions = get_created_collection_versions()

    for collection_version in created_collection_versions:
        collection_version.certification = VERSION_CERTIFIED
        collection_version.save()

        # enqueue task to add collection_version to golden repo
        add_task_args = (collection_version.pk, golden_repo.pk)
        enqueue_with_reservation(add_content_to_repository,
                                 add_locks,
                                 args=add_task_args)

        # enqueue task to remove collection_verion from inbound repo
        remove_task_args = (collection_version.pk, inbound_repository_pk)
        enqueue_with_reservation(remove_content_from_repository,
                                 remove_locks,
                                 args=remove_task_args)

        log.info(
            'Imported and auto approved collection artifact %s to repository %s',
            collection_version.relative_path, golden_repo.latest_version())
Ejemplo n.º 8
0
def import_and_move_to_staging(temp_file_pk, **kwargs):
    """Import collection version and move to staging repository.

    Custom task to call pulp_ansible's import_collection() task then
    enqueue two tasks to add to staging repo and remove from inbound repo.

    This task will not wait for the enqueued tasks to finish.
    """
    inbound_repository_pk = kwargs.get('repository_pk')
    import_collection(temp_file_pk=temp_file_pk,
                      repository_pk=inbound_repository_pk)

    try:
        staging_repo = AnsibleDistribution.objects.get(
            name=STAGING_NAME).repository
    except AnsibleRepository.DoesNotExist:
        raise RuntimeError(
            f'Could not find staging repository: "{STAGING_NAME}"')

    inbound_repo = AnsibleRepository.objects.get(pk=inbound_repository_pk)

    inbound_locks = [inbound_repo]
    staging_locks = [staging_repo]

    created_collection_versions = get_created_collection_versions()

    for collection_version in created_collection_versions:
        # enqueue task to add collection_version to staging repo
        add_task_args = (collection_version.pk, staging_repo.pk)
        enqueue_with_reservation(add_content_to_repository,
                                 staging_locks,
                                 args=add_task_args)

        # enqueue task to remove collection_verion from inbound repo
        remove_task_args = (collection_version.pk, inbound_repository_pk)
        enqueue_with_reservation(remove_content_from_repository,
                                 inbound_locks,
                                 args=remove_task_args)