Statistics
| Branch: | Tag: | Revision:

root / lib / client / gnt_debug.py @ 57de31c0

History | View | Annotate | Download (22.5 kB)

1 c2855a12 Michael Hanselmann
#
2 fd3ee040 Iustin Pop
#
3 fd3ee040 Iustin Pop
4 b469eb4d Iustin Pop
# Copyright (C) 2006, 2007, 2010, 2011 Google Inc.
5 fd3ee040 Iustin Pop
#
6 fd3ee040 Iustin Pop
# This program is free software; you can redistribute it and/or modify
7 fd3ee040 Iustin Pop
# it under the terms of the GNU General Public License as published by
8 fd3ee040 Iustin Pop
# the Free Software Foundation; either version 2 of the License, or
9 fd3ee040 Iustin Pop
# (at your option) any later version.
10 fd3ee040 Iustin Pop
#
11 fd3ee040 Iustin Pop
# This program is distributed in the hope that it will be useful, but
12 fd3ee040 Iustin Pop
# WITHOUT ANY WARRANTY; without even the implied warranty of
13 fd3ee040 Iustin Pop
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 fd3ee040 Iustin Pop
# General Public License for more details.
15 fd3ee040 Iustin Pop
#
16 fd3ee040 Iustin Pop
# You should have received a copy of the GNU General Public License
17 fd3ee040 Iustin Pop
# along with this program; if not, write to the Free Software
18 fd3ee040 Iustin Pop
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 fd3ee040 Iustin Pop
# 02110-1301, USA.
20 fd3ee040 Iustin Pop
21 7260cfbe Iustin Pop
"""Debugging commands"""
22 fd3ee040 Iustin Pop
23 b459a848 Andrea Spadaccini
# pylint: disable=W0401,W0614,C0103
24 2f79bd34 Iustin Pop
# W0401: Wildcard import ganeti.cli
25 2f79bd34 Iustin Pop
# W0614: Unused import %s from wildcard import (since we need cli)
26 7260cfbe Iustin Pop
# C0103: Invalid name gnt-backup
27 2f79bd34 Iustin Pop
28 f1c66d13 Iustin Pop
import simplejson
29 f1c66d13 Iustin Pop
import time
30 e58f87a9 Michael Hanselmann
import socket
31 e58f87a9 Michael Hanselmann
import logging
32 f1c66d13 Iustin Pop
33 fd3ee040 Iustin Pop
from ganeti.cli import *
34 9d5ba39a Iustin Pop
from ganeti import cli
35 e58f87a9 Michael Hanselmann
from ganeti import constants
36 fd3ee040 Iustin Pop
from ganeti import opcodes
37 fd3ee040 Iustin Pop
from ganeti import utils
38 fd3ee040 Iustin Pop
from ganeti import errors
39 92ae7daf Michael Hanselmann
from ganeti import compat
40 c2d22fed Michael Hanselmann
from ganeti import ht
41 fd3ee040 Iustin Pop
42 fd3ee040 Iustin Pop
43 19b9ba9a Michael Hanselmann
#: Default fields for L{ListLocks}
44 19b9ba9a Michael Hanselmann
_LIST_LOCKS_DEF_FIELDS = [
45 19b9ba9a Michael Hanselmann
  "name",
46 19b9ba9a Michael Hanselmann
  "mode",
47 19b9ba9a Michael Hanselmann
  "owner",
48 c31825f7 Michael Hanselmann
  "pending",
49 19b9ba9a Michael Hanselmann
  ]
50 19b9ba9a Michael Hanselmann
51 19b9ba9a Michael Hanselmann
52 fd3ee040 Iustin Pop
def Delay(opts, args):
53 fd3ee040 Iustin Pop
  """Sleeps for a while
54 fd3ee040 Iustin Pop

55 6099bfcf Iustin Pop
  @param opts: the command line options selected by the user
56 6099bfcf Iustin Pop
  @type args: list
57 6099bfcf Iustin Pop
  @param args: should contain only one element, the duration
58 6099bfcf Iustin Pop
      the sleep
59 6099bfcf Iustin Pop
  @rtype: int
60 6099bfcf Iustin Pop
  @return: the desired exit code
61 6099bfcf Iustin Pop

62 fd3ee040 Iustin Pop
  """
63 fd3ee040 Iustin Pop
  delay = float(args[0])
64 fd3ee040 Iustin Pop
  op = opcodes.OpTestDelay(duration=delay,
65 fd3ee040 Iustin Pop
                           on_master=opts.on_master,
66 85a87e21 Guido Trotter
                           on_nodes=opts.on_nodes,
67 85a87e21 Guido Trotter
                           repeat=opts.repeat)
68 400ca2f7 Iustin Pop
  SubmitOpCode(op, opts=opts)
69 fd3ee040 Iustin Pop
70 fd3ee040 Iustin Pop
  return 0
71 fd3ee040 Iustin Pop
72 fd3ee040 Iustin Pop
73 f1c66d13 Iustin Pop
def GenericOpCodes(opts, args):
74 6099bfcf Iustin Pop
  """Send any opcode to the master.
75 6099bfcf Iustin Pop

76 6099bfcf Iustin Pop
  @param opts: the command line options selected by the user
77 6099bfcf Iustin Pop
  @type args: list
78 6099bfcf Iustin Pop
  @param args: should contain only one element, the path of
79 6099bfcf Iustin Pop
      the file with the opcode definition
80 6099bfcf Iustin Pop
  @rtype: int
81 6099bfcf Iustin Pop
  @return: the desired exit code
82 f1c66d13 Iustin Pop

83 f1c66d13 Iustin Pop
  """
84 9d5ba39a Iustin Pop
  cl = cli.GetClient()
85 cb573a31 Iustin Pop
  jex = cli.JobExecutor(cl=cl, verbose=opts.verbose, opts=opts)
86 9d95c3af Iustin Pop
87 9d95c3af Iustin Pop
  job_cnt = 0
88 9d95c3af Iustin Pop
  op_cnt = 0
89 9d95c3af Iustin Pop
  if opts.timing_stats:
90 9d95c3af Iustin Pop
    ToStdout("Loading...")
91 9d95c3af Iustin Pop
  for job_idx in range(opts.rep_job):
92 9d95c3af Iustin Pop
    for fname in args:
93 b459a848 Andrea Spadaccini
      # pylint: disable=W0142
94 4d5fe81b Michael Hanselmann
      op_data = simplejson.loads(utils.ReadFile(fname))
95 9d95c3af Iustin Pop
      op_list = [opcodes.OpCode.LoadOpCode(val) for val in op_data]
96 9d95c3af Iustin Pop
      op_list = op_list * opts.rep_op
97 9d95c3af Iustin Pop
      jex.QueueJob("file %s/%d" % (fname, job_idx), *op_list)
