Esempio n. 1
0
def gen_user(permissions):
    """Create a user with a set of permissions in the pulp database."""
    user = {
        "username": utils.uuid4(),
        "password": utils.uuid4(),
        "permissions": permissions,
    }
    utils.execute_pulpcore_python(
        cli_client,
        "\n".join(CREATE_USER_CMD).format(**user),
    )

    api_config = cfg.get_bindings_config()
    api_config.username = user["username"]
    api_config.password = user["password"]
    user["core_api_client"] = CoreApiClient(api_config)
    user["groups_api"] = GroupsApi(user["core_api_client"])
    user["group_users_api"] = GroupsUsersApi(user["core_api_client"])
    user["api_client"] = ContainerApiClient(api_config)
    user["distribution_api"] = DistributionsContainerApi(user["api_client"])
    user["remote_api"] = RemotesContainerApi(user["api_client"])
    user["repository_api"] = RepositoriesContainerApi(user["api_client"])
    user["pushrepository_api"] = RepositoriesContainerPushApi(user["api_client"])
    user["repo_version_api"] = RepositoriesContainerVersionsApi(user["api_client"])
    user["tags_api"] = ContentTagsApi(user["api_client"])
    user["manifests_api"] = ContentManifestsApi(user["api_client"])
    user["blobs_api"] = ContentBlobsApi(user["api_client"])
    return user
Esempio n. 2
0
    def setUpClass(cls):
        """Define APIs to use and pull images needed later in tests."""
        api_client = gen_container_client()
        cls.tags_api = ContentTagsApi(api_client)
        cls.manifests_api = ContentManifestsApi(api_client)
        cls.repositories_api = RepositoriesContainerPushApi(api_client)

        cfg = config.get_config()
        cls.registry = cli.RegistryClient(cfg)
        cls.registry.raise_if_unsupported(unittest.SkipTest,
                                          "Tests require podman/docker")
        cls.registry_name = urlparse(cfg.get_base_url()).netloc

        cls.repository_name = "namespace/tags"
        cls.registry_repository_name = f"{cls.registry_name}/{cls.repository_name}"
        manifest_a = f"{DOCKERHUB_PULP_FIXTURE_1}:manifest_a"
        tagged_registry_manifest_a = f"{cls.registry_repository_name}:manifest_a"
        manifest_b = f"{DOCKERHUB_PULP_FIXTURE_1}:manifest_b"
        tagged_registry_manifest_b = f"{cls.registry_repository_name}:manifest_b"

        cls.registry.pull(manifest_a)
        cls.registry.pull(manifest_b)
        cls.registry.tag(manifest_a, tagged_registry_manifest_a)
        cls.registry.tag(manifest_b, tagged_registry_manifest_b)
        cls.registry.login("-u", "admin", "-p", "password", cls.registry_name)
        cls.registry.push(tagged_registry_manifest_a)
        cls.registry.push(tagged_registry_manifest_b)

        cls.repository = cls.repositories_api.list(
            name=cls.repository_name).results[0]
Esempio n. 3
0
    def setUpClass(cls):
        """Sync a remote repository and create a new distribution pointing to the repository."""
        client_api = gen_container_client()
        cls.blobs_api = ContentBlobsApi(client_api)
        cls.manifests_api = ContentManifestsApi(client_api)
        cls.tags_api = ContentTagsApi(client_api)
        cls.repo_api = RepositoriesContainerApi(client_api)
        cls.remote_api = RemotesContainerApi(client_api)
        cls.dist_api = DistributionsContainerApi(client_api)

        cls.repo = cls.repo_api.create(gen_repo())
        cls.remote = cls.remote_api.create(gen_container_remote())
        body = ContainerRepositorySyncURL(remote=cls.remote.pulp_href)
        response = cls.repo_api.sync(cls.repo.pulp_href, body)
        monitor_task(response.task)

        cls.repo = cls.repo_api.read(cls.repo.pulp_href)

        response = cls.dist_api.create(
            gen_distribution(repository=cls.repo.pulp_href))
        cls.distro = cls.dist_api.read(
            monitor_task(response.task).created_resources[0])

        relative_path = os.path.join("v2/", f"{cls.distro.base_path}/")
        cls.dist_url = urljoin(PULP_CONTENT_HOST_BASE_URL, relative_path)
