Revision f1c66d13 scripts/gnt-debug

b/scripts/gnt-debug
22 22
import sys
23 23
import os
24 24
import itertools
25
import simplejson
26
import time
27

  
25 28
from optparse import make_option
26 29
from cStringIO import StringIO
27 30

  
......
48 51
  return 0
49 52

  
50 53

  
54
def GenericOpCodes(opts, args):
55
  """Send any opcode to the master
56

  
57
  """
58
  fname = args[0]
59
  op_data = simplejson.loads(open(fname).read())
60
  op_list = [opcodes.OpCode.LoadOpCode(val) for val in op_data]
61
  job = opcodes.Job(op_list=op_list)
62
  jid = SubmitJob(job)
63
  print "Job id:", jid
64
  query = {
65
    "object": "jobs",
66
    "fields": ["status"],
67
    "names": [jid],
68
    }
69

  
70
  # wait for job to complete (either by success or failure)
71
  while True:
72
    jdata = SubmitQuery(query)
73
    if not jdata:
74
      # job not found, gone away!
75
      print "Job lost!"
76
      return 1
77

  
78
    status = jdata[0][0]
79
    print status
80
    if status in (opcodes.Job.STATUS_SUCCESS, opcodes.Job.STATUS_FAIL):
81
      break
82

  
83
    # sleep between checks
84
    time.sleep(0.5)
85

  
86
  # job has finished, get and process its results
87
  query["fields"].extend(["op_list", "op_status", "op_result"])
88
  jdata = SubmitQuery(query)
89
  if not jdata:
90
    # job not found, gone away!
91
    print "Job lost!"
92
    return 1
93
  print jdata[0]
94
  status, op_list, op_status, op_result = jdata[0]
95
  for idx, op in enumerate(op_list):
96
    print idx, op.OP_ID, op_status[idx], op_result[idx]
97
  return 0
98

  
99

  
51 100
commands = {
52 101
  'delay': (Delay, ARGS_ONE,
53 102
            [DEBUG_OPT,
......
59 108
                         help="Select nodes to sleep on"),
60 109
             ],
61 110
            "[opts...] <duration>", "Executes a TestDelay OpCode"),
111
  'submit-job': (GenericOpCodes, ARGS_ONE,
112
                 [DEBUG_OPT,
113
                  ],
114
                 "<op_list_file>", "Submits a job built from a json-file"
115
                 " with a list of serialized opcodes"),
62 116
  }
63 117

  
64 118

  

Also available in: Unified diff