Revision 8b057218

b/lib/cmdlib.py
815 815
          # in a nicer way
816 816
          ipolicy[key] = list(value)
817 817
  try:
818
    objects.InstancePolicy.CheckParameterSyntax(ipolicy)
818
    objects.InstancePolicy.CheckParameterSyntax(ipolicy, not group_policy)
819 819
  except errors.ConfigurationError, err:
820 820
    raise errors.OpPrereqError("Invalid instance policy: %s" % err,
821 821
                               errors.ECODE_INVAL)
......
13627 13627
      cluster = self.cfg.GetClusterInfo()
13628 13628
      full_ipolicy = cluster.SimpleFillIPolicy(self.op.ipolicy)
13629 13629
      try:
13630
        objects.InstancePolicy.CheckParameterSyntax(full_ipolicy)
13630
        objects.InstancePolicy.CheckParameterSyntax(full_ipolicy, False)
13631 13631
      except errors.ConfigurationError, err:
13632 13632
        raise errors.OpPrereqError("Invalid instance policy: %s" % err,
13633 13633
                                   errors.ECODE_INVAL)
b/lib/config.py
480 480
      except errors.ConfigurationError, err:
481 481
        result.append("%s has invalid nicparams: %s" % (owner, err))
482 482

  
483
    def _helper_ipolicy(owner, params):
483
    def _helper_ipolicy(owner, params, check_std):
484 484
      try:
485
        objects.InstancePolicy.CheckParameterSyntax(params)
485
        objects.InstancePolicy.CheckParameterSyntax(params, check_std)
486 486
      except errors.ConfigurationError, err:
487 487
        result.append("%s has invalid instance policy: %s" % (owner, err))
488 488

  
......
510 510
    _helper_nic("cluster", cluster.SimpleFillNIC({}))
511 511
    _helper("cluster", "ndparams", cluster.SimpleFillND({}),
512 512
            constants.NDS_PARAMETER_TYPES)
513
    _helper_ipolicy("cluster", cluster.SimpleFillIPolicy({}))
513
    _helper_ipolicy("cluster", cluster.SimpleFillIPolicy({}), True)
514 514
    _helper_ispecs("cluster", cluster.SimpleFillIPolicy({}))
515 515

  
516 516
    # per-instance checks
......
636 636
      else:
637 637
        nodegroups_names.add(nodegroup.name)
638 638
      group_name = "group %s" % nodegroup.name
639
      _helper_ipolicy(group_name, cluster.SimpleFillIPolicy(nodegroup.ipolicy))
639
      _helper_ipolicy(group_name, cluster.SimpleFillIPolicy(nodegroup.ipolicy),
640
                      False)
640 641
      _helper_ispecs(group_name, cluster.SimpleFillIPolicy(nodegroup.ipolicy))
641 642
      if nodegroup.ndparams:
642 643
        _helper(group_name, "ndparams",
b/lib/objects.py
946 946

  
947 947
  """
948 948
  @classmethod
949
  def CheckParameterSyntax(cls, ipolicy):
949
  def CheckParameterSyntax(cls, ipolicy, check_std):
950 950
    """ Check the instance policy for validity.
951 951

  
952 952
    """
953 953
    for param in constants.ISPECS_PARAMETERS:
954
      InstancePolicy.CheckISpecSyntax(ipolicy, param)
954
      InstancePolicy.CheckISpecSyntax(ipolicy, param, check_std)
955 955
    if constants.IPOLICY_DTS in ipolicy:
956 956
      InstancePolicy.CheckDiskTemplates(ipolicy[constants.IPOLICY_DTS])
957 957
    for key in constants.IPOLICY_PARAMETERS:
......
963 963
                                      utils.CommaJoin(wrong_keys))
964 964

  
965 965
  @classmethod
966
  def CheckISpecSyntax(cls, ipolicy, name):
966
  def CheckISpecSyntax(cls, ipolicy, name, check_std):
967 967
    """Check the instance policy for validity on a given key.
968 968

  
969 969
    We check if the instance policy makes sense for a given key, that is
......
973 973
    @param ipolicy: dictionary with min, max, std specs
974 974
    @type name: string
975 975
    @param name: what are the limits for
976
    @type check_std: bool
977
    @param check_std: Whether to check std value or just assume compliance
976 978
    @raise errors.ConfigureError: when specs for given name are not valid
977 979

  
978 980
    """
979 981
    min_v = ipolicy[constants.ISPECS_MIN].get(name, 0)
980
    std_v = ipolicy[constants.ISPECS_STD].get(name, min_v)
982

  
983
    if check_std:
984
      std_v = ipolicy[constants.ISPECS_STD].get(name, min_v)
985
      std_msg = std_v
986
    else:
987
      std_v = min_v
988
      std_msg = "-"
989

  
981 990
    max_v = ipolicy[constants.ISPECS_MAX].get(name, std_v)
982 991
    err = ("Invalid specification of min/max/std values for %s: %s/%s/%s" %
983 992
           (name,
984 993
            ipolicy[constants.ISPECS_MIN].get(name, "-"),
985 994
            ipolicy[constants.ISPECS_MAX].get(name, "-"),
986
            ipolicy[constants.ISPECS_STD].get(name, "-")))
995
            std_msg))
987 996
    if min_v > std_v or std_v > max_v:
988 997
      raise errors.ConfigurationError(err)
989 998

  

Also available in: Unified diff