Revision 76fda900 qa/qa_config.py

b/qa/qa_config.py
29 29
from ganeti import utils
30 30
from ganeti import serializer
31 31
from ganeti import compat
32
from ganeti import ht
32 33

  
33 34
import qa_error
34 35

  
35 36

  
36 37
_INSTANCE_CHECK_KEY = "instance-check"
37 38
_ENABLED_HV_KEY = "enabled-hypervisors"
39
_VCLUSTER_MASTER_KEY = "vcluster-master"
40
_VCLUSTER_BASEDIR_KEY = "vcluster-basedir"
38 41

  
39 42
#: QA configuration (L{_QaConfig})
40 43
_config = None
......
299 302
      raise qa_error.Error("Unknown hypervisor(s) enabled: %s" %
300 303
                           utils.CommaJoin(difference))
301 304

  
305
    (vc_master, vc_basedir) = self.GetVclusterSettings()
306
    if bool(vc_master) != bool(vc_basedir):
307
      raise qa_error.Error("All or none of the config options '%s' and '%s'"
308
                           " must be set" %
309
                           (_VCLUSTER_MASTER_KEY, _VCLUSTER_BASEDIR_KEY))
310

  
311
    if vc_basedir and not utils.IsNormAbsPath(vc_basedir):
312
      raise qa_error.Error("Path given in option '%s' must be absolute and"
313
                           " normalized" % _VCLUSTER_BASEDIR_KEY)
314

  
302 315
  def __getitem__(self, name):
303 316
    """Returns configuration value.
304 317

  
......
379 392
    return (not self.GetExclusiveStorage() or
380 393
            templ in constants.DTS_EXCL_STORAGE)
381 394

  
395
  def GetVclusterSettings(self):
396
    """Returns settings for virtual cluster.
397

  
398
    """
399
    master = self.get(_VCLUSTER_MASTER_KEY)
400
    basedir = self.get(_VCLUSTER_BASEDIR_KEY)
401

  
402
    return (master, basedir)
403

  
382 404

  
383 405
def Load(path):
384 406
  """Loads the passed configuration file.
......
625 647
def ReleaseManyNodes(nodes):
626 648
  for node in nodes:
627 649
    node.Release()
650

  
651

  
652
def GetVclusterSettings():
653
  """Wrapper for L{_QaConfig.GetVclusterSettings}.
654

  
655
  """
656
  return GetConfig().GetVclusterSettings()
657

  
658

  
659
def UseVirtualCluster(_cfg=None):
660
  """Returns whether a virtual cluster is used.
661

  
662
  @rtype: bool
663

  
664
  """
665
  if _cfg is None:
666
    cfg = GetConfig()
667
  else:
668
    cfg = _cfg
669

  
670
  (master, _) = cfg.GetVclusterSettings()
671

  
672
  return bool(master)
673

  
674

  
675
@ht.WithDesc("No virtual cluster")
676
def NoVirtualCluster():
677
  """Used to disable tests for virtual clusters.
678

  
679
  """
680
  return not UseVirtualCluster()

Also available in: Unified diff