Beispiel #1
0
    def test_all(self):
        """Test whether a particular repository version can be published.

        1. Create a repository with at least 2 repository versions.
        2. Create a publication by supplying the latest ``repository_version``.
        3. Assert that the publication ``repository_version`` attribute points
           to the latest repository version.
        4. Create a publication by supplying the non-latest ``repository_version``.
        5. Create distribution.
        6. Assert that the publication ``repository_version`` attribute points
           to the supplied repository version.
        7. Assert that an exception is raised when providing two different
           repository versions to be published at same time.
        """
        # Step 1
        for file_content in get_content(
                self.repo.to_dict())[FILE_CONTENT_NAME]:
            modify_repo(self.cfg,
                        self.repo.to_dict(),
                        remove_units=[file_content])
        version_hrefs = tuple(ver["pulp_href"]
                              for ver in get_versions(self.repo.to_dict()))
        non_latest = choice(version_hrefs[:-1])

        # Step 2
        publish_data = FileFilePublication(repository=self.repo.pulp_href)
        publication = self.create_publication(publish_data)

        # Step 3
        self.assertEqual(publication.repository_version, version_hrefs[-1])

        # Step 4
        publish_data = FileFilePublication(repository_version=non_latest)
        publication = self.create_publication(publish_data)

        # Step 5
        body = gen_distribution()
        body["base_path"] = "pulp_post_upgrade_test"
        body["publication"] = publication.pulp_href

        distribution_response = self.distributions.create(body)
        created_resources = monitor_task(
            distribution_response.task).created_resources
        distribution = self.distributions.read(created_resources[0])

        # Step 6
        self.assertEqual(publication.repository_version, non_latest)

        # Step 7
        with self.assertRaises(ApiException):
            body = {
                "repository": self.repo.pulp_href,
                "repository_version": non_latest
            }
            self.publications.create(body)

        # Step 8
        url = self.cfg.get_content_host_base_url(
        ) + "/pulp/content/pulp_post_upgrade_test/"
        self.assertEqual(url, distribution.base_url, url)
Beispiel #2
0
    def test_custom_manifest(self):
        """Test whether a repository version can be published with a specified manifest."""
        publish_data = FileFilePublication(repository=self.repo.pulp_href)
        publication = self.create_publication(publish_data)
        self.assertEqual(publication.manifest, "PULP_MANIFEST")

        publish_data = FileFilePublication(repository=self.repo.pulp_href, manifest="listing")
        publication = self.create_publication(publish_data)
        self.assertEqual(publication.manifest, "listing")
    def _repo_sync_distribute(self, policy="immediate"):
        """Helper to create & populate a repository and distribute it."""
        repo = self.repo_api.create(gen_repo())
        self.addCleanup(self.repo_api.delete, repo.pulp_href)

        # sync the repository with passed in policy
        body = gen_file_remote(**{"policy": policy})
        remote = self.remote_api.create(body)
        self.addCleanup(self.remote_api.delete, remote.pulp_href)

        # sync repo
        repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)
        sync_response = self.repo_api.sync(repo.pulp_href,
                                           repository_sync_data)
        monitor_task(sync_response.task)
        repo = self.repo_api.read(repo.pulp_href)

        # Publication
        publication_data = FileFilePublication(repository=repo.pulp_href)
        publication_response = self.publication_api.create(publication_data)
        task_response = monitor_task(publication_response.task)
        publication = self.publication_api.read(
            task_response.created_resources[0])
        self.addCleanup(self.publication_api.delete, publication.pulp_href)

        # Distribution
        body = gen_distribution()
        body["publication"] = publication.pulp_href
        distribution_response = self.distributions_api.create(body)
        created_resources = monitor_task(
            distribution_response.task).created_resources
        distribution = self.distributions_api.read(created_resources[0])
        self.addCleanup(self.distributions_api.delete, distribution.pulp_href)

        return repo, distribution
