Statistics
| Branch: | Tag: | Revision:

root / lib / client / gnt_debug.py @ d6f46b6a

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 7260cfbe Iustin Pop
# pylint: disable-msg=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 7260cfbe Iustin Pop
      # pylint: disable-msg=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 9d95c3af Iustin Pop
    ToStdout("T:submit %4.4f" % (t2-t1))
117 9d95c3af Iustin Pop
    ToStdout("T:exec   %4.4f" % (t3-t2))
118 9d95c3af Iustin Pop
    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 d61df03e 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 823a72bc Iustin Pop
                               evac_nodes=args,
167 42c161cf Michael Hanselmann
                               instances=args,
168 dd47a0f0 Iustin Pop
                               memory=opts.memory,
169 d61df03e Iustin Pop
                               disks=disks,
170 d61df03e Iustin Pop
                               disk_template=opts.disk_template,
171 d61df03e Iustin Pop
                               nics=nic_dict,
172 705dd60e Iustin Pop
                               os=opts.os,
173 d61df03e Iustin Pop
                               vcpus=opts.vcpus,
174 d61df03e Iustin Pop
                               tags=opts.tags,
175 d61df03e Iustin Pop
                               direction=opts.direction,
176 705dd60e Iustin Pop
                               allocator=opts.iallocator,
177 60152bbe Michael Hanselmann
                               evac_mode=opts.evac_mode,
178 36bbf5b0 Iustin Pop
                               target_groups=target_groups)
179 400ca2f7 Iustin Pop
  result = SubmitOpCode(op, opts=opts)
180 3a24c527 Iustin Pop
  ToStdout("%s" % result)
181 d61df03e Iustin Pop
  return 0
182 d61df03e Iustin Pop
183 d61df03e Iustin Pop
184 c2d22fed Michael Hanselmann
def _TestJobDependency(opts):
185 c2d22fed Michael Hanselmann
  """Tests job dependencies.
186 c2d22fed Michael Hanselmann

187 c2d22fed Michael Hanselmann
  """
188 c2d22fed Michael Hanselmann
  ToStdout("Testing job dependencies")
189 c2d22fed Michael Hanselmann
190 c2d22fed Michael Hanselmann
  cl = cli.GetClient()
