Add a gnt-debug tool
authorIustin Pop <iustin@google.com>
Tue, 1 Apr 2008 13:07:20 +0000 (13:07 +0000)
committerIustin Pop <iustin@google.com>
Tue, 1 Apr 2008 13:07:20 +0000 (13:07 +0000)
This patch adds a script which submits a job consisting of the
OpTestDelay opcode. This can be helpful for debugging and can be
extended to execute other 'debug'-like tasks.

Reviewed-by: ultrotter

scripts/Makefile.am
scripts/gnt-debug [new file with mode: 0644]

index 3a62d29..a24b407 100644 (file)
@@ -1 +1 @@
-dist_sbin_SCRIPTS = gnt-instance gnt-cluster gnt-node gnt-os gnt-backup
+dist_sbin_SCRIPTS = gnt-instance gnt-cluster gnt-node gnt-os gnt-backup gnt-debug
diff --git a/scripts/gnt-debug b/scripts/gnt-debug
new file mode 100644 (file)
index 0000000..e570099
--- /dev/null
@@ -0,0 +1,66 @@
+#!/usr/bin/python
+#
+
+# Copyright (C) 2006, 2007 Google Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+# 02110-1301, USA.
+
+
+import sys
+import os
+import itertools
+from optparse import make_option
+from cStringIO import StringIO
+
+from ganeti.cli import *
+from ganeti import opcodes
+from ganeti import logger
+from ganeti import constants
+from ganeti import utils
+from ganeti import errors
+
+
+def Delay(opts, args):
+  """Sleeps for a while
+
+  """
+  delay = float(args[0])
+  op = opcodes.OpTestDelay(duration=delay,
+                           on_master=opts.on_master,
+                           on_nodes=opts.on_nodes)
+
+  job = opcodes.Job(op_list=[op])
+  jid = SubmitJob(job)
+  print "Job id", jid
+  return 0
+
+
+commands = {
+  'delay': (Delay, ARGS_ONE,
+            [DEBUG_OPT,
+             make_option("--no-master", dest="on_master", default=True,
+                         action="store_false",
+                         help="Do not sleep in the master code"),
+             make_option("-n", dest="on_nodes", default=[],
+                         action="append",
+                         help="Select nodes to sleep on"),
+             ],
+            "[opts...] <duration>", "Executes a TestDelay OpCode"),
+  }
+
+
+if __name__ == '__main__':
+  sys.exit(GenericMain(commands))