4 # Copyright (C) 2010, 2011 Google Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 """QA tests for node groups.
26 from ganeti import constants
27 from ganeti import query
28 from ganeti import utils
33 from qa_utils import AssertCommand, AssertEqual, GetCommandOutput
36 def GetDefaultGroup():
37 """Returns the default node group.
40 groups = qa_config.get("groups", {})
41 return groups.get("group-with-nodes", constants.INITIAL_NODE_GROUP_NAME)
44 def TestGroupAddRemoveRename():
45 """gnt-group add/remove/rename"""
46 groups = qa_config.get("groups", {})
48 existing_group_with_nodes = GetDefaultGroup()
50 group1, group2, group3 = groups.get("inexistent-groups",
51 ["group1", "group2", "group3"])[:3]
53 AssertCommand(["gnt-group", "add", group1])
54 AssertCommand(["gnt-group", "add", group2])
55 AssertCommand(["gnt-group", "add", group2], fail=True)
56 AssertCommand(["gnt-group", "add", existing_group_with_nodes], fail=True)
58 AssertCommand(["gnt-group", "rename", group1, group2], fail=True)
59 AssertCommand(["gnt-group", "rename", group1, group3])
62 AssertCommand(["gnt-group", "rename", existing_group_with_nodes, group1])
64 AssertCommand(["gnt-group", "remove", group2])
65 AssertCommand(["gnt-group", "remove", group3])
66 AssertCommand(["gnt-group", "remove", group1], fail=True)
68 # Try to ensure idempotency re groups that already existed.
69 AssertCommand(["gnt-group", "rename", group1, existing_group_with_nodes])
72 def TestGroupAddWithOptions():
73 """gnt-group add with options"""
74 groups = qa_config.get("groups", {})
75 group1 = groups.get("inexistent-groups", ["group1"])[0]
77 AssertCommand(["gnt-group", "add", "--alloc-policy", "notvalid", group1],
80 AssertCommand(["gnt-group", "add", "--alloc-policy", "last_resort",
81 "--node-parameters", "oob_program=/bin/true", group1])
83 AssertCommand(["gnt-group", "remove", group1])
86 def TestGroupModify():
87 """gnt-group modify"""
88 groups = qa_config.get("groups", {})
89 group1 = groups.get("inexistent-groups", ["group1"])[0]
91 AssertCommand(["gnt-group", "add", group1])
94 AssertCommand(["gnt-group", "modify", "--alloc-policy", "unallocable",
95 "--node-parameters", "oob_program=/bin/false", group1])
96 AssertCommand(["gnt-group", "modify",
97 "--alloc-policy", "notvalid", group1], fail=True)
99 AssertCommand(["gnt-group", "remove", group1])
104 qa_utils.GenericQueryTest("gnt-group", query.GROUP_FIELDS.keys())
107 def TestGroupListFields():
108 """gnt-group list-fields"""
109 qa_utils.GenericQueryFieldsTest("gnt-group", query.GROUP_FIELDS.keys())
112 def TestAssignNodesIncludingSplit(orig_group, node1, node2):
113 """gnt-group assign-nodes --force
115 Expects node1 and node2 to be primary and secondary for a common instance.
118 assert node1 != node2
119 groups = qa_config.get("groups", {})
120 other_group = groups.get("inexistent-groups", ["group1"])[0]
122 master_node = qa_config.GetMasterNode()["primary"]
124 def AssertInGroup(group, nodes):
125 real_output = GetCommandOutput(master_node,
126 "gnt-node list --no-headers -o group " +
127 utils.ShellQuoteArgs(nodes))
128 AssertEqual(real_output.splitlines(), [group] * len(nodes))
130 AssertInGroup(orig_group, [node1, node2])
131 AssertCommand(["gnt-group", "add", other_group])
134 AssertCommand(["gnt-group", "assign-nodes", other_group, node1, node2])
135 AssertInGroup(other_group, [node1, node2])
137 # This should fail because moving node1 to orig_group would leave their
138 # common instance split between orig_group and other_group.
139 AssertCommand(["gnt-group", "assign-nodes", orig_group, node1], fail=True)
140 AssertInGroup(other_group, [node1, node2])
142 AssertCommand(["gnt-group", "assign-nodes", "--force", orig_group, node1])
143 AssertInGroup(orig_group, [node1])
144 AssertInGroup(other_group, [node2])
146 AssertCommand(["gnt-group", "assign-nodes", orig_group, node2])
147 AssertInGroup(orig_group, [node1, node2])
149 AssertCommand(["gnt-group", "remove", other_group])