Ejemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser(description='Run SiStrip DCS O2O.')
    parser.add_argument('jobname',
                        metavar='JOBNAME',
                        type=str,
                        help='O2O job name as in DB.')
    parser.add_argument('--mail-from',
                        default='*****@*****.**',
                        help='Account to send email notification.')
    parser.add_argument('--mail-to',
                        default='*****@*****.**',
                        help='List of O2O notification recipients.')
    parser.add_argument('--mail-log-to',
                        default='*****@*****.**',
                        help='List of O2O log recipients.')
    parser.add_argument(
        '--db',
        default='pro',
        help=
        'The database for o2o job management: pro ( for prod ) or dev ( for prep ). Default: %(default)s.'
    )
    parser.add_argument('--debug',
                        action="store_true",
                        default=False,
                        help='Switch on debug mode. Default: %(default)s.')

    args = parser.parse_args()
    args.mail_to = args.mail_to.strip().split(',')
    args.mail_log_to = args.mail_log_to.strip().split(',')

    # Should NOT use logging before it's set up
    try:
        logdir = os.environ[logDirVar] if logDirVar in os.environ else '/tmp'
        if not os.path.exists(logdir):
            os.makedirs(logdir)
        logfile = os.path.join(logdir,
                               'SiStripsDCSO2O_%s.log' % str(args.jobname))
        loglevel = logging.DEBUG if args.debug else logging.INFO
        helper.configLogger(logfile, loglevel)
    except Exception:
        # in case we failed before logging is set up
        # print the error, send an email, and exit
        helper.send_mail('DCS O2O Failure: %s' % args.jobname,
                         traceback.format_exc(), args.mail_to, args.mail_from)
        raise

    try:
        is_ok = run(args)
        summary(args, is_ok, logfile)
    except Exception:
        # in case we failed before logging is set up
        # print the error, send an email, and exit
        helper.send_mail('DCS O2O Failure: %s' % args.jobname,
                         traceback.format_exc(), args.mail_to, args.mail_from)
        raise

    if not is_ok:
        return ' --- O2O FAILED! ---'
Ejemplo n.º 2
0
def summary(args, is_ok, logfile):
    if is_ok:
        return

    # send the detailed log if failed
    debugLabel = '[TEST] ' if args.debug else ''
    with open(logfile, 'rb') as log:
        helper.send_mail(subject='%sDCS O2O Failure: %s' % (debugLabel, args.jobname),
                 message=log.read(),
                 send_to=args.mail_log_to,
                 send_from=args.mail_from)
Ejemplo n.º 3
0
def summary(args, is_ok, logfile):
    if is_ok:
        return

    # send the detailed log if failed
    debugLabel = '[TEST] ' if args.debug else ''
    with open(logfile, 'rb') as log:
        helper.send_mail(subject='%sDCS O2O Failure: %s' %
                         (debugLabel, args.jobname),
                         message=log.read(),
                         send_to=args.mail_log_to,
                         send_from=args.mail_from)
