Revision 76fda900

b/qa/qa-sample.json
9 9
  "# Name used for renaming cluster": null,
10 10
  "rename": "xen-test-rename",
11 11

  
12
  "# Virtual cluster": null,
13
  "#vcluster-master": "xen-vcluster",
14
  "#vcluster-basedir": "/srv/ganeti/vcluster",
15

  
12 16
  "enabled-hypervisors": "xen-pvm",
13 17
  "# Dict of hypervisor name and parameters (like on the cmd line)": null,
14 18
  "hypervisor-parameters": {},
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()
b/test/py/qa.qa_config_unittest.py
222 222
    # Unknown hypervisor
223 223
    testconfig[qa_config._ENABLED_HV_KEY] = ["#unknownhv#"]
224 224
    check_fn("Unknown hypervisor(s) enabled:")
225
    del testconfig[qa_config._ENABLED_HV_KEY]
226

  
227
    # Invalid path for virtual cluster base directory
228
    testconfig[qa_config._VCLUSTER_MASTER_KEY] = "value"
229
    testconfig[qa_config._VCLUSTER_BASEDIR_KEY] = "./not//normalized/"
230
    check_fn("Path given in option 'vcluster-basedir' must be")
231

  
232
    # Inconsistent virtual cluster settings
233
    testconfig.pop(qa_config._VCLUSTER_MASTER_KEY)
234
    testconfig[qa_config._VCLUSTER_BASEDIR_KEY] = "/tmp"
235
    check_fn("All or none of the")
236

  
237
    testconfig[qa_config._VCLUSTER_MASTER_KEY] = "master.example.com"
238
    testconfig.pop(qa_config._VCLUSTER_BASEDIR_KEY)
239
    check_fn("All or none of the")
240

  
241
    # Accepted virtual cluster settings
242
    testconfig[qa_config._VCLUSTER_MASTER_KEY] = "master.example.com"
243
    testconfig[qa_config._VCLUSTER_BASEDIR_KEY] = "/tmp"
244

  
245
    self._WriteConfig(filename, testconfig)
246
    result = qa_config._QaConfig.Load(filename)
247
    self.assertEqual(result.GetVclusterSettings(),
248
                     ("master.example.com", "/tmp"))
225 249

  
226 250

  
227 251
class TestQaConfigWithSampleConfig(unittest.TestCase):
......
257 281
  def testGetMasterNode(self):
258 282
    self.assertEqual(self.config.GetMasterNode(), self.config["nodes"][0])
259 283

  
284
  def testGetVclusterSettings(self):
285
    # Shipped default settings should be to not use a virtual cluster
286
    self.assertEqual(self.config.GetVclusterSettings(), (None, None))
287

  
288
    self.assertFalse(qa_config.UseVirtualCluster(_cfg=self.config))
289

  
260 290

  
261 291
class TestQaConfig(unittest.TestCase):
262 292
  def setUp(self):

Also available in: Unified diff