Beispiel #4
0
    def _setup_repositories(cls):
        """Create and sync a number of repositories to be exported."""
        # create and remember a set of repo
        repos = []
        remotes = []
        publications = []
        for r in range(NUM_REPOS):
            repo = cls.repo_api.create(gen_repo())
            remote = cls.remote_api.create(gen_file_remote())

            repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)
            sync_response = cls.repo_api.sync(repo.pulp_href,
                                              repository_sync_data)
            monitor_task(sync_response.task)

            repo = cls.repo_api.read(file_file_repository_href=repo.pulp_href)
            publish_data = FileFilePublication(repository=repo.pulp_href)
            publish_response = cls.publication_api.create(publish_data)
            created_resources = monitor_task(
                publish_response.task).created_resources
            publication_href = created_resources[0]
            publication = cls.publication_api.read(publication_href)

            repos.append(repo)
            remotes.append(remote)
            publications.append(publication)
        return repos, remotes, publications
    def do_publish(self, download_policy):
        """Publish repository synced with lazy download policy."""
        repo_api = RepositoriesFileApi(self.client)
        remote_api = RemotesFileApi(self.client)
        publications = PublicationsFileApi(self.client)

        repo = repo_api.create(gen_repo())
        self.addCleanup(repo_api.delete, repo.pulp_href)

        body = gen_file_remote(policy=download_policy)
        remote = remote_api.create(body)
        self.addCleanup(remote_api.delete, remote.pulp_href)

        repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)
        sync_response = repo_api.sync(repo.pulp_href, repository_sync_data)
        monitor_task(sync_response.task)
        repo = repo_api.read(repo.pulp_href)

        publish_data = FileFilePublication(repository=repo.pulp_href)
        publish_response = publications.create(publish_data)
        created_resources = monitor_task(
            publish_response.task).created_resources
        publication_href = created_resources[0]
        self.addCleanup(publications.delete, publication_href)
        publication = publications.read(publication_href)
        self.assertIsNotNone(publication.repository_version, publication)
    def setup_download_test(self, policy, url=None, publish=True):
        # Create a repository
        self.repo = self.repo_api.create(gen_repo())
        self.addCleanup(self.repo_api.delete, self.repo.pulp_href)

        # Create a remote
        remote_options = {"policy": policy}
        if url:
            remote_options["url"] = url

        self.remote = self.remote_api.create(gen_file_remote(**remote_options))
        self.addCleanup(self.remote_api.delete, self.remote.pulp_href)

        # Sync the repository.
        repository_sync_data = RepositorySyncURL(remote=self.remote.pulp_href)
        sync_response = self.repo_api.sync(self.repo.pulp_href, repository_sync_data)
        monitor_task(sync_response.task)

        if publish:
            # Create a publication.
            publish_data = FileFilePublication(repository=self.repo.pulp_href)
            publish_response = self.publications_api.create(publish_data)
            publication_href = monitor_task(publish_response.task).created_resources[0]
            self.addCleanup(self.publications_api.delete, publication_href)
            serve, served_href = "publication", publication_href
        else:
            serve, served_href = "repository", self.repo.pulp_href

        # Create a distribution.
        response = self.distributions_api.create(gen_distribution(**{serve: served_href}))
        distribution_href = monitor_task(response.task).created_resources[0]
        self.distribution = self.distributions_api.read(distribution_href)
        self.addCleanup(self.distributions_api.delete, self.distribution.pulp_href)
Beispiel #7
0
 def setUpClass(cls):
     """Sets up class"""
     client = gen_file_client()
     cls.cont_api = ContentFilesApi(client)
     cls.repo_api = RepositoriesFileApi(client)
     cls.remote_api = RemotesFileApi(client)
     cls.pub_api = PublicationsFileApi(client)
     cls.dis_api = DistributionsFileApi(client)
     cls.repo = cls.repo_api.create(gen_repo(autopublish=True))
     cls.remote = cls.remote_api.create(gen_file_remote())
     body = RepositorySyncURL(remote=cls.remote.pulp_href)
     created = monitor_task(
         cls.repo_api.sync(cls.repo.pulp_href, body).task).created_resources
     cls.repo = cls.repo_api.read(cls.repo.pulp_href)
     cls.pub1 = cls.pub_api.read(created[1])
     body = FileFilePublication(repository=cls.repo.pulp_href)
     cls.pub2 = cls.pub_api.read(
         monitor_task(cls.pub_api.create(body).task).created_resources[0])
     cls.pub3 = []
     response = cls.dis_api.create(
         gen_distribution(repository=cls.repo.pulp_href))
     cls.distro = cls.dis_api.read(
         monitor_task(response.task).created_resources[0])
     cls.distro2 = []
     cls.url = urljoin(PULP_CONTENT_BASE_URL, f"{cls.distro.base_path}/")
