-# Copyright (C) 2007 Google Inc.
+#
+#
+
+# Copyright (C) 2007, 2011 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
"""
-import yaml
+from ganeti import utils
+from ganeti import serializer
+from ganeti import compat
import qa_error
"""Loads the passed configuration file.
"""
- global cfg
+ global cfg # pylint: disable-msg=W0603
- f = open(path, 'r')
- try:
- cfg = yaml.load(f.read())
- finally:
- f.close()
+ cfg = serializer.LoadJson(utils.ReadFile(path))
Validate()
raise qa_error.Error("Need at least one node")
if len(cfg['instances']) < 1:
raise qa_error.Error("Need at least one instance")
+ if len(cfg["disk"]) != len(cfg["disk-growth"]):
+ raise qa_error.Error("Config options 'disk' and 'disk-growth' must have"
+ " the same number of items")
def get(name, default=None):
return cfg.get(name, default)
-def TestEnabled(test):
- """Returns True if the given test is enabled."""
- return cfg.get('tests', {}).get(test, False)
+def TestEnabled(tests):
+ """Returns True if the given tests are enabled.
+
+ @param tests: a single test, or a list of tests to check
+
+ """
+ if isinstance(tests, basestring):
+ tests = [tests]
+ return compat.all(cfg.get("tests", {}).get(t, True) for t in tests)
def GetMasterNode():
# TODO: Maybe combine filters
if exclude is None:
nodes = cfg['nodes'][:]
+ elif isinstance(exclude, (list, tuple)):
+ nodes = filter(lambda node: node not in exclude, cfg['nodes'])
else:
nodes = filter(lambda node: node != exclude, cfg['nodes'])