Commit 7d4f1b45 by Bernardo Dal Seno

QA: Added functions to allocate/free N nodes at once

```

These make possible to simplify the logic of tests requiring more
nodes. Used in the following patches.
Signed-off-by: Bernardo Dal Seno <bdalseno@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>```
parent 6a0f22e1
 ... @@ -296,5 +296,41 @@ def AcquireNode(exclude=None): ... @@ -296,5 +296,41 @@ def AcquireNode(exclude=None): return node 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): def ReleaseNode(node): node["_count"] = node.get("_count", 0) - 1 node["_count"] = node.get("_count", 0) - 1 def ReleaseManyNodes(nodes): for n in nodes: ReleaseNode(n)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment