コード例 #1
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()
コード例 #2
0
ファイル: ureport.py プロジェクト: patriczek/faf
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()