Beispiel #8
0
    def test_all(self):
        """Test whether a particular repository version can be published.

        1. Create a repository with at least 2 repository versions.
        2. Create a publication by supplying the latest ``repository_version``.
        3. Assert that the publication ``repository_version`` attribute points
           to the latest repository version.
        4. Create a publication by supplying the non-latest ``repository_version``.
        5. Assert that the publication ``repository_version`` attribute points
           to the supplied repository version.
        6. Assert that an exception is raised when providing two different
           repository versions to be published at same time.
        """
        # Step 1
        for file_content in get_content(
                self.repo.to_dict())[FILE_CONTENT_NAME]:
            modify_repo(self.cfg,
                        self.repo.to_dict(),
                        remove_units=[file_content])
        version_hrefs = tuple(ver["pulp_href"]
                              for ver in get_versions(self.repo.to_dict()))
        non_latest = choice(version_hrefs[:-1])

        # Step 2
        publish_data = FileFilePublication(repository=self.repo.pulp_href)
        publication = self.create_publication(publish_data)

        # Step 3
        self.assertEqual(publication.repository_version, version_hrefs[-1])

        # Step 4
        publish_data = FileFilePublication(repository_version=non_latest)
        publication = self.create_publication(publish_data)

        # Step 5
        self.assertEqual(publication.repository_version, non_latest)

        # Step 6
        with self.assertRaises(ApiException):
            body = {
                "repository": self.repo.pulp_href,
                "repository_version": non_latest
            }
            self.publications.create(body)
Beispiel #9
0
    def setUpClass(cls):
        """
        Initialize Pulp to make authorization assertions using client certificates.

        0. Create a FileRepository
        1. Create a FileRemote
        2. Sync in a few units we can use to fetch with
        3. Create a Publication
        4. Create a CertGuard with the CA cert used to sign all client certificates
        5. Create a Distribution for the publication that is protected by the CertGuard

        """
        cls.teardown_cleanups = []
        cls.cfg = config.get_config()

        file_client = gen_file_client()
        repo_api = RepositoriesFileApi(file_client)
        remote_api = RemotesFileApi(file_client)
        publications = PublicationsFileApi(file_client)
        cls.distributions_api = DistributionsFileApi(file_client)

        cls.repo = repo_api.create(gen_repo())
        cls.teardown_cleanups.append((repo_api.delete, cls.repo.pulp_href))

        body = gen_file_remote(policy="immediate")
        remote = remote_api.create(body)
        cls.teardown_cleanups.append((remote_api.delete, remote.pulp_href))

        # Sync a Repository
        repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)
        sync_response = repo_api.sync(cls.repo.pulp_href, repository_sync_data)
        monitor_task(sync_response.task)
        cls.repo = repo_api.read(cls.repo.pulp_href)

        # Create a publication.
        publish_data = FileFilePublication(repository=cls.repo.pulp_href)
        publish_response = publications.create(publish_data)
        created_resources = monitor_task(publish_response.task)
        publication_href = created_resources[0]
        cls.teardown_cleanups.append((publications.delete, publication_href))

        content_guard_href = cls._setup_content_guard()

        # Create a distribution.
        body = gen_distribution()
        body["publication"] = publication_href
        body["content_guard"] = content_guard_href
        distribution_response = cls.distributions_api.create(body)
        created_resources = monitor_task(distribution_response.task)
        cls.distribution = cls.distributions_api.read(created_resources[0])
        cls.teardown_cleanups.append((cls.distributions_api.delete, cls.distribution.pulp_href))
