Ejemplo n.º 1
0
    def do_test(self, policy):
        """Access lazy synced content on using content endpoint."""
        # delete orphans to assure that no content units are present on the
        # file system
        delete_orphans()
        content_api = ContentFilesApi(self.client)
        repo_api = RepositoriesFileApi(self.client)
        remote_api = RemotesFileApi(self.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 the repository.
        self.assertEqual(repo.latest_version_href,
                         f"{repo.pulp_href}versions/0/")
        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)

        # Assert that no HTTP error was raised.
        # Assert that the number of units present is according to the synced
        # feed.
        content = content_api.list().to_dict()["results"]
        self.assertEqual(len(content), FILE_FIXTURE_COUNT, content)
Ejemplo n.º 2
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)
            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
Ejemplo n.º 3
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)
        publication_href = created_resources[0]
        self.addCleanup(publications.delete, publication_href)
        publication = publications.read(publication_href)
        self.assertIsNotNone(publication.repository_version, publication)
Ejemplo n.º 4
0
 def test_03_duplicate_content_unit(self):
     """Create content unit."""
     attrs = self.attrs.copy()
     attrs["relative_path"] = utils.uuid4()
     response = self.file_content_api.create(**attrs, file=__file__)
     monitor_task(response.task)
     task = tasks.read(response.task)
     self.assertEqual(task.state, "completed")
Ejemplo n.º 5
0
 def _create_export(cls):
     export_response = cls.exports_api.create(cls.exporter.pulp_href, {})
     monitor_task(export_response.task)
     task = cls.client.get(export_response.task)
     resources = task["created_resources"]
     export_href = resources[0]
     export = cls.exports_api.read(export_href)
     return export
Ejemplo n.º 6
0
    def _gen_export(self, exporter, publication):
        """Create and read back an export for the specified FilesystemExporter."""
        body = {"publication": publication.pulp_href}
        export_response = self.exports_api.create(exporter.pulp_href, body)
        monitor_task(export_response.task)

        task = self.client.get(export_response.task)
        resources = task["created_resources"]
        self.assertEqual(1, len(resources))

        return self.exports_api.read(resources[0])
Ejemplo n.º 7
0
 def test_04_fully_update(self):
     """Update a remote using HTTP PUT."""
     body = _gen_verbose_remote()
     response = self.remote_api.update(self.remote.pulp_href, body)
     monitor_task(response.task)
     for key in ("username", "password"):
         del body[key]
     type(self).remote = self.remote_api.read(self.remote.pulp_href)
     for key, val in body.items():
         with self.subTest(key=key):
             self.assertEqual(self.remote.to_dict()[key], val, key)
Ejemplo n.º 8
0
    def test_sync(self):
        """Sync repositories with the file 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. Assert that the correct number of units were added and are present
           in the repo.
        6. Sync the remote one more time.
        7. Assert that repository version is different from the previous one.
        8. Assert that the same number of are present and that no units were
           added.
        """
        repo_api = RepositoriesFileApi(self.client)
        remote_api = RemotesFileApi(self.client)

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

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

        # Sync the repository.
        self.assertEqual(repo.latest_version_href,
                         f"{repo.pulp_href}versions/0/")
        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)

        self.assertIsNotNone(repo.latest_version_href)
        self.assertDictEqual(get_content_summary(repo.to_dict()),
                             FILE_FIXTURE_SUMMARY)
        self.assertDictEqual(get_added_content_summary(repo.to_dict()),
                             FILE_FIXTURE_SUMMARY)

        # Sync the repository again.
        latest_version_href = repo.latest_version_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)

        self.assertEqual(latest_version_href, repo.latest_version_href)
        self.assertDictEqual(get_content_summary(repo.to_dict()),
                             FILE_FIXTURE_SUMMARY)
Ejemplo n.º 9
0
 def _gen_export(self, exporter, body={}):
     """Create and read back an export for the specified PulpExporter."""
     export_response = self.exports_api.create(exporter.pulp_href, body)
     monitor_task(export_response.task)
     task = self.client.get(export_response.task)
     resources = task["created_resources"]
     self.assertEqual(1, len(resources))
     export_href = resources[0]
     export = self.exports_api.read(export_href)
     self.assertIsNotNone(export)
     return export
