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.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=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)

        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.distribution1 = cls.distributions_api.read(created_resources[0])

        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.distribution2 = cls.distributions_api.read(created_resources[0])
    def setUpClass(cls):
        """Create class wide-variables."""
        super().setUpClass()

        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.distribution1 = cls.distributions_api.read(created_resources[0])

        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.distribution2 = cls.distributions_api.read(created_resources[0])
    def test_02_create_same_name(self):
        """Try to create a second distribution with an identical name.

        See: `Pulp Smash #1055
        <https://github.com/pulp/pulp-smash/issues/1055>`_.
        """
        body = gen_distribution()
        body["name"] = self.distribution["name"]
        distribution_data = ContainerContainerDistribution(**body)
        with self.assertRaises(ApiException):
            self.distribution_api.create(distribution_data)
    def test_01_create_distribution(self):
        """Create a distribution."""
        body = gen_distribution()
        distribution_data = ContainerContainerDistribution(**body)
        distribution_response = self.distribution_api.create(distribution_data)
        created_resources = monitor_task(distribution_response.task)

        distribution_obj = self.distribution_api.read(created_resources[0])
        self.distribution.update(distribution_obj.to_dict())
        for key, val in body.items():
            with self.subTest(key=key):
                self.assertEqual(self.distribution[key], val)
    def setUpClass(cls):
        """Create class-wide variables."""
        client_api = gen_container_client()
        cls.distribution_api = DistributionsContainerApi(client_api)

        body = gen_distribution()
        body["base_path"] = body["base_path"].replace("-", "/")
        distribution_data = ContainerContainerDistribution(**body)
        distribution_response = cls.distribution_api.create(distribution_data)
        created_resources = monitor_task(distribution_response.task)

        cls.distribution = cls.distribution_api.read(created_resources[0])
Esempio n. 6
0
    def setUpClass(cls):
        """Create class wide-variables."""
        super().setUpClass()

        distribution_data = gen_distribution(
            repository=cls.repository.pulp_href, private=True)
        distribution_response = cls.distributions_api.create(
            ContainerContainerDistribution(**distribution_data))
        created_resources = monitor_task(
            distribution_response.task).created_resources
        cls.distribution1 = cls.distributions_api.read(created_resources[0])
        cls.namespace1 = cls.namespaces_api.read(cls.distribution1.namespace)

        distribution_data = gen_distribution(
            repository=cls.repository.pulp_href, private=True)
        distribution_response = cls.distributions_api.create(
            ContainerContainerDistribution(**distribution_data))
        created_resources = monitor_task(
            distribution_response.task).created_resources
        cls.distribution2 = cls.distributions_api.read(created_resources[0])

        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.distribution3 = cls.distributions_api.read(created_resources[0])

        cls.user_none = gen_user()
        cls.user_all = gen_user(model_roles=[
            "container.containerdistribution_consumer",
            "container.containernamespace_consumer",
        ])
        cls.user_only_dist1 = gen_user(object_roles=[
            ("container.containerdistribution_consumer",
             cls.distribution1.pulp_href),
            ("container.containernamespace_consumer",
             cls.namespace1.pulp_href),
        ])
    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 = RepositorySyncURL(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()
    def test_04_fully_update(self):
        """Update a distribution using HTTP PUT."""
        body = gen_distribution()
        distribution_data = ContainerContainerDistribution(**body)
        distribution_response = self.distribution_api.update(
            self.distribution["pulp_href"], distribution_data)
        monitor_task(distribution_response.task)

        distribution_obj = self.distribution_api.read(
            self.distribution["pulp_href"])

        self.distribution.clear()
        self.distribution.update(distribution_obj.to_dict())
        for key, val in body.items():
            with self.subTest(key=key):
                self.assertEqual(self.distribution[key], val)
Esempio n. 9
0
    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 = RepositorySyncURL(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()