Fix a broken commandline switch option
[ganeti-local] / scripts / gnt-debug
index e34b409..bf9d98d 100755 (executable)
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 # 02110-1301, USA.
 
+"""Debugging commands"""
 
-# pylint: disable-msg=W0401,W0614
+# pylint: disable-msg=W0401,W0614,C0103
 # W0401: Wildcard import ganeti.cli
 # W0614: Unused import %s from wildcard import (since we need cli)
+# C0103: Invalid name gnt-backup
 
 import sys
 import simplejson
@@ -30,7 +32,6 @@ import time
 from ganeti.cli import *
 from ganeti import cli
 from ganeti import opcodes
-from ganeti import constants
 from ganeti import utils
 from ganeti import errors
 
@@ -49,8 +50,9 @@ def Delay(opts, args):
   delay = float(args[0])
   op = opcodes.OpTestDelay(duration=delay,
                            on_master=opts.on_master,
-                           on_nodes=opts.on_nodes)
-  SubmitOpCode(op)
+                           on_nodes=opts.on_nodes,
+                           repeat=opts.repeat)
+  SubmitOpCode(op, opts=opts)
 
   return 0
 
@@ -58,8 +60,6 @@ def Delay(opts, args):
 def GenericOpCodes(opts, args):
   """Send any opcode to the master.
 
-  @todo: The function is broken and needs to be converted to the
-      current job queue API
   @param opts: the command line options selected by the user
   @type args: list
   @param args: should contain only one element, the path of
@@ -69,7 +69,7 @@ def GenericOpCodes(opts, args):
 
   """
   cl = cli.GetClient()
-  jex = cli.JobExecutor(cl=cl, verbose=opts.verbose)
+  jex = cli.JobExecutor(cl=cl, verbose=opts.verbose, opts=opts)
 
   job_cnt = 0
   op_cnt = 0
@@ -77,6 +77,7 @@ def GenericOpCodes(opts, args):
     ToStdout("Loading...")
   for job_idx in range(opts.rep_job):
     for fname in args:
+      # pylint: disable-msg=W0142
       op_data = simplejson.loads(utils.ReadFile(fname))
       op_list = [opcodes.OpCode.LoadOpCode(val) for val in op_data]
       op_list = op_list * opts.rep_op
@@ -88,7 +89,7 @@ def GenericOpCodes(opts, args):
     t1 = time.time()
     ToStdout("Submitting...")
 
-  jex.SubmitPending()
+  jex.SubmitPending(each=opts.each)
 
   if opts.timing_stats:
     t2 = time.time()
@@ -138,6 +139,7 @@ def TestAllocator(opts, args):
 
   op = opcodes.OpTestAllocator(mode=opts.mode,
                                name=args[0],
+                               evac_nodes=args,
                                mem_size=opts.mem,
                                disks=disks,
                                disk_template=opts.disk_template,
@@ -148,7 +150,7 @@ def TestAllocator(opts, args):
                                direction=opts.direction,
                                allocator=opts.iallocator,
                                )
-  result = SubmitOpCode(op)
+  result = SubmitOpCode(op, opts=opts)
   ToStdout("%s" % result)
   return 0
 
@@ -160,6 +162,8 @@ commands = {
                 action="store_false", help="Do not sleep in the master code"),
      cli_option("-n", dest="on_nodes", default=[],
                 action="append", help="Select nodes to sleep on"),
+     cli_option("-r", "--repeat", type="int", default="0", dest="repeat",
+                help="Number of times to repeat the sleep"),
      ],
     "[opts...] <duration>", "Executes a TestDelay OpCode"),
   'submit-job': (
@@ -171,18 +175,20 @@ commands = {
                 help="Repeat the job this number of times"),
      cli_option("--timing-stats", default=False,
                 action="store_true", help="Show timing stats"),
+     cli_option("--each", default=False, action="store_true",
+                help="Submit each job separately"),
      ],
     "<op_list_file...>", "Submits jobs built from json files"
     " containing a list of serialized opcodes"),
   'allocator': (
-    TestAllocator, ARGS_ONE_INSTANCE,
+    TestAllocator, [ArgUnknown(min=1)],
     [cli_option("--dir", dest="direction",
                 default="in", choices=["in", "out"],
                 help="Show allocator input (in) or allocator"
                 " results (out)"),
      IALLOCATOR_OPT,
      cli_option("-m", "--mode", default="relocate",
-                choices=["relocate", "allocate"],
+                choices=["relocate", "allocate", "multi-evacuate"],
                 help="Request mode, either allocate or relocate"),
      cli_option("--mem", default=128, type="unit",
                 help="Memory size for the instance (MiB)"),