These make possible to simplify the logic of tests requiring more
nodes. Used in the following patches.

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

diff --git a/qa/qa_config.py b/qa/qa_config.py
index 86838ce..0bc00fc 100644
--- a/qa/qa_config.py
+++ b/qa/qa_config.py
@@ -295,5 +295,41 @@ def AcquireNode(exclude=None):
   return node
 
 
+def AcquireManyNodes(num, exclude=None):
+  """Return the least used nodes.
+
+  @type num: int
+  @param num: Number of nodes; can be 0.
+  @type exclude: list of nodes or C{None}
+  @param exclude: nodes to be excluded from the choice
+  @rtype: list of nodes
+  @return: C{num} different nodes
+
+  """
+  nodes = []
+  if exclude is None:
+    exclude = []
+  elif isinstance(exclude, (list, tuple)):
+    # Don't modify the incoming argument
+    exclude = list(exclude)
+  else:
+    exclude = [exclude]
+
+  try:
+    for _ in range(0, num):
+      n = AcquireNode(exclude=exclude)
+      nodes.append(n)
+      exclude.append(n)
+  except qa_error.OutOfNodesError:
+    ReleaseManyNodes(nodes)
+    raise
+  return nodes
+
+
 def ReleaseNode(node):
   node["_count"] = node.get("_count", 0) - 1
+
+
+def ReleaseManyNodes(nodes):
+  for n in nodes:
+    ReleaseNode(n)
-- 
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