def setUpClass(cls):
        """Create class wide-variables."""
        cls.cfg = config.get_config()
        cls.client = api.Client(cls.cfg, api.page_handler)

        api_client = gen_container_client()
        cls.repositories_api = RepositoriesContainerApi(api_client)
        cls.remotes_api = RemotesContainerApi(api_client)
        cls.distributions_api = DistributionsContainerApi(api_client)

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

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

        sync_data = ContainerRepositorySyncURL(remote=cls.remote.pulp_href)
        sync_response = cls.repositories_api.sync(cls.repository.pulp_href,
                                                  sync_data)
        monitor_task(sync_response.task)

        distribution_data = gen_distribution(
            repository=cls.repository.pulp_href)
        distribution_response = cls.distributions_api.create(
            ContainerContainerDistribution(**distribution_data))
        created_resources = monitor_task(
            distribution_response.task).created_resources
        cls.distribution = cls.distributions_api.read(created_resources[0])
Example #2
0
    def test_all(self):
        """
        Sync a repository using a Remote url that does not exist.

        Test that we get a task failure.

        """
        client_api = gen_container_client()

        repository_api = RepositoriesContainerApi(client_api)
        repository = repository_api.create(
            ContainerContainerRepository(**gen_repo()))
        self.addCleanup(repository_api.delete, repository.pulp_href)

        remote_api = RemotesContainerApi(client_api)
        remote_data = gen_container_remote(
            url="http://i-am-an-invalid-url.com/invalid/")
        remote = remote_api.create(ContainerContainerRemote(**remote_data))
        self.addCleanup(remote_api.delete, remote.pulp_href)

        repository_sync_data = ContainerRepositorySyncURL(
            remote=remote.pulp_href)
        sync_response = repository_api.sync(repository.pulp_href,
                                            repository_sync_data)

        with self.assertRaises(PulpTaskError) as context:
            monitor_task(sync_response.task)
        self.assertIsNotNone(context.exception.task.error["description"])
Example #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)
    def setUpClass(cls):
        """Create class-wide variables.

        1. Create a repository.
        2. Create a remote pointing to external registry.
        3. Sync the repository using the remote and re-read the repo data.
        4. Create a container distribution to serve the repository

        This tests targets the following issue:

        * `Pulp #4460 <https://pulp.plan.io/issues/4460>`_
        """
        cls.cfg = config.get_config()
        cls.registry_name = urlparse(cls.cfg.get_base_url()).netloc

        cls.client = api.Client(cls.cfg, api.code_handler)
        client_api = gen_container_client()
        cls.repositories_api = RepositoriesContainerApi(client_api)
        cls.remotes_api = RemotesContainerApi(client_api)
        cls.distributions_api = DistributionsContainerApi(client_api)

        with contextlib.ExitStack() as stack:
            # ensure tearDownClass runs if an error occurs here
            stack.callback(cls.tearDownClass)

            # Step 1
            _repo = cls.repositories_api.create(
                ContainerContainerRepository(**gen_repo()))

            # Step 2
            cls.remote = cls.remotes_api.create(gen_container_remote())

            # Step 3
            sync_data = ContainerRepositorySyncURL(remote=cls.remote.pulp_href)
            sync_response = cls.repositories_api.sync(_repo.pulp_href,
                                                      sync_data)
            monitor_task(sync_response.task)
            cls.repo = cls.repositories_api.read(_repo.pulp_href)

            # Step 4.
            distribution_response = cls.distributions_api.create(
                ContainerContainerDistribution(
                    **gen_distribution(repository=cls.repo.pulp_href,
                                       base_path="pulp_pre_upgrade_test")))
            created_resources = monitor_task(
                distribution_response.task).created_resources
            distribution = cls.distributions_api.read(created_resources[0])
            cls.distribution_with_repo = cls.distributions_api.read(
                distribution.pulp_href)

            # remove callback if everything goes well
            stack.pop_all()
Example #5
0
    def test_sync_idempotency(self):
        """Ensure that sync does not create orphan tags https://pulp.plan.io/issues/5252 ."""
        sync_data = ContainerRepositorySyncURL(remote=self.remote.pulp_href)
        sync_response = self.repository_api.sync(self.from_repo.pulp_href,
                                                 sync_data)
        monitor_task(sync_response.task)

        tags_api = ContentTagsApi(self.client_api)
        first_sync_tags_named_a = tags_api.list(name="manifest_a")

        sync_response = self.repository_api.sync(self.from_repo.pulp_href,
                                                 sync_data)
        monitor_task(sync_response.task)

        second_sync_tags_named_a = tags_api.list(name="manifest_a")

        self.assertEqual(first_sync_tags_named_a.count, 1)
        self.assertEqual(second_sync_tags_named_a.count, 1)
