forked from cms-sw/cms-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdateVOTags
executable file
·85 lines (73 loc) · 2.62 KB
/
updateVOTags
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/python
# This script can be used to sync the production releases which are
# declared as announced in the tag collector and
from optparse import OptionParser
from commands import getstatusoutput
from sys import exit
import urllib2
# Apparently there are many ways to import json, depending on the python
# version. This should make sure you get one.
from os.path import join, dirname
HOME_DIR = dirname(__file__)
def getAnnouncedReleases():
lines = open(join(HOME_DIR, "releases.map")).readlines()
releases = []
for l in lines:
l = l.strip("\n ")
data = dict([p.split("=") for p in l.split(";") if p])
if data["type"] != "Production":
continue
if data["state"] != "Announced":
continue
releases.append(data["label"])
return releases
def withGridEnv(command, **kwds):
opts = {"environment": "/afs/cern.ch/cms/LCG/LCG-2/UI/cms_ui_env.sh",
"command": command % kwds}
return getstatusoutput("source %(environment)s ; %(command)s" % opts)
def availableCes():
error, out = withGridEnv("lcg-info --vo cms --list-ce"
" --query 'Cluster=*.cern.ch'"
" | grep -E -o '[a-zA-Z0-9.-]+[.]cern[.]ch'"
" | sort -u")
if error:
return None
return out.split("\n")
def gridReleases(ce):
error, out = withGridEnv("lcg-tags --vo cms --ce %(ce)s --list", ce=ce)
if error:
return None
return ["CMSSW_" + x.split("CMSSW_")[1]
for x in out.split("\n")
if "CMSSW_" in x]
def announceRelease(ce, release):
error, out = withGridEnv("lcg-tags --ce %(ce)s --vo cms --add --tags VO-cms-%(release)s",
ce=ce,
release=release)
return (release, error)
if __name__ == "__main__":
parser = OptionParser(usage="%(prog)s")
announced = getAnnouncedReleases()
error, out = withGridEnv("voms-proxy-init -voms %(voms)s",
voms="cms:/cms/Role=lcgadmin")
if error:
parser.error("Could not get a proxy")
ces = availableCes()
if not ces:
parser.error("Could not find any CE")
grids = gridReleases(ces[0])
missingReleases = [x for x in announced if x not in grids]
if not missingReleases:
print "No releases to announce"
exit(0)
errors = []
for ce in ces:
announced = [announceRelease(ce, x) for x in missingReleases]
errors += ["Release %s cannot be announced on %s" % (x,ce)
for (x, err) in announced if err]
ok = ["Release %s announced." % (x,ce)
for (x, err) in announced if err]
if not errors:
print "\n".join(ok)
break
print "\n".join(errors)