98 9d95c3af Iustin Pop
      op_cnt += len(op_list)
99 9d95c3af Iustin Pop
      job_cnt += 1
100 9d95c3af Iustin Pop
101 9d95c3af Iustin Pop
  if opts.timing_stats:
102 9d95c3af Iustin Pop
    t1 = time.time()
103 9d95c3af Iustin Pop
    ToStdout("Submitting...")
104 4d5fe81b Michael Hanselmann
105 66ecc479 Guido Trotter
  jex.SubmitPending(each=opts.each)
106 9d95c3af Iustin Pop
107 9d95c3af Iustin Pop
  if opts.timing_stats:
108 9d95c3af Iustin Pop
    t2 = time.time()
109 9d95c3af Iustin Pop
    ToStdout("Executing...")
110 b59252fe Iustin Pop
111 b59252fe Iustin Pop
  jex.GetResults()
112 9d95c3af Iustin Pop
  if opts.timing_stats:
113 9d95c3af Iustin Pop
    t3 = time.time()
114 9d95c3af Iustin Pop
    ToStdout("C:op     %4d" % op_cnt)
115 9d95c3af Iustin Pop
    ToStdout("C:job    %4d" % job_cnt)
116 e687ec01 Michael Hanselmann
    ToStdout("T:submit %4.4f" % (t2 - t1))
117 e687ec01 Michael Hanselmann
    ToStdout("T:exec   %4.4f" % (t3 - t2))
118 e687ec01 Michael Hanselmann
    ToStdout("T:total  %4.4f" % (t3 - t1))
119 f1c66d13 Iustin Pop
  return 0
120 f1c66d13 Iustin Pop
121 f1c66d13 Iustin Pop
122 d61df03e Iustin Pop
def TestAllocator(opts, args):
123 6099bfcf Iustin Pop
  """Runs the test allocator opcode.
124 d61df03e Iustin Pop

125 6099bfcf Iustin Pop
  @param opts: the command line options selected by the user
126 6099bfcf Iustin Pop
  @type args: list
127 6099bfcf Iustin Pop
  @param args: should contain only one element, the iallocator name
128 6099bfcf Iustin Pop
  @rtype: int
129 6099bfcf Iustin Pop
  @return: the desired exit code
130 6099bfcf Iustin Pop

131 6099bfcf Iustin Pop
  """
132 d61df03e Iustin Pop
  try:
133 fdbe29ee Michael Hanselmann
    disks = [{
134 fdbe29ee Michael Hanselmann
      constants.IDISK_SIZE: utils.ParseUnit(val),
135 fdbe29ee Michael Hanselmann
      constants.IDISK_MODE: constants.DISK_RDWR,
136 fdbe29ee Michael Hanselmann
      } for val in opts.disks.split(",")]
137 d61df03e Iustin Pop
  except errors.UnitParseError, err:
138 3a24c527 Iustin Pop
    ToStderr("Invalid disks parameter '%s': %s", opts.disks, err)
139 d61df03e Iustin Pop
    return 1
140 d61df03e Iustin Pop
141 d61df03e Iustin Pop
  nics = [val.split("/") for val in opts.nics.split(",")]
142 d61df03e Iustin Pop
  for row in nics:
143 d61df03e Iustin Pop
    while len(row) < 3:
144 d61df03e Iustin Pop
      row.append(None)
145 d61df03e Iustin Pop
    for i in range(3):
146 d0c8c01d Iustin Pop
      if row[i] == "":
147 d61df03e Iustin Pop
        row[i] = None
148 fdbe29ee Michael Hanselmann
  nic_dict = [{
149 fdbe29ee Michael Hanselmann
    constants.INIC_MAC: v[0],
150 fdbe29ee Michael Hanselmann
    constants.INIC_IP: v[1],
151 fdbe29ee Michael Hanselmann
    # The iallocator interface defines a "bridge" item
152 fdbe29ee Michael Hanselmann
    "bridge": v[2],
153 fdbe29ee Michael Hanselmann
    } for v in nics]
154 d61df03e Iustin Pop
155 d61df03e Iustin Pop
  if opts.tags is None:
156 d61df03e Iustin Pop
    opts.tags = []
157 d61df03e Iustin Pop
  else:
158 d61df03e Iustin Pop
    opts.tags = opts.tags.split(",")
159 36bbf5b0 Iustin Pop
  if opts.target_groups is None:
160 36bbf5b0 Iustin Pop
    target_groups = []
161 36bbf5b0 Iustin Pop
  else:
162 36bbf5b0 Iustin Pop
    target_groups = opts.target_groups
163 d61df03e Iustin Pop
164 d61df03e Iustin Pop
  op = opcodes.OpTestAllocator(mode=opts.mode,
165 d61df03e Iustin Pop
                               name=args[0],
166 42c161cf Michael Hanselmann
                               instances=args,
167 dd47a0f0 Iustin Pop
                               memory=opts.memory,
168 d61df03e Iustin Pop
                               disks=disks,
169 d61df03e Iustin Pop
                               disk_template=opts.disk_template,
170 d61df03e Iustin Pop
                               nics=nic_dict,
171 705dd60e Iustin Pop
                               os=opts.os,
172 d61df03e Iustin Pop
                               vcpus=opts.vcpus,
173 d61df03e Iustin Pop
                               tags=opts.tags,
174 d61df03e Iustin Pop
                               direction=opts.direction,
175 705dd60e Iustin Pop
                               allocator=opts.iallocator,
176 60152bbe Michael Hanselmann
                               evac_mode=opts.evac_mode,
177 36bbf5b0 Iustin Pop
                               target_groups=target_groups)
178 400ca2f7 Iustin Pop
  result = SubmitOpCode(op, opts=opts)
179 3a24c527 Iustin Pop
  ToStdout("%s" % result)
180 d61df03e Iustin Pop
  return 0
181 d61df03e Iustin Pop
182 d61df03e Iustin Pop
183 c2d22fed Michael Hanselmann
def _TestJobDependency(opts):
184 c2d22fed Michael Hanselmann
  """Tests job dependencies.
185 c2d22fed Michael Hanselmann

186 c2d22fed Michael Hanselmann
  """
187 c2d22fed Michael Hanselmann
  ToStdout("Testing job dependencies")
188 c2d22fed Michael Hanselmann
189 c2d22fed Michael Hanselmann
  cl = cli.GetClient()
190 c2d22fed Michael Hanselmann
191 c2d22fed Michael Hanselmann
  try:
192 c2d22fed Michael Hanselmann
    SubmitOpCode(opcodes.OpTestDelay(duration=0, depends=[(-1, None)]), cl=cl)
193 c2d22fed Michael Hanselmann
  except errors.GenericError, err:
194 c2d22fed Michael Hanselmann
    if opts.debug:
195 c2d22fed Michael Hanselmann
      ToStdout("Ignoring error: %s", err)
196 c2d22fed Michael Hanselmann
  else:
197 c2d22fed Michael Hanselmann
    raise errors.OpExecError("Submitting plain opcode with relative job ID"
198 c2d22fed Michael Hanselmann
                             " did not fail as expected")
199 c2d22fed Michael Hanselmann
200 c2d22fed Michael Hanselmann
  # TODO: Test dependencies on errors
201 c2d22fed Michael Hanselmann
  jobs = [
202 c2d22fed Michael Hanselmann
    [opcodes.OpTestDelay(duration=1)],
203 c2d22fed Michael Hanselmann
    [opcodes.OpTestDelay(duration=1,
204 c2d22fed Michael Hanselmann
                         depends=[(-1, [])])],
205 c2d22fed Michael Hanselmann
    [opcodes.OpTestDelay(duration=1,
206 c2d22fed Michael Hanselmann
                         depends=[(-2, [constants.JOB_STATUS_SUCCESS])])],
207 c2d22fed Michael Hanselmann
    [opcodes.OpTestDelay(duration=1,
208 c2d22fed Michael Hanselmann
                         depends=[])],
209 c2d22fed Michael Hanselmann
    [opcodes.OpTestDelay(duration=1,
210 c2d22fed Michael Hanselmann
                         depends=[(-2, [constants.JOB_STATUS_SUCCESS])])],
211 c2d22fed Michael Hanselmann
    ]
212 c2d22fed Michael Hanselmann
213 c2d22fed Michael Hanselmann
  # Function for checking result
214 c2d22fed Michael Hanselmann
  check_fn = ht.TListOf(ht.TAnd(ht.TIsLength(2),
215 c2d22fed Michael Hanselmann
                                ht.TItems([ht.TBool,
216 c2d22fed Michael Hanselmann
                                           ht.TOr(ht.TNonEmptyString,
217 c2d22fed Michael Hanselmann
                                                  ht.TJobId)])))
218 c2d22fed Michael Hanselmann
219 c2d22fed Michael Hanselmann
  result = cl.SubmitManyJobs(jobs)
220 c2d22fed Michael Hanselmann
  if not check_fn(result):
221 c2d22fed Michael Hanselmann
    raise errors.OpExecError("Job submission doesn't match %s: %s" %
222 c2d22fed Michael Hanselmann
                             (check_fn, result))
223 c2d22fed Michael Hanselmann
224 c2d22fed Michael Hanselmann
  # Wait for jobs to finish
225 c2d22fed Michael Hanselmann
  jex = JobExecutor(cl=cl, opts=opts)
226 c2d22fed Michael Hanselmann
227 c2d22fed Michael Hanselmann
  for (status, job_id) in result:
228 c2d22fed Michael Hanselmann
    jex.AddJobId(None, status, job_id)
229 c2d22fed Michael Hanselmann
230 c2d22fed Michael Hanselmann
  job_results = jex.GetResults()
231 c2d22fed Michael Hanselmann
  if not compat.all(row[0] for row in job_results):
232 c2d22fed Michael Hanselmann
    raise errors.OpExecError("At least one of the submitted jobs failed: %s" %
233 c2d22fed Michael Hanselmann
                             job_results)
234 c2d22fed Michael Hanselmann
235 c2d22fed Michael Hanselmann
  # Get details about jobs
236 c2d22fed Michael Hanselmann
  data = cl.QueryJobs([job_id for (_, job_id) in result],
237 c2d22fed Michael Hanselmann
                      ["id", "opexec", "ops"])
238 c2d22fed Michael Hanselmann
  data_job_id = [job_id for (job_id, _, _) in data]
239 c2d22fed Michael Hanselmann
  data_opexec = [opexec for (_, opexec, _) in data]
240 c2d22fed Michael Hanselmann
  data_op = [[opcodes.OpCode.LoadOpCode(op) for op in ops]
241 c2d22fed Michael Hanselmann
             for (_, _, ops) in data]
242 c2d22fed Michael Hanselmann
243 c2d22fed Michael Hanselmann
  assert compat.all(not op.depends or len(op.depends) == 1
244 c2d22fed Michael Hanselmann
                    for ops in data_op
245 c2d22fed Michael Hanselmann
                    for op in ops)
246 c2d22fed Michael Hanselmann
247 c2d22fed Michael Hanselmann
  # Check resolved job IDs in dependencies
248 c2d22fed Michael Hanselmann
  for (job_idx, res_jobdep) in [(1, data_job_id[0]),
249 c2d22fed Michael Hanselmann
                                (2, data_job_id[0]),
250 c2d22fed Michael Hanselmann
                                (4, data_job_id[2])]:
251 c2d22fed Michael Hanselmann
    if data_op[job_idx][0].depends[0][0] != res_jobdep:
252 c2d22fed Michael Hanselmann
      raise errors.OpExecError("Job %s's opcode doesn't depend on correct job"
253 c2d22fed Michael Hanselmann
                               " ID (%s)" % (job_idx, res_jobdep))
254 c2d22fed Michael Hanselmann
255 c2d22fed Michael Hanselmann
  # Check execution order
256 c2d22fed Michael Hanselmann
  if not (data_opexec[0] <= data_opexec[1] and
257 c2d22fed Michael Hanselmann
          data_opexec[0] <= data_opexec[2] and
258 c2d22fed Michael Hanselmann
          data_opexec[2] <= data_opexec[4]):
259 c2d22fed Michael Hanselmann
    raise errors.OpExecError("Jobs did not run in correct order: %s" % data)
260 c2d22fed Michael Hanselmann
261 c2d22fed Michael Hanselmann
  assert len(jobs) == 5 and compat.all(len(ops) == 1 for ops in jobs)
262 c2d22fed Michael Hanselmann
263 c2d22fed Michael Hanselmann
  ToStdout("Job dependency tests were successful")
264 c2d22fed Michael Hanselmann
265 c2d22fed Michael Hanselmann
266 92ae7daf Michael Hanselmann
def _TestJobSubmission(opts):
267 92ae7daf Michael Hanselmann
  """Tests submitting jobs.
268 92ae7daf Michael Hanselmann

269 92ae7daf Michael Hanselmann
  """
270 92ae7daf Michael Hanselmann
  ToStdout("Testing job submission")
271 92ae7daf Michael Hanselmann
272 92ae7daf Michael Hanselmann
  testdata = [
273 92ae7daf Michael Hanselmann
    (0, 0, constants.OP_PRIO_LOWEST),
274 92ae7daf Michael Hanselmann
    (0, 0, constants.OP_PRIO_HIGHEST),
275 92ae7daf Michael Hanselmann
    ]