Ejemplo n.º 10
0
    def do_sync(self, download_policy):
        """Sync repositories with the different ``download_policy``.

        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. Assert that the correct number of possible units to be downloaded
           were shown.
        6. Sync the remote one more time in order to create another repository
           version.
        7. Assert that repository version is the same as the previous one.
        8. Assert that the same number of units are shown, and after the
           second sync no extra units should be shown, since the same remote
           was synced again.
        """
        # delete orphans to assure that no content units are present on the
        # file system
        delete_orphans()
        repo_api = RepositoriesFileApi(self.client)
        remote_api = RemotesFileApi(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)

        # Sync the repository.
        self.assertEqual(repo.latest_version_href,
                         f"{repo.pulp_href}versions/0/")
        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)

        self.assertIsNotNone(repo.latest_version_href)
        self.assertDictEqual(get_content_summary(repo.to_dict()),
                             FILE_FIXTURE_SUMMARY)
        self.assertDictEqual(get_added_content_summary(repo.to_dict()),
                             FILE_FIXTURE_SUMMARY)

        # Sync the repository again.
        latest_version_href = repo.latest_version_href
        sync_response = repo_api.sync(repo.pulp_href, repository_sync_data)
        monitor_task(sync_response.task)
        repo = repo_api.read(repo.pulp_href)

        self.assertEqual(latest_version_href, repo.latest_version_href)
        self.assertDictEqual(get_content_summary(repo.to_dict()),
                             FILE_FIXTURE_SUMMARY)
Ejemplo n.º 11
0
    def _perform_import(self, importer):
        """Perform an import with importer."""
        filenames = list(self.export.output_file_info.keys())
        import_response = self.imports_api.create(importer.pulp_href,
                                                  {"path": filenames[0]})
        monitor_task(import_response.task)
        task = self.client.get(import_response.task)
        resources = task["created_resources"]
        task_group_href = resources[1]
        task_group = monitor_task_group(task_group_href)

        return task_group
Ejemplo n.º 12
0
 def _gen_export(self, exporter):
     """Create and read back an export for the specified PulpExporter."""
     # TODO: at this point we can't create an export unless we do string-surgery on the
     #  exporter-href because there's no way to get just-the-id
     export_response = self.exports_api.create(exporter.pulp_href.split("/")[-2], {})
     monitor_task(export_response.task)
     task = self.client.get(export_response.task)
     resources = task["created_resources"]
     self.assertEqual(1, len(resources))
     export_href = resources[0]
     export = self.exports_api.read(export_href)
     self.assertIsNotNone(export)
     return export
Ejemplo n.º 13
0
    def test_02_change_policy(self):
        """Verify ability to change policy to value other than the default.

        Update the remote policy to a valid value other than `immedaite`
        and verify the new set value.
        """
        changed_policy = choice(
            [item for item in self.policies if item != "immediate"])
        response = self.remote_api.partial_update(self.remote["pulp_href"],
                                                  {"policy": changed_policy})
        monitor_task(response.task)
        self.remote.update(
            self.remote_api.read(self.remote["pulp_href"]).to_dict())
        self.assertEqual(self.remote["policy"], changed_policy, self.remote)
Ejemplo n.º 14
0
 def test_03_fail_duplicate_content_unit(self):
     """Create content unit."""
     response = self.file_content_api.create(**self.attrs, file=__file__)
     task = monitor_task(response.task)
     self.assertEqual(task["state"], "failed")
     error = task["error"]
     for key in ("already", "relative", "path", "digest"):
         self.assertIn(key, error["description"].lower(), error)
Ejemplo n.º 15
0
 def _setup_repositories(cls):
     """Create and sync a number of repositories to be exported."""
     # create and remember a set of repo
     repos = []
     remotes = []
     for r in range(NUM_REPOS):
         a_repo = cls.repo_api.create(gen_repo())
         # give it a remote and sync it
         body = gen_file_remote()
         remote = cls.remote_api.create(body)
         repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)
         sync_response = cls.repo_api.sync(a_repo.pulp_href, repository_sync_data)
         monitor_task(sync_response.task)
         # remember it
         repos.append(a_repo)
         remotes.append(remote)
     return repos, remotes
Ejemplo n.º 16
0
 def test_01_create_content_unit(self):
     """Create content unit."""
     response = self.file_content_api.create(**self.attrs, file=__file__)
     created_resources = monitor_task(response.task)
     content_unit = self.file_content_api.read(created_resources[0])
     self.content_unit.update(content_unit.to_dict())
     for key, val in self.attrs.items():
         with self.subTest(key=key):
             self.assertEqual(self.content_unit[key], val)
Ejemplo n.º 17
0
 def _create_repo_and_versions(self):
     # Create a new file-repo, repo-2
     a_repo = self.repo_api.create(gen_repo())
     self.addCleanup(self.client.delete, a_repo.pulp_href)
     # get a list of all the files from one of our existing repos
     file_list = self.content_api.list(repository_version=self.repos[0].latest_version_href)
     # copy files from repositories[0] into 2, one file at a time
     results = file_list.results
     for a_file in results:
         href = a_file.pulp_href
         modify_response = self.repo_api.modify(a_repo.pulp_href, {"add_content_units": [href]})
         monitor_task(modify_response.task)
     # get all versions of that repo
     # should now be 4, with 0/1/2/3 files as content
     versions = self.versions_api.list(a_repo.pulp_href, ordering="number")
     self.assertIsNotNone(versions)
     self.assertEqual(4, versions.count)
     return a_repo, versions
