def run(self, cmdline, db): try: tasks = self._get_tasks(cmdline, db) except FafError as ex: self.log_error("Unable to process command line arguments: {0}" .format(str(ex))) return 1 new_components = {} i = 0 for osplugin, db_release in tasks: i += 1 self.log_info("[{0} / {1}] Processing '{2} {3}'" .format(i, len(tasks), osplugin.nice_name, db_release.version)) db_components = [c.component.name for c in db_release.components] remote_components = osplugin.get_components(db_release.version) for remote_component in remote_components: if remote_component in db_components: continue db_component = get_component_by_name(db, remote_component, db_release.opsys.name) if db_component is None: key = (db_release.opsys, remote_component) if key in new_components: db_component = new_components[key] else: self.log_info("Creating new component '{0}' in " "operating system '{1}'" .format(remote_component, osplugin.nice_name)) db_component = OpSysComponent() db_component.name = remote_component db_component.opsys = db_release.opsys db.session.add(db_component) new_components[key] = db_component self.log_info("Creating new component '{0}' in {1} {2}" .format(remote_component, osplugin.nice_name, db_release.version)) db_release_component = OpSysReleaseComponent() db_release_component.release = db_release db_release_component.component = db_component db.session.add(db_release_component) db.session.flush() return 0
def run(self, cmdline, db): if cmdline.opsys is None: self.log_error("You must specify an operating system") return 1 if not cmdline.opsys in systems: self.log_error("Operating system '{0}' does not exist".format( cmdline.opsys)) return 1 opsys = systems[cmdline.opsys] db_opsys = get_opsys_by_name(db, opsys.nice_name) if db_opsys is None: self.log_error("Operating system '{0}' is not installed".format( opsys.nice_name)) return 1 db_component = get_component_by_name(db, cmdline.COMPONENT, opsys.nice_name) if db_component is None: self.log_info( "Adding component '{0}' to operating system '{1}'".format( cmdline.COMPONENT, opsys.nice_name)) db_component = OpSysComponent() db_component.opsys = db_opsys db_component.name = cmdline.COMPONENT db.session.add(db_component) for release in cmdline.opsys_release: db_release = get_osrelease(db, opsys.nice_name, release) if db_release is None: self.log_warn("Release '{0} {1}' is not defined".format( opsys.nice_name, release)) continue db_relcomponent = get_component_by_name_release( db, db_release, cmdline.COMPONENT) if db_relcomponent is None: self.log_info("Adding component '{0}' to '{1} {2}'".format( cmdline.COMPONENT, opsys.nice_name, release)) db_relcomponent = OpSysReleaseComponent() db_relcomponent.component = db_component db_relcomponent.release = db_release db.session.add(db_relcomponent) db.session.flush() return 0
def run(self, cmdline, db): if cmdline.opsys is None: self.log_error("You must specify an operating system") return 1 if not cmdline.opsys in systems: self.log_error("Operating system '{0}' does not exist" .format(cmdline.opsys)) return 1 opsys = systems[cmdline.opsys] db_opsys = get_opsys_by_name(db, opsys.nice_name) if db_opsys is None: self.log_error("Operating system '{0}' is not installed" .format(opsys.nice_name)) return 1 db_component = get_component_by_name(db, cmdline.COMPONENT, opsys.nice_name) if db_component is None: self.log_info("Adding component '{0}' to operating system '{1}'" .format(cmdline.COMPONENT, opsys.nice_name)) db_component = OpSysComponent() db_component.opsys = db_opsys db_component.name = cmdline.COMPONENT db.session.add(db_component) for release in cmdline.opsys_release: db_release = get_osrelease(db, opsys.nice_name, release) if db_release is None: self.log_warn("Release '{0} {1}' is not defined" .format(opsys.nice_name, release)) continue db_relcomponent = get_component_by_name_release(db, db_release, cmdline.COMPONENT) if db_relcomponent is None: self.log_info("Adding component '{0}' to '{1} {2}'" .format(cmdline.COMPONENT, opsys.nice_name, release)) db_relcomponent = OpSysReleaseComponent() db_relcomponent.component = db_component db_relcomponent.release = db_release db.session.add(db_relcomponent) db.session.flush() return 0
def save_ureport2(db, ureport, create_component=False, timestamp=None, count=1): """ Save uReport2 """ if timestamp is None: timestamp = datetime.datetime.utcnow() osplugin = systems[ureport["os"]["name"]] problemplugin = problemtypes[ureport["problem"]["type"]] db_osrelease = get_osrelease(db, osplugin.nice_name, ureport["os"]["version"]) if db_osrelease is None: raise FafError( "Operating system '{0} {1}' not found in storage".format( osplugin.nice_name, ureport["os"]["version"])) report_hash = problemplugin.hash_ureport(ureport["problem"]) db_report = get_report(db, report_hash) if db_report is None: component_name = problemplugin.get_component_name(ureport["problem"]) db_component = get_component_by_name(db, component_name, osplugin.nice_name) if db_component is None: if create_component: log.info("Creating an unsupported component '{0}' in " "operating system '{1}'".format( component_name, osplugin.nice_name)) db_component = OpSysComponent() db_component.name = component_name db_component.opsys = db_osrelease.opsys db.session.add(db_component) else: raise FafError("Unknown component '{0}' in operating system " "{1}".format(component_name, osplugin.nice_name)) db_report = Report() db_report.type = problemplugin.name db_report.first_occurrence = timestamp db_report.last_occurrence = timestamp db_report.count = 0 db_report.component = db_component db.session.add(db_report) db_report_hash = ReportHash() db_report_hash.report = db_report db_report_hash.hash = report_hash db.session.add(db_report_hash) if db_report.first_occurrence > timestamp: db_report.first_occurrence = timestamp if db_report.last_occurrence < timestamp: db_report.last_occurrence = timestamp db_reportosrelease = get_reportosrelease(db, db_report, db_osrelease) if db_reportosrelease is None: db_reportosrelease = ReportOpSysRelease() db_reportosrelease.report = db_report db_reportosrelease.opsysrelease = db_osrelease db_reportosrelease.count = 0 db.session.add(db_reportosrelease) db_reportosrelease.count += count db_arch = get_arch_by_name(db, ureport["os"]["architecture"]) if db_arch is None: raise FafError("Architecture '{0}' is not supported".format( ureport["os"]["architecture"])) db_reportarch = get_reportarch(db, db_report, db_arch) if db_reportarch is None: db_reportarch = ReportArch() db_reportarch.report = db_report db_reportarch.arch = db_arch db_reportarch.count = 0 db.session.add(db_reportarch) db_reportarch.count += count reason = ureport["reason"].encode("utf-8") db_reportreason = get_reportreason(db, db_report, reason) if db_reportreason is None: db_reportreason = ReportReason() db_reportreason.report = db_report db_reportreason.reason = reason db_reportreason.count = 0 db.session.add(db_reportreason) db_reportreason.count += count day = timestamp.date() db_daily = get_history_day(db, db_report, db_osrelease, day) if db_daily is None: db_daily = ReportHistoryDaily() db_daily.report = db_report db_daily.opsysrelease = db_osrelease db_daily.day = day db_daily.count = 0 db_daily.unique = 0 db.session.add(db_daily) if "serial" in ureport["problem"] and ureport["problem"]["serial"] == 1: db_daily.unique += 1 db_daily.count += count week = day - datetime.timedelta(days=day.weekday()) db_weekly = get_history_week(db, db_report, db_osrelease, week) if db_weekly is None: db_weekly = ReportHistoryWeekly() db_weekly.report = db_report db_weekly.opsysrelease = db_osrelease db_weekly.week = week db_weekly.count = 0 db_weekly.unique = 0 db.session.add(db_weekly) if "serial" in ureport["problem"] and ureport["problem"]["serial"] == 1: db_weekly.unique += 1 db_weekly.count += count month = day.replace(day=1) db_monthly = get_history_month(db, db_report, db_osrelease, month) if db_monthly is None: db_monthly = ReportHistoryMonthly() db_monthly.report = db_report db_monthly.opsysrelease = db_osrelease db_monthly.month = month db_monthly.count = 0 db_monthly.unique = 0 db.session.add(db_monthly) if "serial" in ureport["problem"] and ureport["problem"]["serial"] == 1: db_monthly.unique += 1 db_monthly.count += count osplugin.save_ureport(db, db_report, ureport["os"], ureport["packages"], count=count) problemplugin.save_ureport(db, db_report, ureport["problem"], count=count) # Update count as last, so that handlers listening to its "set" event have # as much information as possible db_report.count += count db.session.flush() problemplugin.save_ureport_post_flush()
def save_ureport2(db, ureport, create_component=False, timestamp=None, count=1): """ Save uReport2 """ if timestamp is None: timestamp = datetime.datetime.utcnow() osplugin = systems[ureport["os"]["name"]] problemplugin = problemtypes[ureport["problem"]["type"]] db_osrelease = get_osrelease(db, osplugin.nice_name, ureport["os"]["version"]) if db_osrelease is None: raise FafError("Operating system '{0} {1}' not found in storage" .format(osplugin.nice_name, ureport["os"]["version"])) report_hash = problemplugin.hash_ureport(ureport["problem"]) db_report = get_report(db, report_hash) if db_report is None: component_name = problemplugin.get_component_name(ureport["problem"]) db_component = get_component_by_name(db, component_name, osplugin.nice_name) if db_component is None: if create_component: log.info("Creating an unsupported component '{0}' in " "operating system '{1}'".format(component_name, osplugin.nice_name)) db_component = OpSysComponent() db_component.name = component_name db_component.opsys = db_osrelease.opsys db.session.add(db_component) else: raise FafError("Unknown component '{0}' in operating system " "{1}".format(component_name, osplugin.nice_name)) db_report = Report() db_report.type = problemplugin.name db_report.first_occurrence = timestamp db_report.last_occurrence = timestamp db_report.count = 0 db_report.component = db_component db.session.add(db_report) db_report_hash = ReportHash() db_report_hash.report = db_report db_report_hash.hash = report_hash db.session.add(db_report_hash) if db_report.first_occurrence > timestamp: db_report.first_occurrence = timestamp if db_report.last_occurrence < timestamp: db_report.last_occurrence = timestamp db_reportosrelease = get_reportosrelease(db, db_report, db_osrelease) if db_reportosrelease is None: db_reportosrelease = ReportOpSysRelease() db_reportosrelease.report = db_report db_reportosrelease.opsysrelease = db_osrelease db_reportosrelease.count = 0 db.session.add(db_reportosrelease) db_reportosrelease.count += count db_arch = get_arch_by_name(db, ureport["os"]["architecture"]) if db_arch is None: raise FafError("Architecture '{0}' is not supported" .format(ureport["os"]["architecture"])) db_reportarch = get_reportarch(db, db_report, db_arch) if db_reportarch is None: db_reportarch = ReportArch() db_reportarch.report = db_report db_reportarch.arch = db_arch db_reportarch.count = 0 db.session.add(db_reportarch) db_reportarch.count += count reason = ureport["reason"].encode("utf-8") db_reportreason = get_reportreason(db, db_report, reason) if db_reportreason is None: db_reportreason = ReportReason() db_reportreason.report = db_report db_reportreason.reason = reason db_reportreason.count = 0 db.session.add(db_reportreason) db_reportreason.count += count day = timestamp.date() db_daily = get_history_day(db, db_report, db_osrelease, day) if db_daily is None: db_daily = ReportHistoryDaily() db_daily.report = db_report db_daily.opsysrelease = db_osrelease db_daily.day = day db_daily.count = 0 db.session.add(db_daily) db_daily.count += count week = day - datetime.timedelta(days=day.weekday()) db_weekly = get_history_week(db, db_report, db_osrelease, week) if db_weekly is None: db_weekly = ReportHistoryWeekly() db_weekly.report = db_report db_weekly.opsysrelease = db_osrelease db_weekly.week = week db_weekly.count = 0 db.session.add(db_weekly) db_weekly.count += count month = day.replace(day=1) db_monthly = get_history_month(db, db_report, db_osrelease, month) if db_monthly is None: db_monthly = ReportHistoryMonthly() db_monthly.report = db_report db_monthly.opsysrelease = db_osrelease db_monthly.month = month db_monthly.count = 0 db.session.add(db_monthly) db_monthly.count += count osplugin.save_ureport(db, db_report, ureport["os"], ureport["packages"], count=count) problemplugin.save_ureport(db, db_report, ureport["problem"], count=count) # Update count as last, so that handlers listening to its "set" event have # as much information as possible db_report.count += count db.session.flush() problemplugin.save_ureport_post_flush()