-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcheckRequests.py
executable file
·132 lines (111 loc) · 3.97 KB
/
checkRequests.py
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/usr/bin/env python
################################
#
# checkRequests.py
#
# Script to check the status of requests
#
# author: David G. Sheffield (Rutgers)
#
################################
import sys
import os
import subprocess
import argparse
import csv
import pprint
sys.path.append('/afs/cern.ch/cms/PPD/PdmV/tools/McM/')
from rest import * # Load class to access McM
def getArguments():
parser = argparse.ArgumentParser(description='Test McM requests.')
# Command line flags
parser.add_argument('ids', help=
'List of PrepIDs to be checked. Separate range by -.')
args_ = parser.parse_args()
return args_
def fillIDRange(pwg, campaign, first, last):
first = int(first)
last = int(last)
requests = []
if first > last:
print "Error: PrepID range out of order. {0}-{1}-{2:05d} > {0}-{1}-{3:05d}".format(
pwg, campaign, first, last)
sys.exit(4)
for number in range(first, last+1):
requests.append("{0}-{1}-{2:05d}".format(pwg, campaign, number))
return requests
def parseIDList(compactList):
splitList = compactList.split(',')
requests = []
for subList in splitList:
splitSubList = subList.split('-')
if len(splitSubList) == 3:
requests.append(subList)
elif len(splitSubList) == 4:
requests = requests + fillIDRange(splitSubList[0], splitSubList[1],
splitSubList[2], splitSubList[3])
elif len(splitSubList) == 6:
if splitSubList[0] != splitSubList[3]:
print "Error: PrepID range must be for the same PWG."
sys.exit(4)
if splitSubList[1] != splitSubList[4]:
print "Error: PrepID range must be for the same campaign."
sys.exit(4)
requests = requests + fillIDRange(splitSubList[0], splitSubList[1],
splitSubList[2], splitSubList[5])
else:
print "Error: Poorly formed PrepID list."
sys.exit(3)
return requests
def checkRequests(requests, useDev):
mcm = restful(dev=useDev) # Get McM connection
for PrepID in requests:
failed_to_get = True
for tries in range(3):
base_req = mcm.getA('requests', PrepID)
if base_req is not None:
failed_to_get = False
break
if failed_to_get:
print "\033[1;31mCould not get base request {0}\033[1;m\n".format(
PrepID)
continue
print "{0} {1}".format(PrepID, base_req['status'])
for chainID in base_req['member_of_chain']:
#print chainID
failed_to_get = True
for tries in range(3):
chain_req = mcm.getA('chained_requests', chainID)
if chain_req is not None:
failed_to_get = False
break
if failed_to_get:
print "\033[1;31mCould not get chain {0}\033[1;m\n".format(
chainID)
continue
space = ""
for i, member in enumerate(chain_req['chain']):
if i == 0:
continue
space = space + " "
failed_to_get = True
for tries in range(3):
req = mcm.getA('requests', member)
if req is not None:
failed_to_get = False
break
if failed_to_get:
print "\033[1;31mCould not get chained request {0}\033[1;m\n"\
.format(member)
continue
print "{0}{1} {2}".format(space, member, req['status'])
print ""
return
def main():
args = getArguments() # Setup flags and get arguments
requests = parseIDList(args.ids)
useDev = False
checkRequests(requests, useDev)
return
if __name__ == '__main__':
main()