3 Top level script to run SiStrip DCS O2O. 15 from functools
import partial
17 import CondTools.SiStrip.o2o_helper
as helper
19 logDirVar =
'O2O_LOG_FOLDER' 26 o2ocmd =
"SiStripDCSPopCon.py" 27 o2ocmd +=
' --delay {delay}' 28 o2ocmd +=
' --destTags {destTags}' 29 o2ocmd +=
' --destDb {destDb}' 30 o2ocmd +=
' --inputTag {inputTag}' 31 o2ocmd +=
' --condDbRead {condDbRead}' 35 cmd =
'o2o --db {db} -v run -n {jobname} "{o2ocmd}"'.
format(db=args.db, jobname=args.jobname, o2ocmd=o2ocmd)
36 logging.info(
'Start running command:\n %s' % cmd)
38 p = subprocess.Popen(cmd, shell=
True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
39 atexit.register(partial(helper.kill_subproc_noexcept, p))
41 log = p.communicate()[0]
43 logging.info(
'O2OJob %s finished successfully!' % args.jobname)
45 logging.error(
'O2OJob %s FAILED!' % args.jobname)
55 debugLabel =
'[TEST] ' if args.debug
else '' 56 with open(logfile,
'rb')
as log:
57 helper.send_mail(subject=
'%sDCS O2O Failure: %s' % (debugLabel, args.jobname),
59 send_to=args.mail_log_to,
60 send_from=args.mail_from)
65 parser.add_argument(
'jobname', metavar=
'JOBNAME', type=str, help=
'O2O job name as in DB.')
66 parser.add_argument(
'--mail-from', default=
'trk.o2o@cern.ch', help=
'Account to send email notification.')
67 parser.add_argument(
'--mail-to', default=
'trk.o2o@cern.ch', help=
'List of O2O notification recipients.')
68 parser.add_argument(
'--mail-log-to', default=
'trk.o2o@cern.ch', help=
'List of O2O log recipients.')
69 parser.add_argument(
'--db', default=
'pro', help=
'The database for o2o job management: pro ( for prod ) or dev ( for prep ). Default: %(default)s.')
70 parser.add_argument(
'--debug', action=
"store_true", default=
False, help=
'Switch on debug mode. Default: %(default)s.')
72 args = parser.parse_args()
73 args.mail_to = args.mail_to.strip().
split(
',')
74 args.mail_log_to = args.mail_log_to.strip().
split(
',')
78 logdir = os.environ[logDirVar]
if logDirVar
in os.environ
else '/tmp' 79 if not os.path.exists(logdir):
81 logfile = os.path.join(logdir,
'SiStripsDCSO2O_%s.log' %
str(args.jobname))
82 loglevel = logging.DEBUG
if args.debug
else logging.INFO
83 helper.configLogger(logfile, loglevel)
87 helper.send_mail(
'DCS O2O Failure: %s' % args.jobname, traceback.format_exc(), args.mail_to, args.mail_from)
96 helper.send_mail(
'DCS O2O Failure: %s' % args.jobname, traceback.format_exc(), args.mail_to, args.mail_from)
100 return ' --- O2O FAILED! ---' 102 if __name__ ==
'__main__':
def summary(args, is_ok, logfile)