Beispiel #10
0
    def test_access_error(self):
        """HTTP error is not raised when accessing published data."""
        repo_api = RepositoriesFileApi(self.client)
        remote_api = RemotesFileApi(self.client)
        publications = PublicationsFileApi(self.client)
        distributions = DistributionsFileApi(self.client)

        repo = repo_api.create(gen_repo())
        self.addCleanup(repo_api.delete, repo.pulp_href)

        remote = remote_api.create(gen_file_remote())
        self.addCleanup(remote_api.delete, remote.pulp_href)

        repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)
        sync_response = repo_api.sync(repo.pulp_href, repository_sync_data)
        monitor_task(sync_response.task)
        repo = repo_api.read(repo.pulp_href)

        publish_data = FileFilePublication(repository=repo.pulp_href)
        publish_response = publications.create(publish_data)
        created_resources = monitor_task(
            publish_response.task).created_resources
        publication_href = created_resources[0]
        self.addCleanup(publications.delete, publication_href)

        body = gen_distribution()
        body["publication"] = publication_href

        distribution_response = distributions.create(body)
        created_resources = monitor_task(
            distribution_response.task).created_resources
        distribution = distributions.read(created_resources[0])
        self.addCleanup(distributions.delete, distribution.pulp_href)

        pulp_manifest = parse_pulp_manifest(
            self.download_pulp_manifest(distribution.to_dict(),
                                        "PULP_MANIFEST"))

        self.assertEqual(len(pulp_manifest), FILE_FIXTURE_COUNT, pulp_manifest)
    def test_all(self):
        """Create two publications and check view filter."""
        repo = self.repo_api.create(gen_repo())
        self.addCleanup(self.repo_api.delete, repo.pulp_href)

        remote = self.remote_api.create(gen_file_remote())
        self.addCleanup(self.remote_api.delete, remote.pulp_href)

        # Sync and update repository data.
        repo_sync_data = RepositorySyncURL(remote=remote.pulp_href)
        sync_response = self.repo_api.sync(repo.pulp_href, repo_sync_data)
        monitor_task(sync_response.task)
        repo = self.repo_api.read(repo.pulp_href)

        # Test content doesn't exists.
        non_existant_content_href = (
            "/pulp/api/v3/content/file/files/c4ed74cf-a806-490d-a25f-94c3c3dd2dd7/"
        )
        with self.assertRaises(ApiException) as ctx:
            self.publication_api.list(content=non_existant_content_href)
        self.assertEqual(ctx.exception.status, 400)

        # Test not published content.
        content_href = get_content(
            repo.to_dict())[FILE_CONTENT_NAME][0]["pulp_href"]
        self.assertEqual(
            self.publication_api.list(content=content_href).to_dict()["count"],
            0)

        # Publication
        publication_data = FileFilePublication(repository=repo.pulp_href)
        publication_response = self.publication_api.create(publication_data)
        task_response = monitor_task(publication_response.task)
        publication = self.publication_api.read(
            task_response.created_resources[0])
        self.addCleanup(self.publication_api.delete, publication.pulp_href)

        # Second publication
        repo_second = self.repo_api.create(gen_repo())
        self.addCleanup(self.repo_api.delete, repo_second.pulp_href)

        body = gen_file_remote(url=FILE_MANY_FIXTURE_MANIFEST_URL)
        remote_second = self.remote_api.create(body)
        self.addCleanup(self.remote_api.delete, remote_second.pulp_href)

        repo_second_sync_data = RepositorySyncURL(
            remote=remote_second.pulp_href)
        sync_response = self.repo_api.sync(repo_second.pulp_href,
                                           repo_second_sync_data)
        monitor_task(sync_response.task)
        repo_second = self.repo_api.read(repo_second.pulp_href)

        publication_data = FileFilePublication(
            repository=repo_second.pulp_href)
        publication_response = self.publication_api.create(publication_data)
        task_response = monitor_task(publication_response.task)
        publication_second = self.publication_api.read(
            task_response.created_resources[0])
        self.addCleanup(self.publication_api.delete,
                        publication_second.pulp_href)

        # Test there are two publications
        self.assertEqual(self.publication_api.list().count, 2)

        # Test content match publication
        self.assertEqual(
            self.publication_api.list(content=content_href).count, 1)
        self.assertEqual(
            self.publication_api.list(
                content=content_href).results[0].repository_version,
            repo.latest_version_href,
        )
Beispiel #12
0
    def test_all(self):
        """Test whether a particular repository version can be published.

        1. Create a repository with at least 2 repository versions.
        2. Create a publication by supplying the latest ``repository_version``.
        3. Assert that the publication ``repository_version`` attribute points
           to the latest repository version.
        4. Create a publication by supplying the non-latest ``repository_version``.
        5. Assert that the publication ``repository_version`` attribute points
           to the supplied repository version.
        6. Assert that an exception is raised when providing two different
           repository versions to be published at same time.
        """
        cfg = config.get_config()
        client = gen_file_client()
        repo_api = RepositoriesFileApi(client)
        remote_api = RemotesFileApi(client)
        publications = PublicationsFileApi(client)

        body = gen_file_remote()
        remote = remote_api.create(body)
        self.addCleanup(remote_api.delete, remote.pulp_href)

        repo = repo_api.create(gen_repo())
        self.addCleanup(repo_api.delete, repo.pulp_href)

        repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)
        sync_response = repo_api.sync(repo.pulp_href, repository_sync_data)
        monitor_task(sync_response.task)

        # Step 1
        repo = repo_api.read(repo.pulp_href)
        for file_content in get_content(repo.to_dict())[FILE_CONTENT_NAME]:
            modify_repo(cfg, repo.to_dict(), remove_units=[file_content])
        version_hrefs = tuple(ver["pulp_href"]
                              for ver in get_versions(repo.to_dict()))
        non_latest = choice(version_hrefs[:-1])

        # Step 2
        publish_data = FileFilePublication(repository=repo.pulp_href)
        publish_response = publications.create(publish_data)
        created_resources = monitor_task(publish_response.task)
        publication_href = created_resources[0]
        self.addCleanup(publications.delete, publication_href)
        publication = publications.read(publication_href)

        # Step 3
        self.assertEqual(publication.repository_version, version_hrefs[-1])

        # Step 4
        publish_data = FileFilePublication(repository_version=non_latest)
        publish_response = publications.create(publish_data)
        created_resources = monitor_task(publish_response.task)
        publication_href = created_resources[0]
        publication = publications.read(publication_href)

        # Step 5
        self.assertEqual(publication.repository_version, non_latest)

        # Step 6
        with self.assertRaises(ApiException):
            body = {
                "repository": repo.pulp_href,
                "repository_version": non_latest
            }
            publications.create(body)
