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)
Example #2
0
    def setUpClass(cls):
        """Create repos, remotes, and api-clients for all tests."""
        cls.cfg = config.get_config()
        cls.client = ApiClient(configuration=cls.cfg.get_bindings_config())
        file_client = gen_file_client()
        cls.admin_info = {
            "task_api": TasksApi(cls.client),
            "file_client": file_client,
            "remote_api": RemotesFileApi(file_client),
            "repo_api": RepositoriesFileApi(file_client),
        }
        cls.admin_info["a_remote"] = cls.admin_info["remote_api"].create(
            gen_file_remote(policy="on_demand")
        )
        cls.admin_info["a_repo"] = cls.admin_info["repo_api"].create(gen_repo())
        cls.admin_info["sync_data"] = RepositorySyncURL(remote=cls.admin_info["a_remote"].pulp_href)

        cls.new_user = gen_user()
        file_client = gen_file_client()
        cls.user_info = {
            "task_api": TasksApi(cls.client),
            "file_client": file_client,
            "remote_api": RemotesFileApi(file_client),
            "repo_api": RepositoriesFileApi(file_client),
        }
        cls.user_info["a_remote"] = cls.user_info["remote_api"].create(
            gen_file_remote(policy="on_demand")
        )
        cls.user_info["a_repo"] = cls.user_info["repo_api"].create(gen_repo())
        cls.user_info["sync_data"] = RepositorySyncURL(remote=cls.user_info["a_remote"].pulp_href)
Example #3
0
    def test_clean_orphan_artifact(self):
        """Test whether orphan artifacts units can be clean up."""
        repo_api = RepositoriesFileApi(self.api_client)
        repo = repo_api.create(gen_repo())
        self.addCleanup(repo_api.delete, repo.pulp_href)

        artifacts_api = ArtifactsApi(core_client)
        artifact = artifacts_api.create(file=__file__)

        if self.storage == "pulpcore.app.models.storage.FileSystem":
            cmd = ("ls", os.path.join(self.media_root, artifact.file))
            self.cli_client.run(cmd, sudo=True)

        orphans_response = self.orphans_cleanup_api.cleanup({"orphan_protection_time": 10})
        monitor_task(orphans_response.task)

        # assert artifact was not removed
        artifacts = artifacts_api.list().count
        self.assertEqual(artifacts, 1)

        orphans_response = self.orphans_cleanup_api.cleanup({"orphan_protection_time": 0})
        monitor_task(orphans_response.task)

        with self.assertRaises(ApiException):
            artifacts_api.read(artifact.pulp_href)

        if self.storage == "pulpcore.app.models.storage.FileSystem":
            with self.assertRaises(CalledProcessError):
                self.cli_client.run(cmd)
    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)
Example #5
0
def set_distribution_base_path_and_download_a_content_unit_with_cert(
        file_distribution_href,
        base_path,
        file_repository_href,
        cert_path,
        content_path=None,
        url_encode=True):
    """
    Set the base path on the `distribution, read the cert, urlencode it, and then request one unit.

    If `content_path` is set, that path will be requested, otherwise a random, valid content unit
    path will be selected from the FileRepository at `file_repository_href`.

    1. Set the distribution referred to by `file_distribution_href` base_path to `base_path`.
    2. Read the cert from the filesystem and urlencode it.
    3. Make a request to `content_path` if specified, or to a random content item present in the
        `file_repository_href` repository. The urlencoded cert is submitted as the `X-CLIENT-CERT`
        header when requesting content.

    Args:
        file_distribution_href: The distribution href that is to be updated. This must refer to a
            distribution of type `FileDistribution`.
        base_path: The base path to set on the `distribution`.
        file_repository_href: The repository href that will have
        cert_path: The file system path to the certificate to be used in the content request. This
            will be read from the filesystem and urlencoded before being submitted as the
            `X-CLIENT-CERT` header when downloading content.
        content_path: The path to the specific content unit to be fetched. This is the portion of
            the url after the distribution URL. It's optional, and if unspecified a random, valid
            content unit will be selected instead from the repository.
        url_encode: If true, the certificate data read will be urlencoded, otherwise it won't be.
            This is an optional param, and defaults to True.

    Returns:
        The downloaded data.

    """
    distribution = set_distribution_base_path(file_distribution_href, base_path)

    if content_path is None:
        file_client = gen_file_client()
        file_repos_api = RepositoriesFileApi(file_client)
        repo = file_repos_api.read(file_repository_href)
        content_path = choice(get_file_content_paths(repo.to_dict()))

    if url_encode:
        cert_data = read_cert_and_urlencode(cert_path)
    else:
        cert_data = read_cert(cert_path)

    return download_content_unit(
        config.get_config(),
        distribution.to_dict(),
        content_path,
        headers={'X-CLIENT-CERT': cert_data}
    )
