def test_updatecollection_setters(self): col = cr.UpdateCollection() self.assertTrue(col) self.assertEqual(col.shortname, None) self.assertEqual(col.name, None) self.assertEqual(col.packages, []) module = cr.UpdateCollectionModule() module.name = "kangaroo" module.stream = "0" module.version = 20180730223407 module.context = "deadbeef" module.arch = "noarch" pkg = cr.UpdateCollectionPackage() pkg.name = "foo" pkg.version = "1.2" pkg.release = "3" pkg.epoch = "0" pkg.arch = "x86" pkg.src = "foo.src.rpm" pkg.filename = "foo.rpm" pkg.sum = "abcdef" pkg.sum_type = cr.SHA1 pkg.reboot_suggested = True col.shortname = "short name" col.name = "long name" col.module = module col.append(pkg) self.assertEqual(col.shortname, "short name") self.assertEqual(col.name, "long name") self.assertEqual(len(col.packages), 1) # Check if the appended module was appended properly module = col.module self.assertEqual(module.name, "kangaroo") self.assertEqual(module.stream, "0") self.assertEqual(module.version, 20180730223407) self.assertEqual(module.context, "deadbeef") self.assertEqual(module.arch, "noarch") # Also check if the appended package was appended properly pkg = col.packages[0] self.assertEqual(pkg.name, "foo") self.assertEqual(pkg.version, "1.2") self.assertEqual(pkg.release, "3") self.assertEqual(pkg.epoch, "0") self.assertEqual(pkg.arch, "x86") self.assertEqual(pkg.src, "foo.src.rpm") self.assertEqual(pkg.filename, "foo.rpm") self.assertEqual(pkg.sum, "abcdef") self.assertEqual(pkg.sum_type, cr.SHA1) self.assertEqual(pkg.reboot_suggested, True)
def update_record_xml(update_record): """ Return xml for an UpdateRecord. Args: update_record (app.models.UpdateRecord): create xml from this record Returns: str: xml for the UpdateRecord """ rec = cr.UpdateRecord() rec.fromstr = update_record.fromstr rec.status = update_record.status rec.type = update_record.type rec.version = update_record.version rec.id = update_record.id rec.title = update_record.title rec.issued_date = parse_datetime(update_record.issued_date) rec.updated_date = parse_datetime(update_record.updated_date) rec.rights = update_record.rights rec.summary = update_record.summary rec.description = update_record.description for collection in update_record.collections.all(): col = cr.UpdateCollection() col.shortname = collection.shortname col.name = collection.name for package in collection.packages.all(): pkg = cr.UpdateCollectionPackage() pkg.name = package.name pkg.version = package.version pkg.release = package.release pkg.epoch = package.epoch pkg.arch = package.arch pkg.src = package.src pkg.filename = package.filename pkg.reboot_suggested = package.reboot_suggested if package.sum: pkg.sum = package.sum pkg.sum_type = int(package.sum_type or 0) col.append(pkg) rec.append_collection(col) for reference in update_record.references.all(): ref = cr.UpdateReference() ref.href = reference.href ref.id = reference.ref_id ref.type = reference.ref_type ref.title = reference.title rec.append_reference(ref) return cr.xml_dump_updaterecord(rec)
def create_collection_scope(): col = cr.UpdateCollection() col.name = "name" module = cr.UpdateCollectionModule() module.name = "kangaroo" module.stream = "0" module.version = 20180730223407 module.context = "deadbeef" module.arch = "noarch" col.module = module return col
def to_createrepo_c(self): """ Convert to a createrepo_c UpdateCollection object. Returns: col(cr.UpdateCollection): createrepo_c representation of a collection """ col = cr.UpdateCollection() col.shortname = self.shortname col.name = self.name for package in self.packages.all(): col.append(package.to_createrepo_c()) return col
def generate(): pkg = cr.UpdateCollectionPackage() pkg.name = "Foo" pkg.version = "1.2.3" pkg.release = "1" pkg.epoch = "0" pkg.arch = "noarch" pkg.src = "foo.src.rpm" pkg.filename = "foo-1.2.3-1.rpm" pkg.sum = "123456789" pkg.sum_type = cr.MD5 pkg.reboot_suggested = False col = cr.UpdateCollection() col.shortname = "Bar-product" col.name = "Bar Product" col.append(pkg) ref = cr.UpdateReference() ref.href = "http://foo.bar/foobar" ref.id = "123" ref.type = "self" ref.title = "Foo Update" rec = cr.UpdateRecord() rec.fromstr = "*****@*****.**" rec.status = "final" rec.type = "enhancement" rec.version = "1" rec.id = "UPDATE-1" rec.title = "Bar Product Update" rec.issued_date = datetime.datetime(2014, 8, 14) rec.updated_date = datetime.datetime(2014, 8, 14) rec.rights = "Copyright 2014 Bar Inc" rec.summary = "An update for Bar" rec.description = "Fixes a bug" rec.append_collection(col) rec.append_reference(ref) chunk = cr.xml_dump_updaterecord(rec) f = cr.UpdateInfoXmlFile(OUT_FILE) f.add_chunk(chunk) f.close() print "See the %s" % OUT_FILE
def test_updatecollection_setters(self): col = cr.UpdateCollection() self.assertTrue(col) self.assertEqual(col.shortname, None) self.assertEqual(col.name, None) self.assertEqual(col.packages, []) pkg = cr.UpdateCollectionPackage() pkg.name = "foo" pkg.version = "1.2" pkg.release = "3" pkg.epoch = "0" pkg.arch = "x86" pkg.src = "foo.src.rpm" pkg.filename = "foo.rpm" pkg.sum = "abcdef" pkg.sum_type = cr.SHA1 pkg.reboot_suggested = True col.shortname = "short name" col.name = "long name" col.append(pkg) self.assertEqual(col.shortname, "short name") self.assertEqual(col.name, "long name") self.assertEqual(len(col.packages), 1) # Also check if the appended package was appended properly pkg = col.packages[0] self.assertEqual(pkg.name, "foo") self.assertEqual(pkg.version, "1.2") self.assertEqual(pkg.release, "3") self.assertEqual(pkg.epoch, "0") self.assertEqual(pkg.arch, "x86") self.assertEqual(pkg.src, "foo.src.rpm") self.assertEqual(pkg.filename, "foo.rpm") self.assertEqual(pkg.sum, "abcdef") self.assertEqual(pkg.sum_type, cr.SHA1) self.assertEqual(pkg.reboot_suggested, True)
def to_createrepo_c(self): """ Convert to a createrepo_c UpdateCollection object. Returns: col(cr.UpdateCollection): createrepo_c representation of a collection """ col = cr.UpdateCollection() col.shortname = self.shortname col.name = self.name if self.module: module = cr.UpdateCollectionModule() module.name = self.module["name"] module.stream = self.module["stream"] module.version = self.module["version"] module.context = self.module["context"] module.arch = self.module["arch"] col.module = module for package in self.packages.all().order_by("sum"): col.append(package.to_createrepo_c()) return col
def to_createrepo_c(self): """ Convert to a createrepo_c UpdateCollection object. Returns: col(cr.UpdateCollection): createrepo_c representation of a collection """ col = cr.UpdateCollection() col.shortname = self.shortname col.name = self.name if self.module: module = cr.UpdateCollectionModule() module.name = self.module['name'] module.stream = self.module['stream'] module.version = self.module['version'] module.context = self.module['context'] module.arch = self.module['arch'] col.module = module for package in self.packages.all(): col.append(package.to_createrepo_c()) return col
def add_update(self, update): """ Generate the extended metadata for a given update, adding it to self.uinfo. Args: update (bodhi.server.models.Update): The Update to be added to self.uinfo. """ rec = cr.UpdateRecord() rec.version = __version__ rec.fromstr = config.get('bodhi_email') rec.status = update.status.value rec.type = update.type.value rec.id = to_bytes(update.alias) rec.title = to_bytes(update.title) rec.severity = util.severity_updateinfo_str(update.severity.value) rec.summary = to_bytes('%s %s update' % (update.get_title(), update.type.value)) rec.description = to_bytes(update.notes) rec.release = to_bytes(update.release.long_name) rec.rights = config.get('updateinfo_rights') if update.date_pushed: rec.issued_date = update.date_pushed else: # Sometimes we only set the date_pushed after it's pushed out, however, # it seems that Satellite does not like update entries without issued_date. # Since we know that we are pushing it now, and the next push will get the data # correctly, let's just insert utcnow(). rec.issued_date = datetime.utcnow() if update.date_modified: rec.updated_date = update.date_modified else: rec.updated_date = datetime.utcnow() col = cr.UpdateCollection() col.name = to_bytes(update.release.long_name) col.shortname = to_bytes(update.release.name) koji = get_session() for build in update.builds: rpms = self.get_rpms(koji, build.nvr) for rpm in rpms: pkg = cr.UpdateCollectionPackage() pkg.name = rpm['name'] pkg.version = rpm['version'] pkg.release = rpm['release'] if rpm['epoch'] is not None: pkg.epoch = str(rpm['epoch']) else: pkg.epoch = '0' pkg.arch = rpm['arch'] # TODO: how do we handle UpdateSuggestion.logout, etc? pkg.reboot_suggested = update.suggest is UpdateSuggestion.reboot filename = '%s.%s.rpm' % (rpm['nvr'], rpm['arch']) pkg.filename = filename # Build the URL if rpm['arch'] == 'src': arch = 'SRPMS' elif rpm['arch'] in ('noarch', 'i686'): arch = 'i386' else: arch = rpm['arch'] pkg.src = os.path.join( config.get('file_url'), update.status is UpdateStatus.testing and 'testing' or '', str(update.release.version), arch, filename[0], filename) col.append(pkg) rec.append_collection(col) # Create references for each bug for bug in update.bugs: ref = cr.UpdateReference() ref.type = 'bugzilla' ref.id = to_bytes(bug.bug_id) ref.href = to_bytes(bug.url) ref.title = to_bytes(bug.title) rec.append_reference(ref) # Create references for each CVE for cve in update.cves: ref = cr.UpdateReference() ref.type = 'cve' ref.id = to_bytes(cve.cve_id) ref.href = to_bytes(cve.url) rec.append_reference(ref) self.uinfo.append(rec)
def create_pulp3_content(self): """ Create a Pulp 3 Advisory content for saving it later in a bulk operation. """ rec = cr.UpdateRecord() rec.fromstr = self.errata_from rec.status = self.status rec.type = self.errata_type rec.version = self.version rec.id = self.errata_id rec.title = self.title rec.issued_date = get_datetime(self.issued) rec.updated_date = get_datetime(self.updated) rec.rights = self.rights rec.summary = self.summary rec.description = self.description rec.reboot_suggested = get_bool(self.reboot_suggested) rec.severity = self.severity rec.solution = self.solution rec.release = self.release rec.pushcount = self.pushcount collections = self.get_collections() for collection in collections: col = cr.UpdateCollection() col.shortname = collection.get('short') col.name = collection.get('name') module = collection.get('module') if module: cr_module = cr.UpdateCollectionModule() cr_module.name = module['name'] cr_module.stream = module['stream'] cr_module.version = int(module['version']) cr_module.context = module['context'] cr_module.arch = module['arch'] col.module = cr_module for package in collection.get('packages', []): pkg = cr.UpdateCollectionPackage() pkg.name = package['name'] pkg.version = package['version'] pkg.release = package['release'] pkg.epoch = package['epoch'] pkg.arch = package['arch'] pkg.src = package.get('src') pkg.filename = package['filename'] pkg.reboot_suggested = get_bool(package.get('reboot_suggested')) pkg.restart_suggested = get_bool(package.get('restart_suggested')) pkg.relogin_suggested = get_bool(package.get('relogin_suggested')) checksum_tuple = get_package_checksum(package) if checksum_tuple: pkg.sum_type, pkg.sum = checksum_tuple col.append(pkg) rec.append_collection(col) for reference in self.references: ref = cr.UpdateReference() ref.href = reference.get('href') ref.id = reference.get('id') ref.type = reference.get('type') ref.title = reference.get('title') rec.append_reference(ref) update_record = UpdateRecord(**UpdateRecord.createrepo_to_dict(rec)) update_record.digest = hash_update_record(rec) relations = {'collections': defaultdict(list), 'references': []} for collection in rec.collections: coll_dict = UpdateCollection.createrepo_to_dict(collection) coll = UpdateCollection(**coll_dict) for package in collection.packages: pkg_dict = UpdateCollectionPackage.createrepo_to_dict(package) pkg = UpdateCollectionPackage(**pkg_dict) relations['collections'][coll].append(pkg) for reference in rec.references: reference_dict = UpdateReference.createrepo_to_dict(reference) ref = UpdateReference(**reference_dict) relations['references'].append(ref) return (update_record, relations)
def test_updateinfo_xml_dump_05(self): now = datetime.now() # Microseconds are always 0 in updateinfo now = datetime(now.year, now.month, now.day, now.hour, now.minute, now.second, 0) # Collection module with unset fields mod = cr.UpdateCollectionModule() mod.version = 18446744073709551615 mod.context = "deadbeef" mod.arch = "x86" pkg = cr.UpdateCollectionPackage() pkg.name = "foo" pkg.version = "1.2" pkg.release = "3" pkg.epoch = "0" pkg.arch = "x86" pkg.src = "foo.src.rpm" pkg.filename = "foo.rpm" pkg.sum = "abcdef" pkg.sum_type = cr.SHA1 pkg.reboot_suggested = True pkg.restart_suggested = True col = cr.UpdateCollection() col.shortname = "short name" col.name = "long name" col.module = mod col.append(pkg) ref = cr.UpdateReference() ref.href = "href" ref.id = "id" ref.type = "type" ref.title = "title" rec = cr.UpdateRecord() rec.fromstr = "from" rec.status = "status" rec.type = "type" rec.version = "version" rec.id = "id" rec.title = "title" rec.issued_date = now rec.updated_date = now rec.rights = "rights" rec.release = "release" rec.pushcount = "pushcount" rec.severity = "severity" rec.summary = "summary" rec.description = "description" rec.solution = "solution" rec.reboot_suggested = True rec.append_collection(col) rec.append_reference(ref) ui = cr.UpdateInfo() ui.append(rec) xml = ui.xml_dump() self.assertEqual( xml, """<?xml version="1.0" encoding="UTF-8"?> <updates> <update from="from" status="status" type="type" version="version"> <id>id</id> <title>title</title> <issued date="%(now)s"/> <updated date="%(now)s"/> <rights>rights</rights> <release>release</release> <pushcount>pushcount</pushcount> <severity>severity</severity> <summary>summary</summary> <description>description</description> <solution>solution</solution> <reboot_suggested>True</reboot_suggested> <references> <reference href="href" id="id" type="type" title="title"/> </references> <pkglist> <collection short="short name"> <name>long name</name> <module version="18446744073709551615" context="deadbeef" arch="x86"/> <package name="foo" version="1.2" release="3" epoch="0" arch="x86" src="foo.src.rpm"> <filename>foo.rpm</filename> <sum type="sha1">abcdef</sum> <reboot_suggested>True</reboot_suggested> <restart_suggested>True</restart_suggested> </package> </collection> </pkglist> </update> </updates> """ % {"now": now.strftime("%Y-%m-%d %H:%M:%S")})
def test_updaterecord_setters(self): now = datetime.now() # Microseconds are always 0 in updateinfo now = datetime(now.year, now.month, now.day, now.hour, now.minute, now.second, 0) rec = cr.UpdateRecord() self.assertTrue(rec) self.assertEqual(rec.fromstr, None) self.assertEqual(rec.status, None) self.assertEqual(rec.type, None) self.assertEqual(rec.version, None) self.assertEqual(rec.id, None) self.assertEqual(rec.title, None) self.assertEqual(rec.issued_date, None) self.assertEqual(rec.updated_date, None) self.assertEqual(rec.rights, None) self.assertEqual(rec.release, None) self.assertEqual(rec.pushcount, None) self.assertEqual(rec.severity, None) self.assertEqual(rec.summary, None) self.assertEqual(rec.description, None) self.assertEqual(rec.reboot_suggested, 0) self.assertEqual(rec.solution, None) self.assertEqual(rec.references, []) self.assertEqual(rec.collections, []) ref = cr.UpdateReference() ref.href = "href" ref.id = "id" ref.type = "type" ref.title = "title" col = cr.UpdateCollection() col.shortname = "short name" col.name = "long name" rec.fromstr = "from" rec.status = "status" rec.type = "type" rec.version = "version" rec.id = "id" rec.title = "title" rec.issued_date = now rec.updated_date = now rec.rights = "rights" rec.release = "release" rec.pushcount = "pushcount" rec.severity = "severity" rec.summary = "summary" rec.description = "description" rec.reboot_suggested = True rec.solution = "solution" rec.append_reference(ref) rec.append_collection(col) self.assertEqual(rec.fromstr, "from") self.assertEqual(rec.status, "status") self.assertEqual(rec.type, "type") self.assertEqual(rec.version, "version") self.assertEqual(rec.id, "id") self.assertEqual(rec.title, "title") self.assertEqual(rec.issued_date, now) self.assertEqual(rec.updated_date, now) self.assertEqual(rec.rights, "rights") self.assertEqual(rec.release, "release") self.assertEqual(rec.pushcount, "pushcount") self.assertEqual(rec.severity, "severity") self.assertEqual(rec.summary, "summary") self.assertEqual(rec.reboot_suggested, True) self.assertEqual(rec.description, "description") self.assertEqual(rec.solution, "solution") self.assertEqual(len(rec.references), 1) self.assertEqual(len(rec.collections), 1) ref = rec.references[0] self.assertEqual(ref.href, "href") self.assertEqual(ref.id, "id") self.assertEqual(ref.type, "type") self.assertEqual(ref.title, "title") col = rec.collections[0] self.assertEqual(col.shortname, "short name") self.assertEqual(col.name, "long name") self.assertEqual(len(col.packages), 0)
def add_update(self, update): """Generate the extended metadata for a given update""" rec = cr.UpdateRecord() rec.version = __version__ rec.fromstr = config.get('bodhi_email') rec.status = update.status.value rec.type = update.type.value rec.id = to_bytes(update.alias) rec.title = to_bytes(update.title) rec.summary = to_bytes('%s %s update' % (update.get_title(), update.type.value)) rec.description = to_bytes(update.notes) rec.release = to_bytes(update.release.long_name) rec.rights = config.get('updateinfo_rights') if update.date_pushed: rec.issued_date = update.date_pushed if update.date_modified: rec.updated_date = update.date_modified col = cr.UpdateCollection() col.name = to_bytes(update.release.long_name) col.shortname = to_bytes(update.release.name) koji = get_session() for build in update.builds: rpms = self.get_rpms(koji, build.nvr) for rpm in rpms: pkg = cr.UpdateCollectionPackage() pkg.name = rpm['name'] pkg.version = rpm['version'] pkg.release = rpm['release'] if rpm['epoch'] is not None: pkg.epoch = str(rpm['epoch']) else: pkg.epoch = '0' pkg.arch = rpm['arch'] # TODO: how do we handle UpdateSuggestion.logout, etc? pkg.reboot_suggested = update.suggest is UpdateSuggestion.reboot filename = '%s.%s.rpm' % (rpm['nvr'], rpm['arch']) pkg.filename = filename # Build the URL if rpm['arch'] == 'src': arch = 'SRPMS' elif rpm['arch'] in ('noarch', 'i686'): arch = 'i386' else: arch = rpm['arch'] pkg.src = os.path.join( config.get('file_url'), update.status is UpdateStatus.testing and 'testing' or '', str(update.release.version), arch, filename[0], filename) col.append(pkg) rec.append_collection(col) # Create references for each bug for bug in update.bugs: ref = cr.UpdateReference() ref.type = 'bugzilla' ref.id = to_bytes(bug.bug_id) ref.href = to_bytes(bug.url) ref.title = to_bytes(bug.title) rec.append_reference(ref) # Create references for each CVE for cve in update.cves: ref = cr.UpdateReference() ref.type = 'cve' ref.id = to_bytes(cve.cve_id) ref.href = to_bytes(cve.url) rec.append_reference(ref) self.uinfo.append(rec)