示例#1
0
    def setUpClass(cls):
        """Create class-wide variables."""
        cls.cfg = config.get_config()

        client = gen_file_client()
        cls.repo_api = RepositoriesFileApi(client)
        cls.remote_api = RemotesFileApi(client)
        cls.publications = PublicationsFileApi(client)
示例#2
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}
    )
示例#3
0
    def test_all(self):
        """Verify whether is possible to create a remote without a URL.

        This test targets the following issues:

        * `Pulp #3395 <https://pulp.plan.io/issues/3395>`_
        * `Pulp Smash #984 <https://github.com/pulp/pulp-smash/issues/984>`_
        """
        body = gen_file_remote()
        del body["url"]
        with self.assertRaises(ApiException):
            RemotesFileApi(gen_file_client()).create(body)
示例#4
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"
示例#5
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()
示例#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))
示例#7
0
    def test_negative_create_file_remote_with_invalid_parameter(self):
        """Attempt to create file remote passing invalid parameter.

        Assert response returns an error 400 including ["Unexpected field"].

        This test targets the following issue:

        * `Pulp Smash #1085 <https://github.com/pulp/pulp-smash/issues/1085>`_
        """
        with self.assertRaises(ApiException) as exc:
            RemotesFileApi(gen_file_client()).create(
                gen_file_remote(foo="bar"))

        assert exc.exception.status == 400
        assert json.loads(exc.exception.body)["foo"] == ["Unexpected field"]
示例#8
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()
示例#9
0
def set_distribution_base_path(file_distribution_href, base_path):
    """
    Set the base path of a FileDistribution and return the updated representation.

    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`.

    Returns:
        The bindings object representing the updated FileDistribution.
    """
    file_client = gen_file_client()
    distributions_api = DistributionsFileApi(file_client)
    update_response = distributions_api.partial_update(
        file_distribution_href, {"base_path": base_path})
    monitor_task(update_response.task)
    return distributions_api.read(file_distribution_href)
    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)
 def setUpClass(cls):
     """Create class-wide variables."""
     cls.client = gen_file_client()
     cls.DP_ON_DEMAND = "on_demand" in ON_DEMAND_DOWNLOAD_POLICIES
     cls.DP_STREAMED = "streamed" in ON_DEMAND_DOWNLOAD_POLICIES
示例#12
0
def file_client():
    return gen_file_client()
示例#13
0
 def setUpClass(cls):
     """Create class-wide variable."""
     delete_orphans()
     cls.content_unit = {}
     cls.file_content_api = ContentFilesApi(gen_file_client())
     cls.artifact = gen_artifact()
示例#14
0
 def setUpClass(cls):
     """Create class-wide variables."""
     cls.client = gen_file_client()
示例#15
0
 def setUpClass(cls):
     """Create class-wide variables."""
     cls.file_content_api = ContentFilesApi(gen_file_client())
示例#16
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)
示例#17
0
 def setUpClass(cls):
     """Create class-wide variables."""
     cls.cfg = config.get_config()
     cls.client = gen_file_client()
示例#18
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)
示例#19
0
 def setUpClass(cls):
     """Create class-wide variables."""
     cls.remote_api = RemotesFileApi(gen_file_client())
     cls.remote = {}
     cls.policies = ON_DEMAND_DOWNLOAD_POLICIES
     cls.body = _gen_verbose_remote()
示例#20
0
 def setUpClass(cls):
     """Define class-wide variable."""
     cls.client = gen_file_client()
示例#21
0
 def setUpClass(cls):
     """Create class-wide variables."""
     cls.remote_api = RemotesFileApi(gen_file_client())