Revision fa84c8a4

b/qa/ganeti-qa.py
499 499
  (_, old_specs) = qa_cluster.TestClusterSetISpecs({})
500 500
  node = qa_config.AcquireNode()
501 501
  try:
502
    # Log of policy changes, list of tuples: (change, policy_violated)
503
    history = []
502 504
    instance = qa_instance.TestInstanceAddWithPlainDisk([node])
503 505
    try:
504 506
      policyerror = [constants.CV_EINSTANCEPOLICY]
......
507 509
        (iminval, imaxval) = qa_instance.GetInstanceSpec(instance["name"], par)
508 510
        # Some specs must be multiple of 4
509 511
        new_spec = _BuildSpecDict(par, imaxval + 4, imaxval + 4, imaxval + 4)
512
        history.append((new_spec, True))
510 513
        qa_cluster.TestClusterSetISpecs(new_spec)
511 514
        qa_cluster.AssertClusterVerify(warnings=policyerror)
512 515
        if iminval > 0:
......
516 519
          else:
517 520
            upper = iminval - 1
518 521
          new_spec = _BuildSpecDict(par, 0, upper, upper)
522
          history.append((new_spec, True))
519 523
          qa_cluster.TestClusterSetISpecs(new_spec)
520 524
          qa_cluster.AssertClusterVerify(warnings=policyerror)
521 525
        qa_cluster.TestClusterSetISpecs(old_specs)
526
        history.append((old_specs, False))
522 527
      qa_instance.TestInstanceRemove(instance)
523 528
    finally:
524 529
      qa_config.ReleaseInstance(instance)
530

  
531
    # Now we replay the same policy changes, and we expect that the instance
532
    # cannot be created for the cases where we had a policy violation above
533
    for (change, failed) in history:
534
      qa_cluster.TestClusterSetISpecs(change)
535
      if failed:
536
        qa_instance.TestInstanceAddWithPlainDisk([node], fail=True)
537
      # Instance creation with no policy violation has been tested already
525 538
  finally:
526 539
    qa_config.ReleaseNode(node)
527 540

  
b/qa/qa_instance.py
63 63
  return params
64 64

  
65 65

  
66
def _DiskTest(node, disk_template):
66
def _DiskTest(node, disk_template, fail=False):
67 67
  instance = qa_config.AcquireInstance()
68 68
  try:
69 69
    cmd = (["gnt-instance", "add",
......
73 73
           _GetGenericAddParameters(instance))
74 74
    cmd.append(instance["name"])
75 75

  
76
    AssertCommand(cmd)
76
    AssertCommand(cmd, fail=fail)
77 77

  
78
    _CheckSsconfInstanceList(instance["name"])
79
    qa_config.SetInstanceTemplate(instance, disk_template)
78
    if not fail:
79
      _CheckSsconfInstanceList(instance["name"])
80
      qa_config.SetInstanceTemplate(instance, disk_template)
80 81

  
81
    return instance
82
      return instance
82 83
  except:
83 84
    qa_config.ReleaseInstance(instance)
84 85
    raise
85 86

  
87
  # Handle the case where creation is expected to fail
88
  assert fail
89
  qa_config.ReleaseInstance(instance)
90
  return None
91

  
86 92

  
87 93
def _GetInstanceInfo(instance):
88 94
  """Return information about the actual state of an instance.
......
257 263
  return templ == constants.DT_DRBD8
258 264

  
259 265

  
260
@InstanceCheck(None, INST_UP, RETURN_VALUE)
261
def TestInstanceAddWithPlainDisk(nodes):
266
def TestInstanceAddWithPlainDisk(nodes, fail=False):
262 267
  """gnt-instance add -t plain"""
263 268
  assert len(nodes) == 1
264
  return _DiskTest(nodes[0]["primary"], "plain")
269
  instance = _DiskTest(nodes[0]["primary"], constants.DT_PLAIN, fail=fail)
270
  if not fail:
271
    qa_utils.RunInstanceCheck(instance, True)
272
  return instance
265 273

  
266 274

  
267 275
@InstanceCheck(None, INST_UP, RETURN_VALUE)

Also available in: Unified diff