Ejemplo n.º 4
0
def main():
    parser = argparse.ArgumentParser(description='Run all SiStrip DAQ O2Os at the same time.')
    parser.add_argument('since', metavar='SINCE', type=str, help='Run number.')
    parser.add_argument('cfgfile', metavar='CFGLINES', help='File containing configuration lines.')
    parser.add_argument('--skiplistFile', default='', help='File containing the devices to be skipped in G1 O2O.')
    parser.add_argument('--whitelistFile', default='', help='File of the whitelisted devices in G1 O2O.')

    parser.add_argument('--analyzers',
                        default='SiStripO2OBadStrip,SiStripO2OFedCabling,SiStripO2OLatency,SiStripO2ONoises,SiStripO2OPedestals,SiStripO2OThreshold',
                        help='Which EDAnalyzers to run.')
    parser.add_argument('--mail-from', default='*****@*****.**', help='Account to send email notification.')
    parser.add_argument('--mail-to', default='*****@*****.**', help='List of O2O notification recipients.')
    parser.add_argument('--mail-log-to', default='*****@*****.**', help='List of O2O log recipients.')
    parser.add_argument('--db', default='pro', help='The database for o2o job management: pro ( for prod ) or dev ( for prep ). Default: %(default)s.')
    parser.add_argument('--debug', action="store_true", default=False, help='Switch on debug mode. Default: %(default)s.')

    args = parser.parse_args()
    if args.debug:
        args.mail_to = args.mail_log_to

    args.analyzers = args.analyzers.strip().split(',')
    args.mail_to = args.mail_to.strip().split(',')
    args.mail_log_to = args.mail_log_to.strip().split(',')

    # Should NOT use logging before it's set up
    try:
        logdir = os.environ[logDirVar] if logDirVar in os.environ else '/tmp'
        if not os.path.exists(logdir):
            os.makedirs(logdir)
        logfile = os.path.join(logdir, 'SiStripsO2O_Run%s.log' % str(args.since))
        loglevel = logging.DEBUG if args.debug else logging.INFO
        helper.configLogger(logfile, loglevel)
    except Exception:
        # in case we failed before logging is set up
        # print the error, send an email, and exit
        helper.send_mail('O2O Failure, IOV: %s' % args.since, traceback.format_exc(), args.mail_to, args.mail_from)
        raise

    try:
        is_ok, status = run(args)
        summary(args, is_ok, status, logfile)
    except Exception:
        # in case we failed before logging is set up
        # print the error, send an email, and exit
        helper.send_mail('O2O Failure, IOV: %s' % args.since, traceback.format_exc(), args.mail_to, args.mail_from)
        raise

    if not is_ok:
        return ' --- O2O FAILED! ---'
Ejemplo n.º 5
0
def summary(args, is_ok, status, logfile):
    summary = json.dumps(status, sort_keys=True, indent=2)
    if is_ok:
        logging.info('O2O finished successfully! Summary: %s' % summary)
    else:
        logging.error('O2O FAILED! Summary: %s' % summary)

    debugLabel = '[TEST] ' if args.debug else ''

    # send the summary email
    helper.send_mail(subject='%sNew O2O, IOV: %s' % (debugLabel, args.since),
             message=summary,
             send_to=args.mail_to,
             send_from=args.mail_from)
    # send the detailed log
    with open(logfile, 'rb') as log:
        helper.send_mail(subject='%sNew O2O Log, IOV: %s' % (debugLabel, args.since),
                 message=log.read(),
                 send_to=args.mail_log_to,
                 send_from=args.mail_from)
Ejemplo n.º 6
0
def summary(args, is_ok, status, logfile):
    summary = json.dumps(status, sort_keys=True, indent=2)
    if is_ok:
        logging.info('O2O finished successfully! Summary: %s' % summary)
    else:
        logging.error('O2O FAILED! Summary: %s' % summary)

    debugLabel = '[TEST] ' if args.debug else ''

    # send the summary email
    helper.send_mail(subject='%sNew O2O, IOV: %s' % (debugLabel, args.since),
                     message=summary,
                     send_to=args.mail_to,
                     send_from=args.mail_from)
    # send the detailed log
    with open(logfile, 'rb') as log:
        helper.send_mail(subject='%sNew O2O Log, IOV: %s' %
                         (debugLabel, args.since),
                         message=log.read(),
                         send_to=args.mail_log_to,
                         send_from=args.mail_from)
