Statistics
| Branch: | Tag: | Revision:

root / qa / qa_group.py @ 2129c5ff

History | View | Annotate | Download (12.1 kB)

1 30131294 Adeodato Simo
#
2 30131294 Adeodato Simo
#
3 30131294 Adeodato Simo
4 52bebbdf Iustin Pop
# Copyright (C) 2010, 2011, 2012 Google Inc.
5 30131294 Adeodato Simo
#
6 30131294 Adeodato Simo
# This program is free software; you can redistribute it and/or modify
7 30131294 Adeodato Simo
# it under the terms of the GNU General Public License as published by
8 30131294 Adeodato Simo
# the Free Software Foundation; either version 2 of the License, or
9 30131294 Adeodato Simo
# (at your option) any later version.
10 30131294 Adeodato Simo
#
11 30131294 Adeodato Simo
# This program is distributed in the hope that it will be useful, but
12 30131294 Adeodato Simo
# WITHOUT ANY WARRANTY; without even the implied warranty of
13 30131294 Adeodato Simo
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 30131294 Adeodato Simo
# General Public License for more details.
15 30131294 Adeodato Simo
#
16 30131294 Adeodato Simo
# You should have received a copy of the GNU General Public License
17 30131294 Adeodato Simo
# along with this program; if not, write to the Free Software
18 30131294 Adeodato Simo
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 30131294 Adeodato Simo
# 02110-1301, USA.
20 30131294 Adeodato Simo
21 30131294 Adeodato Simo
22 3582eef6 Iustin Pop
"""QA tests for node groups.
23 3582eef6 Iustin Pop

24 3582eef6 Iustin Pop
"""
25 3582eef6 Iustin Pop
26 75cf411a Adeodato Simo
from ganeti import constants
27 ec7b6d63 Petr Pudlak
from ganeti import netutils
28 7ab8b7d7 Adeodato Simo
from ganeti import query
29 f3fd2c9d Adeodato Simo
from ganeti import utils
30 75cf411a Adeodato Simo
31 ec7b6d63 Petr Pudlak
import qa_iptables
32 66787da5 Adeodato Simo
import qa_config
33 7ab8b7d7 Adeodato Simo
import qa_utils
34 7ab8b7d7 Adeodato Simo
35 f3fd2c9d Adeodato Simo
from qa_utils import AssertCommand, AssertEqual, GetCommandOutput
36 30131294 Adeodato Simo
37 30131294 Adeodato Simo
38 fe508a9d Michael Hanselmann
def GetDefaultGroup():
39 fe508a9d Michael Hanselmann
  """Returns the default node group.
40 fe508a9d Michael Hanselmann

41 fe508a9d Michael Hanselmann
  """
42 fe508a9d Michael Hanselmann
  groups = qa_config.get("groups", {})
43 fe508a9d Michael Hanselmann
  return groups.get("group-with-nodes", constants.INITIAL_NODE_GROUP_NAME)
44 fe508a9d Michael Hanselmann
45 fe508a9d Michael Hanselmann
46 ec7b6d63 Petr Pudlak
def ConfigureGroups():
47 ec7b6d63 Petr Pudlak
  """Configures groups and nodes for tests such as custom SSH ports.
48 ec7b6d63 Petr Pudlak

49 ec7b6d63 Petr Pudlak
  """
50 ec7b6d63 Petr Pudlak
51 ec7b6d63 Petr Pudlak
  defgroup = GetDefaultGroup()
52 ec7b6d63 Petr Pudlak
  nodes = qa_config.get("nodes")
53 ec7b6d63 Petr Pudlak
  options = qa_config.get("options", {})
54 ec7b6d63 Petr Pudlak
55 ec7b6d63 Petr Pudlak
  # Clear any old configuration
56 ec7b6d63 Petr Pudlak
  qa_iptables.CleanRules(nodes)
57 ec7b6d63 Petr Pudlak
58 ec7b6d63 Petr Pudlak
  # Custom SSH ports:
59 ec7b6d63 Petr Pudlak
  ssh_port = options.get("ssh-port")
60 ec7b6d63 Petr Pudlak
  default_ssh_port = netutils.GetDaemonPort(constants.SSH)
61 ec7b6d63 Petr Pudlak
  if (ssh_port is not None) and (ssh_port != default_ssh_port):
