Statistics
| Branch: | Tag: | Revision:

root / qa / qa_group.py @ 3582eef6

History | View | Annotate | Download (4.7 kB)

1
#
2
#
3

    
4
# Copyright (C) 2010, 2011 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 TestGroupAddRemoveRename():
37
  """gnt-group add/remove/rename"""
38
  groups = qa_config.get("groups", {})
39

    
40
  existing_group_with_nodes = groups.get("group-with-nodes",
41
                                         constants.INITIAL_NODE_GROUP_NAME)
42
  group1, group2, group3 = groups.get("inexistent-groups",
43
                                      ["group1", "group2", "group3"])[:3]
44

    
45
  AssertCommand(["gnt-group", "add", group1])
46
  AssertCommand(["gnt-group", "add", group2])
47
  AssertCommand(["gnt-group", "add", group2], fail=True)
48
  AssertCommand(["gnt-group", "add", existing_group_with_nodes], fail=True)
49

    
50
  AssertCommand(["gnt-group", "rename", group1, group2], fail=True)
51
  AssertCommand(["gnt-group", "rename", group1, group3])
52

    
53
  try:
54
    AssertCommand(["gnt-group", "rename", existing_group_with_nodes, group1])
55

    
56
    AssertCommand(["gnt-group", "remove", group2])
57
    AssertCommand(["gnt-group", "remove", group3])
58
    AssertCommand(["gnt-group", "remove", group1], fail=True)
59
  finally:
60
    # Try to ensure idempotency re groups that already existed.
61
    AssertCommand(["gnt-group", "rename", group1, existing_group_with_nodes])
62

    
63

    
64
def TestGroupAddWithOptions():
65
  """gnt-group add with options"""
66
  groups = qa_config.get("groups", {})
67
  group1 = groups.get("inexistent-groups", ["group1"])[0]
68

    
69
  AssertCommand(["gnt-group", "add", "--alloc-policy", "notvalid", group1],
70
                fail=True)
71

    
72
  AssertCommand(["gnt-group", "add", "--alloc-policy", "last_resort",
73
                 "--node-parameters", "oob_program=/bin/true", group1])
74

    
75
  AssertCommand(["gnt-group", "remove", group1])
76

    
77

    
78
def TestGroupModify():
79
  """gnt-group modify"""
80
  groups = qa_config.get("groups", {})
81
  group1 = groups.get("inexistent-groups", ["group1"])[0]
82

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

    
85
  try:
86
    AssertCommand(["gnt-group", "modify", "--alloc-policy", "unallocable",
87
                   "--node-parameters", "oob_program=/bin/false", group1])
88
    AssertCommand(["gnt-group", "modify",
89
                   "--alloc-policy", "notvalid", group1], fail=True)
90
  finally:
91
    AssertCommand(["gnt-group", "remove", group1])
92

    
93

    
94
def TestGroupList():
95
  """gnt-group list"""
96
  qa_utils.GenericQueryTest("gnt-group", query.GROUP_FIELDS.keys())
97

    
98

    
99
def TestGroupListFields():
100
  """gnt-group list-fields"""
101
  qa_utils.GenericQueryFieldsTest("gnt-group", query.GROUP_FIELDS.keys())
102

    
103

    
104
def TestAssignNodesIncludingSplit(orig_group, node1, node2):
105
  """gnt-group assign-nodes --force
106

107
  Expects node1 and node2 to be primary and secondary for a common instance.
108

109
  """
110
  assert node1 != node2
111
  groups = qa_config.get("groups", {})
112
  other_group = groups.get("inexistent-groups", ["group1"])[0]
113

    
114
  master_node = qa_config.GetMasterNode()["primary"]
115

    
116
  def AssertInGroup(group, nodes):
117
    real_output = GetCommandOutput(master_node,
118
                                   "gnt-node list --no-headers -o group " +
119
                                   utils.ShellQuoteArgs(nodes))
120
    AssertEqual(real_output.splitlines(), [group] * len(nodes))
121

    
122
  AssertInGroup(orig_group, [node1, node2])
123
  AssertCommand(["gnt-group", "add", other_group])
124

    
125
  try:
126
    AssertCommand(["gnt-group", "assign-nodes", other_group, node1, node2])
127
    AssertInGroup(other_group, [node1, node2])
128

    
129
    # This should fail because moving node1 to orig_group would leave their
130
    # common instance split between orig_group and other_group.
131
    AssertCommand(["gnt-group", "assign-nodes", orig_group, node1], fail=True)
132
    AssertInGroup(other_group, [node1, node2])
133

    
134
    AssertCommand(["gnt-group", "assign-nodes", "--force", orig_group, node1])
135
    AssertInGroup(orig_group, [node1])
136
    AssertInGroup(other_group, [node2])
137

    
138
    AssertCommand(["gnt-group", "assign-nodes", orig_group, node2])
139
    AssertInGroup(orig_group, [node1, node2])
140
  finally:
141
    AssertCommand(["gnt-group", "remove", other_group])