Ejemplo n.º 7
0
def main():
    parser = argparse.ArgumentParser(description='Run SiStrip DCS O2O.')
    parser.add_argument('jobname', metavar='JOBNAME', type=str, help='O2O job name as in DB.')
    parser.add_argument('--mail-from', default='*****@*****.**', help='Account to send email notification.')
    parser.add_argument('--mail-to', default='*****@*****.**', help='List of O2O notification recipients.')
    parser.add_argument('--mail-log-to', default='*****@*****.**', help='List of O2O log recipients.')
    parser.add_argument('--db', default='pro', help='The database for o2o job management: pro ( for prod ) or dev ( for prep ). Default: %(default)s.')
    parser.add_argument('--debug', action="store_true", default=False, help='Switch on debug mode. Default: %(default)s.')

    args = parser.parse_args()
    args.mail_to = args.mail_to.strip().split(',')
    args.mail_log_to = args.mail_log_to.strip().split(',')

    # Should NOT use logging before it's set up
    try:
        logdir = os.environ[logDirVar] if logDirVar in os.environ else '/tmp'
        if not os.path.exists(logdir):
            os.makedirs(logdir)
        logfile = os.path.join(logdir, 'SiStripsDCSO2O_%s.log' % str(args.jobname))
        loglevel = logging.DEBUG if args.debug else logging.INFO
        helper.configLogger(logfile, loglevel)
    except Exception:
        # in case we failed before logging is set up
        # print the error, send an email, and exit
        helper.send_mail('DCS O2O Failure: %s' % args.jobname, traceback.format_exc(), args.mail_to, args.mail_from)
        raise

    try:
        is_ok = run(args)
        summary(args, is_ok, logfile)
    except Exception:
        # in case we failed before logging is set up
        # print the error, send an email, and exit
        helper.send_mail('DCS O2O Failure: %s' % args.jobname, traceback.format_exc(), args.mail_to, args.mail_from)
        raise

    if not is_ok:
        return ' --- O2O FAILED! ---'
Ejemplo n.º 8
0
def main():
    parser = argparse.ArgumentParser(
        description='Run all SiStrip DAQ O2Os at the same time.')
    parser.add_argument('since', metavar='SINCE', type=str, help='Run number.')
    parser.add_argument('cfgfile',
                        metavar='CFGLINES',
                        help='File containing configuration lines.')
    parser.add_argument(
        '--skiplistFile',
        default='',
        help='File containing the devices to be skipped in G1 O2O.')

    parser.add_argument(
        '--analyzers',
        default=
        'SiStripO2OBadStrip,SiStripO2OFedCabling,SiStripO2OLatency,SiStripO2ONoises,SiStripO2OPedestals,SiStripO2OThreshold',
        help='Which EDAnalyzers to run.')
    parser.add_argument('--mail-from',
                        default='*****@*****.**',
                        help='Account to send email notification.')
    parser.add_argument('--mail-to',
                        default='*****@*****.**',
                        help='List of O2O notification recipients.')
    parser.add_argument('--mail-log-to',
                        default='*****@*****.**',
                        help='List of O2O log recipients.')
    parser.add_argument(
        '--db',
        default='pro',
        help=
        'The database for o2o job management: pro ( for prod ) or dev ( for prep ). Default: %(default)s.'
    )
    parser.add_argument('--debug',
                        action="store_true",
                        default=False,
                        help='Switch on debug mode. Default: %(default)s.')

    args = parser.parse_args()
    if args.debug:
        args.mail_to = args.mail_log_to

    args.analyzers = args.analyzers.strip().split(',')
    args.mail_to = args.mail_to.strip().split(',')
    args.mail_log_to = args.mail_log_to.strip().split(',')

    # Should NOT use logging before it's set up
    try:
        logdir = os.environ[logDirVar] if logDirVar in os.environ else '/tmp'
        if not os.path.exists(logdir):
            os.makedirs(logdir)
        logfile = os.path.join(logdir,
                               'SiStripsO2O_Run%s.log' % str(args.since))
        loglevel = logging.DEBUG if args.debug else logging.INFO
        helper.configLogger(logfile, loglevel)
    except Exception:
        # in case we failed before logging is set up
        # print the error, send an email, and exit
        helper.send_mail('O2O Failure, IOV: %s' % args.since,
                         traceback.format_exc(), args.mail_to, args.mail_from)
        raise

    try:
        is_ok, status = run(args)
        summary(args, is_ok, status, logfile)
    except Exception:
        # in case we failed before logging is set up
        # print the error, send an email, and exit
        helper.send_mail('O2O Failure, IOV: %s' % args.since,
                         traceback.format_exc(), args.mail_to, args.mail_from)
        raise

    if not is_ok:
        return ' --- O2O FAILED! ---'