Ejemplo n.º 18
0
    def test_duplicate_file_sync(self):
        """Sync a repository with remotes containing same file names.

        This test does the following.

        1. Create a repository in pulp.
        2. Create two remotes containing the same file.
        3. Check whether the created repo has only one copy of the file.

        This test targets the following issue:

        `Pulp #4738 <https://pulp.plan.io/issues/4738>`_
        """
        repo_api = RepositoriesFileApi(self.client)
        remote_api = RemotesFileApi(self.client)

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

        # Step 2
        remote = remote_api.create(gen_file_remote())
        self.addCleanup(remote_api.delete, remote.pulp_href)
        remote2 = remote_api.create(
            gen_file_remote(url=FILE2_FIXTURE_MANIFEST_URL))

        self.addCleanup(remote_api.delete, remote2.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)
        self.assertDictEqual(get_content_summary(repo.to_dict()),
                             FILE_FIXTURE_SUMMARY)
        self.assertDictEqual(get_added_content_summary(repo.to_dict()),
                             FILE_FIXTURE_SUMMARY)

        repository_sync_data = RepositorySyncURL(remote=remote2.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)
        self.assertDictEqual(get_added_content_summary(repo.to_dict()),
                             FILE_FIXTURE_SUMMARY)
Ejemplo n.º 19
0
 def _gen_export(self, exporter, body={}):
     """Create and read back an export for the specified PulpExporter."""
     export_response = self.exports_api.create(exporter.pulp_href, body)
     monitor_task(export_response.task)
     task = self.client.get(export_response.task)
     resources = task["created_resources"]
     self.assertEqual(1, len(resources))
     reports = task["progress_reports"]
     found_artifacts = False
     found_content = False
     for r in reports:
         self.assertEqual(TASK_STATES.COMPLETED, r["state"])
         found_artifacts |= r["code"] == "export-artifacts"
         found_content |= r["code"] == "export-repo-version-content"
     self.assertTrue(found_artifacts, "No artifacts exported!")
     self.assertTrue(found_content, "No content exported!")
     export_href = resources[0]
     export = self.exports_api.read(export_href)
     self.assertIsNotNone(export)
     return export
Ejemplo n.º 20
0
    def test_non_error(self):
        """Create a duplicate content unit with different relative_path.

        Artifacts are unique by ``relative_path`` and ``file``.

        In order to avoid an HTTP error, use the same ``artifact`` and
        different ``relative_path``.
        """
        delete_orphans()
        artifact = gen_artifact()

        # create first content unit.
        response = self.file_content_api.create(
            **gen_file_content_attrs(artifact))
        monitor_task(response.task)

        # create second content unit.
        response = self.file_content_api.create(
            **gen_file_content_attrs(artifact))
        monitor_task(response.task)
        task = tasks.read(response.task)
        self.assertEqual(task.state, "completed")
Ejemplo n.º 21
0
    def test_second_unit_raises_error(self):
        """Create a duplicate content unit with different ``artifacts`` and same ``relative_path``.

        Artifacts are unique by ``relative_path`` and ``file``.
        """
        delete_orphans()
        content_api = ContentFilesApi(self.client)
        repo_api = RepositoriesFileApi(self.client)

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

        artifact = gen_artifact()

        # create first content unit.
        content_attrs = gen_file_content_attrs(artifact)
        response = content_api.create(**content_attrs)
        monitor_task(response.task)

        artifact = gen_artifact(file=__file__)

        # create second content unit.
        second_content_attrs = gen_file_content_attrs(artifact)
        second_content_attrs["relative_path"] = content_attrs["relative_path"]
        response = content_api.create(**second_content_attrs)
        monitor_task(response.task)

        data = {
            "add_content_units":
            [c.pulp_href for c in content_api.list().results]
        }
        response = repo_api.modify(repo.pulp_href, data)
        task = monitor_task(response.task)

        error_message = ("Cannot create repository version. "
                         "More than one file.file content with "
                         "the duplicate values for relative_path.")
        self.assertEqual(task["error"]["description"], error_message)
