def __init__(self, repo, cacheduinfo=None): self.tag = get_repo_tag(repo) self.repo = repo self.doc = None self.updates = set() self.builds = {} self._from = config.get('bodhi_email') self.koji = get_session() self._create_document() self._fetch_updates() missing_ids = [] if cacheduinfo and exists(cacheduinfo): log.debug("Loading cached updateinfo.xml.gz") umd = UpdateMetadata() umd.add(cacheduinfo) existing_ids = set([up['update_id'] for up in umd.get_notices()]) # Generate metadata for any new builds for update in self.updates: if update.updateid: self.add_update(update) log.debug('Adding new update notice: %s' % update.title) if update.updateid in existing_ids: existing_ids.remove(update.updateid) else: missing_ids.append(update.title) # Add all relevant notices from the metadata to this document for notice in umd.get_notices(): if notice['update_id'] in existing_ids: log.debug("Adding existing notice: %s" % notice['title']) self._add_notice(notice) existing_ids.remove(notice['update_id']) else: if notice['type'] == 'security': log.debug("Adding existing security notice: %s" % notice['title']) self._add_notice(notice) else: log.debug("Removing %s from updateinfo" % notice['title']) else: log.debug("Generating new updateinfo.xml") for update in self.updates: if update.updateid: self.add_update(update) else: missing_ids.append(update.title) # Add *all* security updates # TODO: only the most recent #for update in PackageUpdate.select(PackageUpdate.q.type=='security'): # self.add_update(update) if missing_ids: log.error("%d updates with missing ID!" % len(missing_ids)) log.debug(missing_ids)
def __init__(self, repo, cacheduinfo=None): self.tag = get_repo_tag(repo) self.repo = repo self.doc = None self.updates = set() self.builds = {} self._from = config.get('bodhi_email') self.koji = get_session() self._create_document() self._fetch_updates() missing_ids = [] if cacheduinfo and exists(cacheduinfo): log.debug("Loading cached updateinfo.xml.gz") umd = UpdateMetadata() umd.add(cacheduinfo) # Generate metadata for any new builds for update in self.updates: for build in update.builds: if not umd.get_notice(build.nvr): if update.updateid: self.add_update(update) break else: missing_ids.append(update.title) # Add all relevant notices from the metadata to this document ids = [ update.updateid for update in self.updates if update.updateid ] for notice in umd.get_notices(): if notice['update_id'] in ids or notice['type'] == 'security': self._add_notice(notice) else: log.debug("Removing %s from updateinfo" % notice['title']) else: log.debug("Generating new updateinfo.xml") for update in self.updates: if update.updateid: self.add_update(update) else: missing_ids.append(update.title) # Add *all* security updates # TODO: only the most recent #for update in PackageUpdate.select(PackageUpdate.q.type=='security'): # self.add_update(update) if missing_ids: log.error("%d updates with missing ID!" % len(missing_ids)) log.debug(missing_ids)
def get_update_notices(path_to_updateinfo): """ path_to_updateinfo: path to updateinfo.xml Returns a list of dictionaries Dictionary is based on keys from yum.update_md.UpdateNotice """ um = UpdateMetadata() um.add(path_to_updateinfo) notices = [] for info in um.get_notices(): notices.append(info.get_metadata()) return notices
def __init__(self, repo, cacheduinfo=None): self.tag = get_repo_tag(repo) self.repo = repo self.doc = None self.updates = set() self.builds = {} self._from = config.get('bodhi_email') self.koji = get_session() self._create_document() self._fetch_updates() missing_ids = [] if cacheduinfo and exists(cacheduinfo): log.debug("Loading cached updateinfo.xml.gz") umd = UpdateMetadata() umd.add(cacheduinfo) existing_ids = set([up['update_id'] for up in umd.get_notices()]) seen_ids = set() from_cache = set() # Generate metadata for any new builds for update in self.updates: if update.updateid: seen_ids.add(update.updateid) if update.updateid in existing_ids: notice = umd.get_notice(update.title) if not notice: log.warn('%s ID in cache but notice cannot be found' % (update.title)) self.add_update(update) continue if notice['updated']: if datetime.strptime(notice['updated'], '%Y-%m-%d %H:%M:%S') < update.date_modified: log.debug('Update modified, generating new notice: %s' % update.title) self.add_update(update) else: log.debug('Loading updated %s from cache' % update.title) from_cache.append(update.updateid) elif update.date_modified: log.debug('Update modified, generating new notice: %s' % update.title) self.add_update(update) else: log.debug('Loading %s from cache' % update.title) from_cache.add(update.updateid) else: log.debug('Adding new update notice: %s' % update.title) self.add_update(update) else: missing_ids.append(update.title) # Add all relevant notices from the cache to this document for notice in umd.get_notices(): if notice['update_id'] in from_cache: log.debug("Keeping existing notice: %s" % notice['title']) self._add_notice(notice) else: # Keep all security notices in the stable repo if 'testing' not in self.repo: if notice['type'] == 'security': if notice['update_id'] not in seen_ids: log.debug("Keeping existing security notice: %s" % notice['title']) self._add_notice(notice) else: log.debug('%s already added?' % notice['title']) else: log.debug('Purging cached stable notice %s' % notice['title']) else: log.debug('Purging cached testing update %s' % notice['title']) # Clean metadata generation else: log.debug("Generating new updateinfo.xml") for update in self.updates: if update.updateid: self.add_update(update) else: missing_ids.append(update.title) # Add *all* security updates # TODO: only the most recent #for update in PackageUpdate.select(PackageUpdate.q.type=='security'): # self.add_update(update) if missing_ids: log.error("%d updates with missing ID!" % len(missing_ids)) log.debug(missing_ids)
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 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__[:])
def __init__(self, repo, cacheduinfo=None): self.tag = get_repo_tag(repo) self.repo = repo self.doc = None self.updates = set() self.builds = {} self._from = config.get('bodhi_email') self.koji = get_session() self._create_document() self._fetch_updates() missing_ids = [] if cacheduinfo and exists(cacheduinfo): log.debug("Loading cached updateinfo.xml.gz") umd = UpdateMetadata() umd.add(cacheduinfo) # Drop the old cached updateinfo.xml.gz, it's unneeded now os.unlink(cacheduinfo) existing_ids = set([up['update_id'] for up in umd.get_notices()]) seen_ids = set() from_cache = set() # Generate metadata for any new builds for update in self.updates: if update.updateid: seen_ids.add(update.updateid) if update.updateid in existing_ids: notice = umd.get_notice(update.title) if not notice: log.warn( '%s ID in cache but notice cannot be found' % (update.title)) self.add_update(update) continue if notice['updated']: if datetime.strptime(notice['updated'], '%Y-%m-%d %H:%M:%S' ) < update.date_modified: log.debug( 'Update modified, generating new notice: %s' % update.title) self.add_update(update) else: log.debug('Loading updated %s from cache' % update.title) from_cache.add(update.updateid) elif update.date_modified: log.debug( 'Update modified, generating new notice: %s' % update.title) self.add_update(update) else: log.debug('Loading %s from cache' % update.title) from_cache.add(update.updateid) else: log.debug('Adding new update notice: %s' % update.title) self.add_update(update) else: missing_ids.append(update.title) # Add all relevant notices from the cache to this document for notice in umd.get_notices(): if notice['update_id'] in from_cache: log.debug("Keeping existing notice: %s" % notice['title']) self._add_notice(notice) else: # Keep all security notices in the stable repo if 'testing' not in self.repo: if notice['type'] == 'security': if notice['update_id'] not in seen_ids: log.debug( "Keeping existing security notice: %s" % notice['title']) self._add_notice(notice) else: log.debug('%s already added?' % notice['title']) else: log.debug('Purging cached stable notice %s' % notice['title']) else: log.debug('Purging cached testing update %s' % notice['title']) # Clean metadata generation else: log.debug("Generating new updateinfo.xml") for update in self.updates: if update.updateid: self.add_update(update) else: missing_ids.append(update.title) # Add *all* security updates # TODO: only the most recent #for update in PackageUpdate.select(PackageUpdate.q.type=='security'): # self.add_update(update) if missing_ids: log.error("%d updates with missing ID!" % len(missing_ids)) log.debug(missing_ids)
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 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__[:])