def artifact():
    """Generate a randomized collection for testing."""
    # build_collection will only store one collection, so copy to new location and delete later
    artifact = build_collection("skeleton")
    artifact.filename = shutil.copy(artifact.filename, "/tmp")
    yield artifact
    os.remove(artifact.filename)
Exemple #2
0
    def setUpClass(cls):
        """Set up two distros for the sync tests."""
        super().setUpClass()
        collections = []
        cls.signing_service = create_signing_service()
        col_api = AnsibleCollectionsApi(cls.client)
        for i in range(4):
            collection = build_collection("skeleton", config=TEST_COLLECTION_CONFIGS[i])
            response = col_api.upload_collection(collection.filename)
            task = monitor_task(response.task)
            collections.append(task.created_resources[0])

        cls.repo = cls.repo_api.create(gen_repo())
        body = {"add_content_units": collections}
        monitor_task(cls.repo_api.modify(cls.repo.pulp_href, body).task)

        body = {"content_units": collections[:2], "signing_service": cls.signing_service.pulp_href}
        monitor_task(cls.repo_api.sign(cls.repo.pulp_href, body).task)
        body = {"content_units": collections[2:], "signing_service": cls.signing_service.pulp_href}
        monitor_task(cls.repo_api.sign(cls.repo.pulp_href, body).task)

        body = gen_distribution(repository=cls.repo.pulp_href)
        distro_href = monitor_task(cls.distributions_api.create(body).task).created_resources[0]
        cls.distro1 = cls.distributions_api.read(distro_href)
        body = gen_distribution(repository_version=f"{cls.repo.versions_href}2/")
        distro_href = monitor_task(cls.distributions_api.create(body).task).created_resources[0]
        cls.distro2 = cls.distributions_api.read(distro_href)
def artifact2():
    """
    Generate a second randomized collection for testing.

    This collection will have the same namespace and version, but different name.
    """
    artifact2 = build_collection("skeleton")
    return artifact2
Exemple #4
0
    def _build_and_publish_collections(cls):
        """Builds and publishes the collections to be used in this test."""
        cls.collections = []
        cls.repo, cls.distro = cls._create_empty_repo_and_distribution(
            cls(), cleanup=False)

        upload_api = PulpAnsibleArtifactsCollectionsV3Api(cls.client)
        for config in TEST_COLLECTION_CONFIGS:
            collection = build_collection("skeleton", config=config)
            upload_api.create(cls.distro.base_path, collection.filename)
            cls.collections.append(collection)
        cls.distro.client_url += "api/"
Exemple #5
0
def gen_collection_in_distribution(base_path,
                                   name=None,
                                   namespace=None,
                                   versions=None,
                                   **cfg_kwargs):
    """
    Generate a randomized collection and upload it to the specified repository.

    Params:
        - base_path: distribtion base path for the repository to upload the
          collection to.
        - name: Name of the collection. If none is provided a random name will
          be generated.
        - namespace: Namespace of the collection. If none is provided a random
          name will be generated.
        - versions: A list of versions to create for the collection. If none
          are specified the collection will be generated with version 1.0.0

        Additional galaxy.yaml configuration options can be added as kwargs.
        For example dependencies={"foo.bar": "1.0.0"} will set foo.bar as a
        dependency for the newly generated collection

    Returns: a dictionary with the name and namespace names of the newly generated
    collection.
    """
    if versions is None:
        versions = ["1.0.0"]
    namespace = namespace or randstr()
    name = name or randstr()

    ansible_client = gen_ansible_client()
    upload = PulpAnsibleArtifactsCollectionsV3Api(ansible_client)

    for version in versions:
        artifact = build_collection(
            "skeleton",
            config={
                "namespace": namespace,
                "name": name,
                "version": version,
                **cfg_kwargs
            },
        )

        upload.create(path=base_path, file=artifact.filename)

        wait_tasks()

        os.remove(artifact.filename)

    return {"name": name, "namespace": namespace}
Exemple #6
0
 def setUpClass(cls):
     """Sets up signing service used for creating signatures."""
     super().setUpClass()
     delete_orphans()
     cls.sign_service = create_signing_service()
     cls.collections = []
     cls.signed_collections = []
     cls.repo = {}
     cls.sig_api = ContentCollectionSignaturesApi(cls.client)
     col_api = AnsibleCollectionsApi(cls.client)
     for i in range(4):
         collection = build_collection("skeleton", config=TEST_COLLECTION_CONFIGS[i])
         response = col_api.upload_collection(collection.filename)
         task = monitor_task(response.task)
         cls.collections.append(task.created_resources[0])
Exemple #7
0
    def _build_and_publish_collections(cls):
        """Builds and publishes the collections to be used in this test."""
        cls.collections = []
        cls.repo, cls.distro = cls._create_empty_repo_and_distribution(
            cls(), cleanup=False)

        upload_api = PulpAnsibleArtifactsCollectionsV3Api(cls.client)
        for config in TEST_COLLECTION_CONFIGS:
            collection = build_collection("skeleton", config=config)
            upload_response = upload_api.create(cls.distro.base_path,
                                                collection.filename)
            api_root = os.environ.get("PULP_API_ROOT", "/pulp/")
            monitor_task("{}api/v3/tasks/{}/".format(
                api_root, upload_response.task[-37:-1]))
            cls.collections.append(collection)
        cls.distro.client_url += "api/"
Exemple #8
0
 def setUpClass(cls):
     """Sets up signing service used for creating signatures."""
     super().setUpClass()
     delete_orphans()
     cls.sign_service = create_signing_service()
     cls.collections = []
     cls.signed_collections = []
     cls.repo = {}
     cls.sig_api = ContentCollectionSignaturesApi(cls.client)
     col_api = AnsibleCollectionsApi(cls.client)
     for i in range(5):
         collection = build_collection("skeleton",
                                       config=TEST_COLLECTION_CONFIGS[i])
         response = col_api.upload_collection(collection.filename)
         task = monitor_task(response.task)
         cls.collections.append(task.created_resources[0])
     # Locally sign the last collection
     cls.t = TemporaryDirectory()
     with tarfile.open(collection.filename, mode="r") as tar:
         filename = f"{cls.t.name}/MANIFEST.json"
         tar.extract("MANIFEST.json", path=cls.t.name)
     cls.last_signed_filenames = run_signing_script(filename)
def artifact():
    """Generate a randomized collection for testing."""
    artifact = build_collection("skeleton")
    return artifact