Ejemplo n.º 22
0
    def _perform_import(self, importer, chunked=False):
        """Perform an import with importer."""
        if chunked:
            filenames = [
                f for f in list(self.chunked_export.output_file_info.keys())
                if f.endswith("json")
            ]
            import_response = self.imports_api.create(importer.pulp_href,
                                                      {"toc": filenames[0]})
        else:
            filenames = [
                f for f in list(self.export.output_file_info.keys())
                if f.endswith("tar.gz")
            ]
            import_response = self.imports_api.create(importer.pulp_href,
                                                      {"path": filenames[0]})
        monitor_task(import_response.task)
        task = self.client.get(import_response.task)
        resources = task["created_resources"]
        task_group_href = resources[1]
        task_group = monitor_task_group(task_group_href)

        return task_group
Ejemplo n.º 23
0
    def test_raise_error(self):
        """Create a duplicate content unit using same relative_path.

        Artifacts are unique by ``relative_path`` and ``file``.

        In order to raise an HTTP error, the same ``artifact`` and the same
        ``relative_path`` should be used.
        """
        delete_orphans()
        artifact = gen_artifact()
        attrs = gen_file_content_attrs(artifact)

        # create first content unit.
        response = self.file_content_api.create(**attrs)
        monitor_task(response.task)

        # using the same attrs used to create the first content unit.
        response = self.file_content_api.create(**attrs)
        task = monitor_task(response.task)
        self.assertEqual(task["state"], "failed")
        error = task["error"]
        for key in ("already", "relative", "path", "digest"):
            self.assertIn(key, error["description"].lower(), error)
Ejemplo n.º 24
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)
        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)
        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)
Ejemplo n.º 25
0
    def test_second_unit_replaces_the_first(self):
        """Create a duplicate content unit with different ``artifacts`` and same ``relative_path``.

        Artifacts are unique by ``relative_path`` and ``file``.
        """
        delete_orphans()
        content_api = ContentFilesApi(self.client)
        repo_api = RepositoriesFileApi(self.client)
        versions_api = RepositoriesFileVersionsApi(self.client)

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

        artifact = gen_artifact()

        # create first content unit.
        content_attrs = gen_file_content_attrs(artifact)
        content_attrs["repository"] = repo.pulp_href
        response = content_api.create(**content_attrs)
        monitor_task(response.task)

        artifact = gen_artifact(file=__file__)

        # create second content unit.
        second_content_attrs = gen_file_content_attrs(artifact)
        second_content_attrs["repository"] = repo.pulp_href
        second_content_attrs["relative_path"] = content_attrs["relative_path"]

        response = content_api.create(**second_content_attrs)
        monitor_task(response.task)

        repo_latest_version = versions_api.read(
            repo_api.read(repo.pulp_href).latest_version_href)

        self.assertEqual(
            repo_latest_version.content_summary.present["file.file"]["count"],
            1)
Ejemplo n.º 26
0
    def do_test(self, url):
        """Sync a repository given ``url`` on the remote."""
        repo_api = RepositoriesFileApi(self.client)
        remote_api = RemotesFileApi(self.client)

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

        body = gen_file_remote(url=url)
        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)
        return monitor_task(sync_response.task)
Ejemplo n.º 27
0
    def test_all(self):
        """Perform a lazy sync and change to immeditae to force download."""
        # delete orphans to assure that no content units are present on the
        # file system
        delete_orphans()
        client = gen_file_client()
        artifacts_api = ArtifactsApi(core_client)
        repo_api = RepositoriesFileApi(client)
        remote_api = RemotesFileApi(client)

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

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

        # Sync the repository using a lazy download policy
        repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)
        sync_response = repo_api.sync(repo.pulp_href, repository_sync_data)
        monitor_task(sync_response.task)
        artifacts = artifacts_api.list().to_dict()["results"]
        self.assertEqual(len(artifacts), 0, artifacts)

        # Update the policy to immediate
        response = remote_api.partial_update(remote.pulp_href,
                                             {"policy": "immediate"})
        monitor_task(response.task)
        remote = remote_api.read(remote.pulp_href)
        self.assertEqual(remote.policy, "immediate")

        # Sync using immediate download policy
        repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)
        sync_response = repo_api.sync(repo.pulp_href, repository_sync_data)
        monitor_task(sync_response.task)

        # Assert that missing artifacts are downloaded
        artifacts = artifacts_api.list().to_dict()["results"]
        self.assertEqual(len(artifacts), FILE_FIXTURE_COUNT, artifacts)
Ejemplo n.º 28
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)
Ejemplo n.º 29
0
    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)
Ejemplo n.º 30
0
 def test_05_delete(self):
     """Delete a remote."""
     response = self.remote_api.delete(self.remote.pulp_href)
     monitor_task(response.task)
     with self.assertRaises(ApiException):
         self.remote_api.read(self.remote.pulp_href)