276 92ae7daf Michael Hanselmann
277 92ae7daf Michael Hanselmann
  for priority in (constants.OP_PRIO_SUBMIT_VALID |
278 92ae7daf Michael Hanselmann
                   frozenset([constants.OP_PRIO_LOWEST,
279 92ae7daf Michael Hanselmann
                              constants.OP_PRIO_HIGHEST])):
280 92ae7daf Michael Hanselmann
    for offset in [-1, +1]:
281 92ae7daf Michael Hanselmann
      testdata.extend([
282 92ae7daf Michael Hanselmann
        (0, 0, priority + offset),
283 92ae7daf Michael Hanselmann
        (3, 0, priority + offset),
284 92ae7daf Michael Hanselmann
        (0, 3, priority + offset),
285 92ae7daf Michael Hanselmann
        (4, 2, priority + offset),
286 92ae7daf Michael Hanselmann
        ])
287 92ae7daf Michael Hanselmann
288 92ae7daf Michael Hanselmann
  cl = cli.GetClient()
289 92ae7daf Michael Hanselmann
290 92ae7daf Michael Hanselmann
  for before, after, failpriority in testdata:
291 92ae7daf Michael Hanselmann
    ops = []
292 92ae7daf Michael Hanselmann
    ops.extend([opcodes.OpTestDelay(duration=0) for _ in range(before)])
293 92ae7daf Michael Hanselmann
    ops.append(opcodes.OpTestDelay(duration=0, priority=failpriority))
294 92ae7daf Michael Hanselmann
    ops.extend([opcodes.OpTestDelay(duration=0) for _ in range(after)])
295 92ae7daf Michael Hanselmann
296 92ae7daf Michael Hanselmann
    try:
297 92ae7daf Michael Hanselmann
      cl.SubmitJob(ops)
298 92ae7daf Michael Hanselmann
    except errors.GenericError, err:
299 92ae7daf Michael Hanselmann
      if opts.debug:
300 92ae7daf Michael Hanselmann
        ToStdout("Ignoring error: %s", err)
301 92ae7daf Michael Hanselmann
    else:
302 92ae7daf Michael Hanselmann
      raise errors.OpExecError("Submitting opcode with priority %s did not"
303 92ae7daf Michael Hanselmann
                               " fail when it should (allowed are %s)" %
304 92ae7daf Michael Hanselmann
                               (failpriority, constants.OP_PRIO_SUBMIT_VALID))
305 92ae7daf Michael Hanselmann
306 92ae7daf Michael Hanselmann
    jobs = [
307 92ae7daf Michael Hanselmann
      [opcodes.OpTestDelay(duration=0),
308 92ae7daf Michael Hanselmann
       opcodes.OpTestDelay(duration=0, dry_run=False),
309 92ae7daf Michael Hanselmann
       opcodes.OpTestDelay(duration=0, dry_run=True)],
310 92ae7daf Michael Hanselmann
      ops,
311 92ae7daf Michael Hanselmann
      ]
312 92ae7daf Michael Hanselmann
    result = cl.SubmitManyJobs(jobs)
313 92ae7daf Michael Hanselmann
    if not (len(result) == 2 and
314 92ae7daf Michael Hanselmann
            compat.all(len(i) == 2 for i in result) and
315 92ae7daf Michael Hanselmann
            compat.all(isinstance(i[1], basestring) for i in result) and
316 92ae7daf Michael Hanselmann
            result[0][0] and not result[1][0]):
317 92ae7daf Michael Hanselmann
      raise errors.OpExecError("Submitting multiple jobs did not work as"
318 92ae7daf Michael Hanselmann
                               " expected, result %s" % result)
319 92ae7daf Michael Hanselmann
    assert len(result) == 2
320 92ae7daf Michael Hanselmann
321 92ae7daf Michael Hanselmann
  ToStdout("Job submission tests were successful")
322 92ae7daf Michael Hanselmann
323 92ae7daf Michael Hanselmann
324 e58f87a9 Michael Hanselmann
class _JobQueueTestReporter(cli.StdioJobPollReportCb):
325 e58f87a9 Michael Hanselmann
  def __init__(self):
326 e58f87a9 Michael Hanselmann
    """Initializes this class.
327 e58f87a9 Michael Hanselmann

328 e58f87a9 Michael Hanselmann
    """
329 e58f87a9 Michael Hanselmann
    cli.StdioJobPollReportCb.__init__(self)
330 f99010b2 Michael Hanselmann
    self._expected_msgcount = 0
331 f99010b2 Michael Hanselmann
    self._all_testmsgs = []
332 f99010b2 Michael Hanselmann
    self._testmsgs = None
333 e58f87a9 Michael Hanselmann
    self._job_id = None
334 e58f87a9 Michael Hanselmann
335 e58f87a9 Michael Hanselmann
  def GetTestMessages(self):
336 e58f87a9 Michael Hanselmann
    """Returns all test log messages received so far.
337 e58f87a9 Michael Hanselmann

338 e58f87a9 Michael Hanselmann
    """
339 f99010b2 Michael Hanselmann
    return self._all_testmsgs
340 e58f87a9 Michael Hanselmann
341 e58f87a9 Michael Hanselmann
  def GetJobId(self):
342 e58f87a9 Michael Hanselmann
    """Returns the job ID.
343 e58f87a9 Michael Hanselmann

344 e58f87a9 Michael Hanselmann
    """
345 e58f87a9 Michael Hanselmann
    return self._job_id
346 e58f87a9 Michael Hanselmann
347 e58f87a9 Michael Hanselmann
  def ReportLogMessage(self, job_id, serial, timestamp, log_type, log_msg):
348 e58f87a9 Michael Hanselmann
    """Handles a log message.
349 e58f87a9 Michael Hanselmann

350 e58f87a9 Michael Hanselmann
    """
351 e58f87a9 Michael Hanselmann
    if self._job_id is None:
352 e58f87a9 Michael Hanselmann
      self._job_id = job_id
353 e58f87a9 Michael Hanselmann
    elif self._job_id != job_id:
354 e58f87a9 Michael Hanselmann
      raise errors.ProgrammerError("The same reporter instance was used for"
355 e58f87a9 Michael Hanselmann
                                   " more than one job")
356 e58f87a9 Michael Hanselmann
357 e58f87a9 Michael Hanselmann
    if log_type == constants.ELOG_JQUEUE_TEST:
358 e58f87a9 Michael Hanselmann
      (sockname, test, arg) = log_msg
359 e58f87a9 Michael Hanselmann
      return self._ProcessTestMessage(job_id, sockname, test, arg)
360 e58f87a9 Michael Hanselmann
361 e58f87a9 Michael Hanselmann
    elif (log_type == constants.ELOG_MESSAGE and
362 e58f87a9 Michael Hanselmann
          log_msg.startswith(constants.JQT_MSGPREFIX)):
