def test_publish_with_unsupported_checksum_type(self): """ Sync and try publish an RPM repository. - Sync repository with on_demand policy - Try to publish with 'md5' checksum type - Publish should fail because 'md5' is not allowed This test require disallowed 'MD5' checksum type from ALLOWED_CONTENT_CHECKSUMS settings. """ # 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(policy="on_demand") 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 fail publish_data = RpmRpmPublication(repository=repo.pulp_href, package_checksum_type="md5") with self.assertRaises(ApiException) as ctx: self.publications.create(publish_data) self.assertIn("Checksum must be one of the allowed checksum types.", ctx.exception.body)
def _create_publication_for(self, repo): publish_data = RpmRpmPublication(repository=repo.pulp_href) publish_response = self.publications.create(publish_data) created_resources = monitor_task(publish_response.task).created_resources self.assertIsNotNone(created_resources) self.assertTrue(len(created_resources) > 0) publication_href = created_resources[0] return publication_href
def do_test(self, with_sqlite): """Sync and publish an RPM repository.""" # 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(policy="on_demand") 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, sqlite_metadata=with_sqlite) publish_response = self.publications.create(publish_data) created_resources = monitor_task( publish_response.task).created_resources 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).created_resources distribution = self.distributions.read(created_resources[0]) self.addCleanup(self.distributions.delete, distribution.pulp_href) repomd = ElementTree.fromstring( http_get(os.path.join(distribution.base_url, "repodata/repomd.xml"))) data_xpath = "{{{}}}data".format(RPM_NAMESPACES["metadata/repo"]) data_elems = [elem for elem in repomd.findall(data_xpath)] sqlite_files = [ elem for elem in data_elems if elem.get("type").endswith("_db") ] if with_sqlite: self.assertEqual(3, len(sqlite_files)) for db_elem in sqlite_files: location_xpath = "{{{}}}location".format( RPM_NAMESPACES["metadata/repo"]) db_href = db_elem.find(location_xpath).get("href") http_get(os.path.join(distribution.base_url, db_href)) else: self.assertEqual(0, len(sqlite_files))
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 setUp(self): """Setup method.""" self.repo = self.repo_api.create(gen_repo()) publish_data = RpmRpmPublication(repository=self.repo.pulp_href) publish_response = self.publications_api.create(publish_data) created_resources = monitor_task( publish_response.task).created_resources self.publication = self.publications_api.read(created_resources[0]) dist_data = gen_distribution(publication=self.publication.pulp_href) dist_response = self.distributions_api.create(dist_data) created_resources = monitor_task(dist_response.task).created_resources self.dist = self.distributions_api.read(created_resources[0])
def do_test(self, url=None): """Sync and publish an RPM repository. - create repository - create remote - sync the remote - create publication - create distribution Args: url(string): Optional URL of repositoy that should be use as a remote Returns (string): RPM distribution base_url. """ repo = self.repo_api.create(gen_repo()) self.addCleanup(self.repo_api.delete, repo.pulp_href) if url: body = gen_rpm_remote(url=url) else: body = gen_rpm_remote() 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).created_resources 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).created_resources distribution = self.distributions.read(created_resources[0]) self.addCleanup(self.distributions.delete, distribution.pulp_href) return distribution.to_dict()["base_url"]
def setUp(self) -> None: """Set up the test.""" repo = self.repo_api.create(gen_repo()) self.addCleanup(self.repo_api.delete, repo.pulp_href) publish_data = RpmRpmPublication(repository=repo.pulp_href) publish_response = self.publications_api.create(publish_data) created_resources = monitor_task(publish_response.task) publication_href = created_resources[0] self.addCleanup(self.publications_api.delete, publication_href) dist_data = gen_distribution(publication=publication_href) dist_response = self.distributions_api.create(dist_data) created_resources = monitor_task(dist_response.task) self.dist = self.distributions_api.read(created_resources[0]) self.addCleanup(self.distributions_api.delete, self.dist.pulp_href)
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).created_resources 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).created_resources 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"))) update_xml_url = self._get_updateinfo_xml_path(repomd) update_xml_content = http_get( os.path.join(distribution.base_url, update_xml_url)) update_xml = read_xml_gz(update_xml_content) 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_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): """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).created_resources publication_href = created_resources[0] self.addCleanup(self.publications.delete, publication_href) self.assertIsNotNone(publication_href)
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, 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, 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 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 get_checksum_types(self, **kwargs): """Sync and publish an RPM repository.""" fixture_url = kwargs.get("fixture_url", RPM_UNSIGNED_FIXTURE_URL) package_checksum_type = kwargs.get("package_checksum_type") metadata_checksum_type = kwargs.get("metadata_checksum_type") policy = kwargs.get("policy", "immediate") # 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(policy=policy, url=fixture_url) 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, mirror=False) 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, package_checksum_type=package_checksum_type, metadata_checksum_type=metadata_checksum_type, ) publish_response = self.publications.create(publish_data) created_resources = monitor_task( publish_response.task).created_resources 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).created_resources distribution = self.distributions.read(created_resources[0]) self.addCleanup(self.distributions.delete, distribution.pulp_href) repomd = ElementTree.fromstring( http_get(os.path.join(distribution.base_url, "repodata/repomd.xml"))) data_xpath = "{{{}}}data".format(RPM_NAMESPACES["metadata/repo"]) data_elems = [elem for elem in repomd.findall(data_xpath)] repomd_checksum_types = {} primary_checksum_types = {} checksum_xpath = "{{{}}}checksum".format( RPM_NAMESPACES["metadata/repo"]) for data_elem in data_elems: checksum_type = data_elem.find(checksum_xpath).get("type") repomd_checksum_types[data_elem.get("type")] = checksum_type if data_elem.get("type") == "primary": location_xpath = "{{{}}}location".format( RPM_NAMESPACES["metadata/repo"]) primary_href = data_elem.find(location_xpath).get("href") primary = ElementTree.fromstring( read_xml_gz( http_get( os.path.join(distribution.base_url, primary_href)))) package_checksum_xpath = "{{{}}}checksum".format( RPM_NAMESPACES["metadata/common"]) package_xpath = "{{{}}}package".format( RPM_NAMESPACES["metadata/common"]) package_elems = [ elem for elem in primary.findall(package_xpath) ] pkg_checksum_type = package_elems[0].find( package_checksum_xpath).get("type") primary_checksum_types[package_elems[0].get( "type")] = pkg_checksum_type return repomd_checksum_types, primary_checksum_types
def test_rbac_publication(gen_user, rpm_rpmremote_api, rpm_repository_api, rpm_publication_api): """Test RPM publication CRUD.""" user_creator = gen_user( model_roles=[ "rpm.rpmpublication_creator", "rpm.rpmremote_owner", "rpm.rpmrepository_owner", ] ) user_viewer = gen_user( model_roles=[ "rpm.viewer", "rpm.rpmremote_owner", "rpm.rpmrepository_owner", ] ) user_no = gen_user( model_roles=[ "rpm.rpmremote_owner", "rpm.rpmrepository_owner", ] ) publication = None remote_data = gen_rpm_remote(RPM_UNSIGNED_FIXTURE_URL) remote = rpm_rpmremote_api.create(remote_data) repo = rpm_repository_api.create(gen_repo()) sync_url = RpmRepositorySyncURL(remote=remote.pulp_href) sync_res = rpm_repository_api.sync(repo.pulp_href, sync_url) monitor_task(sync_res.task) repository = rpm_repository_api.read(repo.pulp_href) # Create with user_creator: publish_data = RpmRpmPublication(repository=repo.pulp_href) publish_response = rpm_publication_api.create(publish_data) created_resources = monitor_task(publish_response.task).created_resources publication = rpm_publication_api.read(created_resources[0]) assert rpm_publication_api.list().count == 1 with user_viewer, pytest.raises(ApiException) as exc: publish_data = RpmRpmPublication(repository=repo.pulp_href) rpm_publication_api.create(publish_data) assert exc.value.status == 403 with user_no, pytest.raises(ApiException) as exc: publish_data = RpmRpmPublication(repository=repo.pulp_href) rpm_publication_api.create(publish_data) assert exc.value.status == 403 # Remove with user_no, pytest.raises(ApiException) as exc: rpm_publication_api.delete(publication.pulp_href) assert exc.value.status == 404 with user_viewer, pytest.raises(ApiException) as exc: rpm_publication_api.delete(publication.pulp_href) assert exc.value.status == 403 with user_creator: rpm_publication_api.delete(publication.pulp_href) res = rpm_repository_api.delete(repository.pulp_href) monitor_task(res.task) res = rpm_rpmremote_api.delete(remote.pulp_href) monitor_task(res.task) assert rpm_publication_api.list().count == 0
def test_all(self): """Test whether a particular repository version can be published. 1. Create a repository with at least 2 repository versions. 2. Create a publication by supplying the latest ``repository_version``. 3. Assert that the publication ``repository_version`` attribute points to the latest repository version. 4. Create a publication by supplying the non-latest ``repository_version``. 5. Assert that the publication ``repository_version`` attribute points to the supplied repository version. 6. Assert that an exception is raised when providing two different repository versions to be published at same time. """ cfg = config.get_config() client = gen_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 do_metadata_comparison_test(self, repo_url): """Sync and publish an RPM repository and verify the metadata is what was expected.""" # 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(repo_url, policy="on_demand") remote = self.remote_api.create(body) self.addCleanup(self.remote_api.delete, remote.pulp_href) # 2, 3. Sync, publish and distribute 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).created_resources 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).created_resources distribution = self.distributions.read(created_resources[0]) self.addCleanup(self.distributions.delete, distribution.pulp_href) # 4. Download and parse the metadata. original_repomd = ElementTree.fromstring( http_get(os.path.join(repo_url, "repodata/repomd.xml"))) reproduced_repomd = ElementTree.fromstring( http_get(os.path.join(distribution.base_url, "repodata/repomd.xml"))) def get_metadata_content(base_url, repomd_elem, meta_type): """Return the text contents of metadata file. Provided a url, a repomd root element, and a metadata type, locate the metadata file's location href, download it from the provided url, un-gzip it, parse it, and return the root element node. Don't use this with large repos because it will blow up. """ # <ns0:repomd xmlns:ns0="http://linux.duke.edu/metadata/repo"> # <ns0:data type="primary"> # <ns0:checksum type="sha256">[…]</ns0:checksum> # <ns0:location href="repodata/[…]-primary.xml.gz" /> # … # </ns0:data> # … xpath = "{{{}}}data".format(RPM_NAMESPACES["metadata/repo"]) data_elems = [ elem for elem in repomd_elem.findall(xpath) if elem.get("type") == meta_type ] xpath = "{{{}}}location".format(RPM_NAMESPACES["metadata/repo"]) location_href = data_elems[0].find(xpath).get("href") return read_xml_gz(http_get(os.path.join(base_url, location_href))) # 5, 6. Convert the metadata into a more workable form and then compare. for metadata_file in ["primary", "filelists", "other"]: with self.subTest(metadata_file): original_metadata = get_metadata_content( repo_url, original_repomd, metadata_file) generated_metadata = get_metadata_content( distribution.base_url, reproduced_repomd, metadata_file) self.compare_metadata_file(original_metadata, generated_metadata, metadata_file)
def test_rbac_distribution( gen_user, rpm_repository_api, rpm_rpmremote_api, rpm_publication_api, rpm_distribution_api ): """Test RPM distribution CRUD.""" user_creator = gen_user( model_roles=[ "rpm.rpmdistribution_creator", "rpm.rpmpublication_owner", "rpm.rpmremote_owner", "rpm.rpmrepository_owner", ] ) user_viewer = gen_user( model_roles=[ "rpm.viewer", "rpm.rpmpublication_owner", "rpm.rpmremote_owner", "rpm.rpmrepository_owner", ] ) user_no = gen_user( model_roles=[ "rpm.rpmpublication_owner", "rpm.rpmremote_owner", "rpm.rpmrepository_owner", ] ) distribution = None remote_data = gen_rpm_remote(RPM_UNSIGNED_FIXTURE_URL) remote = rpm_rpmremote_api.create(remote_data) repo = rpm_repository_api.create(gen_repo()) sync_url = RpmRepositorySyncURL(remote=remote.pulp_href) sync_res = rpm_repository_api.sync(repo.pulp_href, sync_url) monitor_task(sync_res.task) publish_data = RpmRpmPublication(repository=repo.pulp_href) publish_response = rpm_publication_api.create(publish_data) created_resources = monitor_task(publish_response.task).created_resources publication = rpm_publication_api.read(created_resources[0]) # Create dist_data = RpmRpmDistribution( name=uuid4(), publication=publication.pulp_href, base_path=uuid4() ) with user_no, pytest.raises(ApiException) as exc: rpm_distribution_api.create(dist_data) assert exc.value.status == 403 with user_viewer, pytest.raises(ApiException) as exc: rpm_distribution_api.create(dist_data) assert exc.value.status == 403 with user_creator: res = rpm_distribution_api.create(dist_data) distribution = rpm_distribution_api.read(monitor_task(res.task).created_resources[0]) assert rpm_distribution_api.list().count == 1 # Update dist_data_to_update = rpm_distribution_api.read(distribution.pulp_href) new_name = uuid4() dist_data_to_update.name = new_name with user_no, pytest.raises(ApiException) as exc: rpm_distribution_api.update(distribution.pulp_href, dist_data_to_update) assert exc.value.status == 404 with user_viewer, pytest.raises(ApiException) as exc: rpm_distribution_api.update(distribution.pulp_href, dist_data_to_update) assert exc.value.status == 403 with user_creator: res = rpm_distribution_api.update(distribution.pulp_href, dist_data_to_update) monitor_task(res.task) assert rpm_distribution_api.list().count == 1 assert new_name in rpm_distribution_api.list().results[0].name # Remove with user_no, pytest.raises(ApiException) as exc: rpm_distribution_api.delete(distribution.pulp_href) assert exc.value.status == 404 with user_viewer, pytest.raises(ApiException) as exc: rpm_distribution_api.delete(distribution.pulp_href) assert exc.value.status == 403 with user_creator: rpm_distribution_api.delete(distribution.pulp_href) rpm_publication_api.delete(publication.pulp_href) res = rpm_repository_api.delete(repo.pulp_href) monitor_task(res.task) res = rpm_rpmremote_api.delete(remote.pulp_href) monitor_task(res.task) assert rpm_distribution_api.list().count == 0 assert rpm_repository_api.list().count == 0 assert rpm_rpmremote_api.list().count == 0
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)
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)