Statistics
| Branch: | Tag: | Revision:

root / qa / qa_group.py @ f3fd2c9d

History | View | Annotate | Download (4.7 kB)

1
#
2
#
3

    
4
# Copyright (C) 2010 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
from ganeti import constants
23
from ganeti import query
24
from ganeti import utils
25

    
26
import qa_config
27
import qa_utils
28

    
29
from qa_utils import AssertCommand, AssertEqual, GetCommandOutput
30

    
31

    
32
def TestGroupAddRemoveRename():
33
  """gnt-group add/remove/rename"""
34
  groups = qa_config.get("groups", {})
35

    
36
  existing_group_with_nodes = groups.get("group-with-nodes",
37
                                         constants.INITIAL_NODE_GROUP_NAME)
38
  group1, group2, group3 = groups.get("inexistent-groups",
39
                                      ["group1", "group2", "group3"])[:3]
40

    
41
  AssertCommand(["gnt-group", "add", group1])
42
  AssertCommand(["gnt-group", "add", group2])
43
  AssertCommand(["gnt-group", "add", group2], fail=True)
44
  AssertCommand(["gnt-group", "add", existing_group_with_nodes], fail=True)
45

    
46
  AssertCommand(["gnt-group", "rename", group1, group2], fail=True)
47
  AssertCommand(["gnt-group", "rename", group1, group3])
48

    
49
  try:
50
    AssertCommand(["gnt-group", "rename", existing_group_with_nodes, group1])
51

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

    
59

    
60
def TestGroupAddWithOptions():
61
  """gnt-group add with options"""
62
  groups = qa_config.get("groups", {})
63
  group1 = groups.get("inexistent-groups", ["group1"])[0]
64

    
65
  AssertCommand(["gnt-group", "add", "--alloc-policy", "notvalid", group1],
66
                fail=True)
67

    
68
  AssertCommand(["gnt-group", "add", "--alloc-policy", "last_resort",
69
                 "--node-parameters", "oob_program=/bin/true", group1])
70

    
71
  AssertCommand(["gnt-group", "remove", group1])
72

    
73

    
74
def TestGroupModify():
75
  """gnt-group modify"""
76
  groups = qa_config.get("groups", {})
77
  group1 = groups.get("inexistent-groups", ["group1"])[0]
78

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

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

    
89

    
90
def TestGroupList():
91
  """gnt-group list"""
92
  qa_utils.GenericQueryTest("gnt-group", query.GROUP_FIELDS.keys())
93

    
94

    
95
def TestGroupListFields():
96
  """gnt-group list-fields"""
97
  qa_utils.GenericQueryFieldsTest("gnt-group", query.GROUP_FIELDS.keys())
98

    
99

    
100
def TestAssignNodesIncludingSplit(orig_group, node1, node2):
101
  """gnt-group assign-nodes --force
102

103
  Expects node1 and node2 to be primary and secondary for a common instance.
104

105
  """
106
  assert node1 != node2
107
  groups = qa_config.get("groups", {})
108
  other_group = groups.get("inexistent-groups", ["group1"])[0]
109

    
110
  master_node = qa_config.GetMasterNode()["primary"]
111

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

    
118
  AssertInGroup(orig_group, [node1, node2])
119
  AssertCommand(["gnt-group", "add", other_group])
120

    
121
  try:
122
    AssertCommand(["gnt-group", "assign-nodes", other_group, node1, node2])
123
    AssertInGroup(other_group, [node1, node2])
124

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

    
130
    AssertCommand(["gnt-group", "assign-nodes", "--force", orig_group, node1])
131
    AssertInGroup(orig_group, [node1])
132
    AssertInGroup(other_group, [node2])
133

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