X-Git-Url: https://code.grnet.gr/git/ganeti-local/blobdiff_plain/1d6933114a7295ab2cbad6e9a1b8eb628e5e4d96..b6aaf437623832b6ddded9a84f1b1b8c152631c2:/qa/qa_config.py diff --git a/qa/qa_config.py b/qa/qa_config.py index 4afe253..b4cff14 100644 --- a/qa/qa_config.py +++ b/qa/qa_config.py @@ -1,7 +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 @@ -24,7 +24,9 @@ """ -import simplejson +from ganeti import utils +from ganeti import serializer +from ganeti import compat import qa_error @@ -37,21 +39,17 @@ def Load(path): """Loads the passed configuration file. """ - global cfg + global cfg # pylint: disable=W0603 - f = open(path, 'r') - try: - cfg = simplejson.load(f) - finally: - f.close() + cfg = serializer.LoadJson(utils.ReadFile(path)) Validate() def Validate(): - if len(cfg['nodes']) < 1: + if len(cfg["nodes"]) < 1: raise qa_error.Error("Need at least one node") - if len(cfg['instances']) < 1: + 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" @@ -62,13 +60,19 @@ 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(): - return cfg['nodes'][0] + return cfg["nodes"][0] def AcquireInstance(): @@ -76,20 +80,20 @@ def AcquireInstance(): """ # Filter out unwanted instances - tmp_flt = lambda inst: not inst.get('_used', False) - instances = filter(tmp_flt, cfg['instances']) + tmp_flt = lambda inst: not inst.get("_used", False) + instances = filter(tmp_flt, cfg["instances"]) del tmp_flt if len(instances) == 0: raise qa_error.OutOfInstancesError("No instances left") inst = instances[0] - inst['_used'] = True + inst["_used"] = True return inst def ReleaseInstance(inst): - inst['_used'] = False + inst["_used"] = False def AcquireNode(exclude=None): @@ -101,13 +105,13 @@ def AcquireNode(exclude=None): # Filter out unwanted nodes # TODO: Maybe combine filters if exclude is None: - nodes = cfg['nodes'][:] + nodes = cfg["nodes"][:] elif isinstance(exclude, (list, tuple)): - nodes = filter(lambda node: node not in exclude, cfg['nodes']) + nodes = filter(lambda node: node not in exclude, cfg["nodes"]) else: - nodes = filter(lambda node: node != exclude, cfg['nodes']) + nodes = filter(lambda node: node != exclude, cfg["nodes"]) - tmp_flt = lambda node: node.get('_added', False) or node == master + tmp_flt = lambda node: node.get("_added", False) or node == master nodes = filter(tmp_flt, nodes) del tmp_flt @@ -116,17 +120,17 @@ def AcquireNode(exclude=None): # Get node with least number of uses def compare(a, b): - result = cmp(a.get('_count', 0), b.get('_count', 0)) + result = cmp(a.get("_count", 0), b.get("_count", 0)) if result == 0: - result = cmp(a['primary'], b['primary']) + result = cmp(a["primary"], b["primary"]) return result nodes.sort(cmp=compare) node = nodes[0] - node['_count'] = node.get('_count', 0) + 1 + node["_count"] = node.get("_count", 0) + 1 return node def ReleaseNode(node): - node['_count'] = node.get('_count', 0) - 1 + node["_count"] = node.get("_count", 0) - 1