CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Functions | Variables
o2oRun_SiStripDCS Namespace Reference

Functions

def main
 
def run
 
def summary
 

Variables

string logDirVar = 'O2O_LOG_FOLDER'
 

Function Documentation

def o2oRun_SiStripDCS.main ( )

Definition at line 64 of file o2oRun_SiStripDCS.py.

References run(), submitPVValidationJobs.split(), str, and summary().

64 
65 def main():
66  parser = argparse.ArgumentParser(description='Run SiStrip DCS O2O.')
67  parser.add_argument('jobname', metavar='JOBNAME', type=str, help='O2O job name as in DB.')
68  parser.add_argument('--mail-from', default='trk.o2o@cern.ch', help='Account to send email notification.')
69  parser.add_argument('--mail-to', default='trk.o2o@cern.ch', help='List of O2O notification recipients.')
70  parser.add_argument('--mail-log-to', default='trk.o2o@cern.ch', help='List of O2O log recipients.')
71  parser.add_argument('--db', default='pro', help='The database for o2o job management: pro ( for prod ) or dev ( for prep ). Default: %(default)s.')
72  parser.add_argument('--debug', action="store_true", default=False, help='Switch on debug mode. Default: %(default)s.')
73 
74  args = parser.parse_args()
75  args.mail_to = args.mail_to.strip().split(',')
76  args.mail_log_to = args.mail_log_to.strip().split(',')
77 
78  # Should NOT use logging before it's set up
79  try:
80  logdir = os.environ[logDirVar] if logDirVar in os.environ else '/tmp'
81  if not os.path.exists(logdir):
82  os.makedirs(logdir)
83  logfile = os.path.join(logdir, 'SiStripsDCSO2O_%s.log' % str(args.jobname))
84  loglevel = logging.DEBUG if args.debug else logging.INFO
85  helper.configLogger(logfile, loglevel)
86  except Exception:
87  # in case we failed before logging is set up
88  # print the error, send an email, and exit
89  helper.send_mail('DCS O2O Failure: %s' % args.jobname, traceback.format_exc(), args.mail_to, args.mail_from)
90  raise
91 
92  try:
93  is_ok = run(args)
94  summary(args, is_ok, logfile)
95  except Exception:
96  # in case we failed before logging is set up
97  # print the error, send an email, and exit
98  helper.send_mail('DCS O2O Failure: %s' % args.jobname, traceback.format_exc(), args.mail_to, args.mail_from)
99  raise
100 
101  if not is_ok:
102  return ' --- O2O FAILED! ---'
#define str(s)
def o2oRun_SiStripDCS.run (   args)

Definition at line 21 of file o2oRun_SiStripDCS.py.

Referenced by main().

21 
22 def run(args):
23  logging.debug(args)
24 
25  is_ok = True
26 
27  o2ocmd = "SiStripDCSPopCon.py"
28  o2ocmd += ' --delay {delay}'
29  o2ocmd += ' --destTags {destTags}'
30  o2ocmd += ' --destDb {destDb}'
31  o2ocmd += ' --inputTag {inputTag}'
32  o2ocmd += ' --sourceDb {sourceDb}'
33  o2ocmd += ' --condDbRead {condDbRead}'
34  if args.debug:
35  o2ocmd += ' --debug'
36 
37  cmd = 'o2o --db {db} -v run -n {jobname} "{o2ocmd}"'.format(db=args.db, jobname=args.jobname, o2ocmd=o2ocmd)
38  logging.info('Start running command:\n %s' % cmd)
39 
40  p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
41  atexit.register(partial(helper.kill_subproc_noexcept, p))
42 
43  log = p.communicate()[0]
44  if p.returncode == 0:
45  logging.info('O2OJob %s finished successfully!' % args.jobname)
46  else:
47  logging.error('O2OJob %s FAILED!' % args.jobname)
48  is_ok = False
49 
50  return is_ok
def o2oRun_SiStripDCS.summary (   args,
  is_ok,
  logfile 
)

Definition at line 51 of file o2oRun_SiStripDCS.py.

Referenced by main().

51 
52 def summary(args, is_ok, logfile):
53  if is_ok:
54  return
55 
56  # send the detailed log if failed
57  debugLabel = '[TEST] ' if args.debug else ''
58  with open(logfile, 'rb') as log:
59  helper.send_mail(subject='%sDCS O2O Failure: %s' % (debugLabel, args.jobname),
60  message=log.read(),
61  send_to=args.mail_log_to,
62  send_from=args.mail_from)
63 

Variable Documentation

string o2oRun_SiStripDCS.logDirVar = 'O2O_LOG_FOLDER'

Definition at line 19 of file o2oRun_SiStripDCS.py.