363 f99010b2 Michael Hanselmann
      if self._testmsgs is None:
364 f99010b2 Michael Hanselmann
        raise errors.OpExecError("Received test message without a preceding"
365 f99010b2 Michael Hanselmann
                                 " start message")
366 f99010b2 Michael Hanselmann
      testmsg = log_msg[len(constants.JQT_MSGPREFIX):]
367 f99010b2 Michael Hanselmann
      self._testmsgs.append(testmsg)
368 f99010b2 Michael Hanselmann
      self._all_testmsgs.append(testmsg)
369 e58f87a9 Michael Hanselmann
      return
370 e58f87a9 Michael Hanselmann
371 e58f87a9 Michael Hanselmann
    return cli.StdioJobPollReportCb.ReportLogMessage(self, job_id, serial,
372 e58f87a9 Michael Hanselmann
                                                     timestamp, log_type,
373 e58f87a9 Michael Hanselmann
                                                     log_msg)
374 e58f87a9 Michael Hanselmann
375 e58f87a9 Michael Hanselmann
  def _ProcessTestMessage(self, job_id, sockname, test, arg):
376 e58f87a9 Michael Hanselmann
    """Handles a job queue test message.
377 e58f87a9 Michael Hanselmann

378 e58f87a9 Michael Hanselmann
    """
379 e58f87a9 Michael Hanselmann
    if test not in constants.JQT_ALL:
380 e58f87a9 Michael Hanselmann
      raise errors.OpExecError("Received invalid test message %s" % test)
381 e58f87a9 Michael Hanselmann
382 e58f87a9 Michael Hanselmann
    sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
383 e58f87a9 Michael Hanselmann
    try:
384 e58f87a9 Michael Hanselmann
      sock.settimeout(30.0)
385 e58f87a9 Michael Hanselmann
386 e58f87a9 Michael Hanselmann
      logging.debug("Connecting to %s", sockname)
387 e58f87a9 Michael Hanselmann
      sock.connect(sockname)
388 e58f87a9 Michael Hanselmann
389 e58f87a9 Michael Hanselmann
      logging.debug("Checking status")
390 e58f87a9 Michael Hanselmann
      jobdetails = cli.GetClient().QueryJobs([job_id], ["status"])[0]
391 e58f87a9 Michael Hanselmann
      if not jobdetails:
392 e58f87a9 Michael Hanselmann
        raise errors.OpExecError("Can't find job %s" % job_id)
393 e58f87a9 Michael Hanselmann
394 e58f87a9 Michael Hanselmann
      status = jobdetails[0]
395 e58f87a9 Michael Hanselmann
396 e58f87a9 Michael Hanselmann
      logging.debug("Status of job %s is %s", job_id, status)
397 e58f87a9 Michael Hanselmann
398 e58f87a9 Michael Hanselmann
      if test == constants.JQT_EXPANDNAMES:
399 47099cd1 Michael Hanselmann
        if status != constants.JOB_STATUS_WAITING:
400 e58f87a9 Michael Hanselmann
          raise errors.OpExecError("Job status while expanding names is '%s',"
401 e58f87a9 Michael Hanselmann
                                   " not '%s' as expected" %
402 47099cd1 Michael Hanselmann
                                   (status, constants.JOB_STATUS_WAITING))
403 e58f87a9 Michael Hanselmann
      elif test in (constants.JQT_EXEC, constants.JQT_LOGMSG):
404 e58f87a9 Michael Hanselmann
        if status != constants.JOB_STATUS_RUNNING:
405 e58f87a9 Michael Hanselmann
          raise errors.OpExecError("Job status while executing opcode is '%s',"
406 e58f87a9 Michael Hanselmann
                                   " not '%s' as expected" %
407 e58f87a9 Michael Hanselmann
                                   (status, constants.JOB_STATUS_RUNNING))
408 e58f87a9 Michael Hanselmann
409 f99010b2 Michael Hanselmann
      if test == constants.JQT_STARTMSG:
410 f99010b2 Michael Hanselmann
        logging.debug("Expecting %s test messages", arg)
411 f99010b2 Michael Hanselmann
        self._testmsgs = []
412 f99010b2 Michael Hanselmann
      elif test == constants.JQT_LOGMSG:
413 e58f87a9 Michael Hanselmann
        if len(self._testmsgs) != arg:
414 e58f87a9 Michael Hanselmann
          raise errors.OpExecError("Received %s test messages when %s are"
415 e58f87a9 Michael Hanselmann
                                   " expected" % (len(self._testmsgs), arg))
416 e58f87a9 Michael Hanselmann
    finally:
417 e58f87a9 Michael Hanselmann
      logging.debug("Closing socket")
418 e58f87a9 Michael Hanselmann
      sock.close()
419 e58f87a9 Michael Hanselmann
420 e58f87a9 Michael Hanselmann
421 e58f87a9 Michael Hanselmann
def TestJobqueue(opts, _):
422 e58f87a9 Michael Hanselmann
  """Runs a few tests on the job queue.
423 e58f87a9 Michael Hanselmann

424 e58f87a9 Michael Hanselmann
  """
425 92ae7daf Michael Hanselmann
  _TestJobSubmission(opts)
426 c2d22fed Michael Hanselmann
  _TestJobDependency(opts)
427 92ae7daf Michael Hanselmann
428 f99010b2 Michael Hanselmann
  (TM_SUCCESS,
429 f99010b2 Michael Hanselmann
   TM_MULTISUCCESS,
430 f99010b2 Michael Hanselmann
   TM_FAIL,
431 f99010b2 Michael Hanselmann
   TM_PARTFAIL) = range(4)
432 f99010b2 Michael Hanselmann
  TM_ALL = frozenset([TM_SUCCESS, TM_MULTISUCCESS, TM_FAIL, TM_PARTFAIL])
433 f99010b2 Michael Hanselmann
434 f99010b2 Michael Hanselmann
  for mode in TM_ALL:
435 f99010b2 Michael Hanselmann
    test_messages = [
436 f99010b2 Michael Hanselmann
      "Testing mode %s" % mode,
437 f99010b2 Michael Hanselmann
      "Hello World",
438 f99010b2 Michael Hanselmann
      "A",
439 f99010b2 Michael Hanselmann
      "",
440 f99010b2 Michael Hanselmann
      "B"
441 f99010b2 Michael Hanselmann
      "Foo|bar|baz",
442 f99010b2 Michael Hanselmann
      utils.TimestampForFilename(),
443 f99010b2 Michael Hanselmann
      ]
444 f99010b2 Michael Hanselmann
445 f99010b2 Michael Hanselmann
    fail = mode in (TM_FAIL, TM_PARTFAIL)