62 ec7b6d63 Petr Pudlak
    ModifyGroupSshPort(qa_iptables.GLOBAL_RULES, defgroup, nodes, ssh_port)
63 ec7b6d63 Petr Pudlak
64 ec7b6d63 Petr Pudlak
65 ec7b6d63 Petr Pudlak
def ModifyGroupSshPort(ipt_rules, group, nodes, ssh_port):
66 ec7b6d63 Petr Pudlak
  """Modifies the node group settings and sets up iptable rules.
67 ec7b6d63 Petr Pudlak

68 ec7b6d63 Petr Pudlak
  For each pair of nodes add two rules that affect SSH connections from one
69 ec7b6d63 Petr Pudlak
  to the other one.
70 ec7b6d63 Petr Pudlak
  The first one redirects port 22 to some unused port so that connecting
71 ec7b6d63 Petr Pudlak
  through 22 fails. The second redirects port `ssh_port` to port 22.
72 ec7b6d63 Petr Pudlak
  Together this results in master seeing the SSH daemons on the nodes on
73 ec7b6d63 Petr Pudlak
  `ssh_port` instead of 22.
74 ec7b6d63 Petr Pudlak
  """
75 ec7b6d63 Petr Pudlak
  default_ssh_port = netutils.GetDaemonPort(constants.SSH)
76 ec7b6d63 Petr Pudlak
  all_nodes = qa_config.get("nodes")
77 ec7b6d63 Petr Pudlak
  AssertCommand(["gnt-group", "modify",
78 ec7b6d63 Petr Pudlak
                 "--node-parameters=ssh_port=" + str(ssh_port),
79 ec7b6d63 Petr Pudlak
                 group])
80 ec7b6d63 Petr Pudlak
  for node in nodes:
81 ec7b6d63 Petr Pudlak
    ipt_rules.RedirectPort(node.primary, "localhost",
82 ec7b6d63 Petr Pudlak
                           default_ssh_port, 65535)
83 ec7b6d63 Petr Pudlak
    ipt_rules.RedirectPort(node.primary, "localhost",
84 ec7b6d63 Petr Pudlak
                           ssh_port, default_ssh_port)
85 ec7b6d63 Petr Pudlak
    for node2 in all_nodes:
86 ec7b6d63 Petr Pudlak
      ipt_rules.RedirectPort(node2.primary, node.primary,
87 ec7b6d63 Petr Pudlak
                             default_ssh_port, 65535)
88 ec7b6d63 Petr Pudlak
      ipt_rules.RedirectPort(node2.primary, node.primary,
89 ec7b6d63 Petr Pudlak
                             ssh_port, default_ssh_port)
90 ec7b6d63 Petr Pudlak
91 ec7b6d63 Petr Pudlak
92 66787da5 Adeodato Simo
def TestGroupAddRemoveRename():
93 66787da5 Adeodato Simo
  """gnt-group add/remove/rename"""
94 fe508a9d Michael Hanselmann
  existing_group_with_nodes = GetDefaultGroup()
95 fe508a9d Michael Hanselmann
96 b4d2d2cb Michael Hanselmann
  (group1, group2, group3) = qa_utils.GetNonexistentGroups(3)
97 66787da5 Adeodato Simo
98 66787da5 Adeodato Simo
  AssertCommand(["gnt-group", "add", group1])
99 66787da5 Adeodato Simo
  AssertCommand(["gnt-group", "add", group2])
100 66787da5 Adeodato Simo
  AssertCommand(["gnt-group", "add", group2], fail=True)
101 66787da5 Adeodato Simo
  AssertCommand(["gnt-group", "add", existing_group_with_nodes], fail=True)
102 66787da5 Adeodato Simo
103 66787da5 Adeodato Simo
  AssertCommand(["gnt-group", "rename", group1, group2], fail=True)
104 66787da5 Adeodato Simo
  AssertCommand(["gnt-group", "rename", group1, group3])
105 66787da5 Adeodato Simo
106 66787da5 Adeodato Simo
  try:
107 66787da5 Adeodato Simo
    AssertCommand(["gnt-group", "rename", existing_group_with_nodes, group1])
108 66787da5 Adeodato Simo
109 66787da5 Adeodato Simo
    AssertCommand(["gnt-group", "remove", group2])
110 66787da5 Adeodato Simo
    AssertCommand(["gnt-group", "remove", group3])
111 66787da5 Adeodato Simo
    AssertCommand(["gnt-group", "remove", group1], fail=True)
