Revision ec996117 qa/qa_cluster.py

b/qa/qa_cluster.py
532 532
  @rtype: tuple
533 533
  @return: (policy, specs), where:
534 534
      - policy is a dictionary of the policy values, instance specs excluded
535
      - specs is dict of dict, specs[par][key] is a spec value, where key is
535
      - specs is dict of dict, specs[key][par] is a spec value, where key is
536 536
        "min", "max", or "std"
537 537

  
538 538
  """
......
541 541
  (ret_policy, ret_specs) = qa_utils.ParseIPolicy(policy)
542 542

  
543 543
  # Sanity checks
544
  assert len(ret_specs) > 0
545
  good = all("min" in d and "std" in d and "max" in d
546
             for d in ret_specs.values())
547
  assert good, "Missing item in specs: %s" % ret_specs
544
  assert "min" in ret_specs and "std" in ret_specs and "max" in ret_specs
548 545
  assert len(ret_policy) > 0
549 546
  return (ret_policy, ret_specs)
550 547

  
......
606 603
      AssertEqual(eff_policy[p], old_policy[p])
607 604

  
608 605

  
609
def TestClusterSetISpecs(new_specs, fail=False, old_values=None):
606
def TestClusterSetISpecs(new_specs=None, diff_specs=None, fail=False,
607
                         old_values=None):
610 608
  """Change instance specs.
611 609

  
612
  @type new_specs: dict of dict
613
  @param new_specs: new_specs[par][key], where key is "min", "max", "std". It
614
      can be an empty dictionary.
610
  At most one of new_specs or diff_specs can be specified.
611

  
612
  @type new_specs: dict
613
  @param new_specs: new complete specs, in the same format returned by
614
      L{_GetClusterIPolicy}
615
  @type diff_specs: dict
616
  @param diff_specs: diff_specs[key][par], where key is "min", "max", "std". It
617
      can be an incomplete specifications or an empty dictionary.
615 618
  @type fail: bool
616 619
  @param fail: if the change is expected to fail
617 620
  @type old_values: tuple
618 621
  @param old_values: (old_policy, old_specs), as returned by
619
     L{_GetClusterIPolicy}
622
      L{_GetClusterIPolicy}
620 623
  @return: same as L{_GetClusterIPolicy}
621 624

  
622 625
  """
623 626
  build_cmd = lambda opts: ["gnt-cluster", "modify"] + opts
624
  return qa_utils.TestSetISpecs(new_specs, get_policy_fn=_GetClusterIPolicy,
625
                                build_cmd_fn=build_cmd, fail=fail,
626
                                old_values=old_values)
627
  return qa_utils.TestSetISpecs(
628
    new_specs=new_specs, diff_specs=diff_specs,
629
    get_policy_fn=_GetClusterIPolicy, build_cmd_fn=build_cmd,
630
    fail=fail, old_values=old_values)
627 631

  
628 632

  
629 633
def TestClusterModifyISpecs():
......
646 650
      (False, 0, 4, "a"),
647 651
      # This is to restore the old values
648 652
      (True,
649
       cur_specs[par]["min"], cur_specs[par]["std"], cur_specs[par]["max"])
653
       cur_specs["min"][par], cur_specs["std"][par], cur_specs["max"][par])
650 654
      ]
651 655
    for (good, mn, st, mx) in test_values:
652
      new_vals = {par: {"min": str(mn), "std": str(st), "max": str(mx)}}
656
      new_vals = {
657
        "min": {par: mn},
658
        "std": {par: st},
659
        "max": {par: mx}
660
        }
653 661
      cur_state = (cur_policy, cur_specs)
654 662
      # We update cur_specs, as we've copied the values to restore already
655
      (cur_policy, cur_specs) = TestClusterSetISpecs(new_vals, fail=not good,
656
                                                     old_values=cur_state)
663
      (cur_policy, cur_specs) = TestClusterSetISpecs(
664
        diff_specs=new_vals, fail=not good, old_values=cur_state)
657 665

  
658 666
    # Get the ipolicy command
659 667
    mnode = qa_config.GetMasterNode()

Also available in: Unified diff