def setUpClass(cls) -> None: """Set up the class.""" cls.client = gen_rpm_client() cls.repo_api = RepositoriesRpmApi(cls.client) cls.publications_api = PublicationsRpmApi(cls.client) cls.distributions_api = DistributionsRpmApi(cls.client) delete_orphans()
def setUpClass(cls): """ Create all the client instances needed to communicate with Pulp. """ configuration = Configuration(**BINDINGS_CONFIGURATION) rpm_client = RpmApiClient(configuration) migration_client = MigrationApiClient(configuration) # Create api clients for all resource types 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), # skip until https://pulp.plan.io/issues/8050 is fixed # '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), } cls.migration_plans_api = MigrationPlansApi(migration_client)
def setUpClass(cls): """ Create all the client instances needed to communicate with Pulp. """ configuration = Configuration(**BINDINGS_CONFIGURATION) rpm_client = RpmApiClient(configuration) migration_client = MigrationApiClient(configuration) # Create api clients for all resource types 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), } cls.migration_plans_api = MigrationPlansApi(migration_client) cls.pulp2content_api = Pulp2ContentApi(migration_client) cls.pulp2repositories_api = Pulp2RepositoriesApi(migration_client)
def setUpClass(cls): """Create class-wide variables.""" cls.cfg = config.get_config() cls.client = gen_rpm_client() cls.repo_api = RepositoriesRpmApi(cls.client) cls.remote_api = RemotesRpmApi(gen_rpm_client()) cls.publications = PublicationsRpmApi(cls.client) cls.distributions = DistributionsRpmApi(cls.client)
def setUpClass(cls): """Create class-wide variables.""" cls.cfg = config.get_config() cls.client = gen_rpm_client() cls.cli_client = cli.Client(cls.cfg) cls.repo_api = RepositoriesRpmApi(cls.client) cls.remote_api = RemotesRpmApi(gen_rpm_client()) cls.publications = PublicationsRpmApi(cls.client) cls.distributions = DistributionsRpmApi(cls.client) cls.md5_allowed = "md5" in get_pulp_setting(cls.cli_client, "ALLOWED_CONTENT_CHECKSUMS")
def setUpClass(cls): """Verify whether dnf or yum are present.""" cls.cfg = config.get_config() configuration = cls.cfg.get_bindings_config() core_client = CoreApiClient(configuration) cls.artifacts_api = ArtifactsApi(core_client) cls.client = gen_rpm_client() cls.repo_api = RepositoriesRpmApi(cls.client) cls.remote_api = RemotesRpmApi(cls.client) cls.publications = PublicationsRpmApi(cls.client) cls.distributions = DistributionsRpmApi(cls.client) cls.before_consumption_artifact_count = 0 cls.pkg_mgr = cli.PackageManager(cls.cfg) cls.pkg_mgr.raise_if_unsupported(unittest.SkipTest, "This test requires dnf or yum.")
def setUpClass(cls): """Create class-wide variables.""" cls.cfg = config.get_config() cls.client = gen_rpm_client() cls.repo_api = RepositoriesRpmApi(cls.client) cls.remote_api = RemotesRpmApi(gen_rpm_client()) cls.publications = PublicationsRpmApi(cls.client) cls.distributions = DistributionsRpmApi(cls.client) if ( os.environ.get("CDN_CLIENT_CERT", None) and os.environ.get("CDN_CLIENT_KEY", None) and os.environ.get("CDN_CA_CERT", None) ): # strings have escaped newlines from environmental variable cls.cdn_client_cert = os.environ["CDN_CLIENT_CERT"].replace("\\n", "\n") cls.cdn_client_key = os.environ["CDN_CLIENT_KEY"].replace("\\n", "\n") cls.cdn_ca_cert = os.environ["CDN_CA_CERT"].replace("\\n", "\n") else: cls.cdn_client_cert = None
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)
def do_test(self, url, policy="on_demand"): """Verify whether content served by pulp can be synced. 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. Sync other repository using as remote url, the distribution base_url from the previous repository. """ client = gen_rpm_client() repo_api = RepositoriesRpmApi(client) remote_api = RemotesRpmApi(client) publications = PublicationsRpmApi(client) distributions = DistributionsRpmApi(client) repo = repo_api.create(gen_repo()) self.addCleanup(repo_api.delete, repo.pulp_href) body = gen_rpm_remote(url=url, policy=policy) remote = remote_api.create(body) self.addCleanup(remote_api.delete, remote.pulp_href) # Sync a Repository repository_sync_data = RpmRepositorySyncURL(remote=remote.pulp_href) sync_response = repo_api.sync(repo.pulp_href, repository_sync_data) monitor_task(sync_response.task) sync_task = tasks.read(sync_response.task) task_duration = sync_task.finished_at - sync_task.started_at waiting_time = sync_task.started_at - sync_task.pulp_created print( "\n-> Sync => Waiting time (s): {wait} | Service time (s): {service}".format( wait=waiting_time.total_seconds(), service=task_duration.total_seconds() ) ) repo = repo_api.read(repo.pulp_href) # Create a publication. publish_data = RpmRpmPublication(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) # Create a distribution. 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) # Create another repo pointing to distribution base_url repo2 = repo_api.create(gen_repo()) self.addCleanup(repo_api.delete, repo2.pulp_href) body = gen_rpm_remote(url=distribution.base_url, policy=policy) remote2 = remote_api.create(body) self.addCleanup(remote_api.delete, remote2.pulp_href) # Sync a Repository repository_sync_data = RpmRepositorySyncURL(remote=remote2.pulp_href) sync_response = repo_api.sync(repo2.pulp_href, repository_sync_data) monitor_task(sync_response.task) sync_task = tasks.read(sync_response.task) task_duration = sync_task.finished_at - sync_task.started_at waiting_time = sync_task.started_at - sync_task.pulp_created print( "\n-> Sync => Waiting time (s): {wait} | Service time (s): {service}".format( wait=waiting_time.total_seconds(), service=task_duration.total_seconds() ) ) repo2 = repo_api.read(repo2.pulp_href) summary = get_content_summary(repo.to_dict()) summary2 = get_content_summary(repo2.to_dict()) self.assertDictEqual(summary, summary2) added = get_added_content_summary(repo.to_dict()) added2 = get_added_content_summary(repo2.to_dict()) self.assertDictEqual(added, added2)
def do_test(self, policy): """Verify whether content served by pulp can be synced. 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. Sync other repository using as remote url, the distribution base_url from the previous repository. """ client = gen_rpm_client() repo_api = RepositoriesRpmApi(client) remote_api = RemotesRpmApi(client) publications = PublicationsRpmApi(client) distributions = DistributionsRpmApi(client) repo = repo_api.create(gen_repo()) self.addCleanup(repo_api.delete, repo.pulp_href) body = gen_rpm_remote(url=RPM_KICKSTART_FIXTURE_URL, policy=policy) remote = remote_api.create(body) self.addCleanup(remote_api.delete, remote.pulp_href) # Sync a Repository repository_sync_data = RpmRepositorySyncURL(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 = RpmRpmPublication( repository=repo.pulp_href, metadata_checksum_type="sha1", package_checksum_type="sha224", ) 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) # Create another repo pointing to distribution base_url repo2 = repo_api.create(gen_repo()) self.addCleanup(repo_api.delete, repo2.pulp_href) body = gen_rpm_remote(url=distribution.base_url, policy=policy) remote2 = remote_api.create(body) self.addCleanup(remote_api.delete, remote2.pulp_href) # Sync a Repository repository_sync_data = RpmRepositorySyncURL(remote=remote2.pulp_href) sync_response = repo_api.sync(repo2.pulp_href, repository_sync_data) monitor_task(sync_response.task) repo2 = repo_api.read(repo2.pulp_href) summary = get_content_summary(repo.to_dict()) summary2 = get_content_summary(repo2.to_dict()) self.assertDictEqual(summary, summary2) added = get_added_content_summary(repo.to_dict()) added2 = get_added_content_summary(repo2.to_dict()) self.assertDictEqual(added, added2)
def rpm_distribution_api(rpm_client): """Fixture for RPM distribution API.""" return DistributionsRpmApi(rpm_client)
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_rpm_client() repo_api = RepositoriesRpmApi(client) remote_api = RemotesRpmApi(client) publications = PublicationsRpmApi(client) distributions = DistributionsRpmApi(client) body = gen_rpm_remote() remote = remote_api.create(body) repo = repo_api.create(gen_repo()) repository_sync_data = RpmRepositorySyncURL(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) repo_content = get_content( repo.to_dict())[RPM_PACKAGE_CONTENT_NAME][:-1] for rpm_content in repo_content: modify_repo(cfg, repo.to_dict(), remove_units=[rpm_content]) version_hrefs = tuple(ver["pulp_href"] for ver in get_versions(repo.to_dict())) non_latest = choice(version_hrefs[1:-1]) # Step 2 publish_data = RpmRpmPublication(repository=repo.pulp_href) publish_response = publications.create(publish_data) created_resources = monitor_task( publish_response.task).created_resources publication_href = created_resources[0] publication = publications.read(publication_href) # Step 3 self.assertEqual(publication.repository_version, version_hrefs[-1]) # Step 4 publish_data.repository_version = non_latest publish_data.repository = None publish_response = publications.create(publish_data) created_resources = monitor_task( publish_response.task).created_resources publication_href = created_resources[0] publication = publications.read(publication_href) # Step 5 body = gen_distribution() body["base_path"] = "pulp_pre_upgrade_test" body["publication"] = publication.pulp_href distribution_response = distributions.create(body) created_resources = monitor_task( distribution_response.task).created_resources distribution = distributions.read(created_resources[0]) # Step 6 self.assertEqual(publication.repository_version, non_latest) # Step 7 with self.assertRaises(ApiException): body = { "repository": repo.pulp_href, "repository_version": non_latest } publications.create(body) # Step 8 url = cfg.get_content_host_base_url( ) + "/pulp/content/pulp_pre_upgrade_test/" self.assertEqual(url, distribution.base_url, url)
def test_all(self): """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_rpm_client() repo_api = RepositoriesRpmApi(client) remote_api = RemotesRpmApi(client) publications = PublicationsRpmApi(client) distributions = DistributionsRpmApi(client) repo = repo_api.create(gen_repo()) self.addCleanup(repo_api.delete, repo.pulp_href) body = gen_rpm_remote(RPM_UNSIGNED_FIXTURE_URL) remote = remote_api.create(body) self.addCleanup(remote_api.delete, remote.pulp_href) # Sync a Repository repository_sync_data = RpmRepositorySyncURL(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 = RpmRpmPublication(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 content unit (of each type), and download it from both Pulp Fixtures… unit_path = choice(get_rpm_package_paths(repo.to_dict())) fixture_hash = hashlib.sha256( utils.http_get(urljoin(RPM_UNSIGNED_FIXTURE_URL, unit_path)) ).hexdigest() # …and Pulp. pkg_path = get_package_repo_path(unit_path) content = download_content_unit(cfg, distribution.to_dict(), pkg_path) pulp_hash = hashlib.sha256(content).hexdigest() self.assertEqual(fixture_hash, pulp_hash)
def do_test(self, policy): """Verify whether content served by Pulp can be synced. The initial sync to Pulp is one of many different download policies, the second sync is immediate in order to exercise downloading all of the files. Do the following: 1. Create, populate, publish, and distribute a repository. 2. Sync other repository using as remote url, the distribution base_url from the previous repository. """ client = gen_rpm_client() repo_api = RepositoriesRpmApi(client) remote_api = RemotesRpmApi(client) publications = PublicationsRpmApi(client) distributions = DistributionsRpmApi(client) repo = repo_api.create(gen_repo()) self.addCleanup(repo_api.delete, repo.pulp_href) body = gen_rpm_remote(url=RPM_KICKSTART_FIXTURE_URL, policy=policy) remote = remote_api.create(body) self.addCleanup(remote_api.delete, remote.pulp_href) # Sync a Repository repository_sync_data = RpmRepositorySyncURL(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 = RpmRpmPublication( repository=repo.pulp_href, metadata_checksum_type="sha384", package_checksum_type="sha224", ) 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) # Create a distribution. 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) # Create another repo pointing to distribution base_url repo2 = repo_api.create(gen_repo()) self.addCleanup(repo_api.delete, repo2.pulp_href) body = gen_rpm_remote(url=distribution.base_url, policy="immediate") remote2 = remote_api.create(body) self.addCleanup(remote_api.delete, remote2.pulp_href) # Sync a Repository repository_sync_data = RpmRepositorySyncURL(remote=remote2.pulp_href) sync_response = repo_api.sync(repo2.pulp_href, repository_sync_data) monitor_task(sync_response.task) repo2 = repo_api.read(repo2.pulp_href) summary = get_content_summary(repo.to_dict()) summary2 = get_content_summary(repo2.to_dict()) self.assertDictEqual(summary, summary2) added = get_added_content_summary(repo.to_dict()) added2 = get_added_content_summary(repo2.to_dict()) self.assertDictEqual(added, added2)