446 f99010b2 Michael Hanselmann
447 f99010b2 Michael Hanselmann
    if mode == TM_PARTFAIL:
448 f99010b2 Michael Hanselmann
      ToStdout("Testing partial job failure")
449 f99010b2 Michael Hanselmann
      ops = [
450 b469eb4d Iustin Pop
        opcodes.OpTestJqueue(notify_waitlock=True, notify_exec=True,
451 b469eb4d Iustin Pop
                             log_messages=test_messages, fail=False),
452 b469eb4d Iustin Pop
        opcodes.OpTestJqueue(notify_waitlock=True, notify_exec=True,
453 b469eb4d Iustin Pop
                             log_messages=test_messages, fail=False),
454 b469eb4d Iustin Pop
        opcodes.OpTestJqueue(notify_waitlock=True, notify_exec=True,
455 b469eb4d Iustin Pop
                             log_messages=test_messages, fail=True),
456 b469eb4d Iustin Pop
        opcodes.OpTestJqueue(notify_waitlock=True, notify_exec=True,
457 b469eb4d Iustin Pop
                             log_messages=test_messages, fail=False),
458 f99010b2 Michael Hanselmann
        ]
459 f99010b2 Michael Hanselmann
      expect_messages = 3 * [test_messages]
460 f99010b2 Michael Hanselmann
      expect_opstatus = [
461 f99010b2 Michael Hanselmann
        constants.OP_STATUS_SUCCESS,
462 f99010b2 Michael Hanselmann
        constants.OP_STATUS_SUCCESS,
463 f99010b2 Michael Hanselmann
        constants.OP_STATUS_ERROR,
464 f99010b2 Michael Hanselmann
        constants.OP_STATUS_ERROR,
465 f99010b2 Michael Hanselmann
        ]
466 f99010b2 Michael Hanselmann
      expect_resultlen = 2
467 f99010b2 Michael Hanselmann
    elif mode == TM_MULTISUCCESS:
468 f99010b2 Michael Hanselmann
      ToStdout("Testing multiple successful opcodes")
469 f99010b2 Michael Hanselmann
      ops = [
470 b469eb4d Iustin Pop
        opcodes.OpTestJqueue(notify_waitlock=True, notify_exec=True,
471 b469eb4d Iustin Pop
                             log_messages=test_messages, fail=False),
472 b469eb4d Iustin Pop
        opcodes.OpTestJqueue(notify_waitlock=True, notify_exec=True,
473 b469eb4d Iustin Pop
                             log_messages=test_messages, fail=False),
474 f99010b2 Michael Hanselmann
        ]
475 f99010b2 Michael Hanselmann
      expect_messages = 2 * [test_messages]
476 f99010b2 Michael Hanselmann
      expect_opstatus = [
477 f99010b2 Michael Hanselmann
        constants.OP_STATUS_SUCCESS,
478 f99010b2 Michael Hanselmann
        constants.OP_STATUS_SUCCESS,
479 f99010b2 Michael Hanselmann
        ]
480 f99010b2 Michael Hanselmann
      expect_resultlen = 2
481 e58f87a9 Michael Hanselmann
    else:
482 f99010b2 Michael Hanselmann
      if mode == TM_SUCCESS:
483 f99010b2 Michael Hanselmann
        ToStdout("Testing job success")
484 f99010b2 Michael Hanselmann
        expect_opstatus = [constants.OP_STATUS_SUCCESS]
485 f99010b2 Michael Hanselmann
      elif mode == TM_FAIL:
486 f99010b2 Michael Hanselmann
        ToStdout("Testing job failure")
487 f99010b2 Michael Hanselmann
        expect_opstatus = [constants.OP_STATUS_ERROR]
488 f99010b2 Michael Hanselmann
      else:
489 f99010b2 Michael Hanselmann
        raise errors.ProgrammerError("Unknown test mode %s" % mode)
490 f99010b2 Michael Hanselmann
491 f99010b2 Michael Hanselmann
      ops = [
492 b469eb4d Iustin Pop
        opcodes.OpTestJqueue(notify_waitlock=True,
493 b469eb4d Iustin Pop
                             notify_exec=True,
494 b469eb4d Iustin Pop
                             log_messages=test_messages,
495 b469eb4d Iustin Pop
                             fail=fail)
496 f99010b2 Michael Hanselmann
        ]
497 f99010b2 Michael Hanselmann
      expect_messages = [test_messages]
498 f99010b2 Michael Hanselmann
      expect_resultlen = 1
499 f99010b2 Michael Hanselmann
500 f99010b2 Michael Hanselmann
    cl = cli.GetClient()
501 f99010b2 Michael Hanselmann
    cli.SetGenericOpcodeOpts(ops, opts)
502 f99010b2 Michael Hanselmann
503 f99010b2 Michael Hanselmann
    # Send job to master daemon
504 f99010b2 Michael Hanselmann
    job_id = cli.SendJob(ops, cl=cl)
505 e58f87a9 Michael Hanselmann
506 e58f87a9 Michael Hanselmann
    reporter = _JobQueueTestReporter()
507 f99010b2 Michael Hanselmann
    results = None
508 f99010b2 Michael Hanselmann
509 e58f87a9 Michael Hanselmann
    try:
510 f99010b2 Michael Hanselmann
      results = cli.PollJob(job_id, cl=cl, reporter=reporter)
511 f99010b2 Michael Hanselmann
    except errors.OpExecError, err:
512 e58f87a9 Michael Hanselmann
      if not fail:
513 e58f87a9 Michael Hanselmann
        raise
514 f99010b2 Michael Hanselmann
      ToStdout("Ignoring error: %s", err)
515 e58f87a9 Michael Hanselmann
    else:
516 e58f87a9 Michael Hanselmann
      if fail:
517 e58f87a9 Michael Hanselmann
        raise errors.OpExecError("Job didn't fail when it should")
518 e58f87a9 Michael Hanselmann
519 f99010b2 Michael Hanselmann
    # Check length of result
520 f99010b2 Michael Hanselmann
    if fail:
521 f99010b2 Michael Hanselmann
      if results is not None:
522 f99010b2 Michael Hanselmann
        raise errors.OpExecError("Received result from failed job")
523 f99010b2 Michael Hanselmann
    elif len(results) != expect_resultlen:
524 f99010b2 Michael Hanselmann
      raise errors.OpExecError("Received %s results (%s), expected %s" %
525 f99010b2 Michael Hanselmann
                               (len(results), results, expect_resultlen))
526 f99010b2 Michael Hanselmann
527 e58f87a9 Michael Hanselmann
    # Check received log messages
528 f99010b2 Michael Hanselmann
    all_messages = [i for j in expect_messages for i in j]
