NovaGridUtils.py
Go to the documentation of this file.
1 #!/bin/env python
2 import os, sys, stat, pwd, glob
3 import datetime
4 import socket
5 from time import sleep
6 
7 KNOWN_OS_CONTAINERS = {
8  "sl6": "/cvmfs/singularity.opensciencegrid.org/fermilab/fnal-wn-sl6:latest",
9  "sl7": "/cvmfs/singularity.opensciencegrid.org/fermilab/fnal-wn-sl7:latest",
10  "el8": "/cvmfs/singularity.opensciencegrid.org/fermilab/fnal-wn-el8:latest",
11 }
12 
13 
14 def fail(msg):
15  sys.stderr.write("\033[91mERROR in %s\033[0m " %prog)
16  sys.stderr.write(msg)
17  sys.stderr.write("\n")
18  sys.exit(-1)
19 
20 def warn(msg):
21  sys.stderr.write("\033[93mWARNING in %s\033[0m " %prog)
22  sys.stderr.write(msg)
23  sys.stderr.write("\n")
24 
25 def info(msg):
26  sys.stderr.write("\033[94mINFO in %s\033[0m " %prog)
27  sys.stderr.write(msg)
28  sys.stderr.write("\n")
29 
30 
31 def get_credentials(role):
32  retval = os.system("cigetcert -ns fifebatch.fnal.gov")
33  if retval != 0:
34  fail("Failed to get a certificate. Check kerberos credentials or run cigetcert -s fifebatch.fnal.gov")
35  return
36 
37 def check_file(fname):
38  fname = os.path.expandvars(fname)
39  if not os.path.isfile(fname):
40  fail("Invalid file %s" %fname)
41 
42 def check_dir(dname):
43  dname = os.path.expandvars(dname)
44  if not os.path.isdir(dname):
45  fail("Invalid directory %s" %dname)
46 
47 def check_make_dir(dname):
48  dname = os.path.expandvars(dname)
49  if not os.path.isdir(dname):
50  print ("Making directory",dname)
51  os.makedirs(dname)
52 
53 def check_tag(tag):
54  novasoft_development = "/cvmfs/nova-development.opensciencegrid.org/novasoft/"
55  if tag == "development":
56  tag = os.path.split(os.readlink(novasoft_development + "releases/development"))[1]
57  print ("Note: using current nightly release '%s' as development..." % tag)
58  else:
59  srt_dist = os.getenv("SRT_DIST", "undefined")
60  if srt_dist != "undefined":
61  if tag[0] == 'N':
62  srt_dist = novasoft_development
63 
64  tag_dir = srt_dist + "/releases/" + tag
65  if not os.path.isdir(tag_dir):
66  tag_dir = "/cvmfs/nova.opensciencegrid.org/novasoft/slf?/novasoft/releases/" + tag
67  if not glob.glob(tag_dir):
68  fail("Specified tag %s doesn't exist" % tag)
69  else:
70  novasoftloc = os.getenv("NOVASOFT_FQ_DIR", "undefined")
71  if(novasoftloc == "undefined"):
72  fail("novasoft location is unspecified, was the ups product setup?")
73  return tag
74 
75 def is_group_writable(fname):
76  stat_info = os.stat(fname)
77  file_stat_mode = stat_info.st_mode
78  return file_stat_mode & stat.S_IWGRP
79 
80 
82  if not is_group_writable(fname):
83  fail("%s is not group writable, but should be" % fname)
84 
86  # Production writable means either owned by "novapro" or group writable
87  file_owner = get_file_owner(fname)
88  if not (file_owner == "novapro" or is_group_writable(fname)):
89  fail("%s is neither group writable nor owned by novapro, but should be" % fname)
90 
91 def get_file_owner(fname):
92  stat_info = os.stat(fname)
93  file_stat_uid = stat_info.st_uid
94  return pwd.getpwuid(file_stat_uid)[0]
95 
97  hostname=socket.getfqdn()
98  if hostname.endswith("smu.edu"):
99  return "/scratch/data/srm/nova/production/DropBox/"
100  else:
101  return "/pnfs/nova/scratch/fts/dropbox"
102 
103 
105 
106  role="Production"
107  args.role=role
108 
109  get_credentials(role)
110 
111  dest=args.dest
112  # Production writable means either owned by "novapro" or group writable
113  if dest.startswith("s3://") and not args.amazon:
114  fail("Not using amazon, but output destination is on s3!")
115  elif not dest.startswith("s3://") and args.amazon:
116  fail("Using amazon, but output destination is not on s3!")
117  elif dest != "/pnfs/nova/scratch/fts/dropbox" and not args.test_submission:
119  warn("Destination directory is "+dest+", not \"/pnfs/nova/scratch/fts/dropbox\", but you are submitting production jobs. Is that what you meant? Pausing for 5s")
120  sleep(5)
121 
122  if not dest.startswith("s3://"):
123  args.hashDirs = True
124 
125  args.jsonMetadata = True
126  args.zipLogs = True
127  if (None == args.outTier) and (None == args.cafTier) and (None == args.h5Tier):
128  fail("Running in production mode, but no tiers (art or caf) specified")
129 
130 
132 
133  role="Production"
134  args.role=role
135 
136  get_credentials(role)
137 
138  dest=args.dest
139  # Production writable means either owned by "novapro" or group writable
141 
142 def setup_analysis(args):
143 
144  role="Analysis"
145  args.role=role
146 
147  get_credentials(role)
148 
150  parser.add_argument(
151  '--node-features',
152  help = (
153  'Comma separated list of grid node requirements.'
154  ' Example: ssse3,sse4_1'
155  ),
156  dest = 'node_features',
157  default = '',
158  type = lambda s : [ x for x in s.split(',') if x ],
159  )
160 
162 
163  if len(features) == 0:
164  return ''
165 
166  result = "&&".join([ "(TARGET.has_%s==true)" % (x) for x in features ])
167  result = "--append_condor_requirements='(%s)'" % (result)
168 
169  return result
170 
def setup_production(args)
def fail(msg)
def check_file(fname)
def check_is_group_writable(fname)
def info(msg)
def setup_analysis(args)
if(dump)
def make_jobsub_node_features_arg(features)
def check_tag(tag)
def get_file_owner(fname)
def get_prod_dropbox()
def check_dir(dname)
def add_node_features_arg(parser)
def get_credentials(role)
def check_is_production_writable(fname)
def warn(msg)
def setup_calibration(args)
def check_make_dir(dname)
def is_group_writable(fname)