Esempio n. 4
0
    def setUpClass(cls):
        """Create class-wide variable."""
        delete_orphans()
        cls.content_unit = {}

        # FIXME: Instantiate APIs for all content types.
        cls.container_content_api = ContentManifestsApi(gen_container_client())
        cls.artifact = gen_artifact()
Esempio n. 5
0
    def setUpClass(cls):
        """Create class wide-variables."""
        api_client = gen_container_client()
        cls.repositories_api = RepositoriesContainerApi(api_client)
        cls.versions_api = RepositoriesContainerVersionsApi(api_client)
        cls.remotes_api = RemotesContainerApi(api_client)
        cls.tags_api = ContentTagsApi(api_client)
        cls.manifests_api = ContentManifestsApi(api_client)

        cls.repository = cls.repositories_api.create(ContainerContainerRepository(**gen_repo()))

        remote_data = gen_container_remote(upstream_name=DOCKERHUB_PULP_FIXTURE_1)
        cls.remote = cls.remotes_api.create(ContainerContainerRemote(**remote_data))

        sync_data = RepositorySyncURL(remote=cls.remote.pulp_href)
        sync_response = cls.repositories_api.sync(cls.repository.pulp_href, sync_data)
        monitor_task(sync_response.task)
Esempio n. 6
0
    def setUpClass(cls):
        """
        Define APIs to use and pull images needed later in tests
        """
        api_client = gen_container_client()
        cfg = config.get_config()

        cls.repositories_api = RepositoriesContainerApi(api_client)
        cls.repo_version_api = RepositoriesContainerVersionsApi(api_client)
        cls.tags_api = ContentTagsApi(api_client)
        cls.manifests_api = ContentManifestsApi(api_client)

        admin_user, admin_password = cfg.pulp_auth
        cls.user_admin = {"username": admin_user, "password": admin_password}
        cls.user_creator = gen_user(
            [
                "container.add_containerrepository",
                "container.add_containerremote",
            ]
        )
        cls.user_repov_remover = gen_user(
            [
                "container.delete_containerrepository_versions",
                "container.view_containerrepository",
            ]
        )
        cls.user_repo_remover = gen_user(
            [
                "container.delete_containerrepository",
                "container.view_containerrepository",
            ]
        )
        cls.user_reader = gen_user(["container.view_containerrepository"])
        cls.user_helpless = gen_user([])

        # sync a repo
        cls.repository = cls.user_creator["repository_api"].create(
            ContainerContainerRepository(**gen_repo())
        )
        cls.remote = cls.user_creator["remote_api"].create(
            gen_container_remote(upstream_name=DOCKERHUB_PULP_FIXTURE_1)
        )
        sync_data = RepositorySyncURL(remote=cls.remote.pulp_href)
        sync_response = cls.user_creator["repository_api"].sync(cls.repository.pulp_href, sync_data)
        monitor_task(sync_response.task)
Esempio n. 7
0
    def setUpClass(cls):
        """
        Define APIs to use and pull images needed later in tests
        """
        api_client = gen_container_client()
        cfg = config.get_config()

        cls.repositories_api = RepositoriesContainerApi(api_client)
        cls.repo_version_api = RepositoriesContainerVersionsApi(api_client)
        cls.tags_api = ContentTagsApi(api_client)
        cls.manifests_api = ContentManifestsApi(api_client)

        admin_user, admin_password = cfg.pulp_auth
        cls.user_admin = {"username": admin_user, "password": admin_password}
        cls.user_creator = gen_user(
            model_roles=[
                "container.containerrepository_creator",
                "container.containerremote_creator",
            ]
        )
        cls.user_repov_remover = gen_user(
            model_roles=[
                "container.containerrepository_content_manager",
            ]
        )
        # TODO: Not sure what is the right role for this user...
        cls.user_repo_remover = gen_user(
            model_roles=[
                "container.containerrepository_owner",
            ]
        )
        cls.user_reader = gen_user(model_roles=["container.containerrepository_viewer"])
        cls.user_helpless = gen_user()

        # sync a repo
        cls.repository = cls.user_creator["repository_api"].create(
            ContainerContainerRepository(**gen_repo())
        )
        cls.remote = cls.user_creator["remote_api"].create(
            gen_container_remote(upstream_name=PULP_FIXTURE_1)
        )
        sync_data = ContainerRepositorySyncURL(remote=cls.remote.pulp_href)
        sync_response = cls.user_creator["repository_api"].sync(cls.repository.pulp_href, sync_data)
        monitor_task(sync_response.task)
