Beispiel #1
0
def create_distribution(repository_href=None):
    """Utility to create a pulp_file distribution."""
    file_client = gen_file_client()
    distro_api = DistributionsFileApi(file_client)

    body = {"name": utils.uuid4(), "base_path": utils.uuid4()}
    if repository_href:
        body["repository"] = repository_href

    result = distro_api.create(body)
    distro_href = monitor_task(result.task).created_resources[0]
    distro = distro_api.read(distro_href)
    return distro
Beispiel #2
0
 def setUpClass(cls):
     """Sets up class"""
     client = gen_file_client()
     cls.cont_api = ContentFilesApi(client)
     cls.repo_api = RepositoriesFileApi(client)
     cls.remote_api = RemotesFileApi(client)
     cls.pub_api = PublicationsFileApi(client)
     cls.dis_api = DistributionsFileApi(client)
     cls.repo = cls.repo_api.create(gen_repo(autopublish=True))
     cls.remote = cls.remote_api.create(gen_file_remote())
     body = RepositorySyncURL(remote=cls.remote.pulp_href)
     created = monitor_task(
         cls.repo_api.sync(cls.repo.pulp_href, body).task).created_resources
     cls.repo = cls.repo_api.read(cls.repo.pulp_href)
     cls.pub1 = cls.pub_api.read(created[1])
     body = FileFilePublication(repository=cls.repo.pulp_href)
     cls.pub2 = cls.pub_api.read(
         monitor_task(cls.pub_api.create(body).task).created_resources[0])
     cls.pub3 = []
     response = cls.dis_api.create(
         gen_distribution(repository=cls.repo.pulp_href))
     cls.distro = cls.dis_api.read(
         monitor_task(response.task).created_resources[0])
     cls.distro2 = []
     cls.url = urljoin(PULP_CONTENT_BASE_URL, f"{cls.distro.base_path}/")
Beispiel #3
0
def gen_user(cfg=config.get_config(), model_permissions=None, object_permissions=None):
    """Create a user with a set of permissions in the pulp database."""
    cli_client = cli.Client(cfg)

    if model_permissions is None:
        model_permissions = []

    if object_permissions is None:
        object_permissions = []

    user = {
        "username": utils.uuid4(),
        "password": utils.uuid4(),
        "model_permissions": model_permissions,
        "object_permissions": object_permissions,
    }
    utils.execute_pulpcore_python(
        cli_client,
        "\n".join(CREATE_USER_CMD).format(**user),
    )

    api_config = cfg.get_bindings_config()
    api_config.username = user["username"]
    api_config.password = user["password"]
    user["core_api_client"] = CoreApiClient(api_config)
    user["api_client"] = FileApiClient(api_config)
    user["distribution_api"] = DistributionsFileApi(user["api_client"])
    return user
Beispiel #4
0
    def setUpClass(cls):
        """Set up test variables"""
        client = gen_file_client(
        )  # This is admin client, following apis are for admin user
        core_client = CoreApiClient(config.get_config().get_bindings_config())
        cls.groups_api = GroupsApi(core_client)
        cls.group_users_api = GroupsUsersApi(core_client)
        cls.distro_api = DistributionsFileApi(client)
        response = monitor_task(cls.distro_api.create(gen_distribution()).task)
        cls.distro = cls.distro_api.read(response.created_resources[0])
        cls.rbac_guard_api = ContentguardsRbacApi(client)

        cls.admin = {
            "username": client.configuration.username,
            "password": client.configuration.password,
        }
        user = gen_user(model_permissions=["core.add_rbaccontentguard"])
        user["rbac_guard_api"] = ContentguardsRbacApi(user["core_api_client"])
        cls.creator_user = user
        cls.user_a = gen_user()
        cls.user_b = gen_user()
        cls.all_users = [
            cls.creator_user, cls.user_a, cls.user_a, cls.admin, None
        ]

        cls.group = cls.groups_api.create({"name": utils.uuid4()})
        cls.group_users_api.create(cls.group.pulp_href,
                                   {"username": cls.user_b["username"]})
        cls.group_users_api.create(cls.group.pulp_href,
                                   {"username": cls.user_a["username"]})

        cls.url = urljoin(PULP_CONTENT_BASE_URL, f"{cls.distro.base_path}/")
    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 = []
Beispiel #6
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)
        cls.distributions = DistributionsFileApi(client)
Beispiel #7
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()
Beispiel #8
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 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"
Beispiel #10
0
    def test_access_error(self):
        """HTTP error is not raised when accessing published data."""
        repo_api = RepositoriesFileApi(self.client)
        remote_api = RemotesFileApi(self.client)
        publications = PublicationsFileApi(self.client)
        distributions = DistributionsFileApi(self.client)

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

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

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

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

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

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

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

        self.assertEqual(len(pulp_manifest), FILE_FIXTURE_COUNT, pulp_manifest)