529 f99010b2 Michael Hanselmann
    if reporter.GetTestMessages() != all_messages:
530 e58f87a9 Michael Hanselmann
      raise errors.OpExecError("Received test messages don't match input"
531 e58f87a9 Michael Hanselmann
                               " (input %r, received %r)" %
532 f99010b2 Michael Hanselmann
                               (all_messages, reporter.GetTestMessages()))
533 e58f87a9 Michael Hanselmann
534 e58f87a9 Michael Hanselmann
    # Check final status
535 f99010b2 Michael Hanselmann
    reported_job_id = reporter.GetJobId()
536 f99010b2 Michael Hanselmann
    if reported_job_id != job_id:
537 f99010b2 Michael Hanselmann
      raise errors.OpExecError("Reported job ID %s doesn't match"
538 f99010b2 Michael Hanselmann
                               "submission job ID %s" %
539 f99010b2 Michael Hanselmann
                               (reported_job_id, job_id))
540 e58f87a9 Michael Hanselmann
541 f99010b2 Michael Hanselmann
    jobdetails = cli.GetClient().QueryJobs([job_id], ["status", "opstatus"])[0]
542 e58f87a9 Michael Hanselmann
    if not jobdetails:
543 e58f87a9 Michael Hanselmann
      raise errors.OpExecError("Can't find job %s" % job_id)
544 e58f87a9 Michael Hanselmann
545 e58f87a9 Michael Hanselmann
    if fail:
546 e58f87a9 Michael Hanselmann
      exp_status = constants.JOB_STATUS_ERROR
547 e58f87a9 Michael Hanselmann
    else:
548 e58f87a9 Michael Hanselmann
      exp_status = constants.JOB_STATUS_SUCCESS
549 e58f87a9 Michael Hanselmann
550 f99010b2 Michael Hanselmann
    (final_status, final_opstatus) = jobdetails
551 e58f87a9 Michael Hanselmann
    if final_status != exp_status:
552 e58f87a9 Michael Hanselmann
      raise errors.OpExecError("Final job status is %s, not %s as expected" %
553 e58f87a9 Michael Hanselmann
                               (final_status, exp_status))
554 f99010b2 Michael Hanselmann
    if len(final_opstatus) != len(ops):
555 f99010b2 Michael Hanselmann
      raise errors.OpExecError("Did not receive status for all opcodes (got %s,"
556 f99010b2 Michael Hanselmann
                               " expected %s)" %
557 f99010b2 Michael Hanselmann
                               (len(final_opstatus), len(ops)))
558 f99010b2 Michael Hanselmann
    if final_opstatus != expect_opstatus:
559 f99010b2 Michael Hanselmann
      raise errors.OpExecError("Opcode status is %s, expected %s" %
560 f99010b2 Michael Hanselmann
                               (final_opstatus, expect_opstatus))
561 f99010b2 Michael Hanselmann
562 f99010b2 Michael Hanselmann
  ToStdout("Job queue test successful")
563 e58f87a9 Michael Hanselmann
564 e58f87a9 Michael Hanselmann
  return 0
565 e58f87a9 Michael Hanselmann
566 e58f87a9 Michael Hanselmann
567 b459a848 Andrea Spadaccini
def ListLocks(opts, args): # pylint: disable=W0613
568 19b9ba9a Michael Hanselmann
  """List all locks.
569 19b9ba9a Michael Hanselmann

570 19b9ba9a Michael Hanselmann
  @param opts: the command line options selected by the user
571 19b9ba9a Michael Hanselmann
  @type args: list
572 19b9ba9a Michael Hanselmann
  @param args: should be an empty list
573 19b9ba9a Michael Hanselmann
  @rtype: int
574 19b9ba9a Michael Hanselmann
  @return: the desired exit code
575 19b9ba9a Michael Hanselmann

576 19b9ba9a Michael Hanselmann
  """
577 19b9ba9a Michael Hanselmann
  selected_fields = ParseFields(opts.output, _LIST_LOCKS_DEF_FIELDS)
578 19b9ba9a Michael Hanselmann
579 24d16f76 Michael Hanselmann
  def _DashIfNone(fn):
580 24d16f76 Michael Hanselmann
    def wrapper(value):
581 24d16f76 Michael Hanselmann
      if not value:
582 24d16f76 Michael Hanselmann
        return "-"
583 24d16f76 Michael Hanselmann
      return fn(value)
584 24d16f76 Michael Hanselmann
    return wrapper
585 24d16f76 Michael Hanselmann
586 24d16f76 Michael Hanselmann
  def _FormatPending(value):
587 24d16f76 Michael Hanselmann
    """Format pending acquires.
588 24d16f76 Michael Hanselmann

589 24d16f76 Michael Hanselmann
    """
590 24d16f76 Michael Hanselmann
    return utils.CommaJoin("%s:%s" % (mode, ",".join(threads))
591 24d16f76 Michael Hanselmann
                           for mode, threads in value)
592 24d16f76 Michael Hanselmann
593 24d16f76 Michael Hanselmann
  # Format raw values
594 24d16f76 Michael Hanselmann
  fmtoverride = {
595 24d16f76 Michael Hanselmann
    "mode": (_DashIfNone(str), False),
596 24d16f76 Michael Hanselmann
    "owner": (_DashIfNone(",".join), False),
597 24d16f76 Michael Hanselmann
    "pending": (_DashIfNone(_FormatPending), False),
598 24d16f76 Michael Hanselmann
    }
599 19b9ba9a Michael Hanselmann
600 19b9ba9a Michael Hanselmann
  while True:
601 24d16f76 Michael Hanselmann
    ret = GenericList(constants.QR_LOCK, selected_fields, None, None,
602 24d16f76 Michael Hanselmann
                      opts.separator, not opts.no_headers,
603 f0b1bafe Iustin Pop
                      format_override=fmtoverride, verbose=opts.verbose)
604 24d16f76 Michael Hanselmann
605 24d16f76 Michael Hanselmann
    if ret != constants.EXIT_SUCCESS:
606 24d16f76 Michael Hanselmann
      return ret
607 19b9ba9a Michael Hanselmann
608 19b9ba9a Michael Hanselmann
    if not opts.interval:
609 19b9ba9a Michael Hanselmann
      break
610 19b9ba9a Michael Hanselmann
611 19b9ba9a Michael Hanselmann
    ToStdout("")
612 19b9ba9a Michael Hanselmann
    time.sleep(opts.interval)
613 19b9ba9a Michael Hanselmann
614 19b9ba9a Michael Hanselmann
  return 0
