コード例 #1
0
    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)
コード例 #2
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)
コード例 #3
0
class RepoVersionRetentionTestCase(unittest.TestCase):
    """Test retain_repo_versions for repositories

    This test targets the following issues:

    *  `Pulp #8368 <https:://pulp.plan.io/issues/8368>`_
    """

    @classmethod
    def setUp(self):
        """Add content to Pulp."""
        self.cfg = config.get_config()
        self.client = api.Client(self.cfg, api.json_handler)
        self.core_client = CoreApiClient(configuration=self.cfg.get_bindings_config())
        self.file_client = gen_file_client()

        self.content_api = ContentFilesApi(self.file_client)
        self.repo_api = RepositoriesFileApi(self.file_client)
        self.version_api = RepositoriesFileVersionsApi(self.file_client)
        self.distro_api = DistributionsFileApi(self.file_client)
        self.publication_api = PublicationsFileApi(self.file_client)

        delete_orphans()
        populate_pulp(self.cfg, url=FILE_LARGE_FIXTURE_MANIFEST_URL)
        self.content = sample(self.content_api.list().results, 3)
        self.publications = []

    def _create_repo_versions(self, repo_attributes={}):
        self.repo = self.repo_api.create(gen_repo(**repo_attributes))
        self.addCleanup(self.repo_api.delete, self.repo.pulp_href)

        if "autopublish" in repo_attributes and repo_attributes["autopublish"]:
            self.distro = create_distribution(repository_href=self.repo.pulp_href)
            self.addCleanup(self.distro_api.delete, self.distro.pulp_href)

        for content in self.content:
            result = self.repo_api.modify(
                self.repo.pulp_href, {"add_content_units": [content.pulp_href]}
            )
            monitor_task(result.task)
            self.repo = self.repo_api.read(self.repo.pulp_href)
            self.publications += self.publication_api.list(
                repository_version=self.repo.latest_version_href
            ).results

    def test_retain_repo_versions(self):
        """Test repo version retention."""
        self._create_repo_versions({"retain_repo_versions": 1})

        versions = self.version_api.list(file_file_repository_href=self.repo.pulp_href).results
        self.assertEqual(len(versions), 1)

        latest_version = self.version_api.read(
            file_file_repository_version_href=self.repo.latest_version_href
        )
        self.assertEqual(latest_version.number, 3)
        self.assertEqual(latest_version.content_summary.present["file.file"]["count"], 3)
        self.assertEqual(latest_version.content_summary.added["file.file"]["count"], 3)

    def test_retain_repo_versions_on_update(self):
        """Test repo version retention when retain_repo_versions is set."""
        self._create_repo_versions()

        versions = self.version_api.list(file_file_repository_href=self.repo.pulp_href).results
        self.assertEqual(len(versions), 4)

        # update retain_repo_versions to 2
        result = self.repo_api.partial_update(self.repo.pulp_href, {"retain_repo_versions": 2})
        monitor_task(result.task)

        versions = self.version_api.list(file_file_repository_href=self.repo.pulp_href).results
        self.assertEqual(len(versions), 2)

        latest_version = self.version_api.read(
            file_file_repository_version_href=self.repo.latest_version_href
        )
        self.assertEqual(latest_version.number, 3)
        self.assertEqual(latest_version.content_summary.present["file.file"]["count"], 3)
        self.assertEqual(latest_version.content_summary.added["file.file"]["count"], 1)

    def test_autodistribute(self):
        """Test repo version retention with autopublish/autodistribute."""
        self._create_repo_versions({"retain_repo_versions": 1, "autopublish": True})

        # all but the last publication should be gone
        for publication in self.publications[:-1]:
            with self.assertRaises(ApiException) as ae:
                self.publication_api.read(publication.pulp_href)
            self.assertEqual(404, ae.exception.status)

        # check that the last publication is distributed
        manifest = download_content_unit(self.cfg, self.distro.to_dict(), "PULP_MANIFEST")
        self.assertEqual(manifest.decode("utf-8").count("\n"), len(self.content))