112 66787da5 Adeodato Simo
  finally:
113 66787da5 Adeodato Simo
    # Try to ensure idempotency re groups that already existed.
114 66787da5 Adeodato Simo
    AssertCommand(["gnt-group", "rename", group1, existing_group_with_nodes])
115 66787da5 Adeodato Simo
116 66787da5 Adeodato Simo
117 4b10fb65 Adeodato Simo
def TestGroupAddWithOptions():
118 4b10fb65 Adeodato Simo
  """gnt-group add with options"""
119 b4d2d2cb Michael Hanselmann
  (group1, ) = qa_utils.GetNonexistentGroups(1)
120 4b10fb65 Adeodato Simo
121 4b10fb65 Adeodato Simo
  AssertCommand(["gnt-group", "add", "--alloc-policy", "notvalid", group1],
122 4b10fb65 Adeodato Simo
                fail=True)
123 4b10fb65 Adeodato Simo
124 4b10fb65 Adeodato Simo
  AssertCommand(["gnt-group", "add", "--alloc-policy", "last_resort",
125 4b10fb65 Adeodato Simo
                 "--node-parameters", "oob_program=/bin/true", group1])
126 4b10fb65 Adeodato Simo
127 4b10fb65 Adeodato Simo
  AssertCommand(["gnt-group", "remove", group1])
128 4b10fb65 Adeodato Simo
129 4b10fb65 Adeodato Simo
130 e44b72bb Petr Pudlak
class NewGroupCtx(object):
131 e44b72bb Petr Pudlak
  """Creates a new group and disposes afterwards."""
132 e44b72bb Petr Pudlak
133 e44b72bb Petr Pudlak
  def __enter__(self):
134 e44b72bb Petr Pudlak
    (self._group, ) = qa_utils.GetNonexistentGroups(1)
135 e44b72bb Petr Pudlak
    AssertCommand(["gnt-group", "add", self._group])
136 e44b72bb Petr Pudlak
    return self._group
137 e44b72bb Petr Pudlak
138 e44b72bb Petr Pudlak
  def __exit__(self, exc_type, exc_val, exc_tb):
139 e44b72bb Petr Pudlak
    AssertCommand(["gnt-group", "remove", self._group])
140 e44b72bb Petr Pudlak
141 e44b72bb Petr Pudlak
142 cbaf1652 Bernardo Dal Seno
def _GetGroupIPolicy(groupname):
143 cbaf1652 Bernardo Dal Seno
  """Return the run-time values of the cluster-level instance policy.
144 cbaf1652 Bernardo Dal Seno

145 cbaf1652 Bernardo Dal Seno
  @type groupname: string
146 cbaf1652 Bernardo Dal Seno
  @param groupname: node group name
147 cbaf1652 Bernardo Dal Seno
  @rtype: tuple
148 cbaf1652 Bernardo Dal Seno
  @return: (policy, specs), where:
149 cbaf1652 Bernardo Dal Seno
      - policy is a dictionary of the policy values, instance specs excluded
150 7c8ae421 Bernardo Dal Seno
      - specs is a dictionary containing only the specs, using the internal
151 7c8ae421 Bernardo Dal Seno
        format (see L{constants.IPOLICY_DEFAULTS} for an example), but without
152 7c8ae421 Bernardo Dal Seno
        the standard values
153 cbaf1652 Bernardo Dal Seno

154 cbaf1652 Bernardo Dal Seno
  """
155 cbaf1652 Bernardo Dal Seno
  info = qa_utils.GetObjectInfo(["gnt-group", "info", groupname])
156 cbaf1652 Bernardo Dal Seno
  assert len(info) == 1
157 cbaf1652 Bernardo Dal Seno
  policy = info[0]["Instance policy"]
158 cbaf1652 Bernardo Dal Seno
159 cbaf1652 Bernardo Dal Seno
  (ret_policy, ret_specs) = qa_utils.ParseIPolicy(policy)
160 cbaf1652 Bernardo Dal Seno
161 cbaf1652 Bernardo Dal Seno
  # Sanity checks
162 7c8ae421 Bernardo Dal Seno
  assert "minmax" in ret_specs
163 7c8ae421 Bernardo Dal Seno
  assert len(ret_specs["minmax"]) > 0
164 cbaf1652 Bernardo Dal Seno
  assert len(ret_policy) > 0