Esempio n. 8
0
    def setUpClass(cls):
        """Define class-wide variables and initialize a repository needed later in the tests."""
        cfg = config.get_config()
        cls.registry = cli.RegistryClient(cfg)
        cls.registry.raise_if_unsupported(unittest.SkipTest,
                                          "Tests require podman/docker")
        cls.registry_name = urlparse(cfg.get_base_url()).netloc

        admin_user, admin_password = cfg.pulp_auth
        cls.user_admin = {"username": admin_user, "password": admin_password}

        api_client = gen_container_client()
        api_client.configuration.username = cls.user_admin["username"]
        api_client.configuration.password = cls.user_admin["password"]

        cls.repositories_api = RepositoriesContainerPushApi(api_client)
        cls.versions_api = RepositoriesContainerVersionsApi(api_client)
        cls.namespaces_api = PulpContainerNamespacesApi(api_client)
        cls.manifests_api = ContentManifestsApi(api_client)
        cls.distributions_api = DistributionsContainerApi(api_client)

        # the image tagged as 'manifest_a' consists of 3 blobs, 1 manifest, and 1 tag
        manifest_a_path = f"{REGISTRY_V2_REPO_PULP}:manifest_a"
        cls._pull(manifest_a_path)

        local_url = "/".join([cls.registry_name, "foo/bar:tag"])
        cls._push(manifest_a_path, local_url, cls.user_admin)

        cls.repo = cls.repositories_api.list(name="foo/bar").results[0]
        cls.distribution = cls.distributions_api.list(
            name="foo/bar").results[0]
        cls.namespace = cls.namespaces_api.list(name="foo").results[0]

        # create a new tag to test if all tags pointing to the same manifest will be removed
        cls.manifest_a = cls.manifests_api.list().results[0]
        tag_data = TagImage(tag="new_tag", digest=cls.manifest_a.digest)
        tag_response = cls.repositories_api.tag(cls.repo.pulp_href, tag_data)
        monitor_task(tag_response.task)

        latest_version_href = cls.repositories_api.read(
            cls.repo.pulp_href).latest_version_href
        cls.content_to_remove = cls.versions_api.read(
            latest_version_href).content_summary.present
Esempio n. 9
0
def gen_user(model_roles=None, object_roles=None):
    """Create a user with a set of permissions in the pulp database."""
    if model_roles is None:
        model_roles = []

    if object_roles is None:
        object_roles = []

    user = {
        "username": utils.uuid4(),
        "password": utils.uuid4(),
    }
    new_user = users_api.create(user)
    user["pulp_href"] = new_user.pulp_href

    for role in model_roles:
        assign_role_to_user(user, role)
    for role, content_object in object_roles:
        assign_role_to_user(user, role, content_object)

    api_config = cfg.get_bindings_config()
    api_config.username = user["username"]
    api_config.password = user["password"]
    user["core_api_client"] = CoreApiClient(api_config)
    user["groups_api"] = GroupsApi(user["core_api_client"])
    user["group_users_api"] = GroupsUsersApi(user["core_api_client"])
    user["container_api_client"] = ContainerApiClient(api_config)
    user["namespace_api"] = PulpContainerNamespacesApi(
        user["container_api_client"])
    user["distribution_api"] = DistributionsContainerApi(
        user["container_api_client"])
    user["remote_api"] = RemotesContainerApi(user["container_api_client"])
    user["repository_api"] = RepositoriesContainerApi(
        user["container_api_client"])
    user["pushrepository_api"] = RepositoriesContainerPushApi(
        user["container_api_client"])
    user["repo_version_api"] = RepositoriesContainerVersionsApi(
        user["container_api_client"])
    user["tags_api"] = ContentTagsApi(user["container_api_client"])
    user["manifests_api"] = ContentManifestsApi(user["container_api_client"])
    user["blobs_api"] = ContentBlobsApi(user["container_api_client"])
    return user
