Revision 288d6440

b/qa/ganeti-qa.py
121 121
  """
122 122
  RunTestIf("create-cluster", qa_cluster.TestClusterInit,
123 123
            rapi_user, rapi_secret)
124

  
125
  # Test on empty cluster
126
  RunTestIf("node-list", qa_node.TestNodeList)
127
  RunTestIf("instance-list", qa_instance.TestInstanceList)
128

  
124 129
  RunTestIf("create-cluster", qa_node.TestNodeAddAll)
125 130
  if not qa_config.TestEnabled("create-cluster"):
126 131
    # consider the nodes are already there
......
131 136
  # enable the watcher (unconditionally)
132 137
  RunTest(qa_daemon.TestResumeWatcher)
133 138

  
139
  RunTestIf("node-list", qa_node.TestNodeList)
140

  
134 141
  RunTestIf("node-info", qa_node.TestNodeInfo)
135 142

  
136 143

  
......
217 224

  
218 225
  RunTestIf("rapi", qa_rapi.TestInstance, instance)
219 226

  
227
  # Lists instances, too
228
  RunTestIf("node-list", qa_node.TestNodeList)
229

  
220 230

  
221 231
def RunCommonNodeTests():
222 232
  """Run a few common node tests.
b/qa/qa-sample.json
65 65
    "group-list": true,
66 66
    "group-rwops": true,
67 67

  
68
    "node-list": true,
68 69
    "node-info": true,
69 70
    "node-volumes": true,
70 71
    "node-readd": true,
b/qa/qa_instance.py
28 28

  
29 29
from ganeti import utils
30 30
from ganeti import constants
31
from ganeti import query
31 32

  
32 33
import qa_config
33 34
import qa_utils
......
209 210

  
210 211
def TestInstanceList():
211 212
  """gnt-instance list"""
212
  AssertCommand(["gnt-instance", "list"])
213
  qa_utils.GenericQueryTest("gnt-instance", query.INSTANCE_FIELDS.keys())
213 214

  
214 215

  
215 216
def TestInstanceConsole(instance):
b/qa/qa_node.py
21 21

  
22 22
from ganeti import utils
23 23
from ganeti import constants
24
from ganeti import query
24 25

  
25 26
import qa_config
26 27
import qa_error
......
189 190

  
190 191
  AssertCommand(["gnt-node", "modify", "--master-candidate=yes",
191 192
                 "--auto-promote", node["primary"]])
193

  
194

  
195
def TestNodeList():
196
  """gnt-node list"""
197
  qa_utils.GenericQueryTest("gnt-node", query.NODE_FIELDS.keys())
b/qa/qa_utils.py
27 27
import re
28 28
import sys
29 29
import subprocess
30
import random
30 31

  
31 32
from ganeti import utils
33
from ganeti import compat
32 34

  
33 35
import qa_config
34 36
import qa_error
......
284 286
  return instances
285 287

  
286 288

  
289
def _SelectQueryFields(rnd, fields):
290
  """Generates a list of fields for query tests.
291

  
292
  """
293
  # Create copy for shuffling
294
  fields = list(fields)
295
  rnd.shuffle(fields)
296

  
297
  # Check all fields
298
  yield fields
299
  yield sorted(fields)
300

  
301
  # Duplicate fields
302
  yield fields + fields
303

  
304
  # Check small groups of fields
305
  while fields:
306
    yield [fields.pop() for _ in range(rnd.randint(2, 10)) if fields]
307

  
308

  
309
def _List(listcmd, fields, names):
310
  """Runs a list command.
311

  
312
  """
313
  master = qa_config.GetMasterNode()
314

  
315
  cmd = [listcmd, "list", "--separator=|", "--no-header",
316
         "--output", ",".join(fields)]
317

  
318
  if names:
319
    cmd.extend(names)
320

  
321
  return GetCommandOutput(master["primary"],
322
                          utils.ShellQuoteArgs(cmd)).splitlines()
323

  
324

  
325
def GenericQueryTest(cmd, fields):
326
  """Runs a number of tests on query commands.
327

  
328
  @param cmd: Command name
329
  @param fields: List of field names
330

  
331
  """
332
  rnd = random.Random(hash(cmd))
333

  
334
  randfields = list(fields)
335
  rnd.shuffle(fields)
336

  
337
  # Test a number of field combinations
338
  for testfields in _SelectQueryFields(rnd, fields):
339
    AssertCommand([cmd, "list", "--output", ",".join(testfields)])
340

  
341
  namelist_fn = compat.partial(_List, cmd, ["name"])
342

  
343
  # When no names were requested, the list must be sorted
344
  names = namelist_fn(None)
345
  AssertEqual(names, utils.NiceSort(names))
346

  
347
  # When requesting specific names, the order must be kept
348
  revnames = list(reversed(names))
349
  AssertEqual(namelist_fn(revnames), revnames)
350

  
351
  randnames = list(names)
352
  rnd.shuffle(randnames)
353
  AssertEqual(namelist_fn(randnames), randnames)
354

  
355

  
287 356
def _FormatWithColor(text, seq):
288 357
  if not seq:
289 358
    return text

Also available in: Unified diff