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.pushrepository_api = RepositoriesContainerPushApi(api_client)
        cls.namespace_api = PulpContainerNamespacesApi(api_client)
        cls.repo_version_api = RepositoriesContainerVersionsApi(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

        admin_user, admin_password = cfg.pulp_auth
        cls.user_admin = {"username": admin_user, "password": admin_password}
        cls.user_creator = gen_user(
            [
                "container.add_containerdistribution",
                "container.add_containernamespace",
            ]
        )
        cls.user_reader = gen_user(["container.view_containerpushrepository"])
        cls.user_helpless = gen_user([])

        # create a push repo
        image_path = f"{DOCKERHUB_PULP_FIXTURE_1}:manifest_d"
        cls._pull(image_path)
        repo_name = "testrv/perms"
        local_url = "/".join([cls.registry_name, f"{repo_name}:1.0"])
        cls._push(image_path, local_url, cls.user_creator)
        cls.repository = cls.pushrepository_api.list(name=repo_name).results[0]
Esempio n. 3
0
    def setUpClass(cls):
        """Create class-wide variables."""
        client_api = gen_container_client()
        cls.repositories_api = RepositoriesContainerApi(client_api)
        cls.remotes_api = RemotesContainerApi(client_api)
        cls.tags_api = ContentTagsApi(client_api)
        cls.versions_api = RepositoriesContainerVersionsApi(client_api)

        cls.repository = None
Esempio n. 4
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. 5
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. 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(
            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. 7
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. 8
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
    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.remotes_api = RemotesContainerApi(api_client)
        cls.tags_api = ContentTagsApi(api_client)
        cls.versions_api = RepositoriesContainerVersionsApi(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. 10
0
    def setUpClass(cls):
        """Initialize class-wide variables and create a new repository by pushing content to it."""
        cls.cfg = config.get_config()
        cls.client = api.Client(cls.cfg, api.code_handler)
        cls.registry = cli.RegistryClient(cls.cfg)
        cls.registry.raise_if_unsupported(unittest.SkipTest, "Tests require podman/docker")

        cls.registry_name = urlparse(cls.cfg.get_base_url()).netloc

        admin_user, admin_password = cls.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.distributions_api = DistributionsContainerApi(api_client)
        cls.pushrepository_api = RepositoriesContainerPushApi(api_client)
        cls.repo_version_api = RepositoriesContainerVersionsApi(api_client)
        cls.blobs_api = ContentBlobsApi(api_client)

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

        local_url = f"{cls.registry_name}/test-1:manifest_a"
        image_path = f"{REGISTRY_V2_REPO_PULP}:manifest_a"
        cls._push(image_path, local_url, cls.user_admin)

        repository = cls.pushrepository_api.list(name="test-1").results[0]
        cls.blobs = cls.blobs_api.list(repository_version=repository.latest_version_href).results
        cls.distribution = cls.distributions_api.list(name="test-1").results[0]

        cls.user_pull = gen_user(
            object_roles=[("container.containernamespace_consumer", cls.distribution.namespace)]
        )
        cls.user_push = gen_user(
            object_roles=[("container.containernamespace_collaborator", cls.distribution.namespace)]
        )
        cls.user_anon = gen_user()
    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)