Commit b4d2d2cb authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

QA: Factorize retrieving non-existent groups from config



Also add a check to make sure there are enough groups defined.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 7cf58cad
......@@ -43,12 +43,9 @@ def GetDefaultGroup():
def TestGroupAddRemoveRename():
"""gnt-group add/remove/rename"""
groups = qa_config.get("groups", {})
existing_group_with_nodes = GetDefaultGroup()
group1, group2, group3 = groups.get("inexistent-groups",
["group1", "group2", "group3"])[:3]
(group1, group2, group3) = qa_utils.GetNonexistentGroups(3)
AssertCommand(["gnt-group", "add", group1])
AssertCommand(["gnt-group", "add", group2])
......@@ -71,8 +68,7 @@ def TestGroupAddRemoveRename():
def TestGroupAddWithOptions():
"""gnt-group add with options"""
groups = qa_config.get("groups", {})
group1 = groups.get("inexistent-groups", ["group1"])[0]
(group1, ) = qa_utils.GetNonexistentGroups(1)
AssertCommand(["gnt-group", "add", "--alloc-policy", "notvalid", group1],
fail=True)
......@@ -85,8 +81,7 @@ def TestGroupAddWithOptions():
def TestGroupModify():
"""gnt-group modify"""
groups = qa_config.get("groups", {})
group1 = groups.get("inexistent-groups", ["group1"])[0]
(group1, ) = qa_utils.GetNonexistentGroups(1)
AssertCommand(["gnt-group", "add", group1])
......@@ -130,8 +125,8 @@ def TestAssignNodesIncludingSplit(orig_group, node1, node2):
"""
assert node1 != node2
groups = qa_config.get("groups", {})
other_group = groups.get("inexistent-groups", ["group1"])[0]
(other_group, ) = qa_utils.GetNonexistentGroups(1)
master_node = qa_config.GetMasterNode()["primary"]
......
......@@ -492,9 +492,7 @@ def TestRapiNodeGroups():
"""Test several node group operations using RAPI.
"""
groups = qa_config.get("groups", {})
group1, group2, group3 = groups.get("inexistent-groups",
["group1", "group2", "group3"])[:3]
(group1, group2, group3) = qa_utils.GetNonexistentGroups(3)
# Create a group with no attributes
body = {
......
......@@ -647,3 +647,23 @@ def InstanceCheck(before, after, instarg):
return result
return wrapper
return decorator
def GetNonexistentGroups(count):
"""Gets group names which shouldn't exist on the cluster.
@param count: Number of groups to get
@rtype: list
"""
groups = qa_config.get("groups", {})
default = ["group1", "group2", "group3"]
assert count <= len(default)
candidates = groups.get("inexistent-groups", default)[:count]
if len(candidates) < count:
raise Exception("At least %s non-existent groups are needed" % count)
return candidates
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