Example #6
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))
Example #7
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)
Example #8
0
    def setUpClass(cls):
        """Create class-wide variables."""
        cls.cfg = config.get_config()
        cls.cli_client = cli.Client(cls.cfg)
        allowed_imports = get_pulp_setting(cls.cli_client,
                                           "ALLOWED_IMPORT_PATHS")
        if not allowed_imports or "/tmp" not in allowed_imports:
            raise unittest.SkipTest(
                "Cannot run import-tests unless /tmp is in ALLOWED_IMPORT_PATHS ({})."
                .format(allowed_imports), )

        cls.client = api.Client(cls.cfg, api.json_handler)
        cls.core_client = CoreApiClient(
            configuration=cls.cfg.get_bindings_config())
        cls.file_client = gen_file_client()

        cls.repo_api = RepositoriesFileApi(cls.file_client)
        cls.remote_api = RemotesFileApi(cls.file_client)
        cls.versions_api = RepositoriesFileVersionsApi(cls.file_client)
        cls.content_api = ContentFilesApi(cls.file_client)
        cls.exporter_api = ExportersPulpApi(cls.core_client)
        cls.exports_api = ExportersCoreExportsApi(cls.core_client)
        cls.importer_api = ImportersPulpApi(cls.core_client)
        cls.imports_api = ImportersCoreImportsApi(cls.core_client)

        cls.import_check_api = ImportersCoreImportCheckApi(cls.core_client)

        (cls.import_repos, cls.export_repos,
         cls.remotes) = cls._setup_repositories()
        cls.exporter = cls._create_exporter()
        cls.export = cls._create_export()
        cls.chunked_export = cls._create_chunked_export()
        cls._setup_import_check_directories()
Example #9
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}/")
Example #10
0
    def setUpClass(cls):
        """Create class-wide variables."""
        cls.cfg = config.get_config()
        cls.file_repositories_api = RepositoriesFileApi(
            FileApiClient(cls.cfg.get_bindings_config()))
        cls.repo = cls.file_repositories_api.create(gen_repo())

        cls.file_content_api = ContentFilesApi(
            FileApiClient(cls.cfg.get_bindings_config()))
        with tempfile.NamedTemporaryFile() as tmp_file:
            tmp_file.write(b"not empty")
            tmp_file.flush()
            monitor_task(
                cls.file_content_api.create(relative_path=utils.uuid4(),
                                            file=tmp_file.name).task)

        cls.cert_guards_api = ContentGuardsX509Api(
            CertGuardApiClient(cls.cfg.get_bindings_config()))
        with open(X509_CA_CERT_FILE_PATH, "r") as x509_ca_cert_data_file:
            x509_ca_cert_data = x509_ca_cert_data_file.read()

        cls.content_guard = cls.cert_guards_api.create({
            "name":
            utils.uuid4(),
            "ca_certificate":
            x509_ca_cert_data
        })
Example #11
0
 def setUpClass(cls):
     """Create class-wide variables."""
     cls.cfg = config.get_config()
     cls.file_client = gen_file_client()
     cls.repo_api = RepositoriesFileApi(cls.file_client)
     cls.publication_api = PublicationsFileApi(cls.file_client)
     cls.remote_api = RemotesFileApi(cls.file_client)
Example #12
0
 def setUpClass(cls):
     """Clean out Pulp before testing."""
     delete_orphans()
     client = gen_file_client()
     cls.cont_api = ContentFilesApi(client)
     cls.repo_api = RepositoriesFileApi(client)
     cls.remote_api = RemotesFileApi(client)
Example #13
0
    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 = []
Example #14
0
 def setUpClass(cls):
     """Clean out Pulp before testing."""
     delete_orphans()
     client = gen_file_client()
     cls.repo_api = RepositoriesFileApi(client)
     cls.remote_api = RemotesFileApi(client)
     cls.publication_api = PublicationsFileApi(client)
     cls.distributions_api = DistributionsFileApi(client)
     cls.cfg = config.get_config()
Example #15
0
    def test_clean_orphan_content_unit(self):
        """Test whether orphaned content units can be cleaned up."""
        repo_api = RepositoriesFileApi(self.api_client)
        remote_api = RemotesFileApi(self.api_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)
        content = choice(get_content(repo.to_dict())[FILE_CONTENT_NAME])

        # Create an orphan content unit.
        repo_api.modify(repo.pulp_href, dict(remove_content_units=[content["pulp_href"]]))

        artifacts_api = ArtifactsApi(core_client)

        if self.storage == "pulpcore.app.models.storage.FileSystem":
            # Verify that the artifact is present on disk.
            relative_path = artifacts_api.read(content["artifact"]).file
            artifact_path = os.path.join(self.media_root, relative_path)
            cmd = ("ls", artifact_path)
            self.cli_client.run(cmd, sudo=True)

        file_contents_api = ContentFilesApi(self.api_client)
        # Delete first repo version. The previous removed content unit will be
        # an orphan.
        delete_version(repo, get_versions(repo.to_dict())[1]["pulp_href"])
        content_units = file_contents_api.list().to_dict()["results"]
        content_units_href = [c["pulp_href"] for c in content_units]
        self.assertIn(content["pulp_href"], content_units_href)

        content_before_cleanup = file_contents_api.list().count
        orphans_response = self.orphans_cleanup_api.cleanup({"orphan_protection_time": 10})
        monitor_task(orphans_response.task)

        # assert content was not removed
        content_after_cleanup = file_contents_api.list().count
        self.assertEqual(content_after_cleanup, content_before_cleanup)

        orphans_response = self.orphans_cleanup_api.cleanup({"orphan_protection_time": 0})
        monitor_task(orphans_response.task)

        content_units = file_contents_api.list().to_dict()["results"]
        content_units_href = [c["pulp_href"] for c in content_units]
        self.assertNotIn(content["pulp_href"], content_units_href)

        if self.storage == "pulpcore.app.models.storage.FileSystem":
            # Verify that the artifact was removed from disk.
            with self.assertRaises(CalledProcessError):
                self.cli_client.run(cmd)
Example #16
0
    def test_clean_orphan_artifact(self):
        """Test whether orphan artifacts units can be clean up."""
        repo_api = RepositoriesFileApi(self.api_client)
        repo = repo_api.create(gen_repo())
        self.addCleanup(repo_api.delete, repo.pulp_href)

        artifacts_api = ArtifactsApi(core_client)
        artifact = artifacts_api.create(file=__file__)

        if self.storage == "pulpcore.app.models.storage.FileSystem":
            cmd = ("ls", os.path.join(MEDIA_PATH, artifact.file))
            self.cli_client.run(cmd, sudo=True)

        delete_orphans()

        with self.assertRaises(ApiException):
            artifacts_api.read(artifact.pulp_href)

        if self.storage == "pulpcore.app.models.storage.FileSystem":
            with self.assertRaises(CalledProcessError):
                self.cli_client.run(cmd)
Example #17
0
    def setUpClass(cls):
        """Create class-wide variables."""
        cls.cfg = config.get_config()
        cls.client = gen_file_client()

        cls.content_api = ContentFilesApi(cls.client)
        cls.repo_api = RepositoriesFileApi(cls.client)
        cls.remote_api = RemotesFileApi(cls.client)
        cls.publications_api = PublicationsFileApi(cls.client)
        cls.distributions_api = DistributionsFileApi(cls.client)

        cls.CUSTOM_MANIFEST = "TEST_MANIFEST"
Example #18
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)
        with self.assertRaises(PulpTaskError) as cm:
            monitor_task(response.task)
        task = cm.exception.task.to_dict()

        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)
