Statistics
| Branch: | Tag: | Revision:

root / qa / qa_group.py @ cb178a1e

History | View | Annotate | Download (5.9 kB)

1
#
2
#
3

    
4
# Copyright (C) 2010, 2011, 2012 Google Inc.
5
#
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.
10
#
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.
15
#
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
19
# 02110-1301, USA.
20

    
21

    
22
"""QA tests for node groups.
23

24
"""
25

    
26
from ganeti import constants
27
from ganeti import query
28
from ganeti import utils
29

    
30
import qa_config
31
import qa_utils
32

    
33
from qa_utils import AssertCommand, AssertEqual, GetCommandOutput
34

    
35

    
36
def GetDefaultGroup():
37
  """Returns the default node group.
38

39
  """
40
  groups = qa_config.get("groups", {})
41
  return groups.get("group-with-nodes", constants.INITIAL_NODE_GROUP_NAME)
42

    
43

    
44
def TestGroupAddRemoveRename():
45
  """gnt-group add/remove/rename"""
46
  existing_group_with_nodes = GetDefaultGroup()
47

    
48
  (group1, group2, group3) = qa_utils.GetNonexistentGroups(3)
49

    
50
  AssertCommand(["gnt-group", "add", group1])
51
  AssertCommand(["gnt-group", "add", group2])
52
  AssertCommand(["gnt-group", "add", group2], fail=True)
53
  AssertCommand(["gnt-group", "add", existing_group_with_nodes], fail=True)
54

    
55
  AssertCommand(["gnt-group", "rename", group1, group2], fail=True)
56
  AssertCommand(["gnt-group", "rename", group1, group3])
57

    
58
  try:
59
    AssertCommand(["gnt-group", "rename", existing_group_with_nodes, group1])
60

    
61
    AssertCommand(["gnt-group", "remove", group2])
62
    AssertCommand(["gnt-group", "remove", group3])
63
    AssertCommand(["gnt-group", "remove", group1], fail=True)
64
  finally:
65
    # Try to ensure idempotency re groups that already existed.
66
    AssertCommand(["gnt-group", "rename", group1, existing_group_with_nodes])
67

    
68

    
69
def TestGroupAddWithOptions():
70
  """gnt-group add with options"""
71
  (group1, ) = qa_utils.GetNonexistentGroups(1)
72

    
73
  AssertCommand(["gnt-group", "add", "--alloc-policy", "notvalid", group1],
74
                fail=True)
75

    
76
  AssertCommand(["gnt-group", "add", "--alloc-policy", "last_resort",
77
                 "--node-parameters", "oob_program=/bin/true", group1])
78

    
79
  AssertCommand(["gnt-group", "remove", group1])
80

    
81

    
82
def _TestGroupModifyISpecs(groupname):
83
  # Get the ipolicy command (from the cluster config)
84
  mnode = qa_config.GetMasterNode()
85
  addcmd = GetCommandOutput(mnode.primary, utils.ShellQuoteArgs([
86
    "gnt-group", "show-ispecs-cmd", "--include-defaults", groupname,
87
    ]))
88
  modcmd = ["gnt-group", "modify"]
89
  opts = addcmd.split()
90
  assert opts[0:2] == ["gnt-group", "add"]
91
  for k in range(2, len(opts) - 1):
92
    if opts[k].startswith("--ipolicy-"):
93
      assert k + 2 <= len(opts)
94
      modcmd.extend(opts[k:k + 2])
95
  modcmd.append(groupname)
96
  # Apply the ipolicy to the group and verify the result
97
  AssertCommand(modcmd)
98
  new_addcmd = GetCommandOutput(mnode.primary, utils.ShellQuoteArgs([
99
    "gnt-group", "show-ispecs-cmd", groupname,
100
    ]))
101
  AssertEqual(addcmd, new_addcmd)
102

    
103

    
104
def _TestGroupModifyIPolicy(groupname):
105
  _TestGroupModifyISpecs(groupname)
106
  AssertCommand(["gnt-group", "modify", "--ipolicy-vcpu-ratio",
107
                 "3.5", groupname])
108
  AssertCommand(["gnt-group", "modify", "--ipolicy-vcpu-ratio",
109
                 "default", groupname])
110

    
111

    
112
def TestGroupModify():
113
  """gnt-group modify"""
114
  (group1, ) = qa_utils.GetNonexistentGroups(1)
115

    
116
  AssertCommand(["gnt-group", "add", group1])
117

    
118
  try:
119
    _TestGroupModifyIPolicy(group1)
120
    AssertCommand(["gnt-group", "modify", "--alloc-policy", "unallocable",
121
                   "--node-parameters", "oob_program=/bin/false", group1])
122
    AssertCommand(["gnt-group", "modify",
123
                   "--alloc-policy", "notvalid", group1], fail=True)
124
    AssertCommand(["gnt-group", "modify",
125
                   "--node-parameters", "spindle_count=10", group1])
126
    if qa_config.TestEnabled("htools"):
127
      AssertCommand(["hbal", "-L", "-G", group1])
128
    AssertCommand(["gnt-group", "modify",
129
                   "--node-parameters", "spindle_count=default", group1])
130
  finally:
131
    AssertCommand(["gnt-group", "remove", group1])
132

    
133

    
134
def TestGroupList():
135
  """gnt-group list"""
136
  qa_utils.GenericQueryTest("gnt-group", query.GROUP_FIELDS.keys())
137

    
138

    
139
def TestGroupListFields():
140
  """gnt-group list-fields"""
141
  qa_utils.GenericQueryFieldsTest("gnt-group", query.GROUP_FIELDS.keys())
142

    
143

    
144
def TestAssignNodesIncludingSplit(orig_group, node1, node2):
145
  """gnt-group assign-nodes --force
146

147
  Expects node1 and node2 to be primary and secondary for a common instance.
148

149
  """
150
  assert node1 != node2
151

    
152
  (other_group, ) = qa_utils.GetNonexistentGroups(1)
153

    
154
  master_node = qa_config.GetMasterNode().primary
155

    
156
  def AssertInGroup(group, nodes):
157
    real_output = GetCommandOutput(master_node,
158
                                   "gnt-node list --no-headers -o group " +
159
                                   utils.ShellQuoteArgs(nodes))
160
    AssertEqual(real_output.splitlines(), [group] * len(nodes))
161

    
162
  AssertInGroup(orig_group, [node1, node2])
163
  AssertCommand(["gnt-group", "add", other_group])
164

    
165
  try:
166
    AssertCommand(["gnt-group", "assign-nodes", other_group, node1, node2])
167
    AssertInGroup(other_group, [node1, node2])
168

    
169
    # This should fail because moving node1 to orig_group would leave their
170
    # common instance split between orig_group and other_group.
171
    AssertCommand(["gnt-group", "assign-nodes", orig_group, node1], fail=True)
172
    AssertInGroup(other_group, [node1, node2])
173

    
174
    AssertCommand(["gnt-group", "assign-nodes", "--force", orig_group, node1])
175
    AssertInGroup(orig_group, [node1])
176
    AssertInGroup(other_group, [node2])
177

    
178
    AssertCommand(["gnt-group", "assign-nodes", orig_group, node2])
179
    AssertInGroup(orig_group, [node1, node2])
180
  finally:
181
    AssertCommand(["gnt-group", "remove", other_group])