615 19b9ba9a Michael Hanselmann
616 19b9ba9a Michael Hanselmann
617 fd3ee040 Iustin Pop
commands = {
618 d0c8c01d Iustin Pop
  "delay": (
619 6ea815cf Iustin Pop
    Delay, [ArgUnknown(min=1, max=1)],
620 064c21f8 Iustin Pop
    [cli_option("--no-master", dest="on_master", default=True,
621 6ea815cf Iustin Pop
                action="store_false", help="Do not sleep in the master code"),
622 6ea815cf Iustin Pop
     cli_option("-n", dest="on_nodes", default=[],
623 6ea815cf Iustin Pop
                action="append", help="Select nodes to sleep on"),
624 85a87e21 Guido Trotter
     cli_option("-r", "--repeat", type="int", default="0", dest="repeat",
625 85a87e21 Guido Trotter
                help="Number of times to repeat the sleep"),
626 aa06f8c6 Michael Hanselmann
     DRY_RUN_OPT, PRIORITY_OPT,
627 6ea815cf Iustin Pop
     ],
628 6ea815cf Iustin Pop
    "[opts...] <duration>", "Executes a TestDelay OpCode"),
629 d0c8c01d Iustin Pop
  "submit-job": (
630 6ea815cf Iustin Pop
    GenericOpCodes, [ArgFile(min=1)],
631 064c21f8 Iustin Pop
    [VERBOSE_OPT,
632 6ea815cf Iustin Pop
     cli_option("--op-repeat", type="int", default="1", dest="rep_op",
633 6ea815cf Iustin Pop
                help="Repeat the opcode sequence this number of times"),
634 6ea815cf Iustin Pop
     cli_option("--job-repeat", type="int", default="1", dest="rep_job",
635 6ea815cf Iustin Pop
                help="Repeat the job this number of times"),
636 6ea815cf Iustin Pop
     cli_option("--timing-stats", default=False,
637 6ea815cf Iustin Pop
                action="store_true", help="Show timing stats"),
638 66ecc479 Guido Trotter
     cli_option("--each", default=False, action="store_true",
639 66ecc479 Guido Trotter
                help="Submit each job separately"),
640 aa06f8c6 Michael Hanselmann
     DRY_RUN_OPT, PRIORITY_OPT,
641 6ea815cf Iustin Pop
     ],
642 6ea815cf Iustin Pop
    "<op_list_file...>", "Submits jobs built from json files"
643 6ea815cf Iustin Pop
    " containing a list of serialized opcodes"),
644 d0c8c01d Iustin Pop
  "iallocator": (
645 823a72bc Iustin Pop
    TestAllocator, [ArgUnknown(min=1)],
646 9133387e Michael Hanselmann
    [cli_option("--dir", dest="direction", default=constants.IALLOCATOR_DIR_IN,
647 9133387e Michael Hanselmann
                choices=list(constants.VALID_IALLOCATOR_DIRECTIONS),
648 6ea815cf Iustin Pop
                help="Show allocator input (in) or allocator"
649 6ea815cf Iustin Pop
                " results (out)"),
650 6ea815cf Iustin Pop
     IALLOCATOR_OPT,
651 6ea815cf Iustin Pop
     cli_option("-m", "--mode", default="relocate",
652 42c161cf Michael Hanselmann
                choices=list(constants.VALID_IALLOCATOR_MODES),
653 42c161cf Michael Hanselmann
                help=("Request mode (one of %s)" %
654 42c161cf Michael Hanselmann
                      utils.CommaJoin(constants.VALID_IALLOCATOR_MODES))),
655 dd47a0f0 Iustin Pop
     cli_option("--memory", default=128, type="unit",
656 6ea815cf Iustin Pop
                help="Memory size for the instance (MiB)"),
657 6ea815cf Iustin Pop
     cli_option("--disks", default="4096,4096",
658 6ea815cf Iustin Pop
                help="Comma separated list of disk sizes (MiB)"),
659 6ea815cf Iustin Pop
     DISK_TEMPLATE_OPT,
660 6ea815cf Iustin Pop
     cli_option("--nics", default="00:11:22:33:44:55",
661 6ea815cf Iustin Pop
                help="Comma separated list of nics, each nic"
662 6ea815cf Iustin Pop
                " definition is of form mac/ip/bridge, if"
663 6ea815cf Iustin Pop
                " missing values are replace by None"),
664 6ea815cf Iustin Pop
     OS_OPT,
665 6ea815cf Iustin Pop
     cli_option("-p", "--vcpus", default=1, type="int",
666 6ea815cf Iustin Pop
                help="Select number of VCPUs for the instance"),
667 6ea815cf Iustin Pop
     cli_option("--tags", default=None,
668 6ea815cf Iustin Pop
                help="Comma separated list of tags"),
669 60152bbe Michael Hanselmann
     cli_option("--evac-mode", default=constants.IALLOCATOR_NEVAC_ALL,
670 60152bbe Michael Hanselmann
                choices=list(constants.IALLOCATOR_NEVAC_MODES),
671 60152bbe Michael Hanselmann
                help=("Node evacuation mode (one of %s)" %
672 60152bbe Michael Hanselmann
                      utils.CommaJoin(constants.IALLOCATOR_NEVAC_MODES))),
673 60152bbe Michael Hanselmann
     cli_option("--target-groups", help="Target groups for relocation",
674 60152bbe Michael Hanselmann
                default=[], action="append"),
675 aa06f8c6 Michael Hanselmann
     DRY_RUN_OPT, PRIORITY_OPT,
676 6ea815cf Iustin Pop
     ],
677 6ea815cf Iustin Pop
    "{opts...} <instance>", "Executes a TestAllocator OpCode"),
678 e58f87a9 Michael Hanselmann
  "test-jobqueue": (
679 aa06f8c6 Michael Hanselmann
    TestJobqueue, ARGS_NONE, [PRIORITY_OPT],
680 19b9ba9a Michael Hanselmann
    "", "Test a few aspects of the job queue"),
681 19b9ba9a Michael Hanselmann
  "locks": (
682 f0b1bafe Iustin Pop
    ListLocks, ARGS_NONE,
683 f0b1bafe Iustin Pop
    [NOHDR_OPT, SEP_OPT, FIELDS_OPT, INTERVAL_OPT, VERBOSE_OPT],
684 19b9ba9a Michael Hanselmann
    "[--interval N]", "Show a list of locks in the master daemon"),
685 fd3ee040 Iustin Pop
  }
686 fd3ee040 Iustin Pop
687 3f1e065d Iustin Pop
#: dictionary with aliases for commands
688 3f1e065d Iustin Pop
aliases = {
689 3f1e065d Iustin Pop
  "allocator": "iallocator",
690 3f1e065d Iustin Pop
  }
691 fd3ee040 Iustin Pop
692 e687ec01 Michael Hanselmann
693 c2855a12 Michael Hanselmann
def Main():
694 3f1e065d Iustin Pop
  return GenericMain(commands, aliases=aliases)