Statistics
| Branch: | Tag: | Revision:

root / qa / qa_group.py @ debian-2.6

History | View | Annotate | Download (5.5 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
  groups = qa_config.get("groups", {})
47

    
48
  existing_group_with_nodes = GetDefaultGroup()
49

    
50
  group1, group2, group3 = groups.get("inexistent-groups",
51
                                      ["group1", "group2", "group3"])[:3]
52

    
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)
57

    
58
  AssertCommand(["gnt-group", "rename", group1, group2], fail=True)
59
  AssertCommand(["gnt-group", "rename", group1, group3])
60

    
61
  try:
62
    AssertCommand(["gnt-group", "rename", existing_group_with_nodes, group1])
63

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

    
71

    
72
def TestGroupAddWithOptions():
73
  """gnt-group add with options"""
74
  groups = qa_config.get("groups", {})
75
  group1 = groups.get("inexistent-groups", ["group1"])[0]
76

    
77
  AssertCommand(["gnt-group", "add", "--alloc-policy", "notvalid", group1],
78
                fail=True)
79

    
80
  AssertCommand(["gnt-group", "add", "--alloc-policy", "last_resort",
81
                 "--node-parameters", "oob_program=/bin/true", group1])
82

    
83
  AssertCommand(["gnt-group", "remove", group1])
84

    
85

    
86
def TestGroupModify():
87
  """gnt-group modify"""
88
  groups = qa_config.get("groups", {})
89
  group1 = groups.get("inexistent-groups", ["group1"])[0]
90

    
91
  AssertCommand(["gnt-group", "add", group1])
92

    
93
  std_defaults = constants.IPOLICY_DEFAULTS[constants.ISPECS_STD]
94
  min_v = std_defaults[constants.ISPEC_MEM_SIZE] * 10
95
  max_v = min_v * 10
96

    
97
  try:
98
    AssertCommand(["gnt-group", "modify", "--alloc-policy", "unallocable",
99
                   "--node-parameters", "oob_program=/bin/false", group1])
100
    AssertCommand(["gnt-group", "modify",
101
                   "--alloc-policy", "notvalid", group1], fail=True)
102
    AssertCommand(["gnt-group", "modify", "--specs-mem-size",
103
                   "min=%s,max=%s,std=0" % (min_v, max_v), group1], fail=True)
104
    AssertCommand(["gnt-group", "modify", "--specs-mem-size",
105
                   "min=%s,max=%s" % (min_v, max_v), group1])
106
    AssertCommand(["gnt-group", "modify",
107
                   "--node-parameters", "spindle_count=10", group1])
108
    if qa_config.TestEnabled("htools"):
109
      AssertCommand(["hbal", "-L", "-G", group1])
110
    AssertCommand(["gnt-group", "modify",
111
                   "--node-parameters", "spindle_count=default", group1])
112
  finally:
113
    AssertCommand(["gnt-group", "remove", group1])
114

    
115

    
116
def TestGroupList():
117
  """gnt-group list"""
118
  qa_utils.GenericQueryTest("gnt-group", query.GROUP_FIELDS.keys())
119

    
120

    
121
def TestGroupListFields():
122
  """gnt-group list-fields"""
123
  qa_utils.GenericQueryFieldsTest("gnt-group", query.GROUP_FIELDS.keys())
124

    
125

    
126
def TestAssignNodesIncludingSplit(orig_group, node1, node2):
127
  """gnt-group assign-nodes --force
128

129
  Expects node1 and node2 to be primary and secondary for a common instance.
130

131
  """
132
  assert node1 != node2
133
  groups = qa_config.get("groups", {})
134
  other_group = groups.get("inexistent-groups", ["group1"])[0]
135

    
136
  master_node = qa_config.GetMasterNode()["primary"]
137

    
138
  def AssertInGroup(group, nodes):
139
    real_output = GetCommandOutput(master_node,
140
                                   "gnt-node list --no-headers -o group " +
141
                                   utils.ShellQuoteArgs(nodes))
142
    AssertEqual(real_output.splitlines(), [group] * len(nodes))
143

    
144
  AssertInGroup(orig_group, [node1, node2])
145
  AssertCommand(["gnt-group", "add", other_group])
146

    
147
  try:
148
    AssertCommand(["gnt-group", "assign-nodes", other_group, node1, node2])
149
    AssertInGroup(other_group, [node1, node2])
150

    
151
    # This should fail because moving node1 to orig_group would leave their
152
    # common instance split between orig_group and other_group.
153
    AssertCommand(["gnt-group", "assign-nodes", orig_group, node1], fail=True)
154
    AssertInGroup(other_group, [node1, node2])
155

    
156
    AssertCommand(["gnt-group", "assign-nodes", "--force", orig_group, node1])
157
    AssertInGroup(orig_group, [node1])
158
    AssertInGroup(other_group, [node2])
159

    
160
    AssertCommand(["gnt-group", "assign-nodes", orig_group, node2])
161
    AssertInGroup(orig_group, [node1, node2])
162
  finally:
163
    AssertCommand(["gnt-group", "remove", other_group])