|
13 | 13 | username = getpass.getuser() |
14 | 14 |
|
15 | 15 | def rejector(url, specific, options=None): |
| 16 | + |
| 17 | + if options.test: |
| 18 | + print "Test mode - no changes propagate to the production system" |
16 | 19 |
|
17 | 20 | if not componentInfo(soft=['wtc','jira']).check(): return |
18 | 21 |
|
@@ -62,19 +65,30 @@ def rejector(url, specific, options=None): |
62 | 65 |
|
63 | 66 | comment="" |
64 | 67 | 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] |
67 | 74 | 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)) |
69 | 79 |
|
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)) |
71 | 81 |
|
72 | 82 | if all(results): |
73 | 83 | print wfo.name,"rejected" |
74 | 84 | if options and options.clone: |
75 | | - wfo.status = 'trouble' |
76 | | - session.commit() |
| 85 | + if not options.test: |
| 86 | + wfo.status = 'trouble' |
| 87 | + session.commit() |
77 | 88 | schema = wfi.getSchema() |
| 89 | + if options.test: |
| 90 | + print "Original schema" |
| 91 | + print json.dumps( schema, indent=2 ) |
78 | 92 | schema['Requestor'] = os.getenv('USER') |
79 | 93 | schema['Group'] = 'DATAOPS' |
80 | 94 | schema['OriginalRequestName'] = wfo.name |
@@ -206,11 +220,20 @@ def rejector(url, specific, options=None): |
206 | 220 | if 'Task%d'%step in schema: |
207 | 221 | sname = 'Step%d'%step |
208 | 222 | schema[sname] = schema.pop('Task%d'%step) |
209 | | - tmcore = schema[sname].pop('Multicore') |
| 223 | + if 'Multicore' in schema[sname] and schema[sname]['Multicore']==1: |
| 224 | + # enforce single-core mode assuming that all Tasks with |
| 225 | + # Multicore=1 are not thread-safe |
| 226 | + tmcore = schema[sname]['Multicore'] |
| 227 | + else: |
| 228 | + # remove explicit assignment of the number of cores |
| 229 | + tmcore = schema[sname].pop('Multicore') |
210 | 230 | tmem = schema[sname].pop('Memory') |
211 | 231 | 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') |
| 232 | + if options.test: |
| 233 | + print 'the conversion of %s to stepchain encoutered different value of Multicore %d != %d' % (wfo.name, tmcore, mcore) |
| 234 | + else: |
| 235 | + wfi.sendLog('rejector','the conversion to stepchain encoutered different value of Multicore %d != %d'%( tmcore, mcore)) |
| 236 | + sendLog('rejector','the conversion of %s to stepchain encoutered different value of Multicore %d != %d'%( wfo.name, tmcore, mcore), level='critical') |
214 | 237 | mcore = max(mcore, tmcore) |
215 | 238 | mem = max(mem, tmem) |
216 | 239 | schema[sname]['StepName'] = schema[sname].pop('TaskName') |
@@ -239,40 +262,47 @@ def rejector(url, specific, options=None): |
239 | 262 | break |
240 | 263 | schema['Multicore'] = mcore |
241 | 264 | schema['Memory'] = mem |
| 265 | + print "New request schema" |
242 | 266 | 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 |
| 267 | + if not options.test: |
| 268 | + newWorkflow = reqMgrClient.submitWorkflow(url, schema) |
| 269 | + if not newWorkflow: |
| 270 | + msg = "Error in cloning {}".format(wfo.name) |
| 271 | + print(msg) |
| 272 | + wfi.sendLog('rejector',msg) |
| 273 | + |
| 274 | + # Get the error message |
| 275 | + time.sleep(5) |
| 276 | + data = reqMgrClient.requestManagerPost(url, "/reqmgr2/data/request", schema) |
| 277 | + wfi.sendLog('rejector',data) |
257 | 278 |
|
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) |
| 279 | + print json.dumps( schema, indent=2 ) |
| 280 | + return |
| 281 | + print newWorkflow |
| 282 | + |
| 283 | + data = reqMgrClient.setWorkflowApproved(url, newWorkflow) |
| 284 | + print data |
| 285 | + wfi.sendLog('rejector','Cloned into %s by unified operator %s'%( newWorkflow, comment )) |
| 286 | + #wfi.notifyRequestor('Cloned into %s by unified operator %s'%( newWorkflow, comment ),do_batch=False) |
262 | 287 | 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() |
| 288 | + if options.test: |
| 289 | + print 'Rejected by unified operator %s'%( comment ) |
| 290 | + else: |
| 291 | + wfo.status = 'trouble' if options.set_trouble else 'forget' |
| 292 | + wfi.notifyRequestor('Rejected by unified operator %s'%( comment ),do_batch=False) |
| 293 | + session.commit() |
266 | 294 |
|
267 | 295 | else: |
268 | | - msg = "Error in rejecting {}: {}".format(wfo.name,results) |
269 | | - print(msg) |
270 | | - wfi.sendLog('rejector',msg) |
| 296 | + msg = "Error in rejecting {}: {}".format(wfo.name, results) |
| 297 | + print msg |
| 298 | + if not options.test: |
| 299 | + wfi.sendLog('rejector', msg) |
271 | 300 |
|
272 | 301 | if __name__ == "__main__": |
273 | 302 | url = reqmgr_url |
274 | 303 |
|
275 | 304 | parser = optparse.OptionParser() |
| 305 | + parser.add_option('-t', '--test', help="test mode - no changes are made", default=False, action="store_true") |
276 | 306 | parser.add_option('-c','--clone',help="clone the workflow",default=False,action="store_true") |
277 | 307 | parser.add_option('--comments', help="Give a comment to the clone",default="") |
278 | 308 | parser.add_option('-k','--keep',help="keep the outpuy in current status", default=False,action="store_true") |
|
0 commit comments