def do_test(self, repository=None, remote=None): """Sync a repository. Args: repository (pulp_rpm.app.models.repository.RpmRepository): object of RPM repository remote (pulp_rpm.app.models.repository.RpmRemote): object of RPM Remote Returns (tuple): tuple of instances of pulp_rpm.app.models.repository.RpmRepository, pulp_rpm.app.models.repository.RpmRemote """ if repository: repo = self.repo_api.read(repository.pulp_href) else: repo = self.repo_api.create(gen_repo()) self.assertEqual(repo.latest_version_href, f"{repo.pulp_href}versions/0/") if not remote: body = gen_rpm_remote() remote = self.remote_api.create(body) else: remote = self.remote_api.read(remote.pulp_href) repository_sync_data = RpmRepositorySyncURL(remote=remote.pulp_href) sync_response = self.repo_api.sync(repo.pulp_href, repository_sync_data) monitor_task(sync_response.task) return self.repo_api.read(repo.pulp_href), self.remote_api.read( remote.pulp_href)
def test_upload_non_ascii(self): """Test whether one can upload an RPM with non-ascii metadata.""" packages_count = self.content_api.list().count upload = self.do_test(RPM_WITH_NON_ASCII_URL) monitor_task(upload.task) new_packages_count = self.content_api.list().count self.assertTrue((packages_count + 1) == new_packages_count)
def test_04_fully_update(self): """Update a remote using HTTP PUT.""" body = _gen_verbose_remote() response = self.remote_api.update(self.remote.pulp_href, body) monitor_task(response.task) for key in ("username", "password"): del body[key] type(self).remote = self.remote_api.read(self.remote.pulp_href) for key, val in body.items(): with self.subTest(key=key): self.assertEqual(self.remote.to_dict()[key], val, key)
def test_all(self): """Sync and publish an RPM repository and verify the checksum.""" # 1. create repo and remote repo = self.repo_api.create(gen_repo()) self.addCleanup(self.repo_api.delete, repo.pulp_href) body = gen_rpm_remote() remote = self.remote_api.create(body) self.addCleanup(self.remote_api.delete, remote.pulp_href) # 2. Sync it repository_sync_data = RpmRepositorySyncURL(remote=remote.pulp_href) sync_response = self.repo_api.sync(repo.pulp_href, repository_sync_data) monitor_task(sync_response.task) # 3. Publish and distribute publish_data = RpmRpmPublication(repository=repo.pulp_href) publish_response = self.publications.create(publish_data) created_resources = monitor_task(publish_response.task) publication_href = created_resources[0] self.addCleanup(self.publications.delete, publication_href) body = gen_distribution() body["publication"] = publication_href distribution_response = self.distributions.create(body) created_resources = monitor_task(distribution_response.task) distribution = self.distributions.read(created_resources[0]) self.addCleanup(self.distributions.delete, distribution.pulp_href) # 4. check the tag 'sum' is not present in updateinfo.xml repomd = ElementTree.fromstring( http_get(os.path.join(distribution.base_url, 'repodata/repomd.xml'))) with NamedTemporaryFile() as temp_file: update_xml_url = self._get_updateinfo_xml_path(repomd) update_xml_content = http_get( os.path.join(distribution.base_url, update_xml_url)) temp_file.write(update_xml_content) temp_file.seek(0) # TODO: fix this as in CI update_info.xml has '.gz' but # it is not gzipped try: update_xml = gzip.open(temp_file.name).read() except OSError: update_xml = temp_file.read() update_info_content = ElementTree.fromstring(update_xml) tags = {elem.tag for elem in update_info_content.iter()} self.assertNotIn('sum', tags, update_info_content)
def test_02_change_policy(self): """Verify ability to change policy to value other than the default. Update the remote policy to a valid value other than `immedaite` and verify the new set value. """ changed_policy = choice( [item for item in self.policies if item != "immediate"]) response = self.remote_api.partial_update(self.remote["pulp_href"], {"policy": changed_policy}) monitor_task(response.task) self.remote.update( self.remote_api.read(self.remote["pulp_href"]).to_dict()) self.assertEqual(self.remote["policy"], changed_policy, self.remote)
def test_05_duplicate_raise_error(self): """Attempt to create duplicate package.""" attrs = gen_rpm_content_attrs(self.artifact, RPM_PACKAGE_FILENAME) response = self.rpm_content_api.create(**attrs) task_result = monitor_task(response.task) msg = "There is already a package with" self.assertTrue(msg in task_result['error']['description'])
def sync(self, repository=None, remote=None, optimize=True): """Sync a repository and return the task. Args: repository (pulp_rpm.app.models.repository.RpmRepository): object of RPM repository remote (pulp_rpm.app.models.repository.RpmRemote): object of RPM Remote Returns (list): list of the ProgressReport objects created from this sync """ repository_sync_data = RpmRepositorySyncURL(remote=remote.pulp_href, optimize=optimize) sync_response = self.repo_api.sync(repository.pulp_href, repository_sync_data) monitor_task(sync_response.task) return progress_reports(sync_response.task)
def test_single_request_unit_and_duplicate_unit(self): """Test single request upload unit. 1. Upload a unit 2. Attempt to upload same unit """ # Single unit upload upload = self.do_test(self.file_to_use) content = monitor_task(upload.task)[0] package = self.content_api.read(content) self.assertTrue(package.location_href == RPM_PACKAGE_FILENAME) # Duplicate unit upload = self.do_test(self.file_to_use) monitor_task(upload.task) task_report = self.tasks_api.read(upload.task) msg = 'There is already a package with' self.assertTrue(msg in task_report.error['description'])
def test_second_unit_raises_error(self): """ Create a duplicate content unit with different ``artifacts`` and same ``repo_key_fields``. """ delete_orphans() client = gen_rpm_client() packages_api = ContentPackagesApi(client) repo_api = RepositoriesRpmApi(client) repo = repo_api.create(gen_repo()) self.addCleanup(repo_api.delete, repo.pulp_href) artifact = gen_artifact() # create first content unit. content_attrs = { "artifact": artifact["pulp_href"], "relative_path": "test_package" } response = packages_api.create(**content_attrs) monitor_task(response.task) artifact = gen_artifact(url=RPM_SIGNED_URL2) # create second content unit. second_content_attrs = {"artifact": artifact["pulp_href"]} second_content_attrs["relative_path"] = content_attrs["relative_path"] response = packages_api.create(**second_content_attrs) monitor_task(response.task) data = { "add_content_units": [c.pulp_href for c in packages_api.list().results] } response = repo_api.modify(repo.pulp_href, data) task = monitor_task(response.task) error_message = "Cannot create repository version. Path is duplicated: {}.".format( content_attrs["relative_path"]) self.assertEqual(task["error"]["description"], error_message)
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) publication_href = created_resources[0] self.assertIsNotNone(publication_href) self.addCleanup(publications.delete, publication_href)
def test_01_create_content_unit(self): """Create content unit.""" attrs = gen_rpm_content_attrs(self.artifact, RPM_PACKAGE_FILENAME) response = self.rpm_content_api.create(**attrs) # rpm package doesn't keep relative_path but the location href del attrs['relative_path'] created_resources = monitor_task(response.task) content_unit = self.rpm_content_api.read(created_resources[0]) self.content_unit.update(content_unit.to_dict()) for key, val in attrs.items(): with self.subTest(key=key): self.assertEqual(self.content_unit[key], val)
def do_test(self, url): """Sync and publish an RPM repository given a feed URL.""" repo = self.repo_api.create(gen_repo()) self.addCleanup(self.repo_api.delete, repo.pulp_href) body = gen_rpm_remote(url=url) remote = self.remote_api.create(body) self.addCleanup(self.remote_api.delete, remote.pulp_href) repository_sync_data = RpmRepositorySyncURL(remote=remote.pulp_href) sync_response = self.repo_api.sync(repo.pulp_href, repository_sync_data) monitor_task(sync_response.task) publish_data = RpmRpmPublication(repository=repo.pulp_href) publish_response = self.publications.create(publish_data) created_resources = monitor_task(publish_response.task) publication_href = created_resources[0] self.addCleanup(self.publications.delete, publication_href) self.assertIsNotNone(publication_href)
def do_test(self, url): """Sync a repository given ``url`` on the remote.""" repo_api = RepositoriesRpmApi(self.client) remote_api = RemotesRpmApi(self.client) repo = repo_api.create(gen_repo()) self.addCleanup(repo_api.delete, repo.pulp_href) body = gen_rpm_remote(url=url) remote = remote_api.create(body) self.addCleanup(remote_api.delete, remote.pulp_href) repository_sync_data = RpmRepositorySyncURL(remote=remote.pulp_href) sync_response = repo_api.sync(repo.pulp_href, repository_sync_data) return monitor_task(sync_response.task)
def test_file_decriptors(self): """Test whether file descriptors are closed properly. This test targets the following issue: `Pulp #4073 <https://pulp.plan.io/issues/4073>`_ Do the following: 1. Check if 'lsof' is installed. If it is not, skip this test. 2. Create and sync a repo. 3. Run the 'lsof' command to verify that files in the path ``/var/lib/pulp/`` are closed after the sync. 4. Assert that issued command returns `0` opened files. """ cli_client = cli.Client(self.cfg, cli.echo_handler) # check if 'lsof' is available if cli_client.run(("which", "lsof")).returncode != 0: raise unittest.SkipTest("lsof package is not present") repo_api = RepositoriesRpmApi(self.client) repo = repo_api.create(gen_repo()) self.addCleanup(repo_api.delete, repo.pulp_href) remote_api = RemotesRpmApi(self.client) remote = remote_api.create(gen_rpm_remote()) self.addCleanup(remote_api.delete, remote.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) cmd = "lsof -t +D {}".format(MEDIA_PATH).split() response = cli_client.run(cmd).stdout self.assertEqual(len(response), 0, response)
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, 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) 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) 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 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 test_05_delete(self): """Delete a remote.""" response = self.remote_api.delete(self.remote.pulp_href) monitor_task(response.task) with self.assertRaises(ApiException): self.remote_api.read(self.remote.pulp_href)
def test_optimize(self): """Sync is no-op without changes. This test targets the following issue: `Pulp #6313 <https://pulp.plan.io/issues/6313>`_ If there are no changes, a full sync should not be done. Do the following: 1. Sync (a repo and a remote will be created automatically). 2. Sync again to get our task dictionary. 3. Assert an "Optimizing Sync" progress report is present. 4. Sync again with flag "optimize=False". 5. Assert "Optimizing Sync" progress report is absent. # 6. **Create a new repo version. # 7. Sync again (no flag). # 8. Assert "Optimizing Sync" progress report is absent. 9. Update remote to have "policy=immediate". 10. Sync again. 11. Assert "Optimizing Sync" progress report is absent. 12. Create a new (different) remote. 13. Sync using the new remote. 14. Assert "Optimizing Sync" progress report is absent. # 15. Sync again with the new remote. # 16. Assert an "Optimizing Sync" progress report is present. """ # sync repo, remote = self.do_test() # add resources to clean up self.addCleanup(self.repo_api.delete, repo.pulp_href) self.addCleanup(self.remote_api.delete, remote.pulp_href) # sync, get progress reports from task report_list = self.sync(repository=repo, remote=remote) # check for an optimization progress report optimized = self.optimize_report(progress_reports=report_list) # check that sync was optimized self.assertTrue(optimized) # sync again with flag optimize=False report_list = self.sync(repository=repo, remote=remote, optimize=False) # check for an optimization progress report optimized = self.optimize_report(progress_reports=report_list) # check that sync was not optimized self.assertFalse(optimized) # create a new repo version content = choice(get_content(repo.to_dict())[RPM_PACKAGE_CONTENT_NAME]) modify_repo(config.get_config(), repo.to_dict(), remove_units=[content]) # sync, get progress reports from task report_list = self.sync(repository=repo, remote=remote) # check for an optimization progress report optimized = self.optimize_report(progress_reports=report_list) # check that sync was not optimized self.assertFalse(optimized) # update remote body = {"policy": "immediate"} response = self.remote_api.partial_update(remote.pulp_href, body) monitor_task(response.task) # sync, get progress reports from task report_list = self.sync(repository=repo, remote=remote) # check for an optimization progress report optimized = self.optimize_report(progress_reports=report_list) # check that sync was not optimized self.assertFalse(optimized) # create new remote body = gen_rpm_remote() body['url'] = RPM_RICH_WEAK_FIXTURE_URL new_remote = self.remote_api.create(body) # add resource to clean up self.addCleanup(self.remote_api.delete, new_remote.pulp_href) # sync with new remote report_list = self.sync(repository=repo, remote=new_remote) # check for an optimization progress report optimized = self.optimize_report(progress_reports=report_list) # check that sync was not optimized self.assertFalse(optimized) # sync again with new remote report_list = self.sync(repository=repo, remote=new_remote) # check for an optimization progress report optimized = self.optimize_report(progress_reports=report_list) # check that sync was optimized self.assertTrue(optimized)
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) 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) 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)