Esempio n. 10
0
    def setUpClass(cls):
        """Sync pulp/test-fixture-1 so we can copy content from it."""
        api_client = gen_container_client()
        cls.repositories_api = RepositoriesContainerApi(api_client)
        cls.versions_api = RepositoriesContainerVersionsApi(api_client)
        cls.remotes_api = RemotesContainerApi(api_client)
        cls.tags_api = ContentTagsApi(api_client)
        cls.manifests_api = ContentManifestsApi(api_client)

        cls.from_repo = cls.repositories_api.create(ContainerContainerRepository(**gen_repo()))

        remote_data = gen_container_remote(upstream_name=DOCKERHUB_PULP_FIXTURE_1)
        cls.remote = cls.remotes_api.create(ContainerContainerRemote(**remote_data))

        sync_data = RepositorySyncURL(remote=cls.remote.pulp_href)
        sync_response = cls.repositories_api.sync(cls.from_repo.pulp_href, sync_data)
        monitor_task(sync_response.task)

        cls.latest_from_version = cls.repositories_api.read(
            cls.from_repo.pulp_href
        ).latest_version_href
Esempio n. 11
0
    def setUpClass(cls):
        """Initialize a new manifest list that will be pushed to the registry."""
        cfg = config.get_config()
        cls.registry = cli.RegistryClient(cfg)
        cls.registry.raise_if_unsupported(unittest.SkipTest,
                                          "Tests require podman/docker")
        cls.registry_name = urlparse(cfg.get_base_url()).netloc

        admin_user, admin_password = cfg.pulp_auth
        cls.user_admin = {"username": admin_user, "password": admin_password}

        api_client = gen_container_client()
        api_client.configuration.username = cls.user_admin["username"]
        api_client.configuration.password = cls.user_admin["password"]
        cls.pushrepository_api = RepositoriesContainerPushApi(api_client)
        cls.distributions_api = DistributionsContainerApi(api_client)
        cls.manifests_api = ContentManifestsApi(api_client)
        cls.tags_api = ContentTagsApi(api_client)

        cls.manifest_a = f"{REGISTRY_V2_REPO_PULP}:manifest_a"
        cls.manifest_b = f"{REGISTRY_V2_REPO_PULP}:manifest_b"
        cls.manifest_c = f"{REGISTRY_V2_REPO_PULP}:manifest_c"
        cls._pull(cls.manifest_a)
        cls._pull(cls.manifest_b)
        cls._pull(cls.manifest_c)

        # get default manifests' digests for the further comparison
        manifest_a_digest = cls.registry.inspect(cls.manifest_a)[0]["Digest"]
        manifest_b_digest = cls.registry.inspect(cls.manifest_b)[0]["Digest"]
        manifest_c_digest = cls.registry.inspect(cls.manifest_c)[0]["Digest"]
        cls.manifests_v2s2_digests = sorted(
            [manifest_a_digest, manifest_b_digest, manifest_c_digest])

        # create a new manifest list composed of the pulled manifest images
        cls.image_v2s2_tag = "manifest_list"
        cls.image_v2s2_path = f"{REGISTRY_V2_REPO_PULP}:{cls.image_v2s2_tag}"
        cls.local_v2s2_url = f"{cls.registry_name}/foo:{cls.image_v2s2_tag}"
        cls.registry._dispatch_command("manifest", "create",
                                       cls.image_v2s2_path)
        cls.registry._dispatch_command("manifest", "add", cls.image_v2s2_path,
                                       cls.manifest_a)
        cls.registry._dispatch_command("manifest", "add", cls.image_v2s2_path,
                                       cls.manifest_b)
        cls.registry._dispatch_command("manifest", "add", cls.image_v2s2_path,
                                       cls.manifest_c)

        # get digests of manifests after converting images to the OCI format by reloading them
        cls.registry._dispatch_command("save", cls.manifest_a, "--format",
                                       "oci-dir", "-o", "manifest_a.tar")
        cls.registry._dispatch_command("save", cls.manifest_b, "--format",
                                       "oci-dir", "-o", "manifest_b.tar")
        cls.registry._dispatch_command("save", cls.manifest_c, "--format",
                                       "oci-dir", "-o", "manifest_c.tar")

        cls.registry._dispatch_command("load", "-q", "-i", "manifest_a.tar")
        cls.registry._dispatch_command("load", "-q", "-i", "manifest_b.tar")
        cls.registry._dispatch_command("load", "-q", "-i", "manifest_c.tar")

        manifest_a_digest = cls.registry.inspect("manifest_a.tar")[0]["Digest"]
        manifest_b_digest = cls.registry.inspect("manifest_b.tar")[0]["Digest"]
        manifest_c_digest = cls.registry.inspect("manifest_c.tar")[0]["Digest"]
        cls.manifests_oci_digests = sorted(
            [manifest_a_digest, manifest_b_digest, manifest_c_digest])

        # create an empty manifest list
        cls.empty_image_tag = "empty_manifest_list"
        cls.empty_image_path = f"{REGISTRY_V2_REPO_PULP}:{cls.empty_image_tag}"
        cls.empty_image_local_url = f"{cls.registry_name}/foo:{cls.empty_image_tag}"
        cls.registry._dispatch_command("manifest", "create",
                                       cls.empty_image_path)
    def test_import_export(self):
        """
        Test exporting and importing of a container repository.
        """
        core_client = CoreApiClient(configuration)
        container_client = ContainerApiClient(configuration)
        remotes_api = RemotesContainerApi(container_client)
        repositories_api = RepositoriesContainerApi(container_client)
        repository_versions_api = RepositoriesContainerVersionsApi(
            container_client)
        manifests_api = ContentManifestsApi(container_client)
        exporters_api = ExportersPulpApi(core_client)
        exports_api = ExportersPulpExportsApi(core_client)
        importers_api = ImportersPulpApi(core_client)
        imports_api = ImportersPulpImportsApi(core_client)

        # Setup
        remote = remotes_api.create(gen_container_remote())
        self.addCleanup(remotes_api.delete, remote.pulp_href)
        sync_data = ContainerRepositorySyncURL(remote=remote.pulp_href)
        repository = repositories_api.create(gen_repo())
        self.addCleanup(repositories_api.delete, repository.pulp_href)
        sync_response = repositories_api.sync(repository.pulp_href, sync_data)
        monitor_task(sync_response.task).created_resources

        # Export the repository
        body = {
            "name": uuid4(),
            "path": "/tmp/{}/".format(uuid4()),
            "repositories": [repository.pulp_href],
        }
        exporter = exporters_api.create(body)
        self.addCleanup(exporters_api.delete, exporter.pulp_href)

        export_response = exports_api.create(exporter.pulp_href, {})
        export_href = monitor_task(export_response.task).created_resources[0]
        export = exports_api.read(export_href)

        # Clean the old repository out
        monitor_task(
            repository_versions_api.delete(
                repository.latest_version_href).task)
        delete_orphans()

        # Import the repository
        import_repository = repositories_api.create(gen_repo())
        self.addCleanup(repositories_api.delete, import_repository.pulp_href)

        body = {
            "name": uuid4(),
            "repo_mapping": {
                repository.name: import_repository.name
            },
        }
        importer = importers_api.create(body)
        self.addCleanup(importers_api.delete, importer.pulp_href)

        filenames = [
            f for f in list(export.output_file_info.keys())
            if f.endswith("tar.gz")
        ]
        import_response = imports_api.create(importer.pulp_href,
                                             {"path": filenames[0]})
        if hasattr(import_response, "task_group"):
            task_group_href = import_response.task_group
        else:
            task_group_href = monitor_task(
                import_response.task).created_resources[1]
        monitor_task_group(task_group_href)

        # Verify that the imported repository contains the right associations
        import_repository = repositories_api.read(import_repository.pulp_href)
        manifests = manifests_api.list(
            repository_version=import_repository.latest_version_href).results

        for manifest in manifests:
            if "manifest.list" in manifest.media_type:
                self.assertNotEqual(manifest.listed_manifests, [])
            else:
                self.assertNotEqual(manifest.blobs, [])
                self.assertIsNotNone(manifest.config_blob)