191 c2d22fed Michael Hanselmann
192 c2d22fed Michael Hanselmann
  try:
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 c2d22fed Michael Hanselmann
      ToStdout("Ignoring error: %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 c2d22fed Michael Hanselmann
  result = cl.SubmitManyJobs(jobs)
221 c2d22fed Michael Hanselmann
  if not check_fn(result):
222 c2d22fed Michael Hanselmann
    raise errors.OpExecError("Job submission doesn't match %s: %s" %
223 c2d22fed Michael Hanselmann
                             (check_fn, result))
224 c2d22fed Michael Hanselmann
225 c2d22fed Michael Hanselmann
  # Wait for jobs to finish
226 c2d22fed Michael Hanselmann
  jex = JobExecutor(cl=cl, opts=opts)
227 c2d22fed Michael Hanselmann
228 c2d22fed Michael Hanselmann
  for (status, job_id) in result:
229 c2d22fed Michael Hanselmann
    jex.AddJobId(None, status, job_id)
230 c2d22fed Michael Hanselmann
231 c2d22fed Michael Hanselmann
  job_results = jex.GetResults()
232 c2d22fed Michael Hanselmann
  if not compat.all(row[0] for row in job_results):
233 c2d22fed Michael Hanselmann
    raise errors.OpExecError("At least one of the submitted jobs failed: %s" %
234 c2d22fed Michael Hanselmann
                             job_results)
235 c2d22fed Michael Hanselmann
236 c2d22fed Michael Hanselmann
  # Get details about jobs
237 c2d22fed Michael Hanselmann
  data = cl.QueryJobs([job_id for (_, job_id) in result],
238 c2d22fed Michael Hanselmann
                      ["id", "opexec", "ops"])
239 c2d22fed Michael Hanselmann
  data_job_id = [job_id for (job_id, _, _) in data]
240 c2d22fed Michael Hanselmann
  data_opexec = [opexec for (_, opexec, _) in data]
241 c2d22fed Michael Hanselmann
  data_op = [[opcodes.OpCode.LoadOpCode(op) for op in ops]
242 c2d22fed Michael Hanselmann
             for (_, _, ops) in data]
243 c2d22fed Michael Hanselmann
244 c2d22fed Michael Hanselmann
  assert compat.all(not op.depends or len(op.depends) == 1
245 c2d22fed Michael Hanselmann
                    for ops in data_op
246 c2d22fed Michael Hanselmann
                    for op in ops)
247 c2d22fed Michael Hanselmann
248 c2d22fed Michael Hanselmann
  # Check resolved job IDs in dependencies
249 c2d22fed Michael Hanselmann
  for (job_idx, res_jobdep) in [(1, data_job_id[0]),
250 c2d22fed Michael Hanselmann
                                (2, data_job_id[0]),
251 c2d22fed Michael Hanselmann
                                (4, data_job_id[2])]:
252 c2d22fed Michael Hanselmann
    if data_op[job_idx][0].depends[0][0] != res_jobdep:
253 c2d22fed Michael Hanselmann
      raise errors.OpExecError("Job %s's opcode doesn't depend on correct job"
254 c2d22fed Michael Hanselmann
                               " ID (%s)" % (job_idx, res_jobdep))
255 c2d22fed Michael Hanselmann
256 c2d22fed Michael Hanselmann
  # Check execution order
257 c2d22fed Michael Hanselmann
  if not (data_opexec[0] <= data_opexec[1] and
258 c2d22fed Michael Hanselmann
          data_opexec[0] <= data_opexec[2] and
259 c2d22fed Michael Hanselmann
          data_opexec[2] <= data_opexec[4]):
260 c2d22fed Michael Hanselmann
    raise errors.OpExecError("Jobs did not run in correct order: %s" % data)
261 c2d22fed Michael Hanselmann
262 c2d22fed Michael Hanselmann
  assert len(jobs) == 5 and compat.all(len(ops) == 1 for ops in jobs)
263 c2d22fed Michael Hanselmann
264 c2d22fed Michael Hanselmann
  ToStdout("Job dependency tests were successful")
265 c2d22fed Michael Hanselmann
266 c2d22fed Michael Hanselmann
267 92ae7daf Michael Hanselmann
def _TestJobSubmission(opts):
268 92ae7daf Michael Hanselmann
  """Tests submitting jobs.
269 92ae7daf Michael Hanselmann

270 92ae7daf Michael Hanselmann
  """
271 92ae7daf Michael Hanselmann
  ToStdout("Testing job submission")
272 92ae7daf Michael Hanselmann
273 92ae7daf Michael Hanselmann
  testdata = [
274 92ae7daf Michael Hanselmann
    (0, 0, constants.OP_PRIO_LOWEST),
275 92ae7daf Michael Hanselmann
    (0, 0, constants.OP_PRIO_HIGHEST),
276 92ae7daf Michael Hanselmann
    ]
277 92ae7daf Michael Hanselmann
278 92ae7daf Michael Hanselmann
  for priority in (constants.OP_PRIO_SUBMIT_VALID |
279 92ae7daf Michael Hanselmann
                   frozenset([constants.OP_PRIO_LOWEST,
280 92ae7daf Michael Hanselmann
                              constants.OP_PRIO_HIGHEST])):
281 92ae7daf Michael Hanselmann
    for offset in [-1, +1]:
282 92ae7daf Michael Hanselmann
      testdata.extend([
283 92ae7daf Michael Hanselmann
        (0, 0, priority + offset),
284 92ae7daf Michael Hanselmann
        (3, 0, priority + offset),
285 92ae7daf Michael Hanselmann
        (0, 3, priority + offset),
286 92ae7daf Michael Hanselmann
        (4, 2, priority + offset),
287 92ae7daf Michael Hanselmann
        ])
288 92ae7daf Michael Hanselmann
289 92ae7daf Michael Hanselmann
  cl = cli.GetClient()
290 92ae7daf Michael Hanselmann
291 92ae7daf Michael Hanselmann
  for before, after, failpriority in testdata:
292 92ae7daf Michael Hanselmann
    ops = []
293 92ae7daf Michael Hanselmann
    ops.extend([opcodes.OpTestDelay(duration=0) for _ in range(before)])
294 92ae7daf Michael Hanselmann
    ops.append(opcodes.OpTestDelay(duration=0, priority=failpriority))
295 92ae7daf Michael Hanselmann
    ops.extend([opcodes.OpTestDelay(duration=0) for _ in range(after)])
296 92ae7daf Michael Hanselmann
297 92ae7daf Michael Hanselmann
    try:
298 92ae7daf Michael Hanselmann
      cl.SubmitJob(ops)
299 92ae7daf Michael Hanselmann
    except errors.GenericError, err:
300 92ae7daf Michael Hanselmann
      if opts.debug:
301 92ae7daf Michael Hanselmann
        ToStdout("Ignoring error: %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 92ae7daf Michael Hanselmann
    result = cl.SubmitManyJobs(jobs)
314 92ae7daf Michael Hanselmann
    if not (len(result) == 2 and
315 92ae7daf Michael Hanselmann
            compat.all(len(i) == 2 for i in result) and
316 92ae7daf Michael Hanselmann
            compat.all(isinstance(i[1], basestring) for i in result) and
317 92ae7daf Michael Hanselmann
            result[0][0] and not result[1][0]):
318 92ae7daf Michael Hanselmann
      raise errors.OpExecError("Submitting multiple jobs did not work as"
319 92ae7daf Michael Hanselmann
                               " expected, result %s" % result)
320 92ae7daf Michael Hanselmann
    assert len(result) == 2
321 92ae7daf Michael Hanselmann
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 f99010b2 Michael Hanselmann
  TM_ALL = frozenset([TM_SUCCESS, TM_MULTISUCCESS, TM_FAIL, TM_PARTFAIL])
434 f99010b2 Michael Hanselmann
435 f99010b2 Michael Hanselmann
  for mode in TM_ALL:
436 f99010b2 Michael Hanselmann
    test_messages = [
437 f99010b2 Michael Hanselmann
      "Testing mode %s" % mode,
438 f99010b2 Michael Hanselmann
      "Hello World",
439 f99010b2 Michael Hanselmann
      "A",
440 f99010b2 Michael Hanselmann
      "",
441 f99010b2 Michael Hanselmann
      "B"
442 f99010b2 Michael Hanselmann
      "Foo|bar|baz",
443 f99010b2 Michael Hanselmann
      utils.TimestampForFilename(),
444 f99010b2 Michael Hanselmann
      ]
445 f99010b2 Michael Hanselmann
446 f99010b2 Michael Hanselmann
    fail = mode in (TM_FAIL, TM_PARTFAIL)
447 f99010b2 Michael Hanselmann
448 f99010b2 Michael Hanselmann
    if mode == TM_PARTFAIL:
449 f99010b2 Michael Hanselmann
      ToStdout("Testing partial job failure")
450 f99010b2 Michael Hanselmann
      ops = [
451 b469eb4d Iustin Pop
        opcodes.OpTestJqueue(notify_waitlock=True, notify_exec=True,
452 b469eb4d Iustin Pop
                             log_messages=test_messages, fail=False),
453 b469eb4d Iustin Pop
        opcodes.OpTestJqueue(notify_waitlock=True, notify_exec=True,
454 b469eb4d Iustin Pop
                             log_messages=test_messages, fail=False),
455 b469eb4d Iustin Pop
        opcodes.OpTestJqueue(notify_waitlock=True, notify_exec=True,
456 b469eb4d Iustin Pop
                             log_messages=test_messages, fail=True),
457 b469eb4d Iustin Pop
        opcodes.OpTestJqueue(notify_waitlock=True, notify_exec=True,
458 b469eb4d Iustin Pop
                             log_messages=test_messages, fail=False),
459 f99010b2 Michael Hanselmann
        ]
460 f99010b2 Michael Hanselmann
      expect_messages = 3 * [test_messages]
461 f99010b2 Michael Hanselmann
      expect_opstatus = [
462 f99010b2 Michael Hanselmann
        constants.OP_STATUS_SUCCESS,
463 f99010b2 Michael Hanselmann
        constants.OP_STATUS_SUCCESS,
464 f99010b2 Michael Hanselmann
        constants.OP_STATUS_ERROR,
465 f99010b2 Michael Hanselmann
        constants.OP_STATUS_ERROR,
466 f99010b2 Michael Hanselmann
        ]
467 f99010b2 Michael Hanselmann
      expect_resultlen = 2
468 f99010b2 Michael Hanselmann
    elif mode == TM_MULTISUCCESS:
469 f99010b2 Michael Hanselmann
      ToStdout("Testing multiple successful opcodes")
470 f99010b2 Michael Hanselmann
      ops = [
471 b469eb4d Iustin Pop
        opcodes.OpTestJqueue(notify_waitlock=True, notify_exec=True,
472 b469eb4d Iustin Pop
                             log_messages=test_messages, fail=False),
473 b469eb4d Iustin Pop
        opcodes.OpTestJqueue(notify_waitlock=True, notify_exec=True,
474 b469eb4d Iustin Pop
                             log_messages=test_messages, fail=False),
475 f99010b2 Michael Hanselmann
        ]
476 f99010b2 Michael Hanselmann
      expect_messages = 2 * [test_messages]
477 f99010b2 Michael Hanselmann
      expect_opstatus = [
478 f99010b2 Michael Hanselmann
        constants.OP_STATUS_SUCCESS,
479 f99010b2 Michael Hanselmann
        constants.OP_STATUS_SUCCESS,
480 f99010b2 Michael Hanselmann
        ]
481 f99010b2 Michael Hanselmann
      expect_resultlen = 2
482 e58f87a9 Michael Hanselmann
    else:
483 f99010b2 Michael Hanselmann
      if mode == TM_SUCCESS:
484 f99010b2 Michael Hanselmann
        ToStdout("Testing job success")
485 f99010b2 Michael Hanselmann
        expect_opstatus = [constants.OP_STATUS_SUCCESS]
486 f99010b2 Michael Hanselmann
      elif mode == TM_FAIL:
487 f99010b2 Michael Hanselmann
        ToStdout("Testing job failure")
488 f99010b2 Michael Hanselmann
        expect_opstatus = [constants.OP_STATUS_ERROR]
489 f99010b2 Michael Hanselmann
      else:
490 f99010b2 Michael Hanselmann
        raise errors.ProgrammerError("Unknown test mode %s" % mode)
491 f99010b2 Michael Hanselmann
492 f99010b2 Michael Hanselmann
      ops = [
493 b469eb4d Iustin Pop
        opcodes.OpTestJqueue(notify_waitlock=True,
494 b469eb4d Iustin Pop
                             notify_exec=True,
495 b469eb4d Iustin Pop
                             log_messages=test_messages,
496 b469eb4d Iustin Pop
                             fail=fail)
497 f99010b2 Michael Hanselmann
        ]
498 f99010b2 Michael Hanselmann
      expect_messages = [test_messages]
499 f99010b2 Michael Hanselmann
      expect_resultlen = 1
500 f99010b2 Michael Hanselmann
501 f99010b2 Michael Hanselmann
    cl = cli.GetClient()
502 f99010b2 Michael Hanselmann
    cli.SetGenericOpcodeOpts(ops, opts)
503 f99010b2 Michael Hanselmann
504 f99010b2 Michael Hanselmann
    # Send job to master daemon
505 f99010b2 Michael Hanselmann
    job_id = cli.SendJob(ops, cl=cl)
506 e58f87a9 Michael Hanselmann
507 e58f87a9 Michael Hanselmann
    reporter = _JobQueueTestReporter()
508 f99010b2 Michael Hanselmann
    results = None
509 f99010b2 Michael Hanselmann
510 e58f87a9 Michael Hanselmann
    try:
511 f99010b2 Michael Hanselmann
      results = cli.PollJob(job_id, cl=cl, reporter=reporter)
512 f99010b2 Michael Hanselmann
    except errors.OpExecError, err:
513 e58f87a9 Michael Hanselmann
      if not fail:
514 e58f87a9 Michael Hanselmann
        raise
515 f99010b2 Michael Hanselmann
      ToStdout("Ignoring error: %s", err)
516 e58f87a9 Michael Hanselmann
    else:
517 e58f87a9 Michael Hanselmann
      if fail:
518 e58f87a9 Michael Hanselmann
        raise errors.OpExecError("Job didn't fail when it should")
519 e58f87a9 Michael Hanselmann
520 f99010b2 Michael Hanselmann
    # Check length of result
521 f99010b2 Michael Hanselmann
    if fail:
522 f99010b2 Michael Hanselmann
      if results is not None:
523 f99010b2 Michael Hanselmann
        raise errors.OpExecError("Received result from failed job")
524 f99010b2 Michael Hanselmann
    elif len(results) != expect_resultlen:
525 f99010b2 Michael Hanselmann
      raise errors.OpExecError("Received %s results (%s), expected %s" %
526 f99010b2 Michael Hanselmann
                               (len(results), results, expect_resultlen))
527 f99010b2 Michael Hanselmann
528 e58f87a9 Michael Hanselmann
    # Check received log messages
529 f99010b2 Michael Hanselmann
    all_messages = [i for j in expect_messages for i in j]
530 f99010b2 Michael Hanselmann
    if reporter.GetTestMessages() != all_messages:
531 e58f87a9 Michael Hanselmann
      raise errors.OpExecError("Received test messages don't match input"
532 e58f87a9 Michael Hanselmann
                               " (input %r, received %r)" %
533 f99010b2 Michael Hanselmann
                               (all_messages, reporter.GetTestMessages()))
534 e58f87a9 Michael Hanselmann
535 e58f87a9 Michael Hanselmann
    # Check final status
536 f99010b2 Michael Hanselmann
    reported_job_id = reporter.GetJobId()
537 f99010b2 Michael Hanselmann
    if reported_job_id != job_id:
538 f99010b2 Michael Hanselmann
      raise errors.OpExecError("Reported job ID %s doesn't match"
539 f99010b2 Michael Hanselmann
                               "submission job ID %s" %
540 f99010b2 Michael Hanselmann
                               (reported_job_id, job_id))
541 e58f87a9 Michael Hanselmann
542 f99010b2 Michael Hanselmann
    jobdetails = cli.GetClient().QueryJobs([job_id], ["status", "opstatus"])[0]
543 e58f87a9 Michael Hanselmann
    if not jobdetails:
544 e58f87a9 Michael Hanselmann
      raise errors.OpExecError("Can't find job %s" % job_id)
545 e58f87a9 Michael Hanselmann
546 e58f87a9 Michael Hanselmann
    if fail:
547 e58f87a9 Michael Hanselmann
      exp_status = constants.JOB_STATUS_ERROR
548 e58f87a9 Michael Hanselmann
    else:
549 e58f87a9 Michael Hanselmann
      exp_status = constants.JOB_STATUS_SUCCESS
550 e58f87a9 Michael Hanselmann
551 f99010b2 Michael Hanselmann
    (final_status, final_opstatus) = jobdetails
552 e58f87a9 Michael Hanselmann
    if final_status != exp_status:
553 e58f87a9 Michael Hanselmann
      raise errors.OpExecError("Final job status is %s, not %s as expected" %
554 e58f87a9 Michael Hanselmann
                               (final_status, exp_status))
555 f99010b2 Michael Hanselmann
    if len(final_opstatus) != len(ops):
556 f99010b2 Michael Hanselmann
      raise errors.OpExecError("Did not receive status for all opcodes (got %s,"
557 f99010b2 Michael Hanselmann
                               " expected %s)" %
558 f99010b2 Michael Hanselmann
                               (len(final_opstatus), len(ops)))
559 f99010b2 Michael Hanselmann
    if final_opstatus != expect_opstatus:
560 f99010b2 Michael Hanselmann
      raise errors.OpExecError("Opcode status is %s, expected %s" %
561 f99010b2 Michael Hanselmann
                               (final_opstatus, expect_opstatus))
562 f99010b2 Michael Hanselmann
563 f99010b2 Michael Hanselmann
  ToStdout("Job queue test successful")
564 e58f87a9 Michael Hanselmann
565 e58f87a9 Michael Hanselmann
  return 0
566 e58f87a9 Michael Hanselmann
567 e58f87a9 Michael Hanselmann
568 19b9ba9a Michael Hanselmann
def ListLocks(opts, args): # pylint: disable-msg=W0613
569 19b9ba9a Michael Hanselmann
  """List all locks.
570 19b9ba9a Michael Hanselmann

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

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

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