def get_build(self, nvr='TurboGears-1.0.2.2-2.fc7'): package = get_pkg('-'.join(nvr.split('-')[:-2])) package.committers = ['bobvila'] try: build = PackageBuild.byNvr(nvr) except SQLObjectNotFound: build = PackageBuild(nvr=nvr, package=package) return build
def expire_buildroot_overrides(): """ Iterate over all of the buildroot overrides, expiring appropriately """ log.info('Running expire_buildroot_overrides job') now = datetime.utcnow() for override in BuildRootOverride.select(BuildRootOverride.q.date_expired == None): if override.expiration and now > override.expiration: log.info('Automatically expiring buildroot override: %s' % override.build) # Hack around overrides w/o a release. if not override.release: try: build = PackageBuild.byNvr(override.build) if len(build.updates): override.release = build.updates[0].release print "Fixing release for %s: %s" % (override.build, override.release.name) override.untag() override.date_expired = now else: log.error("Cannot determine release for override: %s" % override) except SQLObjectNotFound: log.error("Cannot find build for override: %s" % override) else: override.untag() override.date_expired = now log.info('expire_buildroot_overrides job complete!')
def compare_builds(testing_build, stable_build, untag, tag): if stable_build['package_name'] == testing_build['package_name']: if rpm.labelCompare((str(testing_build['epoch']), testing_build['version'], testing_build['release']), (str(stable_build['epoch']), stable_build['version'], stable_build['release'])) < 0: print "%s is older than %s" % (testing_build['nvr'], stable_build['nvr']) try: build = PackageBuild.byNvr(testing_build['nvr']) for update in build.updates: if update.status != 'stable': print "%s not stable in bodhi!" % update.title raise SQLObjectNotFound else: pass # TODO: do the untagging? except SQLObjectNotFound: if untag: print "Untagging via koji" koji = get_session() koji.untagBuild(tag, testing_build['nvr'], force=True) else: print "Need to untag koji build %s" % testing_build['nvr']
def compare_builds(testing_build, stable_build, untag, tag): if stable_build['package_name'] == testing_build['package_name']: if rpm.labelCompare( (str(testing_build['epoch']), testing_build['version'], testing_build['release']), (str(stable_build['epoch']), stable_build['version'], stable_build['release'])) < 0: print "%s is older than %s" % (testing_build['nvr'], stable_build['nvr']) try: build = PackageBuild.byNvr(testing_build['nvr']) for update in build.updates: if update.status != 'testing': print "%s not testing in bodhi!" % update.title raise SQLObjectNotFound else: if untag: print "Obsoleting via bodhi" update.obsolete(newer=stable_build['nvr']) else: print "Need to obsolete via bodhi" except SQLObjectNotFound: if untag: print "Untagging via koji" koji = get_session() koji.untagBuild(tag, testing_build['nvr'], force=True) else: print "Need to untag koji build %s" % testing_build['nvr']
def expire_buildroot_overrides(): """ Iterate over all of the buildroot overrides, expiring appropriately """ log.info('Running expire_buildroot_overrides job') now = datetime.utcnow() for override in BuildRootOverride.select( BuildRootOverride.q.date_expired == None): if override.expiration and now > override.expiration: log.info('Automatically expiring buildroot override: %s' % override.build) # Hack around overrides w/o a release. if not override.release: try: build = PackageBuild.byNvr(override.build) if len(build.updates): override.release = build.updates[0].release print "Fixing release for %s: %s" % ( override.build, override.release.name) override.untag() override.date_expired = now else: log.error("Cannot determine release for override: %s" % override) except SQLObjectNotFound: log.error("Cannot find build for override: %s" % override) else: override.untag() override.date_expired = now log.info('expire_buildroot_overrides job complete!')
def compare_builds(testing_build, stable_build, untag, tag): if stable_build["package_name"] == testing_build["package_name"]: if ( rpm.labelCompare( (str(testing_build["epoch"]), testing_build["version"], testing_build["release"]), (str(stable_build["epoch"]), stable_build["version"], stable_build["release"]), ) < 0 ): print "%s is older than %s" % (testing_build["nvr"], stable_build["nvr"]) try: build = PackageBuild.byNvr(testing_build["nvr"]) for update in build.updates: if update.status != "testing": print "%s not testing in bodhi!" % update.title raise SQLObjectNotFound else: if untag: print "Obsoleting via bodhi" update.obsolete(newer=stable_build["nvr"]) else: print "Need to obsolete via bodhi" except SQLObjectNotFound: if untag: print "Untagging via koji" koji = get_session() koji.untagBuild(tag, testing_build["nvr"], force=True) else: print "Need to untag koji build %s" % testing_build["nvr"]
def test_multibuild(self): builds = ['yum-3.2.1-1.fc7', 'httpd-2.2.4-4.1.fc7'] package_builds = [] release = get_rel() update = PackageUpdate(title=','.join(builds), release=release, submitter='*****@*****.**', notes='Testing!', type='bugfix') for build in builds: nvr = get_nvr(build) pkg = Package(name=nvr[0]) b = PackageBuild(nvr=build, package=pkg) package_builds.append(b) map(update.addPackageBuild, package_builds) assert update.builds[0].nvr == builds[0] assert update.builds[1].nvr == builds[1] assert update.title == ','.join(builds) assert update.release.name == 'fc7' assert release.updates[0] == update assert update.status == 'pending' assert update.type == 'bugfix' assert update.notes == 'Testing!' for build in package_builds: assert build.updates[0] == update
def get_build(self, nvr='TurboGears-1.0.2.2-2.fc7'): package = get_pkg('-'.join(nvr.split('-')[:-2])) package.committers = ['bobvila',] try: build = PackageBuild.byNvr(nvr) except SQLObjectNotFound: build = PackageBuild(nvr=nvr, package=package) return build
def clean_tables(): from bodhi.model import (Release, Package, PackageBuild, PackageUpdate, Comment, CVE, Bugzilla, BuildRootOverride) from bodhi.identity.tables import (Visit, VisitIdentity, Group, User, Permission) print "Cleaning out tables" Release.dropTable(ifExists=True, cascade=True) Package.dropTable(ifExists=True, cascade=True) PackageBuild.dropTable(ifExists=True, cascade=True) PackageUpdate.dropTable(ifExists=True, cascade=True) Comment.dropTable(ifExists=True, cascade=True) CVE.dropTable(ifExists=True, cascade=True) Bugzilla.dropTable(ifExists=True, cascade=True) BuildRootOverride.dropTable(ifExists=True, cascade=True) Visit.dropTable(ifExists=True, cascade=True) VisitIdentity.dropTable(ifExists=True, cascade=True) Group.dropTable(ifExists=True, cascade=True) User.dropTable(ifExists=True, cascade=True) Permission.dropTable(ifExists=True, cascade=True) hub.commit() Release.createTable(ifNotExists=True) Package.createTable(ifNotExists=True) PackageBuild.createTable(ifNotExists=True) PackageUpdate.createTable(ifNotExists=True) Comment.createTable(ifNotExists=True) CVE.createTable(ifNotExists=True) Bugzilla.createTable(ifNotExists=True) BuildRootOverride.createTable(ifNotExists=True) Visit.createTable(ifNotExists=True) VisitIdentity.createTable(ifNotExists=True) Group.createTable(ifNotExists=True) User.createTable(ifNotExists=True) Permission.createTable(ifNotExists=True)
def clean_pending_tags(): """ Clean up any stray pending tags """ koji = get_session() for release in Release.select(): log.info("Finding all stray pending-testing builds...") if release.name.startswith('E'): continue tag = release.pending_testing_tag tagged = [build['nvr'] for build in koji.listTagged(tag)] for nvr in tagged: try: build = PackageBuild.byNvr(nvr) for update in build.updates: if update.status in ('testing', 'stable', 'obsolete'): log.info("%s %s" % (nvr, update.status)) log.info("Untagging %s" % nvr) koji.untagBuild(tag, nvr, force=True) except SQLObjectNotFound: log.info("Can't find build for %s" % nvr) log.info("Untagging %s" % nvr) koji.untagBuild(tag, nvr, force=True) log.info("Finding all stray pending-stable builds...") tag = release.pending_stable_tag tagged = [build['nvr'] for build in koji.listTagged(tag)] for nvr in tagged: try: build = PackageBuild.byNvr(nvr) for update in build.updates: if update.status in ('pending', 'obsolete', 'stable'): log.info("%s %s" % (nvr, update.status)) log.info("Untagging %s" % nvr) koji.untagBuild(tag, nvr, force=True) except SQLObjectNotFound: log.info("Untagging %s" % nvr) koji.untagBuild(tag, nvr, force=True)
def clean_pending_tags(): """ Clean up any stray pending tags """ koji = get_session() for release in Release.select(): log.info("Finding all stray pending-testing builds...") if release.name.startswith('EL'): continue tag = release.pending_testing_tag tagged = [build['nvr'] for build in koji.listTagged(tag)] for nvr in tagged: try: build = PackageBuild.byNvr(nvr) for update in build.updates: if update.status in ('testing', 'stable', 'obsolete'): log.info("%s %s" % (nvr, update.status)) log.info("Untagging %s" % nvr) koji.untagBuild(tag, nvr, force=True) except SQLObjectNotFound: log.info("Can't find build for %s" % nvr) log.info("Untagging %s" % nvr) koji.untagBuild(tag, nvr, force=True) log.info("Finding all stray pending-stable builds...") tag = release.pending_stable_tag tagged = [build['nvr'] for build in koji.listTagged(tag)] for nvr in tagged: try: build = PackageBuild.byNvr(nvr) for update in build.updates: if update.status in ('pending', 'obsolete', 'stable'): log.info("%s %s" % (nvr, update.status)) log.info("Untagging %s" % nvr) koji.untagBuild(tag, nvr, force=True) except SQLObjectNotFound: log.info("Untagging %s" % nvr) koji.untagBuild(tag, nvr, force=True)
def _fetch_updates(self): """ Based on our given koji tag, populate a list of PackageUpdates. """ log.debug("Fetching builds tagged with '%s'" % self.tag) kojiBuilds = self.koji.listTagged(self.tag, latest=True) nonexistent = [] log.debug("%d builds found" % len(kojiBuilds)) for build in kojiBuilds: self.builds[build['nvr']] = build try: b = PackageBuild.byNvr(build['nvr']) for update in b.updates: if update.status in ('testing', 'stable'): self.updates.add(update) except SQLObjectNotFound, e: nonexistent.append(build['nvr'])
def parse_output(out): updates = defaultdict(set) num_critpath = defaultdict(int) debug = file('bodhi.debug', 'a') deltas = [] occurrences = {} accumulative = timedelta() for line in out.split('\n'): line = line.strip() if '}' in line: continue if line: debug.write(line + '\n') title = line.split()[-1] update = None for build in title.split(','): try: update = PackageBuild.byNvr(build).updates[0] break except SQLObjectNotFound: pass #print "Cannot find update for %s" % build if update: if update.title not in updates[update.release.name]: updates[update.release.name].add(update.title) if update.critpath: num_critpath[update.release.name] += 1 for comment in update.comments: if comment.text == 'This update has been pushed to testing': for othercomment in update.comments: if othercomment.text == 'This update has been pushed to stable': delta = othercomment.timestamp - comment.timestamp deltas.append(delta) occurrences[ delta.days] = occurrences.setdefault( delta.days, 0) + 1 accumulative += delta break break debug.close() deltas.sort() return updates, num_critpath, deltas, accumulative, occurrences
def parse_output(out): updates = defaultdict(set) num_critpath = defaultdict(int) debug = file('bodhi.debug', 'a') deltas = [] occurrences = {} accumulative = timedelta() for line in out.split('\n'): line = line.strip() if '}' in line: continue if line: debug.write(line + '\n') title = line.split()[-1] update = None for build in title.split(','): try: update = PackageBuild.byNvr(build).updates[0] break except SQLObjectNotFound: pass #print "Cannot find update for %s" % build if update: if update.title not in updates[update.release.name]: updates[update.release.name].add(update.title) if update.critpath: num_critpath[update.release.name] += 1 for comment in update.comments: if comment.text == 'This update has been pushed to testing': for othercomment in update.comments: if othercomment.text == 'This update has been pushed to stable': delta = othercomment.timestamp - comment.timestamp deltas.append(delta) occurrences[delta.days] = occurrences.setdefault(delta.days, 0) + 1 accumulative += delta break break debug.close() deltas.sort() return updates, num_critpath, deltas, accumulative, occurrences
def test_url(self): nvr = 'TurboGears-4.0.3.3-1.fc9' build = PackageBuild(nvr=nvr, package=0) assert build.get_url() == '/' + nvr
def load_db(): print "\nLoading pickled database %s" % sys.argv[2] db = file(sys.argv[2], 'r') data = pickle.load(db) # Legacy format was just a list of update dictionaries # Now we'll pull things out into an organized dictionary: # {'updates': [], 'releases': []} if isinstance(data, dict): for release in data['releases']: try: Release.byName(release['name']) except SQLObjectNotFound: Release(**release) data = data['updates'] progress = ProgressBar(maxValue=len(data)) for u in data: try: release = Release.byName(u['release'][0]) except SQLObjectNotFound: release = Release(name=u['release'][0], long_name=u['release'][1], id_prefix=u['release'][2], dist_tag=u['release'][3]) ## Backwards compatbility request = u['request'] if u['request'] == 'move': request = 'stable' elif u['request'] == 'push': request = 'testing' elif u['request'] == 'unpush': request = 'obsolete' if u['approved'] in (True, False): u['approved'] = None if u.has_key('update_id'): u['updateid'] = u['update_id'] if not u.has_key('date_modified'): u['date_modified'] = None try: update = PackageUpdate.byTitle(u['title']) except SQLObjectNotFound: update = PackageUpdate(title=u['title'], date_submitted=u['date_submitted'], date_pushed=u['date_pushed'], date_modified=u['date_modified'], release=release, submitter=u['submitter'], updateid=u['updateid'], type=u['type'], status=u['status'], pushed=u['pushed'], notes=u['notes'], karma=u['karma'], request=request, approved=u['approved']) ## Create Package and PackageBuild objects for pkg, nvr in u['builds']: try: package = Package.byName(pkg) except SQLObjectNotFound: package = Package(name=pkg) try: build = PackageBuild.byNvr(nvr) except SQLObjectNotFound: build = PackageBuild(nvr=nvr, package=package) update.addPackageBuild(build) ## Create all Bugzilla objects for this update for bug_num, bug_title, security, parent in u['bugs']: try: bug = Bugzilla.byBz_id(bug_num) except SQLObjectNotFound: bug = Bugzilla(bz_id=bug_num, security=security, parent=parent) bug.title = bug_title update.addBugzilla(bug) ## Create all CVE objects for this update for cve_id in u['cves']: try: cve = CVE.byCve_id(cve_id) except SQLObjectNotFound: cve = CVE(cve_id=cve_id) update.addCVE(cve) for timestamp, author, text, karma, anonymous in u['comments']: comment = Comment(timestamp=timestamp, author=author, text=text, karma=karma, update=update, anonymous=anonymous) progress()
def main(): load_config() __connection__ = hub = PackageHub("bodhi") koji = get_session() tasks = [] broke = set() # Clean up any stray pending tags for release in Release.select(): print "Finding all pending-testing builds..." if release.name.startswith('EL'): continue tag = release.pending_testing_tag tagged = [build['nvr'] for build in koji.listTagged(tag)] for nvr in tagged: try: build = PackageBuild.byNvr(nvr) for update in build.updates: if update.status in ('testing', 'stable', 'obsolete'): print "%s %s" % (nvr, update.status) if '--fix' in sys.argv: print "Untagging %s" % nvr koji.untagBuild(tag, nvr, force=True) except SQLObjectNotFound: print "Can't find build for %s" % nvr if '--fix' in sys.argv: print "Untagging %s" % nvr koji.untagBuild(tag, nvr, force=True) tag = release.pending_stable_tag tagged = [build['nvr'] for build in koji.listTagged(tag)] for nvr in tagged: try: build = PackageBuild.byNvr(nvr) for update in build.updates: if update.status in ('pending', 'obsolete'): print "%s %s" % (nvr, update.status) if '--fix' in sys.argv: print "Untagging %s" % nvr koji.untagBuild(tag, nvr, force=True) except SQLObjectNotFound: print "Can't find build for %s" % nvr if '--fix' in sys.argv: print "Untagging %s" % nvr koji.untagBuild(tag, nvr, force=True) # Check for testing updates that aren't tagged properly for update in PackageUpdate.select(PackageUpdate.q.status=='testing'): dest_tag = update.release.testing_tag for build in update.builds: tags = [tag['name'] for tag in koji.listTags(build=build.nvr)] if dest_tag not in tags: print "%s marked as testing, but tagged with %s" % (build.nvr, tags) if '--fix' in sys.argv: broke.add((tags[0], dest_tag, build.nvr)) # Check all candidate updates to see if they are in a different bodhi state for release in Release.select(): tag = release.candidate_tag tagged = [build['nvr'] for build in koji.listTagged(tag, latest=True)] for nvr in tagged: try: build = PackageBuild.byNvr(nvr) for update in build.updates: if update.status in ('testing', 'stable'): print "%s %s but tagged as %s" % (nvr, update.status, tag) if '--fix' in sys.argv: dest = release.testing_tag if update.status == 'stable': dest = release.stable_tag elif update.status == 'obsolete': dest = release.candidate_tag broke.add((tag, dest, nvr)) except SQLObjectNotFound: pass # Make sure that all builds in koji tagged as an update exist # in bodhi, and are in the expect state. for release in Release.select(): for tag in (release.testing_tag, release.stable_tag): tagged = [build['nvr'] for build in koji.listTagged(tag, latest=True)] for nvr in tagged: try: build = PackageBuild.byNvr(nvr) except SQLObjectNotFound: print "PackageUpdate(%s) not found!" % nvr continue if not len(build.updates): print "PackageBuild(%s) has no updates" % (build.nvr) status = 'testing' in tag and 'testing' or 'stable' for update in build.updates: if update.status != status: print "%s is %s in bodhi but tagged as %s in koji" % ( update.title, update.status, tag) if '--fix' in sys.argv: dest = release.testing_tag if update.status == 'stable': dest = release.stable_tag elif update.status == 'obsolete': dest = release.candidate_tag for b in update.builds: broke.add((tag, dest, b.nvr)) if broke: print " ** Fixing broken tags! **" koji.multicall = True for tag, dest, build in broke: print "Moving %s from %s to %s" % (build, tag, dest) koji.moveBuild(tag, dest, build, force=True) print "Running koji.multiCall()" results = koji.multiCall() success = False print "Waiting for tasks" bad_tasks = wait_for_tasks([task[0] for task in results]) if bad_tasks == 0: success = True if success: print "Tags successfully moved!" else: print "Error moving tags!" print "bad_tasks = %r" % bad_tasks
def load_db(): print "\nLoading pickled database %s" % sys.argv[2] db = file(sys.argv[2], 'r') data = pickle.load(db) # Load up all of the overrides for override in data.get('overrides', []): try: BuildRootOverride.byBuild(override['build']) except SQLObjectNotFound: BuildRootOverride(**override) # Legacy format was just a list of update dictionaries # Now we'll pull things out into an organized dictionary: # {'updates': [], 'releases': []} if isinstance(data, dict): for release in data['releases']: try: Release.byName(release['name']) except SQLObjectNotFound: Release(**release) data = data['updates'] progress = ProgressBar(maxValue=len(data)) for u in data: try: release = Release.byName(u['release'][0]) except SQLObjectNotFound: release = Release(name=u['release'][0], long_name=u['release'][1], id_prefix=u['release'][2], dist_tag=u['release'][3]) ## Backwards compatbility request = u['request'] if u['request'] == 'move': request = 'stable' elif u['request'] == 'push': request = 'testing' elif u['request'] == 'unpush': request = 'obsolete' if u['approved'] in (True, False): u['approved'] = None if 'update_id' in u: u['updateid'] = u['update_id'] if not 'date_modified' in u: u['date_modified'] = None try: update = PackageUpdate.byTitle(u['title']) except SQLObjectNotFound: update = PackageUpdate(title=u['title'], date_submitted=u['date_submitted'], date_pushed=u['date_pushed'], date_modified=u['date_modified'], release=release, submitter=u['submitter'], updateid=u['updateid'], type=u['type'], status=u['status'], pushed=u['pushed'], notes=u['notes'], karma=u['karma'], request=request, approved=u['approved']) ## Create Package and PackageBuild objects for pkg, nvr in u['builds']: try: package = Package.byName(pkg) except SQLObjectNotFound: package = Package(name=pkg) try: build = PackageBuild.byNvr(nvr) except SQLObjectNotFound: build = PackageBuild(nvr=nvr, package=package) update.addPackageBuild(build) ## Create all Bugzilla objects for this update for bug_num, bug_title, security, parent in u['bugs']: try: bug = Bugzilla.byBz_id(bug_num) except SQLObjectNotFound: bug = Bugzilla(bz_id=bug_num, security=security, parent=parent) bug.title = bug_title update.addBugzilla(bug) ## Create all CVE objects for this update for cve_id in u['cves']: try: cve = CVE.byCve_id(cve_id) except SQLObjectNotFound: cve = CVE(cve_id=cve_id) update.addCVE(cve) for timestamp, author, text, karma, anonymous in u['comments']: comment = Comment(timestamp=timestamp, author=author, text=text, karma=karma, update=update, anonymous=anonymous) progress()
def test_extended_metadata_updating(self): # grab the name of a build in updates-testing, and create it in our db koji = get_session() builds = koji.listTagged('dist-f13-updates-testing', latest=True) # Create all of the necessary database entries release = Release(name='F13', long_name='Fedora 13', id_prefix='FEDORA', dist_tag='dist-f13') package = Package(name=builds[0]['package_name']) update = PackageUpdate(title=builds[0]['nvr'], release=release, submitter=builds[0]['owner_name'], status='testing', notes='foobar', type='bugfix') build = PackageBuild(nvr=builds[0]['nvr'], package=package) update.addPackageBuild(build) bug = Bugzilla(bz_id=1) bug.title = u'test bug' update.addBugzilla(bug) cve = CVE(cve_id="CVE-2007-0000") update.addCVE(cve) update.assign_id() ## Initialize our temporary repo temprepo = join(tempfile.mkdtemp('bodhi'), 'f7-updates-testing') print "Inserting updateinfo into temprepo: %s" % temprepo mkmetadatadir(join(temprepo, 'i386')) repodata = join(temprepo, 'i386', 'repodata') assert exists(join(repodata, 'repomd.xml')) ## Generate the XML md = ExtendedMetadata(temprepo) ## Insert the updateinfo.xml into the repository md.insert_updateinfo() updateinfo = join(repodata, 'updateinfo.xml.gz') assert exists(updateinfo) ## Read an verify the updateinfo.xml.gz uinfo = UpdateMetadata() uinfo.add(updateinfo) notice = uinfo.get_notice(('mutt', '1.5.14', '1.fc13')) assert not notice notice = uinfo.get_notice(get_nvr(update.title)) assert notice assert notice['status'] == update.status assert notice['updated'] == update.date_modified assert notice['from'] == str(config.get('bodhi_email')) assert notice['description'] == update.notes assert notice['issued'] != None assert notice['update_id'] == update.updateid cve = notice['references'][0] assert cve['type'] == 'cve' assert cve['href'] == update.cves[0].get_url() assert cve['id'] == update.cves[0].cve_id bug = notice['references'][1] assert bug['href'] == update.bugs[0].get_url() assert bug['id'] == '1' assert bug['type'] == 'bugzilla' assert bug['title'] == 'test bug' # FC6's yum update metadata parser doesn't know about some stuff from yum import __version__ if __version__ >= '3.0.6': assert notice['title'] == update.title assert notice['release'] == update.release.long_name assert cve['title'] == None ## Test out updateinfo.xml updating via our ExtendedMetadata md = ExtendedMetadata(temprepo, updateinfo) md.insert_updateinfo() updateinfo = join(repodata, 'updateinfo.xml.gz') assert exists(updateinfo) ## Read an verify the updateinfo.xml.gz uinfo = UpdateMetadata() uinfo.add(updateinfo) notice = uinfo.get_notice(('mutt', '1.5.14', '1.fc13')) assert not notice notice = uinfo.get_notice(get_nvr(update.title)) assert notice assert notice['status'] == update.status assert notice['updated'] == update.date_modified assert notice['from'] == str(config.get('bodhi_email')) assert notice['description'] == update.notes assert notice['issued'] != None assert notice['update_id'] == update.updateid cve = notice['references'][0] assert cve['type'] == 'cve' assert cve['href'] == update.cves[0].get_url() assert cve['id'] == update.cves[0].cve_id bug = notice['references'][1] assert bug['href'] == update.bugs[0].get_url() assert bug['id'] == '1' assert bug['type'] == 'bugzilla' assert bug['title'] == 'test bug', bug # FC6's yum update metadata parser doesn't know about some stuff from yum import __version__ if __version__ >= '3.0.6': assert notice['title'] == update.title assert notice['release'] == update.release.long_name assert cve['title'] == None ## Clean up shutil.rmtree(temprepo)
def main(): load_config() __connection__ = hub = PackageHub("bodhi") koji = get_session() tasks = [] broke = set() # Clean up any stray pending tags for release in Release.select(): print "Finding all pending-testing builds..." if release.name.startswith('EL'): continue tag = release.pending_testing_tag tagged = [build['nvr'] for build in koji.listTagged(tag)] for nvr in tagged: try: build = PackageBuild.byNvr(nvr) for update in build.updates: if update.status in ('testing', 'stable', 'obsolete'): print "%s %s" % (nvr, update.status) if '--fix' in sys.argv: print "Untagging %s" % nvr koji.untagBuild(tag, nvr, force=True) except SQLObjectNotFound: print "Can't find build for %s" % nvr if '--fix' in sys.argv: print "Untagging %s" % nvr koji.untagBuild(tag, nvr, force=True) tag = release.pending_stable_tag tagged = [build['nvr'] for build in koji.listTagged(tag)] for nvr in tagged: try: build = PackageBuild.byNvr(nvr) for update in build.updates: if update.status in ('pending', 'obsolete', 'stable'): print "%s %s" % (nvr, update.status) if '--fix' in sys.argv: print "Untagging %s" % nvr koji.untagBuild(tag, nvr, force=True) except SQLObjectNotFound: print "Can't find build for %s" % nvr if '--fix' in sys.argv: print "Untagging %s" % nvr koji.untagBuild(tag, nvr, force=True) # Check for testing updates that aren't tagged properly for update in PackageUpdate.select(PackageUpdate.q.status == 'testing'): dest_tag = update.release.testing_tag for build in update.builds: tags = [tag['name'] for tag in koji.listTags(build=build.nvr)] if dest_tag not in tags: print "%s marked as testing, but tagged with %s" % (build.nvr, tags) if '--fix' in sys.argv: broke.add((tags[0], dest_tag, build.nvr)) # Check all candidate updates to see if they are in a different bodhi state for release in Release.select(): tag = release.candidate_tag tagged = [build['nvr'] for build in koji.listTagged(tag, latest=True)] for nvr in tagged: try: build = PackageBuild.byNvr(nvr) for update in build.updates: if update.status in ('testing', 'stable'): print "%s %s but tagged as %s" % (nvr, update.status, tag) if '--fix' in sys.argv: dest = release.testing_tag if update.status == 'stable': dest = release.stable_tag elif update.status == 'obsolete': dest = release.candidate_tag broke.add((tag, dest, nvr)) except SQLObjectNotFound: pass # Make sure that all builds in koji tagged as an update exist # in bodhi, and are in the expect state. for release in Release.select(): for tag in (release.testing_tag, release.stable_tag): tagged = [ build['nvr'] for build in koji.listTagged(tag, latest=True) ] for nvr in tagged: try: build = PackageBuild.byNvr(nvr) except SQLObjectNotFound: print "PackageUpdate(%s) not found!" % nvr continue if not len(build.updates): print "PackageBuild(%s) has no updates" % (build.nvr) status = 'testing' in tag and 'testing' or 'stable' for update in build.updates: if update.status != status: print "%s is %s in bodhi but tagged as %s in koji" % ( update.title, update.status, tag) if '--fix' in sys.argv: dest = release.testing_tag if update.status == 'stable': dest = release.stable_tag elif update.status == 'obsolete': dest = release.candidate_tag for b in update.builds: broke.add((tag, dest, b.nvr)) if broke: print " ** Fixing broken tags! **" koji.multicall = True for tag, dest, build in broke: print "Moving %s from %s to %s" % (build, tag, dest) koji.moveBuild(tag, dest, build, force=True) print "Running koji.multiCall()" results = koji.multiCall() success = False print "Waiting for tasks" bad_tasks = wait_for_tasks([task[0] for task in results]) if bad_tasks == 0: success = True if success: print "Tags successfully moved!" else: print "Error moving tags!" print "bad_tasks = %r" % bad_tasks
def test_extended_metadata_updating_with_old_stable_security(self): testutil.capture_log(['bodhi.metadata']) koji = get_session() del (koji.__untag__[:]) assert not koji.__untag__, koji.__untag__ builds = koji.listTagged('dist-f7-updates', latest=True) # Create all of the necessary database entries release = Release(name='F17', long_name='Fedora 17', id_prefix='FEDORA', dist_tag='dist-f17') package = Package(name='TurboGears') update = PackageUpdate(title='TurboGears-1.0.2.2-2.fc7', release=release, submitter=builds[0]['owner_name'], status='stable', notes='foobar', type='security') build = PackageBuild(nvr='TurboGears-1.0.2.2-2.fc7', package=package) update.addPackageBuild(build) update.assign_id() assert update.updateid ## Initialize our temporary repo temprepo = join(tempfile.mkdtemp('bodhi'), 'f7-updates') print "Inserting updateinfo into temprepo: %s" % temprepo mkmetadatadir(join(temprepo, 'i386')) repodata = join(temprepo, 'i386', 'repodata') assert exists(join(repodata, 'repomd.xml')) ## Generate the XML md = ExtendedMetadata(temprepo) ## Insert the updateinfo.xml into the repository md.insert_updateinfo() updateinfo = self.__verify_updateinfo(repodata) # Create a new non-security update for the same package newbuild = 'TurboGears-1.0.2.2-3.fc7' update = PackageUpdate(title=newbuild, release=release, submitter=builds[0]['owner_name'], status='stable', notes='foobar', type='enhancement') build = PackageBuild(nvr=newbuild, package=package) update.addPackageBuild(build) update.assign_id() koji.__untag__.append('TurboGears-1.0.2.2-2.fc7') ## Test out updateinfo.xml updating via our ExtendedMetadata md = ExtendedMetadata(temprepo, updateinfo) md.insert_updateinfo() updateinfo = self.__verify_updateinfo(repodata) ## Read an verify the updateinfo.xml.gz uinfo = UpdateMetadata() uinfo.add(updateinfo) print(testutil.get_log()) assert len(uinfo.get_notices()) == 2, len(uinfo.get_notices()) assert uinfo.get_notice(get_nvr('TurboGears-1.0.2.2-2.fc7')) notice = uinfo.get_notice(get_nvr(update.title)) assert notice, 'Cannot find update for %r' % get_nvr(update.title) assert notice['status'] == update.status assert notice['updated'] == update.date_modified assert notice['from'] == str(config.get('bodhi_email')) assert notice['description'] == update.notes assert notice['issued'] is not None assert notice['update_id'] == update.updateid ## Clean up shutil.rmtree(temprepo) del (koji.__untag__[:])
def load_db(): print "\nLoading pickled database %s" % sys.argv[2] db = file(sys.argv[2], "r") data = pickle.load(db) # Legacy format was just a list of update dictionaries # Now we'll pull things out into an organized dictionary: # {'updates': [], 'releases': []} if isinstance(data, dict): for release in data["releases"]: try: Release.byName(release["name"]) except SQLObjectNotFound: Release(**release) data = data["updates"] progress = ProgressBar(maxValue=len(data)) for u in data: try: release = Release.byName(u["release"][0]) except SQLObjectNotFound: release = Release( name=u["release"][0], long_name=u["release"][1], id_prefix=u["release"][2], dist_tag=u["release"][3] ) ## Backwards compatbility request = u["request"] if u["request"] == "move": request = "stable" elif u["request"] == "push": request = "testing" elif u["request"] == "unpush": request = "obsolete" if u["approved"] in (True, False): u["approved"] = None if u.has_key("update_id"): u["updateid"] = u["update_id"] if not u.has_key("date_modified"): u["date_modified"] = None try: update = PackageUpdate.byTitle(u["title"]) except SQLObjectNotFound: update = PackageUpdate( title=u["title"], date_submitted=u["date_submitted"], date_pushed=u["date_pushed"], date_modified=u["date_modified"], release=release, submitter=u["submitter"], updateid=u["updateid"], type=u["type"], status=u["status"], pushed=u["pushed"], notes=u["notes"], karma=u["karma"], request=request, approved=u["approved"], ) ## Create Package and PackageBuild objects for pkg, nvr in u["builds"]: try: package = Package.byName(pkg) except SQLObjectNotFound: package = Package(name=pkg) try: build = PackageBuild.byNvr(nvr) except SQLObjectNotFound: build = PackageBuild(nvr=nvr, package=package) update.addPackageBuild(build) ## Create all Bugzilla objects for this update for bug_num, bug_title, security, parent in u["bugs"]: try: bug = Bugzilla.byBz_id(bug_num) except SQLObjectNotFound: bug = Bugzilla(bz_id=bug_num, security=security, parent=parent) bug.title = bug_title update.addBugzilla(bug) ## Create all CVE objects for this update for cve_id in u["cves"]: try: cve = CVE.byCve_id(cve_id) except SQLObjectNotFound: cve = CVE(cve_id=cve_id) update.addCVE(cve) for timestamp, author, text, karma, anonymous in u["comments"]: comment = Comment( timestamp=timestamp, author=author, text=text, karma=karma, update=update, anonymous=anonymous ) progress()
def get_build(self, nvr='TurboGears-1.0.2.2-2.fc7'): package = get_pkg('-'.join(nvr.split('-')[:-2])) build = PackageBuild(nvr=nvr, package=package) return build
def test_extended_metadata_updating_with_edited_updates(self): testutil.capture_log(['bodhi.metadata']) # grab the name of a build in updates-testing, and create it in our db koji = get_session() builds = koji.listTagged('dist-f13-updates-testing', latest=True) # Create all of the necessary database entries release = Release(name='F13', long_name='Fedora 13', id_prefix='FEDORA', dist_tag='dist-f13') package = Package(name=builds[0]['package_name']) update = PackageUpdate(title=builds[0]['nvr'], release=release, submitter=builds[0]['owner_name'], status='testing', notes='foobar', type='bugfix') build = PackageBuild(nvr=builds[0]['nvr'], package=package) update.addPackageBuild(build) update.assign_id() ## Initialize our temporary repo temprepo = join(tempfile.mkdtemp('bodhi'), 'f13-updates-testing') print "Inserting updateinfo into temprepo: %s" % temprepo mkmetadatadir(join(temprepo, 'i386')) repodata = join(temprepo, 'i386', 'repodata') assert exists(join(repodata, 'repomd.xml')) ## Generate the XML md = ExtendedMetadata(temprepo) ## Insert the updateinfo.xml into the repository md.insert_updateinfo() updateinfo = self.__verify_updateinfo(repodata) ## Read an verify the updateinfo.xml.gz uinfo = UpdateMetadata() uinfo.add(updateinfo) notice = uinfo.get_notice(('mutt', '1.5.14', '1.fc13')) assert not notice notice = uinfo.get_notice(get_nvr(update.title)) assert notice assert notice['status'] == update.status assert notice['updated'] == update.date_modified assert notice['from'] == str(config.get('bodhi_email')) assert notice['description'] == update.notes assert notice['issued'] is not None assert notice['update_id'] == update.updateid assert notice['title'] == update.title assert notice['release'] == update.release.long_name ## Edit the update and bump the build revision nvr = 'TurboGears-1.0.2.2-3.fc7' newbuild = PackageBuild(nvr=nvr, package=package) update.removePackageBuild(build) update.addPackageBuild(newbuild) update.title = nvr update.date_modified = datetime.utcnow() # Pretend -2 was unpushed assert len(koji.__untag__) == 0 koji.__untag__.append('TurboGears-1.0.2.2-2.fc7') ## Test out updateinfo.xml updating via our ExtendedMetadata md = ExtendedMetadata(temprepo, updateinfo) md.insert_updateinfo() updateinfo = self.__verify_updateinfo(repodata) ## Read an verify the updateinfo.xml.gz uinfo = UpdateMetadata() uinfo.add(updateinfo) print(testutil.get_log()) notice = uinfo.get_notice(('TurboGears', '1.0.2.2', '2.fc7')) assert not notice, "Old TG notice did not get pruned: %s" % notice notice = uinfo.get_notice(('TurboGears', '1.0.2.2', '3.fc7')) assert notice, uinfo assert notice['title'] == update.title num_notices = len(uinfo.get_notices()) assert num_notices == 1, num_notices ## Clean up shutil.rmtree(temprepo) del (koji.__untag__[:])