Skip to content
Snippets Groups Projects
Commit f1c66d13 authored by Iustin Pop's avatar Iustin Pop
Browse files

Add generic opcode submit functionality to gnt-debug

This patch enhances gnt-debug to be able to submit any opcodes. The
opcodes are input from a json file containing a list of opcodes.

This allows enhanced testing of opcodes until the other gnt-* commands
are converted to use the master daemon.

Reviewed-by: ultrotter
parent b77acb3e
No related branches found
No related tags found
No related merge requests found
...@@ -22,6 +22,9 @@ ...@@ -22,6 +22,9 @@
import sys import sys
import os import os
import itertools import itertools
import simplejson
import time
from optparse import make_option from optparse import make_option
from cStringIO import StringIO from cStringIO import StringIO
...@@ -48,6 +51,52 @@ def Delay(opts, args): ...@@ -48,6 +51,52 @@ def Delay(opts, args):
return 0 return 0
def GenericOpCodes(opts, args):
"""Send any opcode to the master
"""
fname = args[0]
op_data = simplejson.loads(open(fname).read())
op_list = [opcodes.OpCode.LoadOpCode(val) for val in op_data]
job = opcodes.Job(op_list=op_list)
jid = SubmitJob(job)
print "Job id:", jid
query = {
"object": "jobs",
"fields": ["status"],
"names": [jid],
}
# wait for job to complete (either by success or failure)
while True:
jdata = SubmitQuery(query)
if not jdata:
# job not found, gone away!
print "Job lost!"
return 1
status = jdata[0][0]
print status
if status in (opcodes.Job.STATUS_SUCCESS, opcodes.Job.STATUS_FAIL):
break
# sleep between checks
time.sleep(0.5)
# job has finished, get and process its results
query["fields"].extend(["op_list", "op_status", "op_result"])
jdata = SubmitQuery(query)
if not jdata:
# job not found, gone away!
print "Job lost!"
return 1
print jdata[0]
status, op_list, op_status, op_result = jdata[0]
for idx, op in enumerate(op_list):
print idx, op.OP_ID, op_status[idx], op_result[idx]
return 0
commands = { commands = {
'delay': (Delay, ARGS_ONE, 'delay': (Delay, ARGS_ONE,
[DEBUG_OPT, [DEBUG_OPT,
...@@ -59,6 +108,11 @@ commands = { ...@@ -59,6 +108,11 @@ commands = {
help="Select nodes to sleep on"), help="Select nodes to sleep on"),
], ],
"[opts...] <duration>", "Executes a TestDelay OpCode"), "[opts...] <duration>", "Executes a TestDelay OpCode"),
'submit-job': (GenericOpCodes, ARGS_ONE,
[DEBUG_OPT,
],
"<op_list_file>", "Submits a job built from a json-file"
" with a list of serialized opcodes"),
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment