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)))
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 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