Example #6
0
def populate_pulp(url=REGISTRY_V2_FEED_URL):
    """Add container contents to Pulp.

    :param url: The container repository URL. Defaults to
        :data:`pulp_container.tests.functional.constants.REGISTRY_V2_FEED_URL`
    :returns: A dictionary of created resources.
    """
    container_client = ContainerApiClient(configuration)
    remotes_api = RemotesContainerApi(container_client)
    repositories_api = RepositoriesContainerApi(container_client)

    container_remote = remotes_api.create(gen_container_remote(url))
    sync_data = ContainerRepositorySyncURL(remote=container_remote.pulp_href)
    container_repository = repositories_api.create(gen_repo())
    sync_response = repositories_api.sync(container_repository.pulp_href,
                                          sync_data)

    return monitor_task(sync_response.task).created_resources
Example #7
0
    def test_sync(self):
        """Sync repositories with the container plugin.

        In order to sync a repository a remote has to be associated within
        this repository. When a repository is created this version field is set
        as None. After a sync the repository version is updated.

        Do the following:

        1. Create a repository, and a remote.
        2. Assert that repository version is None.
        3. Sync the remote.
        4. Assert that repository version is not None.
        5. Sync the remote one more time.
        6. Assert that repository version is the same from the previous one.
        """
        repository_api = RepositoriesContainerApi(self.client_api)
        repository = repository_api.create(
            ContainerContainerRepository(**gen_repo()))
        self.addCleanup(repository_api.delete, repository.pulp_href)

        remote_api = RemotesContainerApi(self.client_api)
        remote = remote_api.create(gen_container_remote())
        self.addCleanup(remote_api.delete, remote.pulp_href)

        self.assertEqual(repository.latest_version_href,
                         f"{repository.pulp_href}versions/0/")
        repository_sync_data = ContainerRepositorySyncURL(
            remote=remote.pulp_href)

        # Sync the repository.
        sync_response = repository_api.sync(repository.pulp_href,
                                            repository_sync_data)
        monitor_task(sync_response.task)
        repository = repository_api.read(repository.pulp_href)
        self.assertIsNotNone(repository.latest_version_href)

        # Sync the repository again.
        latest_version_href = repository.latest_version_href
        sync_response = repository_api.sync(repository.pulp_href,
                                            repository_sync_data)
        monitor_task(sync_response.task)
        repository = repository_api.read(repository.pulp_href)
        self.assertEqual(latest_version_href, repository.latest_version_href)
Example #8
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)
    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=PULP_FIXTURE_1)
        cls.remote = cls.remotes_api.create(
            ContainerContainerRemote(**remote_data))

        sync_data = ContainerRepositorySyncURL(remote=cls.remote.pulp_href)
        sync_response = cls.repositories_api.sync(cls.repository.pulp_href,
                                                  sync_data)
        monitor_task(sync_response.task)
