Statistics
| Branch: | Tag: | Revision:

root / qa / qa_group.py @ 6d3d13ab

History | View | Annotate | Download (5.3 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 7ab8b7d7 Adeodato Simo
from ganeti import query
28 f3fd2c9d Adeodato Simo
from ganeti import utils
29 75cf411a Adeodato Simo
30 66787da5 Adeodato Simo
import qa_config
31 7ab8b7d7 Adeodato Simo
import qa_utils
32 7ab8b7d7 Adeodato Simo
33 f3fd2c9d Adeodato Simo
from qa_utils import AssertCommand, AssertEqual, GetCommandOutput
34 30131294 Adeodato Simo
35 30131294 Adeodato Simo
36 fe508a9d Michael Hanselmann
def GetDefaultGroup():
37 fe508a9d Michael Hanselmann
  """Returns the default node group.
38 fe508a9d Michael Hanselmann

39 fe508a9d Michael Hanselmann
  """
40 fe508a9d Michael Hanselmann
  groups = qa_config.get("groups", {})
41 fe508a9d Michael Hanselmann
  return groups.get("group-with-nodes", constants.INITIAL_NODE_GROUP_NAME)
42 fe508a9d Michael Hanselmann
43 fe508a9d Michael Hanselmann
44 66787da5 Adeodato Simo
def TestGroupAddRemoveRename():
45 66787da5 Adeodato Simo
  """gnt-group add/remove/rename"""
46 fe508a9d Michael Hanselmann
  existing_group_with_nodes = GetDefaultGroup()
47 fe508a9d Michael Hanselmann
48 b4d2d2cb Michael Hanselmann
  (group1, group2, group3) = qa_utils.GetNonexistentGroups(3)
49 66787da5 Adeodato Simo
50 66787da5 Adeodato Simo
  AssertCommand(["gnt-group", "add", group1])
51 66787da5 Adeodato Simo
  AssertCommand(["gnt-group", "add", group2])
52 66787da5 Adeodato Simo
  AssertCommand(["gnt-group", "add", group2], fail=True)
53 66787da5 Adeodato Simo
  AssertCommand(["gnt-group", "add", existing_group_with_nodes], fail=True)
54 66787da5 Adeodato Simo
55 66787da5 Adeodato Simo
  AssertCommand(["gnt-group", "rename", group1, group2], fail=True)
56 66787da5 Adeodato Simo
  AssertCommand(["gnt-group", "rename", group1, group3])
57 66787da5 Adeodato Simo
58 66787da5 Adeodato Simo
  try:
59 66787da5 Adeodato Simo
    AssertCommand(["gnt-group", "rename", existing_group_with_nodes, group1])
60 66787da5 Adeodato Simo
61 66787da5 Adeodato Simo
    AssertCommand(["gnt-group", "remove", group2])
62 66787da5 Adeodato Simo
    AssertCommand(["gnt-group", "remove", group3])
63 66787da5 Adeodato Simo
    AssertCommand(["gnt-group", "remove", group1], fail=True)
64 66787da5 Adeodato Simo
  finally:
65 66787da5 Adeodato Simo
    # Try to ensure idempotency re groups that already existed.
66 66787da5 Adeodato Simo
    AssertCommand(["gnt-group", "rename", group1, existing_group_with_nodes])
67 66787da5 Adeodato Simo
68 66787da5 Adeodato Simo
69 4b10fb65 Adeodato Simo
def TestGroupAddWithOptions():
70 4b10fb65 Adeodato Simo
  """gnt-group add with options"""
71 b4d2d2cb Michael Hanselmann
  (group1, ) = qa_utils.GetNonexistentGroups(1)
72 4b10fb65 Adeodato Simo
73 4b10fb65 Adeodato Simo
  AssertCommand(["gnt-group", "add", "--alloc-policy", "notvalid", group1],
74 4b10fb65 Adeodato Simo
                fail=True)
75 4b10fb65 Adeodato Simo
76 4b10fb65 Adeodato Simo
  AssertCommand(["gnt-group", "add", "--alloc-policy", "last_resort",
77 4b10fb65 Adeodato Simo
                 "--node-parameters", "oob_program=/bin/true", group1])
78 4b10fb65 Adeodato Simo
79 4b10fb65 Adeodato Simo
  AssertCommand(["gnt-group", "remove", group1])
80 4b10fb65 Adeodato Simo
81 4b10fb65 Adeodato Simo
82 4b10fb65 Adeodato Simo
def TestGroupModify():
83 4b10fb65 Adeodato Simo
  """gnt-group modify"""
84 b4d2d2cb Michael Hanselmann
  (group1, ) = qa_utils.GetNonexistentGroups(1)
85 4b10fb65 Adeodato Simo
86 4b10fb65 Adeodato Simo
  AssertCommand(["gnt-group", "add", group1])
87 4b10fb65 Adeodato Simo
88 93ddfce2 René Nussbaumer
  std_defaults = constants.IPOLICY_DEFAULTS[constants.ISPECS_STD]
89 93ddfce2 René Nussbaumer
  min_v = std_defaults[constants.ISPEC_MEM_SIZE] * 10
90 93ddfce2 René Nussbaumer
  max_v = min_v * 10
91 93ddfce2 René Nussbaumer
92 4b10fb65 Adeodato Simo
  try:
93 4b10fb65 Adeodato Simo
    AssertCommand(["gnt-group", "modify", "--alloc-policy", "unallocable",
94 4b10fb65 Adeodato Simo
                   "--node-parameters", "oob_program=/bin/false", group1])
95 4b10fb65 Adeodato Simo
    AssertCommand(["gnt-group", "modify",
96 4b10fb65 Adeodato Simo
                   "--alloc-policy", "notvalid", group1], fail=True)
97 93ddfce2 René Nussbaumer
    AssertCommand(["gnt-group", "modify", "--specs-mem-size",
98 93ddfce2 René Nussbaumer
                   "min=%s,max=%s,std=0" % (min_v, max_v), group1], fail=True)
99 93ddfce2 René Nussbaumer
    AssertCommand(["gnt-group", "modify", "--specs-mem-size",
100 93ddfce2 René Nussbaumer
                   "min=%s,max=%s" % (min_v, max_v), group1])
101 52bebbdf Iustin Pop
    AssertCommand(["gnt-group", "modify",
102 52bebbdf Iustin Pop
                   "--node-parameters", "spindle_count=10", group1])
103 52bebbdf Iustin Pop
    if qa_config.TestEnabled("htools"):
104 52bebbdf Iustin Pop
      AssertCommand(["hbal", "-L", "-G", group1])
105 52bebbdf Iustin Pop
    AssertCommand(["gnt-group", "modify",
106 52bebbdf Iustin Pop
                   "--node-parameters", "spindle_count=default", group1])
107 4b10fb65 Adeodato Simo
  finally:
108 4b10fb65 Adeodato Simo
    AssertCommand(["gnt-group", "remove", group1])
109 4b10fb65 Adeodato Simo
110 4b10fb65 Adeodato Simo
111 7ab8b7d7 Adeodato Simo
def TestGroupList():
112 30131294 Adeodato Simo
  """gnt-group list"""
113 7ab8b7d7 Adeodato Simo
  qa_utils.GenericQueryTest("gnt-group", query.GROUP_FIELDS.keys())
114 30131294 Adeodato Simo
115 30131294 Adeodato Simo
116 7ab8b7d7 Adeodato Simo
def TestGroupListFields():
117 7ab8b7d7 Adeodato Simo
  """gnt-group list-fields"""
118 7ab8b7d7 Adeodato Simo
  qa_utils.GenericQueryFieldsTest("gnt-group", query.GROUP_FIELDS.keys())
119 f3fd2c9d Adeodato Simo
120 f3fd2c9d Adeodato Simo
121 f3fd2c9d Adeodato Simo
def TestAssignNodesIncludingSplit(orig_group, node1, node2):
122 f3fd2c9d Adeodato Simo
  """gnt-group assign-nodes --force
123 f3fd2c9d Adeodato Simo

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

126 f3fd2c9d Adeodato Simo
  """
127 f3fd2c9d Adeodato Simo
  assert node1 != node2
128 b4d2d2cb Michael Hanselmann
129 b4d2d2cb Michael Hanselmann
  (other_group, ) = qa_utils.GetNonexistentGroups(1)
130 f3fd2c9d Adeodato Simo
131 f3fd2c9d Adeodato Simo
  master_node = qa_config.GetMasterNode()["primary"]
132 f3fd2c9d Adeodato Simo
133 f3fd2c9d Adeodato Simo
  def AssertInGroup(group, nodes):
134 f3fd2c9d Adeodato Simo
    real_output = GetCommandOutput(master_node,
135 f3fd2c9d Adeodato Simo
                                   "gnt-node list --no-headers -o group " +
136 f3fd2c9d Adeodato Simo
                                   utils.ShellQuoteArgs(nodes))
137 f3fd2c9d Adeodato Simo
    AssertEqual(real_output.splitlines(), [group] * len(nodes))
138 f3fd2c9d Adeodato Simo
139 f3fd2c9d Adeodato Simo
  AssertInGroup(orig_group, [node1, node2])
140 f3fd2c9d Adeodato Simo
  AssertCommand(["gnt-group", "add", other_group])
141 f3fd2c9d Adeodato Simo
142 f3fd2c9d Adeodato Simo
  try:
143 f3fd2c9d Adeodato Simo
    AssertCommand(["gnt-group", "assign-nodes", other_group, node1, node2])
144 f3fd2c9d Adeodato Simo
    AssertInGroup(other_group, [node1, node2])
145 f3fd2c9d Adeodato Simo
146 f3fd2c9d Adeodato Simo
    # This should fail because moving node1 to orig_group would leave their
147 f3fd2c9d Adeodato Simo
    # common instance split between orig_group and other_group.
148 f3fd2c9d Adeodato Simo
    AssertCommand(["gnt-group", "assign-nodes", orig_group, node1], fail=True)
149 f3fd2c9d Adeodato Simo
    AssertInGroup(other_group, [node1, node2])
150 f3fd2c9d Adeodato Simo
151 f3fd2c9d Adeodato Simo
    AssertCommand(["gnt-group", "assign-nodes", "--force", orig_group, node1])
152 f3fd2c9d Adeodato Simo
    AssertInGroup(orig_group, [node1])
153 f3fd2c9d Adeodato Simo
    AssertInGroup(other_group, [node2])
154 f3fd2c9d Adeodato Simo
155 f3fd2c9d Adeodato Simo
    AssertCommand(["gnt-group", "assign-nodes", orig_group, node2])
156 f3fd2c9d Adeodato Simo
    AssertInGroup(orig_group, [node1, node2])
157 f3fd2c9d Adeodato Simo
  finally:
158 f3fd2c9d Adeodato Simo
    AssertCommand(["gnt-group", "remove", other_group])