def test_all(self): """Sync/publish a repo that ``updateinfo.xml`` contains references. This test targets the following issue: `Pulp #3998 <https://pulp.plan.io/issues/3998>`_. """ client = gen_rpm_client() repo_api = RepositoriesRpmApi(client) remote_api = RemotesRpmApi(client) publications = PublicationsRpmApi(client) repo = repo_api.create(gen_repo()) self.addCleanup(repo_api.delete, repo.pulp_href) body = gen_rpm_remote(RPM_REFERENCES_UPDATEINFO_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 = 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) self.assertIsNotNone(repo.latest_version_href) content_summary = get_content_summary(repo.to_dict()) self.assertDictEqual(content_summary, RPM_FIXTURE_SUMMARY, content_summary) 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.assertIsNotNone(publication_href) self.addCleanup(publications.delete, publication_href)
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 do_test(self, download_policy): """Sync repositories with the different ``download_policy``. Do the following: 1. Create a repository, and a remote. 2. Sync the remote. 3. Assert that repository version is not None. 4. Assert that the correct number of possible units to be downloaded were shown. 5. Sync the remote one more time in order to create another repository version. 6. Assert that repository version is different from the previous one. 7. 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. 8. Publish repository synced with lazy ``download_policy``. """ repo_api = RepositoriesRpmApi(self.client) remote_api = RemotesRpmApi(self.client) publications = PublicationsRpmApi(self.client) repo = repo_api.create(gen_repo()) self.addCleanup(repo_api.delete, repo.pulp_href) body = gen_rpm_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 = 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) self.assertDictEqual(get_content_summary(repo.to_dict()), RPM_FIXTURE_SUMMARY) self.assertDictEqual(get_added_content_summary(repo.to_dict()), RPM_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()), RPM_FIXTURE_SUMMARY) # Publish 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) publication = publications.read(publication_href) self.assertIsNotNone(publication.repository) self.assertIsNotNone(publication.repository_version)
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) body = gen_rpm_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 = 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) for rpm_content in get_content( repo.to_dict())[RPM_PACKAGE_CONTENT_NAME]: modify_repo(cfg, repo.to_dict(), add_units=[rpm_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 = 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) 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 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)
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)