X-Git-Url: https://code.grnet.gr/git/ganeti-local/blobdiff_plain/f1c66d13a12d474b6d998fde20956f5cec69165b..da961187f97344fde390140ebb2f10d10d334d51:/scripts/gnt-debug diff --git a/scripts/gnt-debug b/scripts/gnt-debug old mode 100644 new mode 100755 index 20c5da5..d3bf054 --- a/scripts/gnt-debug +++ b/scripts/gnt-debug @@ -19,18 +19,19 @@ # 02110-1301, USA. +# pylint: disable-msg=W0401,W0614 +# W0401: Wildcard import ganeti.cli +# W0614: Unused import %s from wildcard import (since we need cli) + import sys -import os -import itertools import simplejson import time from optparse import make_option -from cStringIO import StringIO from ganeti.cli import * +from ganeti import cli from ganeti import opcodes -from ganeti import logger from ganeti import constants from ganeti import utils from ganeti import errors @@ -39,61 +40,98 @@ from ganeti import errors def Delay(opts, args): """Sleeps for a while + @param opts: the command line options selected by the user + @type args: list + @param args: should contain only one element, the duration + the sleep + @rtype: int + @return: the desired exit code + """ delay = float(args[0]) op = opcodes.OpTestDelay(duration=delay, on_master=opts.on_master, on_nodes=opts.on_nodes) + SubmitOpCode(op) - job = opcodes.Job(op_list=[op]) - jid = SubmitJob(job) - print "Job id", jid return 0 def GenericOpCodes(opts, args): - """Send any opcode to the master + """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 + the file with the opcode definition + @rtype: int + @return: the desired exit code + + """ + cl = cli.GetClient() + job_data = [] + job_ids = [] + for fname in args: + op_data = simplejson.loads(open(fname).read()) + op_list = [opcodes.OpCode.LoadOpCode(val) for val in op_data] + job_data.append((fname, op_list)) + for fname, op_list in job_data: + jid = cli.SendJob(op_list, cl=cl) + ToStdout("File '%s', job id: %s", fname, jid) + job_ids.append(jid) + for jid in job_ids: + ToStdout("Waiting for job id %s", jid) + cli.PollJob(jid, cl=cl) + return 0 + + +def TestAllocator(opts, args): + """Runs the test allocator opcode. + + @param opts: the command line options selected by the user + @type args: list + @param args: should contain only one element, the iallocator name + @rtype: int + @return: the desired exit code """ - 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!" + try: + disks = [{"size": utils.ParseUnit(val), "mode": 'w'} + for val in opts.disks.split(",")] + except errors.UnitParseError, err: + ToStderr("Invalid disks parameter '%s': %s", opts.disks, err) 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] + + nics = [val.split("/") for val in opts.nics.split(",")] + for row in nics: + while len(row) < 3: + row.append(None) + for i in range(3): + if row[i] == '': + row[i] = None + nic_dict = [{"mac": v[0], "ip": v[1], "bridge": v[2]} for v in nics] + + if opts.tags is None: + opts.tags = [] + else: + opts.tags = opts.tags.split(",") + + op = opcodes.OpTestAllocator(mode=opts.mode, + name=args[0], + mem_size=opts.mem, + disks=disks, + disk_template=opts.disk_template, + nics=nic_dict, + os=opts.os_type, + vcpus=opts.vcpus, + tags=opts.tags, + direction=opts.direction, + allocator=opts.allocator, + ) + result = SubmitOpCode(op) + ToStdout("%s" % result) return 0 @@ -108,11 +146,42 @@ commands = { help="Select nodes to sleep on"), ], "[opts...] ", "Executes a TestDelay OpCode"), - 'submit-job': (GenericOpCodes, ARGS_ONE, + 'submit-job': (GenericOpCodes, ARGS_ATLEAST(1), [DEBUG_OPT, ], - "", "Submits a job built from a json-file" - " with a list of serialized opcodes"), + "", "Submits jobs built from json files" + " containing a list of serialized opcodes"), + 'allocator': (TestAllocator, ARGS_ONE, + [DEBUG_OPT, + make_option("--dir", dest="direction", + default="in", choices=["in", "out"], + help="Show allocator input (in) or allocator" + " results (out)"), + make_option("--algorithm", dest="allocator", + default=None, + help="Allocator algorithm name"), + make_option("-m", "--mode", default="relocate", + choices=["relocate", "allocate"], + help="Request mode, either allocate or" + " relocate"), + cli_option("--mem", default=128, type="unit", + help="Memory size for the instance (MiB)"), + make_option("--disks", default="4096,4096", + help="Comma separated list of disk sizes (MiB)"), + make_option("-t", "--disk-template", default="drbd", + help="Select the disk template"), + make_option("--nics", default="00:11:22:33:44:55", + help="Comma separated list of nics, each nic" + " definition is of form mac/ip/bridge, if" + " missing values are replace by None"), + make_option("-o", "--os-type", default=None, + help="Select os for the instance"), + make_option("-p", "--vcpus", default=1, type="int", + help="Select number of VCPUs for the instance"), + make_option("--tags", default=None, + help="Comma separated list of tags"), + ], + "{opts...} ", "Executes a TestAllocator OpCode"), }