Statistics
| Branch: | Tag: | Revision:

root / lib / client / gnt_debug.py @ 653bc0f1

History | View | Annotate | Download (22.9 kB)

1 c2855a12 Michael Hanselmann
#
2 fd3ee040 Iustin Pop
#
3 fd3ee040 Iustin Pop
4 9b12c120 Iustin Pop
# Copyright (C) 2006, 2007, 2010, 2011, 2012 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 bb600388 Michael Hanselmann
  SubmitOrSend(op, 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 55b7e783 Iustin Pop
                               iallocator=opts.iallocator,
176 60152bbe Michael Hanselmann
                               evac_mode=opts.evac_mode,
177 09123222 René Nussbaumer
                               target_groups=target_groups,
178 3c049cd3 René Nussbaumer
                               spindle_use=opts.spindle_use,
179 3c049cd3 René Nussbaumer
                               count=opts.count)
180 400ca2f7 Iustin Pop
  result = SubmitOpCode(op, opts=opts)
181 3a24c527 Iustin Pop
  ToStdout("%s" % result)
182 d61df03e Iustin Pop
  return 0
183 d61df03e Iustin Pop
184 d61df03e Iustin Pop
185 c2d22fed Michael Hanselmann
def _TestJobDependency(opts):
186 c2d22fed Michael Hanselmann
  """Tests job dependencies.
187 c2d22fed Michael Hanselmann

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

271 92ae7daf Michael Hanselmann
  """
272 92ae7daf Michael Hanselmann
  ToStdout("Testing job submission")
273 92ae7daf Michael Hanselmann
274 92ae7daf Michael Hanselmann
  testdata = [
275 92ae7daf Michael Hanselmann
    (0, 0, constants.OP_PRIO_LOWEST),
276 92ae7daf Michael Hanselmann
    (0, 0, constants.OP_PRIO_HIGHEST),
277 92ae7daf Michael Hanselmann
    ]
278 92ae7daf Michael Hanselmann
279 92ae7daf Michael Hanselmann
  for priority in (constants.OP_PRIO_SUBMIT_VALID |
280 92ae7daf Michael Hanselmann
                   frozenset([constants.OP_PRIO_LOWEST,
281 92ae7daf Michael Hanselmann
                              constants.OP_PRIO_HIGHEST])):
282 92ae7daf Michael Hanselmann
    for offset in [-1, +1]:
283 92ae7daf Michael Hanselmann
      testdata.extend([
284 92ae7daf Michael Hanselmann
        (0, 0, priority + offset),
285 92ae7daf Michael Hanselmann
        (3, 0, priority + offset),
286 92ae7daf Michael Hanselmann
        (0, 3, priority + offset),
287 92ae7daf Michael Hanselmann
        (4, 2, priority + offset),
288 92ae7daf Michael Hanselmann
        ])
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 03b179ce Klaus Aehlig
      cl = cli.GetClient()
298 92ae7daf Michael Hanselmann
      cl.SubmitJob(ops)
299 92ae7daf Michael Hanselmann
    except errors.GenericError, err:
300 92ae7daf Michael Hanselmann
      if opts.debug:
301 9b12c120 Iustin Pop
        ToStdout("Ignoring error for 'wrong priority' test: %s", err)
302 92ae7daf Michael Hanselmann
    else:
303 92ae7daf Michael Hanselmann
      raise errors.OpExecError("Submitting opcode with priority %s did not"
304 92ae7daf Michael Hanselmann
                               " fail when it should (allowed are %s)" %
305 92ae7daf Michael Hanselmann
                               (failpriority, constants.OP_PRIO_SUBMIT_VALID))
306 92ae7daf Michael Hanselmann
307 92ae7daf Michael Hanselmann
    jobs = [
308 92ae7daf Michael Hanselmann
      [opcodes.OpTestDelay(duration=0),
309 92ae7daf Michael Hanselmann
       opcodes.OpTestDelay(duration=0, dry_run=False),
310 92ae7daf Michael Hanselmann
       opcodes.OpTestDelay(duration=0, dry_run=True)],
311 92ae7daf Michael Hanselmann
      ops,
312 92ae7daf Michael Hanselmann
      ]
313 c0827de8 Klaus Aehlig
    try:
314 03b179ce Klaus Aehlig
      cl = cli.GetClient()
315 c0827de8 Klaus Aehlig
      cl.SubmitManyJobs(jobs)
316 c0827de8 Klaus Aehlig
    except errors.GenericError, err:
317 c0827de8 Klaus Aehlig
      if opts.debug:
318 c0827de8 Klaus Aehlig
        ToStdout("Ignoring error for 'wrong priority' test: %s", err)
319 c0827de8 Klaus Aehlig
    else:
320 c0827de8 Klaus Aehlig
      raise errors.OpExecError("Submitting manyjobs with an incorrect one"
321 c0827de8 Klaus Aehlig
                               " did not fail when it should.")
322 92ae7daf Michael Hanselmann
  ToStdout("Job submission tests were successful")
323 92ae7daf Michael Hanselmann
324 92ae7daf Michael Hanselmann
325 e58f87a9 Michael Hanselmann
class _JobQueueTestReporter(cli.StdioJobPollReportCb):
326 e58f87a9 Michael Hanselmann
  def __init__(self):
327 e58f87a9 Michael Hanselmann
    """Initializes this class.
328 e58f87a9 Michael Hanselmann

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

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

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

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

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

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

576 19b9ba9a Michael Hanselmann
  @param opts: the command line options selected by the user
577 19b9ba9a Michael Hanselmann
  @type args: list
578 19b9ba9a Michael Hanselmann
  @param args: should be an empty list
579 19b9ba9a Michael Hanselmann
  @rtype: int
580 19b9ba9a Michael Hanselmann
  @return: the desired exit code
581 19b9ba9a Michael Hanselmann

582 19b9ba9a Michael Hanselmann
  """
583 19b9ba9a Michael Hanselmann
  selected_fields = ParseFields(opts.output, _LIST_LOCKS_DEF_FIELDS)
584 19b9ba9a Michael Hanselmann
585 24d16f76 Michael Hanselmann
  def _DashIfNone(fn):
586 24d16f76 Michael Hanselmann
    def wrapper(value):
587 24d16f76 Michael Hanselmann
      if not value:
588 24d16f76 Michael Hanselmann
        return "-"
589 24d16f76 Michael Hanselmann
      return fn(value)
590 24d16f76 Michael Hanselmann
    return wrapper
591 24d16f76 Michael Hanselmann
592 24d16f76 Michael Hanselmann
  def _FormatPending(value):
593 24d16f76 Michael Hanselmann
    """Format pending acquires.
594 24d16f76 Michael Hanselmann

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