165 cbaf1652 Bernardo Dal Seno
  return (ret_policy, ret_specs)
166 cbaf1652 Bernardo Dal Seno
167 cbaf1652 Bernardo Dal Seno
168 ec996117 Bernardo Dal Seno
def _TestGroupSetISpecs(groupname, new_specs=None, diff_specs=None,
169 ec996117 Bernardo Dal Seno
                        fail=False, old_values=None):
170 cbaf1652 Bernardo Dal Seno
  """Change instance specs on a group.
171 cbaf1652 Bernardo Dal Seno

172 ec996117 Bernardo Dal Seno
  At most one of new_specs or diff_specs can be specified.
173 ec996117 Bernardo Dal Seno

174 cbaf1652 Bernardo Dal Seno
  @type groupname: string
175 cbaf1652 Bernardo Dal Seno
  @param groupname: group name
176 ec996117 Bernardo Dal Seno
  @type new_specs: dict
177 ec996117 Bernardo Dal Seno
  @param new_specs: new complete specs, in the same format returned by
178 ec996117 Bernardo Dal Seno
      L{_GetGroupIPolicy}
179 ec996117 Bernardo Dal Seno
  @type diff_specs: dict
180 7c8ae421 Bernardo Dal Seno
  @param diff_specs: partial specs, it can be an incomplete specifications, but
181 7c8ae421 Bernardo Dal Seno
      if min/max specs are specified, their number must match the number of the
182 7c8ae421 Bernardo Dal Seno
      existing specs
183 cbaf1652 Bernardo Dal Seno
  @type fail: bool
184 cbaf1652 Bernardo Dal Seno
  @param fail: if the change is expected to fail
185 cbaf1652 Bernardo Dal Seno
  @type old_values: tuple
186 cbaf1652 Bernardo Dal Seno
  @param old_values: (old_policy, old_specs), as returned by
187 ec996117 Bernardo Dal Seno
      L{_GetGroupIPolicy}
188 cbaf1652 Bernardo Dal Seno
  @return: same as L{_GetGroupIPolicy}
189 cbaf1652 Bernardo Dal Seno

190 cbaf1652 Bernardo Dal Seno
  """
191 cbaf1652 Bernardo Dal Seno
  build_cmd = lambda opts: ["gnt-group", "modify"] + opts + [groupname]
192 cbaf1652 Bernardo Dal Seno
  get_policy = lambda: _GetGroupIPolicy(groupname)
193 ec996117 Bernardo Dal Seno
  return qa_utils.TestSetISpecs(
194 ec996117 Bernardo Dal Seno
    new_specs=new_specs, diff_specs=diff_specs,
195 ec996117 Bernardo Dal Seno
    get_policy_fn=get_policy, build_cmd_fn=build_cmd,
196 ec996117 Bernardo Dal Seno
    fail=fail, old_values=old_values)
197 cbaf1652 Bernardo Dal Seno
198 cbaf1652 Bernardo Dal Seno
199 b5a93c73 Bernardo Dal Seno
def _TestGroupModifyISpecs(groupname):
200 cbaf1652 Bernardo Dal Seno
  # This test is built on the assumption that the default ipolicy holds for
201 cbaf1652 Bernardo Dal Seno
  # the node group under test
202 cbaf1652 Bernardo Dal Seno
  old_values = _GetGroupIPolicy(groupname)
203 ec996117 Bernardo Dal Seno
  samevals = dict((p, 4) for p in constants.ISPECS_PARAMETERS)
204 7c8ae421 Bernardo Dal Seno
  base_specs = {
205 7c8ae421 Bernardo Dal Seno
    constants.ISPECS_MINMAX: [{
206 7c8ae421 Bernardo Dal Seno
      constants.ISPECS_MIN: samevals,
207 7c8ae421 Bernardo Dal Seno
      constants.ISPECS_MAX: samevals,
208 7c8ae421 Bernardo Dal Seno
      }],
209 7c8ae421 Bernardo Dal Seno
    }
210 ec996117 Bernardo Dal Seno
  mod_values = _TestGroupSetISpecs(groupname, new_specs=base_specs,
211 cbaf1652 Bernardo Dal Seno
                                   old_values=old_values)
212 cbaf1652 Bernardo Dal Seno
  for par in constants.ISPECS_PARAMETERS:
213 cbaf1652 Bernardo Dal Seno
    # First make sure that the test works with good values