Beispiel #11
0
    def setUpClass(cls):
        """
        Initialize Pulp to make authorization assertions using client certificates.

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

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

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

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

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

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

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

        content_guard_href = cls._setup_content_guard()

        # Create a distribution.
        body = gen_distribution()
        body["publication"] = publication_href
        body["content_guard"] = content_guard_href
        distribution_response = cls.distributions_api.create(body)
        created_resources = monitor_task(distribution_response.task)
        cls.distribution = cls.distributions_api.read(created_resources[0])
        cls.teardown_cleanups.append((cls.distributions_api.delete, cls.distribution.pulp_href))
Beispiel #12
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"]
    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)
    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)
    def setUpClass(cls):
        """
        Create all the client instances needed to communicate with Pulp.
        """
        configuration = Configuration(**BINDINGS_CONFIGURATION)

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

        # Create api clients for File
        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)

        # Create api clients for RPM
        cls.rpm_repo_api = RepositoriesRpmApi(rpm_client)
        cls.rpm_repo_versions_api = RepositoriesRpmVersionsApi(rpm_client)
        cls.rpm_remote_api = RemotesRpmApi(rpm_client)
        cls.rpm_distribution_api = DistributionsRpmApi(rpm_client)
        cls.rpm_publication_api = PublicationsRpmApi(rpm_client)
        cls.rpm_content_apis = {
            'advisory': ContentAdvisoriesApi(rpm_client),
            'disttree': ContentDistributionTreesApi(rpm_client),
            'modulemd': ContentModulemdsApi(rpm_client),
            'modulemd-defaults': ContentModulemdDefaultsApi(rpm_client),
            'category': ContentPackagecategoriesApi(rpm_client),
            'environment': ContentPackageenvironmentsApi(rpm_client),
            'group': ContentPackagegroupsApi(rpm_client),
            'langpack': ContentPackagelangpacksApi(rpm_client),
            'package': ContentPackagesApi(rpm_client),
        }

        # Create api clients for Migration
        cls.migration_plans_api = MigrationPlansApi(migration_client)
        cls.pulp2content_api = Pulp2ContentApi(migration_client)
        cls.pulp2repositories_api = Pulp2RepositoriesApi(migration_client)
class RepoVersionRetentionTestCase(unittest.TestCase):
    """Test retained_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_retained_versions(self):
        """Test repo version retention."""
        self._create_repo_versions({"retained_versions": 1})

        versions = self.version_api.list(
            file_file_repository_href=self.repo.pulp_href).results
        self.assertEqual(len(versions), 1)
        self.assertEqual(self.repo.latest_version_href.split("/")[-2], "3")

    def test_retained_versions_on_update(self):
        """Test repo version retention when retained_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 retained_versions to 2
        result = self.repo_api.partial_update(self.repo.pulp_href,
                                              {"retained_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)
        self.assertEqual(self.repo.latest_version_href.split("/")[-2], "3")

    def test_autodistribute(self):
        """Test repo version retention with autopublish/autodistribute."""
        self._create_repo_versions({
            "retained_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
        self.distro = self.distro_api.read(self.distro.pulp_href)
        self.assertEqual(self.distro.publication,
                         self.publications[-1].pulp_href)
Beispiel #17
0
# Configure HTTP basic authorization: basic
configuration = Configuration()
configuration.username = '******'
configuration.password = '******'
configuration.safe_chars_for_path_param = '/'

core_client = CoreApiClient(configuration)
file_client = FileApiClient(configuration)

# Create api clients for all resource types
artifacts = ArtifactsApi(core_client)
repositories = RepositoriesApi(core_client)
repoversions = RepositoriesVersionsApi(core_client)
filecontent = ContentFilesApi(file_client)
filedistributions = DistributionsFileApi(core_client)
filepublications = PublicationsFileApi(file_client)
fileremotes = RemotesFileApi(file_client)
tasks = TasksApi(core_client)
uploads = UploadsApi(core_client)


# Test creating an Artifact from a 1mb file uploaded in 200kb chunks
with NamedTemporaryFile() as downloaded_file:
    response = requests.get(
        'https://repos.fedorapeople.org/repos/pulp/pulp/demo_repos/test_bandwidth_repo/'
        'pulp-large_1mb_test-packageA-0.1.1-1.fc14.noarch.rpm')
    response.raise_for_status()
    downloaded_file.write(response.content)
    artifact = upload_file_in_chunks(downloaded_file.name)
    pprint(artifact)
    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)