Example #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.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=PULP_FIXTURE_1)
        cls.remote = cls.remotes_api.create(
            ContainerContainerRemote(**remote_data))

        sync_data = ContainerRepositorySyncURL(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
Example #11
0
    def setUpClass(cls):
        """Create class wide-variables."""
        api_client = gen_container_client()
        cls.repositories_api = RepositoriesContainerApi(api_client)
        cls.remotes_api = RemotesContainerApi(api_client)
        cls.distributions_api = DistributionsContainerApi(api_client)
        cls.namespaces_api = PulpContainerNamespacesApi(api_client)

        cls.cfg = config.get_config()
        cls.client = api.Client(cls.cfg, api.json_handler)

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

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

        sync_data = ContainerRepositorySyncURL(remote=cls.remote.pulp_href)
        sync_response = cls.repositories_api.sync(cls.repository.pulp_href,
                                                  sync_data)
        monitor_task(sync_response.task)
Example #12
0
    def sync_repository_with_filtered_tags(self,
                                           include_tags=None,
                                           exclude_tags=None):
        """Sync a new repository with the included tags passed as an argument."""
        self.repository = self.repositories_api.create(
            ContainerContainerRepository(**gen_repo()))
        self.addCleanup(self.repositories_api.delete,
                        self.repository.pulp_href)

        remote_data = gen_container_remote(
            upstream_name=PULP_FIXTURE_1,
            include_tags=include_tags,
            exclude_tags=exclude_tags,
        )
        remote = self.remotes_api.create(remote_data)
        self.addCleanup(self.remotes_api.delete, remote.pulp_href)

        repository_sync_data = ContainerRepositorySyncURL(
            remote=remote.pulp_href)

        sync_response = self.repositories_api.sync(self.repository.pulp_href,
                                                   repository_sync_data)
        monitor_task(sync_response.task)
    def setUpClass(cls):
        """
        Define APIs to use and pull images needed later in tests
        """
        api_client = gen_container_client()
        cfg = config.get_config()

        cls.repository_api = RepositoriesContainerApi(api_client)
        cls.pushrepository_api = RepositoriesContainerPushApi(api_client)
        cls.tags_api = ContentTagsApi(api_client)

        cls.namespace_api = PulpContainerNamespacesApi(api_client)
        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(model_roles=[
            "container.containernamespace_creator",
            "container.containerremote_creator",
            "container.containerrepository_creator",
        ], )
        cls.user_creator2 = gen_user(model_roles=[
            "container.containernamespace_creator",
            "container.containerremote_creator",
        ])
        cls.user_reader = gen_user(model_roles=[
            "container.containerrepository_viewer",
            "container.containerdistribution_consumer",
        ])
        cls.user_reader2 = gen_user(
            model_roles=["container.containerrepository_viewer"])
        cls.user_reader3 = gen_user(
            model_roles=["container.containerdistribution_consumer"])
        cls.user_helpless = gen_user()

        # create a push repo with user_creator
        image_path = f"{REGISTRY_V2_REPO_PULP}:manifest_a"
        cls._pull(image_path)
        repo_name = "testcontent/perms"
        local_url = "/".join([cls.registry_name, f"{repo_name}:1.0"])
        cls._push(image_path, local_url, cls.user_creator)
        cls.push_repository = cls.pushrepository_api.list(
            name=repo_name).results[0]

        # create a second push repo with user_creator2
        image_path = f"{REGISTRY_V2_REPO_PULP}:manifest_b"
        cls._pull(image_path)
        repo_name = "testcontent2/perms"
        local_url = "/".join([cls.registry_name, f"{repo_name}:1.0"])
        cls._push(image_path, local_url, cls.user_creator2)
        cls.push_repository2 = cls.pushrepository_api.list(
            name=repo_name).results[0]

        # sync a repo with user_creator
        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)
    def setUpClass(cls):
        """Create class-wide variables and delete orphans.

        1. Create a repository.
        2. Create a remote pointing to external registry with policy=on_demand.
        3. Sync the repository using the remote and re-read the repo data.
        4. Create a container distribution to serve the repository
        5. Create another container distribution to the serve the repository version

        This tests targets the following issue:

        * `Pulp #4460 <https://pulp.plan.io/issues/4460>`_
        """
        cls.cfg = config.get_config()
        cls.registry_name = urlparse(cls.cfg.get_base_url()).netloc

        client_api = gen_container_client()
        cls.repositories_api = RepositoriesContainerApi(client_api)
        cls.remotes_api = RemotesContainerApi(client_api)
        cls.distributions_api = DistributionsContainerApi(client_api)

        cls.teardown_cleanups = []

        delete_orphans()

        with contextlib.ExitStack() as stack:
            # ensure tearDownClass runs if an error occurs here
            stack.callback(cls.tearDownClass)

            # Step 1
            _repo = cls.repositories_api.create(
                ContainerContainerRepository(**gen_repo()))
            cls.teardown_cleanups.append(
                (cls.repositories_api.delete, _repo.pulp_href))

            # Step 2
            cls.remote = cls.remotes_api.create(
                gen_container_remote(policy="on_demand"))
            cls.teardown_cleanups.append(
                (cls.remotes_api.delete, cls.remote.pulp_href))

            # Step 3
            sync_data = ContainerRepositorySyncURL(remote=cls.remote.pulp_href)
            sync_response = cls.repositories_api.sync(_repo.pulp_href,
                                                      sync_data)
            monitor_task(sync_response.task)

            cls.repo = cls.repositories_api.read(_repo.pulp_href)
            cls.artifacts_api = ArtifactsApi(core_client)
            cls.artifact_count = cls.artifacts_api.list().count

            # Step 4.
            distribution_response = cls.distributions_api.create(
                ContainerContainerDistribution(**gen_distribution(
                    repository=cls.repo.pulp_href)))
            created_resources = monitor_task(
                distribution_response.task).created_resources

            distribution = cls.distributions_api.read(created_resources[0])
            cls.distribution_with_repo = cls.distributions_api.read(
                distribution.pulp_href)
            cls.teardown_cleanups.append(
                (cls.distributions_api.delete,
                 cls.distribution_with_repo.pulp_href))

            # Step 5.
            distribution_response = cls.distributions_api.create(
                ContainerContainerDistribution(**gen_distribution(
                    repository_version=cls.repo.latest_version_href)))
            created_resources = monitor_task(
                distribution_response.task).created_resources
            distribution = cls.distributions_api.read(created_resources[0])
            cls.distribution_with_repo_version = cls.distributions_api.read(
                distribution.pulp_href)
            cls.teardown_cleanups.append(
                (cls.distributions_api.delete,
                 cls.distribution_with_repo_version.pulp_href))

            # remove callback if everything goes well
            stack.pop_all()
    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)