214 7c8ae421 Bernardo Dal Seno
    good_specs = {
215 7c8ae421 Bernardo Dal Seno
      constants.ISPECS_MINMAX: [{
216 7c8ae421 Bernardo Dal Seno
        constants.ISPECS_MIN: {par: 8},
217 7c8ae421 Bernardo Dal Seno
        constants.ISPECS_MAX: {par: 8},
218 7c8ae421 Bernardo Dal Seno
        }],
219 7c8ae421 Bernardo Dal Seno
      }
220 ec996117 Bernardo Dal Seno
    mod_values = _TestGroupSetISpecs(groupname, diff_specs=good_specs,
221 cbaf1652 Bernardo Dal Seno
                                     old_values=mod_values)
222 7c8ae421 Bernardo Dal Seno
    bad_specs = {
223 7c8ae421 Bernardo Dal Seno
      constants.ISPECS_MINMAX: [{
224 7c8ae421 Bernardo Dal Seno
        constants.ISPECS_MIN: {par: 8},
225 7c8ae421 Bernardo Dal Seno
        constants.ISPECS_MAX: {par: 4},
226 7c8ae421 Bernardo Dal Seno
        }],
227 7c8ae421 Bernardo Dal Seno
      }
228 ec996117 Bernardo Dal Seno
    _TestGroupSetISpecs(groupname, diff_specs=bad_specs, fail=True,
229 ec996117 Bernardo Dal Seno
                        old_values=mod_values)
230 cbaf1652 Bernardo Dal Seno
  AssertCommand(["gnt-group", "modify", "--ipolicy-bounds-specs", "default",
231 cbaf1652 Bernardo Dal Seno
                 groupname])
232 cbaf1652 Bernardo Dal Seno
  AssertEqual(_GetGroupIPolicy(groupname), old_values)
233 cbaf1652 Bernardo Dal Seno
234 b5a93c73 Bernardo Dal Seno
  # Get the ipolicy command (from the cluster config)
235 b5a93c73 Bernardo Dal Seno
  mnode = qa_config.GetMasterNode()
236 b5a93c73 Bernardo Dal Seno
  addcmd = GetCommandOutput(mnode.primary, utils.ShellQuoteArgs([
237 b5a93c73 Bernardo Dal Seno
    "gnt-group", "show-ispecs-cmd", "--include-defaults", groupname,
238 b5a93c73 Bernardo Dal Seno
    ]))
239 b5a93c73 Bernardo Dal Seno
  modcmd = ["gnt-group", "modify"]
240 b5a93c73 Bernardo Dal Seno
  opts = addcmd.split()
241 b5a93c73 Bernardo Dal Seno
  assert opts[0:2] == ["gnt-group", "add"]
242 b5a93c73 Bernardo Dal Seno
  for k in range(2, len(opts) - 1):
243 b5a93c73 Bernardo Dal Seno
    if opts[k].startswith("--ipolicy-"):
244 b5a93c73 Bernardo Dal Seno
      assert k + 2 <= len(opts)
245 b5a93c73 Bernardo Dal Seno
      modcmd.extend(opts[k:k + 2])
246 b5a93c73 Bernardo Dal Seno
  modcmd.append(groupname)
247 b5a93c73 Bernardo Dal Seno
  # Apply the ipolicy to the group and verify the result
248 b5a93c73 Bernardo Dal Seno
  AssertCommand(modcmd)
249 b5a93c73 Bernardo Dal Seno
  new_addcmd = GetCommandOutput(mnode.primary, utils.ShellQuoteArgs([
250 b5a93c73 Bernardo Dal Seno
    "gnt-group", "show-ispecs-cmd", groupname,
251 b5a93c73 Bernardo Dal Seno
    ]))
252 b5a93c73 Bernardo Dal Seno
  AssertEqual(addcmd, new_addcmd)
253 b5a93c73 Bernardo Dal Seno
254 b5a93c73 Bernardo Dal Seno
255 b5a93c73 Bernardo Dal Seno
def _TestGroupModifyIPolicy(groupname):
256 b5a93c73 Bernardo Dal Seno
  _TestGroupModifyISpecs(groupname)
257 cbaf1652 Bernardo Dal Seno
258 cbaf1652 Bernardo Dal Seno
  # We assume that the default ipolicy holds
259 cbaf1652 Bernardo Dal Seno
  (old_policy, old_specs) = _GetGroupIPolicy(groupname)