Example #19
0
    def do_test(self, url):
        """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(url)
        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)
Example #20
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 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)
    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)
Example #23
0
    def setUpClass(cls):
        """Create class-wide variables."""
        cls.cfg = config.get_config()
        cls.client = api.Client(cls.cfg, api.json_handler)
        cls.core_client = CoreApiClient(configuration=cls.cfg.get_bindings_config())
        cls.file_client = gen_file_client()

        cls.repo_api = RepositoriesFileApi(cls.file_client)
        cls.remote_api = RemotesFileApi(cls.file_client)
        cls.exporter_api = ExportersPulpApi(cls.core_client)
        cls.exports_api = ExportersCoreExportsApi(cls.core_client)

        (cls.repos, cls.remotes) = cls._setup_repositories()
Example #24
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)
    def setUpClass(cls):
        """Create class-wide variables."""
        cls.cfg = config.get_config()
        cls.client = gen_file_client()
        cls.orphans_api = OrphansCleanupApi(core_client)
        cls.reclaim_api = RepositoriesReclaimSpaceApi(core_client)
        cls.artifacts_api = ArtifactsApi(core_client)
        cls.publication_api = PublicationsFileApi(cls.client)
        cls.distributions_api = DistributionsFileApi(cls.client)
        cls.repo_api = RepositoriesFileApi(cls.client)
        cls.remote_api = RemotesFileApi(cls.client)

        orphans_response = cls.orphans_api.cleanup(
            {"orphan_protection_time": 0})
        monitor_task(orphans_response.task)
Example #26
0
    def setUpClass(cls):
        """
        Create class-wide variables.

        Variables 'paths' and 'paths_updated' are defined as strings.
        In same way data are send from user.
        """
        cls.cfg = config.get_config()
        cls.file_client = gen_file_client()
        cls.repo_api = RepositoriesFileApi(cls.file_client)
        cls.file_remote_api = RemotesFileApi(cls.file_client)
        cls.file_acs_api = AcsFileApi(cls.file_client)
        cls.publication_api = PublicationsFileApi(cls.file_client)
        cls.distribution_api = DistributionsFileApi(cls.file_client)
        cls.paths = ["goodpath/PULP_MANIFEST", "test", "whatever/test"]
Example #27
0
    def setUpClass(cls):
        """Create class-wide variables."""
        cls.cfg = config.get_config()
        cls.client = api.Client(cls.cfg, api.json_handler)
        cls.file_client = gen_file_client()

        cls.content_api = ContentFilesApi(cls.file_client)
        cls.repo_api = RepositoriesFileApi(cls.file_client)
        cls.versions_api = RepositoriesFileVersionsApi(cls.file_client)
        cls.remote_api = RemotesFileApi(cls.file_client)
        cls.publication_api = PublicationsFileApi(cls.file_client)
        cls.exporter_api = ExportersFilesystemApi(cls.file_client)
        cls.exports_api = ExportersFileExportsApi(cls.file_client)

        cls.repos, cls.remotes, cls.publications = cls._setup_repositories()
    def setUpClass(cls):
        """
        Create all the client instances needed to communicate with Pulp.
        """
        configuration = Configuration(**BINDINGS_CONFIGURATION)

        file_client = FileApiClient(configuration)
        migration_client = MigrationApiClient(configuration)

        # Create api clients for all resource types
        cls.file_repo_api = RepositoriesFileApi(file_client)
        cls.file_content_api = ContentFilesApi(file_client)
        cls.migration_plans_api = MigrationPlansApi(migration_client)
        cls.pulp2content_api = Pulp2ContentApi(migration_client)
        cls.pulp2repositories_api = Pulp2RepositoriesApi(migration_client)

        set_pulp2_snapshot(name='file_base_4repos')
Example #29
0
class BaseLabelTestCase(unittest.TestCase):
    """Base class for label test classes."""
    @classmethod
    def setUpClass(cls):
        """Create class-wide variables."""
        cls.cfg = config.get_config()
        cls.repo = None

    def setUp(self):
        """Create an API client."""
        self.client = FileApiClient(self.cfg.get_bindings_config())
        self.repo_api = RepositoriesFileApi(self.client)

    def _create_repo(self, labels={}):
        attrs = {"name": str(uuid4())}
        if labels:
            attrs["pulp_labels"] = labels
        self.repo = self.repo_api.create(attrs)
        self.addCleanup(self.repo_api.delete, self.repo.pulp_href)
    def setUpClass(cls):
        """
        Create all the client instances needed to communicate with Pulp.
        """
        configuration = Configuration(**BINDINGS_CONFIGURATION)

        file_client = FileApiClient(configuration)
        migration_client = MigrationApiClient(configuration)

        # Create api clients for all resource types
        cls.file_repo_api = RepositoriesFileApi(file_client)
        cls.file_repo_versions_api = RepositoriesFileVersionsApi(file_client)
        cls.file_remote_api = RemotesFileApi(file_client)
        cls.file_distribution_api = DistributionsFileApi(file_client)
        cls.file_publication_api = PublicationsFileApi(file_client)
        cls.file_content_api = ContentFilesApi(file_client)
        cls.migration_plans_api = MigrationPlansApi(migration_client)
        cls.pulp2content_api = Pulp2ContentApi(migration_client)
        cls.pulp2repositories_api = Pulp2RepositoriesApi(migration_client)