Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.

Commit b5015a3

Browse files
committed
added a test mode
1 parent f5b1760 commit b5015a3

1 file changed

Lines changed: 52 additions & 32 deletions

File tree

Unified/rejector.py

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
username = getpass.getuser()
1414

1515
def rejector(url, specific, options=None):
16+
17+
if options.test:
18+
print "Test mode - no changes propagate to the production system"
1619

1720
if not componentInfo(soft=['wtc','jira']).check(): return
1821

@@ -62,18 +65,26 @@ def rejector(url, specific, options=None):
6265

6366
comment=""
6467
if options.comments: comment = ", reason: "+options.comments
65-
if options.keep:
66-
wfi.sendLog('rejector','invalidating the workflow by unified operator {}{}'.format(username, comment))
68+
if options.test:
69+
if options.keep:
70+
print 'invalidating the workflow by unified operator {}{}'.format(username, comment)
71+
else:
72+
print 'invalidating the workflow and outputs by unified operator {}{}'.format(username, comment)
73+
results = [True]
6774
else:
68-
wfi.sendLog('rejector','invalidating the workflow and outputs by unified operator {}{}'.format(username, comment))
75+
if options.keep:
76+
wfi.sendLog('rejector','invalidating the workflow by unified operator {}{}'.format(username, comment))
77+
else:
78+
wfi.sendLog('rejector','invalidating the workflow and outputs by unified operator {}{}'.format(username, comment))
6979

70-
results = invalidate(url, wfi, only_resub=True, with_output= (not options.keep))
80+
results = invalidate(url, wfi, only_resub=True, with_output= (not options.keep))
7181

7282
if all(results):
7383
print wfo.name,"rejected"
7484
if options and options.clone:
75-
wfo.status = 'trouble'
76-
session.commit()
85+
if not options.test:
86+
wfo.status = 'trouble'
87+
session.commit()
7788
schema = wfi.getSchema()
7889
schema['Requestor'] = os.getenv('USER')
7990
schema['Group'] = 'DATAOPS'
@@ -209,8 +220,11 @@ def rejector(url, specific, options=None):
209220
tmcore = schema[sname].pop('Multicore')
210221
tmem = schema[sname].pop('Memory')
211222
if mcore and tmcore != mcore:
212-
wfi.sendLog('rejector','the conversion to stepchain encoutered different value of Multicore %d != %d'%( tmcore, mcore))
213-
sendLog('rejector','the conversion of %s to stepchain encoutered different value of Multicore %d != %d'%( wfo.name, tmcore, mcore), level='critical')
223+
if options.test:
224+
print 'the conversion of %s to stepchain encoutered different value of Multicore %d != %d' % (wfo.name, tmcore, mcore)
225+
else:
226+
wfi.sendLog('rejector','the conversion to stepchain encoutered different value of Multicore %d != %d'%( tmcore, mcore))
227+
sendLog('rejector','the conversion of %s to stepchain encoutered different value of Multicore %d != %d'%( wfo.name, tmcore, mcore), level='critical')
214228
mcore = max(mcore, tmcore)
215229
mem = max(mem, tmem)
216230
schema[sname]['StepName'] = schema[sname].pop('TaskName')
@@ -240,39 +254,45 @@ def rejector(url, specific, options=None):
240254
schema['Multicore'] = mcore
241255
schema['Memory'] = mem
242256
print json.dumps( schema, indent=2 )
243-
newWorkflow = reqMgrClient.submitWorkflow(url, schema)
244-
if not newWorkflow:
245-
msg = "Error in cloning {}".format(wfo.name)
246-
print(msg)
247-
wfi.sendLog('rejector',msg)
248-
249-
# Get the error message
250-
time.sleep(5)
251-
data = reqMgrClient.requestManagerPost(url, "/reqmgr2/data/request", schema)
252-
wfi.sendLog('rejector',data)
253-
254-
print json.dumps( schema, indent=2 )
255-
return
256-
print newWorkflow
257+
if not options.test:
258+
newWorkflow = reqMgrClient.submitWorkflow(url, schema)
259+
if not newWorkflow:
260+
msg = "Error in cloning {}".format(wfo.name)
261+
print(msg)
262+
wfi.sendLog('rejector',msg)
257263

258-
data = reqMgrClient.setWorkflowApproved(url, newWorkflow)
259-
print data
260-
wfi.sendLog('rejector','Cloned into %s by unified operator %s'%( newWorkflow, comment ))
261-
#wfi.notifyRequestor('Cloned into %s by unified operator %s'%( newWorkflow, comment ),do_batch=False)
264+
# Get the error message
265+
time.sleep(5)
266+
data = reqMgrClient.requestManagerPost(url, "/reqmgr2/data/request", schema)
267+
wfi.sendLog('rejector',data)
268+
269+
print json.dumps( schema, indent=2 )
270+
return
271+
print newWorkflow
272+
273+
data = reqMgrClient.setWorkflowApproved(url, newWorkflow)
274+
print data
275+
wfi.sendLog('rejector','Cloned into %s by unified operator %s'%( newWorkflow, comment ))
276+
#wfi.notifyRequestor('Cloned into %s by unified operator %s'%( newWorkflow, comment ),do_batch=False)
262277
else:
263-
wfo.status = 'trouble' if options.set_trouble else 'forget'
264-
wfi.notifyRequestor('Rejected by unified operator %s'%( comment ),do_batch=False)
265-
session.commit()
278+
if options.test:
279+
print 'Rejected by unified operator %s'%( comment )
280+
else:
281+
wfo.status = 'trouble' if options.set_trouble else 'forget'
282+
wfi.notifyRequestor('Rejected by unified operator %s'%( comment ),do_batch=False)
283+
session.commit()
266284

267285
else:
268-
msg = "Error in rejecting {}: {}".format(wfo.name,results)
269-
print(msg)
270-
wfi.sendLog('rejector',msg)
286+
msg = "Error in rejecting {}: {}".format(wfo.name, results)
287+
print msg
288+
if not options.test:
289+
wfi.sendLog('rejector', msg)
271290

272291
if __name__ == "__main__":
273292
url = reqmgr_url
274293

275294
parser = optparse.OptionParser()
295+
parser.add_option('-t', '--test', help="test mode - no changes are made", default=False, action="store_true")
276296
parser.add_option('-c','--clone',help="clone the workflow",default=False,action="store_true")
277297
parser.add_option('--comments', help="Give a comment to the clone",default="")
278298
parser.add_option('-k','--keep',help="keep the outpuy in current status", default=False,action="store_true")

0 commit comments

Comments
 (0)