Beispiel #13
0
# Create a FileContent from the artifact
filecontent_response = filecontent.create(relative_path="foo.tar.gz", artifact=artifact.pulp_href)
created_resources = monitor_task(filecontent_response.task)

# Add the new FileContent to a repository version
repo_version_data = {"add_content_units": [created_resources[0]]}
repo_version_response = filerepositories.modify(repository.pulp_href, repo_version_data)

# Monitor the repo version creation task
created_resources = monitor_task(repo_version_response.task)

repository_version_2 = filerepoversions.read(created_resources[0])
pprint(repository_version_2)

# List all the repository versions
filerepoversions.list(repository.pulp_href)

# Create a publication from the latest version of the repository
publish_data = FileFilePublication(repository=repository.pulp_href)
publish_response = filepublications.create(publish_data)

# Monitor the publish task
created_resources = monitor_task(publish_response.task)
publication_href = created_resources[0]

distribution_data = FileFileDistribution(
    name="baz25", base_path="foo25", publication=publication_href
)
distribution = filedistributions.create(distribution_data)
pprint(distribution)
    def do_test(self, policy):
        """Verify whether content served by pulp can be downloaded.

        The process of publishing content is more involved in Pulp 3 than it
        was under Pulp 2. Given a repository, the process is as follows:

        1. Create a publication from the repository. (The latest repository
           version is selected if no version is specified.) A publication is a
           repository version plus metadata.
        2. Create a distribution from the publication. The distribution defines
           at which URLs a publication is available, e.g.
           ``http://example.com/content/foo/`` and
           ``http://example.com/content/bar/``.

        Do the following:

        1. Create, populate, publish, and distribute a repository.
        2. Select a random content unit in the distribution. Download that
           content unit from Pulp, and verify that the content unit has the
           same checksum when fetched directly from Pulp-Fixtures.

        This test targets the following issues:

        * `Pulp #2895 <https://pulp.plan.io/issues/2895>`_
        * `Pulp Smash #872 <https://github.com/pulp/pulp-smash/issues/872>`_
        """
        cfg = config.get_config()
        client = gen_file_client()
        repo_api = RepositoriesFileApi(client)
        remote_api = RemotesFileApi(client)
        publications = PublicationsFileApi(client)
        distributions = DistributionsFileApi(client)

        repo = repo_api.create(gen_repo())
        self.addCleanup(repo_api.delete, repo.pulp_href)

        body = gen_file_remote(policy=policy)
        remote = remote_api.create(body)
        self.addCleanup(remote_api.delete, remote.pulp_href)

        # Sync a Repository
        repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)
        sync_response = repo_api.sync(repo.pulp_href, repository_sync_data)
        monitor_task(sync_response.task)
        repo = repo_api.read(repo.pulp_href)

        # Create a publication.
        publish_data = FileFilePublication(repository=repo.pulp_href)
        publish_response = publications.create(publish_data)
        created_resources = monitor_task(publish_response.task)
        publication_href = created_resources[0]
        self.addCleanup(publications.delete, publication_href)

        # Create a distribution.
        body = gen_distribution()
        body["publication"] = publication_href
        distribution_response = distributions.create(body)
        created_resources = monitor_task(distribution_response.task)
        distribution = distributions.read(created_resources[0])
        self.addCleanup(distributions.delete, distribution.pulp_href)

        # Pick a file, and download it from both Pulp Fixtures…
        unit_path = choice(get_file_content_paths(repo.to_dict()))
        fixtures_hash = hashlib.sha256(
            utils.http_get(urljoin(FILE_FIXTURE_URL, unit_path))).hexdigest()

        # …and Pulp.
        content = download_content_unit(cfg, distribution.to_dict(), unit_path)
        pulp_hash = hashlib.sha256(content).hexdigest()

        self.assertEqual(fixtures_hash, pulp_hash)