Revision 090128b6 qa/qa_config.py

b/qa/qa_config.py
280 280
    if not self.get("instances"):
281 281
      raise qa_error.Error("Need at least one instance")
282 282

  
283
    if (self.get("disk") is None or
284
        self.get("disk-growth") is None or
285
        len(self.get("disk")) != len(self.get("disk-growth"))):
286
      raise qa_error.Error("Config options 'disk' and 'disk-growth' must exist"
287
                           " and have the same number of items")
288

  
283
    disks = self.GetDiskOptions()
284
    if disks is None:
285
      raise qa_error.Error("Config option 'disks' must exist")
286
    else:
287
      for d in disks:
288
        if d.get("size") is None or d.get("growth") is None:
289
          raise qa_error.Error("Config options `size` and `growth` must exist"
290
                               " for all `disks` items")
289 291
    check = self.GetInstanceCheckScript()
290 292
    if check:
291 293
      try:
......
425 427

  
426 428
    return (master, basedir)
427 429

  
430
  def GetDiskOptions(self):
431
    """Return options for the disks of the instances.
432

  
433
    Get 'disks' parameter from the configuration data. If 'disks' is missing,
434
    try to create it from the legacy 'disk' and 'disk-growth' parameters.
435

  
436
    """
437
    try:
438
      return self._data["disks"]
439
    except KeyError:
440
      pass
441

  
442
    # Legacy interface
443
    sizes = self._data.get("disk")
444
    growths = self._data.get("disk-growth")
445
    if sizes or growths:
446
      if (sizes is None or growths is None or len(sizes) != len(growths)):
447
        raise qa_error.Error("Config options 'disk' and 'disk-growth' must"
448
                             " exist and have the same number of items")
449
      disks = []
450
      for (size, growth) in zip(sizes, growths):
451
        disks.append({"size": size, "growth": growth})
452
      return disks
453
    else:
454
      return None
455

  
428 456

  
429 457
def Load(path):
430 458
  """Loads the passed configuration file.
......
718 746

  
719 747
  """
720 748
  return not UseVirtualCluster()
749

  
750

  
751
def GetDiskOptions():
752
  """Wrapper for L{_QaConfig.GetDiskOptions}.
753

  
754
  """
755
  return GetConfig().GetDiskOptions()

Also available in: Unified diff