This function will be used in following patches.

Signed-off-by: Bernardo Dal Seno <[email protected]>
---
 qa/qa_cluster.py | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/qa/qa_cluster.py b/qa/qa_cluster.py
index 0a8bce8..f0e9890 100644
--- a/qa/qa_cluster.py
+++ b/qa/qa_cluster.py
@@ -60,6 +60,40 @@ def _CheckFileOnAllNodes(filename, content):
     AssertEqual(qa_utils.GetCommandOutput(node["primary"], cmd), content)
 
 
+# "gnt-cluster info" fields
+_CIFIELD_RE = re.compile(r"^[-\s]*([^\s:]+):\s*(\S.*)$")
+
+
+def _GetBoolClusterField(field):
+  """Get the Boolean value of a cluster field.
+
+  This function currently assumes that the field name is unique in the cluster
+  configuration. An assertion checks this assumption.
+
+  @type field: string
+  @param field: Name of the field
+  @rtype: bool
+  @return: The effective value of the field
+
+  """
+  master = qa_config.GetMasterNode()
+  infocmd = "gnt-cluster info"
+  info_out = qa_utils.GetCommandOutput(master["primary"], infocmd)
+  ret = None
+  for l in info_out.splitlines():
+    m = _CIFIELD_RE.match(l)
+    # FIXME: There should be a way to specify a field through a hierarchy
+    if m and m.group(1) == field:
+      assert ret is None
+      if m.group(2).lower() == "true":
+        ret = True
+      else:
+        ret = False
+  if ret is not None:
+    return ret
+  raise qa_error.Error("Field not found in cluster configuration: %s" % field)
+
+
 # Cluster-verify errors (date, "ERROR", then error code)
 _CVERROR_RE = re.compile(r"^[A-Z][a-z]{2} [A-Z][a-z]{2} [0-9]{2}"
                          " [0-9]{2}:[0-9]{2}:[0-9]{2} [0-9]{4}"
-- 
1.8.1

-- 
You received this message because you are subscribed to the Google Groups 
"ganeti-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to