--select-instances hbal manpage update
[ganeti-local] / qa / qa_config.py
index bf176ba..62b0a07 100644 (file)
@@ -1,4 +1,7 @@
-# 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
@@ -21,7 +24,9 @@
 """
 
 
-import yaml
+from ganeti import utils
+from ganeti import serializer
+from ganeti import compat
 
 import qa_error
 
@@ -34,13 +39,9 @@ def Load(path):
   """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()
 
@@ -50,15 +51,24 @@ def 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():
@@ -96,6 +106,8 @@ def AcquireNode(exclude=None):
   # 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'])