260 cbaf1652 Bernardo Dal Seno
  for (par, setval, iname, expval) in [
261 cbaf1652 Bernardo Dal Seno
    ("vcpu-ratio", 1.5, None, 1.5),
262 cbaf1652 Bernardo Dal Seno
    ("spindle-ratio", 1.5, None, 1.5),
263 cbaf1652 Bernardo Dal Seno
    ("disk-templates", constants.DT_PLAIN,
264 9db0b351 Bernardo Dal Seno
     "allowed disk templates", constants.DT_PLAIN)
265 cbaf1652 Bernardo Dal Seno
    ]:
266 cbaf1652 Bernardo Dal Seno
    if not iname:
267 cbaf1652 Bernardo Dal Seno
      iname = par
268 cbaf1652 Bernardo Dal Seno
    build_cmdline = lambda val: ["gnt-group", "modify", "--ipolicy-" + par,
269 cbaf1652 Bernardo Dal Seno
                                 str(val), groupname]
270 cbaf1652 Bernardo Dal Seno
271 cbaf1652 Bernardo Dal Seno
    AssertCommand(build_cmdline(setval))
272 cbaf1652 Bernardo Dal Seno
    (new_policy, new_specs) = _GetGroupIPolicy(groupname)
273 cbaf1652 Bernardo Dal Seno
    AssertEqual(new_specs, old_specs)
274 cbaf1652 Bernardo Dal Seno
    for (p, val) in new_policy.items():
275 cbaf1652 Bernardo Dal Seno
      if p == iname:
276 cbaf1652 Bernardo Dal Seno
        AssertEqual(val, expval)
277 cbaf1652 Bernardo Dal Seno
      else:
278 cbaf1652 Bernardo Dal Seno
        AssertEqual(val, old_policy[p])
279 cbaf1652 Bernardo Dal Seno
280 cbaf1652 Bernardo Dal Seno
    AssertCommand(build_cmdline("default"))
281 cbaf1652 Bernardo Dal Seno
    (new_policy, new_specs) = _GetGroupIPolicy(groupname)
282 cbaf1652 Bernardo Dal Seno
    AssertEqual(new_specs, old_specs)
283 cbaf1652 Bernardo Dal Seno
    AssertEqual(new_policy, old_policy)
284 b5a93c73 Bernardo Dal Seno
285 b5a93c73 Bernardo Dal Seno
286 4b10fb65 Adeodato Simo
def TestGroupModify():
287 4b10fb65 Adeodato Simo
  """gnt-group modify"""
288 bab4f56a Helga Velroyen
  # This tests assumes LVM to be enabled, thus it should skip if
289 bab4f56a Helga Velroyen
  # this is not the case
290 bab4f56a Helga Velroyen
  if not qa_config.IsStorageTypeSupported(constants.ST_LVM_VG):
291 bab4f56a Helga Velroyen
    return
292 b4d2d2cb Michael Hanselmann
  (group1, ) = qa_utils.GetNonexistentGroups(1)
293 4b10fb65 Adeodato Simo
294 4b10fb65 Adeodato Simo
  AssertCommand(["gnt-group", "add", group1])
295 4b10fb65 Adeodato Simo
296 4b10fb65 Adeodato Simo
  try:
297 b5a93c73 Bernardo Dal Seno
    _TestGroupModifyIPolicy(group1)
298 4b10fb65 Adeodato Simo
    AssertCommand(["gnt-group", "modify", "--alloc-policy", "unallocable",
299 4b10fb65 Adeodato Simo
                   "--node-parameters", "oob_program=/bin/false", group1])
300 4b10fb65 Adeodato Simo
    AssertCommand(["gnt-group", "modify",
301 4b10fb65 Adeodato Simo
                   "--alloc-policy", "notvalid", group1], fail=True)
302 52bebbdf Iustin Pop
    AssertCommand(["gnt-group", "modify",
303 52bebbdf Iustin Pop
                   "--node-parameters", "spindle_count=10", group1])
304 52bebbdf Iustin Pop
    if qa_config.TestEnabled("htools"):
305 52bebbdf Iustin Pop
      AssertCommand(["hbal", "-L", "-G", group1])
306 52bebbdf Iustin Pop
    AssertCommand(["gnt-group", "modify",
307 52bebbdf Iustin Pop
                   "--node-parameters", "spindle_count=default", group1])
308 4b10fb65 Adeodato Simo
  finally:
309 4b10fb65 Adeodato Simo
    AssertCommand(["gnt-group", "remove", group1])
310 4b10fb65 Adeodato Simo
311 4b10fb65 Adeodato Simo
312 7ab8b7d7 Adeodato Simo
def TestGroupList():
313 30131294 Adeodato Simo
  """gnt-group list"""
314 7ab8b7d7 Adeodato Simo
  qa_utils.GenericQueryTest("gnt-group", query.GROUP_FIELDS.keys())
315 30131294 Adeodato Simo
316 30131294 Adeodato Simo
317 7ab8b7d7 Adeodato Simo
def TestGroupListFields():
318 7ab8b7d7 Adeodato Simo
  """gnt-group list-fields"""
319 7ab8b7d7 Adeodato Simo
  qa_utils.GenericQueryFieldsTest("gnt-group", query.GROUP_FIELDS.keys())
320 f3fd2c9d Adeodato Simo
321 f3fd2c9d Adeodato Simo
322 f3fd2c9d Adeodato Simo
def TestAssignNodesIncludingSplit(orig_group, node1, node2):
323 f3fd2c9d Adeodato Simo
  """gnt-group assign-nodes --force
324 f3fd2c9d Adeodato Simo

325 f3fd2c9d Adeodato Simo
  Expects node1 and node2 to be primary and secondary for a common instance.
326 f3fd2c9d Adeodato Simo

327 f3fd2c9d Adeodato Simo
  """
328 f3fd2c9d Adeodato Simo
  assert node1 != node2
329 b4d2d2cb Michael Hanselmann
330 b4d2d2cb Michael Hanselmann
  (other_group, ) = qa_utils.GetNonexistentGroups(1)
331 f3fd2c9d Adeodato Simo
332 aecba21e Michael Hanselmann
  master_node = qa_config.GetMasterNode().primary
333 f3fd2c9d Adeodato Simo
334 f3fd2c9d Adeodato Simo
  def AssertInGroup(group, nodes):
335 f3fd2c9d Adeodato Simo
    real_output = GetCommandOutput(master_node,
336 f3fd2c9d Adeodato Simo
                                   "gnt-node list --no-headers -o group " +
337 f3fd2c9d Adeodato Simo
                                   utils.ShellQuoteArgs(nodes))
338 f3fd2c9d Adeodato Simo
    AssertEqual(real_output.splitlines(), [group] * len(nodes))
339 f3fd2c9d Adeodato Simo
340 f3fd2c9d Adeodato Simo
  AssertInGroup(orig_group, [node1, node2])
341 f3fd2c9d Adeodato Simo
  AssertCommand(["gnt-group", "add", other_group])
342 f3fd2c9d Adeodato Simo
343 f3fd2c9d Adeodato Simo
  try:
344 f3fd2c9d Adeodato Simo
    AssertCommand(["gnt-group", "assign-nodes", other_group, node1, node2])
345 f3fd2c9d Adeodato Simo
    AssertInGroup(other_group, [node1, node2])
346 f3fd2c9d Adeodato Simo
347 f3fd2c9d Adeodato Simo
    # This should fail because moving node1 to orig_group would leave their
348 f3fd2c9d Adeodato Simo
    # common instance split between orig_group and other_group.
349 f3fd2c9d Adeodato Simo
    AssertCommand(["gnt-group", "assign-nodes", orig_group, node1], fail=True)
350 f3fd2c9d Adeodato Simo
    AssertInGroup(other_group, [node1, node2])
351 f3fd2c9d Adeodato Simo
352 f3fd2c9d Adeodato Simo
    AssertCommand(["gnt-group", "assign-nodes", "--force", orig_group, node1])
353 f3fd2c9d Adeodato Simo
    AssertInGroup(orig_group, [node1])
354 f3fd2c9d Adeodato Simo
    AssertInGroup(other_group, [node2])
355 f3fd2c9d Adeodato Simo
356 f3fd2c9d Adeodato Simo
    AssertCommand(["gnt-group", "assign-nodes", orig_group, node2])
357 f3fd2c9d Adeodato Simo
    AssertInGroup(orig_group, [node1, node2])
358 f3fd2c9d Adeodato Simo
  finally:
359 f3fd2c9d Adeodato Simo
    AssertCommand(["gnt-group", "remove", other_group])