Statistics
| Branch: | Tag: | Revision:

root / qa / qa_group.py @ ff699aa9

History | View | Annotate | Download (4.7 kB)

1 30131294 Adeodato Simo
#
2 30131294 Adeodato Simo
#
3 30131294 Adeodato Simo
4 3582eef6 Iustin Pop
# Copyright (C) 2010, 2011 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 66787da5 Adeodato Simo
def TestGroupAddRemoveRename():
37 66787da5 Adeodato Simo
  """gnt-group add/remove/rename"""
38 66787da5 Adeodato Simo
  groups = qa_config.get("groups", {})
39 66787da5 Adeodato Simo
40 75cf411a Adeodato Simo
  existing_group_with_nodes = groups.get("group-with-nodes",
41 75cf411a Adeodato Simo
                                         constants.INITIAL_NODE_GROUP_NAME)
42 66787da5 Adeodato Simo
  group1, group2, group3 = groups.get("inexistent-groups",
43 66787da5 Adeodato Simo
                                      ["group1", "group2", "group3"])[:3]
44 66787da5 Adeodato Simo
45 66787da5 Adeodato Simo
  AssertCommand(["gnt-group", "add", group1])
46 66787da5 Adeodato Simo
  AssertCommand(["gnt-group", "add", group2])
47 66787da5 Adeodato Simo
  AssertCommand(["gnt-group", "add", group2], fail=True)
48 66787da5 Adeodato Simo
  AssertCommand(["gnt-group", "add", existing_group_with_nodes], fail=True)
49 66787da5 Adeodato Simo
50 66787da5 Adeodato Simo
  AssertCommand(["gnt-group", "rename", group1, group2], fail=True)
51 66787da5 Adeodato Simo
  AssertCommand(["gnt-group", "rename", group1, group3])
52 66787da5 Adeodato Simo
53 66787da5 Adeodato Simo
  try:
54 66787da5 Adeodato Simo
    AssertCommand(["gnt-group", "rename", existing_group_with_nodes, group1])
55 66787da5 Adeodato Simo
56 66787da5 Adeodato Simo
    AssertCommand(["gnt-group", "remove", group2])
57 66787da5 Adeodato Simo
    AssertCommand(["gnt-group", "remove", group3])
58 66787da5 Adeodato Simo
    AssertCommand(["gnt-group", "remove", group1], fail=True)
59 66787da5 Adeodato Simo
  finally:
60 66787da5 Adeodato Simo
    # Try to ensure idempotency re groups that already existed.
61 66787da5 Adeodato Simo
    AssertCommand(["gnt-group", "rename", group1, existing_group_with_nodes])
62 66787da5 Adeodato Simo
63 66787da5 Adeodato Simo
64 4b10fb65 Adeodato Simo
def TestGroupAddWithOptions():
65 4b10fb65 Adeodato Simo
  """gnt-group add with options"""
66 4b10fb65 Adeodato Simo
  groups = qa_config.get("groups", {})
67 4b10fb65 Adeodato Simo
  group1 = groups.get("inexistent-groups", ["group1"])[0]
68 4b10fb65 Adeodato Simo
69 4b10fb65 Adeodato Simo
  AssertCommand(["gnt-group", "add", "--alloc-policy", "notvalid", group1],
70 4b10fb65 Adeodato Simo
                fail=True)
71 4b10fb65 Adeodato Simo
72 4b10fb65 Adeodato Simo
  AssertCommand(["gnt-group", "add", "--alloc-policy", "last_resort",
73 4b10fb65 Adeodato Simo
                 "--node-parameters", "oob_program=/bin/true", group1])
74 4b10fb65 Adeodato Simo
75 4b10fb65 Adeodato Simo
  AssertCommand(["gnt-group", "remove", group1])
76 4b10fb65 Adeodato Simo
77 4b10fb65 Adeodato Simo
78 4b10fb65 Adeodato Simo
def TestGroupModify():
79 4b10fb65 Adeodato Simo
  """gnt-group modify"""
80 4b10fb65 Adeodato Simo
  groups = qa_config.get("groups", {})
81 4b10fb65 Adeodato Simo
  group1 = groups.get("inexistent-groups", ["group1"])[0]
82 4b10fb65 Adeodato Simo
83 4b10fb65 Adeodato Simo
  AssertCommand(["gnt-group", "add", group1])
84 4b10fb65 Adeodato Simo
85 4b10fb65 Adeodato Simo
  try:
86 4b10fb65 Adeodato Simo
    AssertCommand(["gnt-group", "modify", "--alloc-policy", "unallocable",
87 4b10fb65 Adeodato Simo
                   "--node-parameters", "oob_program=/bin/false", group1])
88 4b10fb65 Adeodato Simo
    AssertCommand(["gnt-group", "modify",
89 4b10fb65 Adeodato Simo
                   "--alloc-policy", "notvalid", group1], fail=True)
90 4b10fb65 Adeodato Simo
  finally:
91 4b10fb65 Adeodato Simo
    AssertCommand(["gnt-group", "remove", group1])
92 4b10fb65 Adeodato Simo
93 4b10fb65 Adeodato Simo
94 7ab8b7d7 Adeodato Simo
def TestGroupList():
95 30131294 Adeodato Simo
  """gnt-group list"""
96 7ab8b7d7 Adeodato Simo
  qa_utils.GenericQueryTest("gnt-group", query.GROUP_FIELDS.keys())
97 30131294 Adeodato Simo
98 30131294 Adeodato Simo
99 7ab8b7d7 Adeodato Simo
def TestGroupListFields():
100 7ab8b7d7 Adeodato Simo
  """gnt-group list-fields"""
101 7ab8b7d7 Adeodato Simo
  qa_utils.GenericQueryFieldsTest("gnt-group", query.GROUP_FIELDS.keys())
102 f3fd2c9d Adeodato Simo
103 f3fd2c9d Adeodato Simo
104 f3fd2c9d Adeodato Simo
def TestAssignNodesIncludingSplit(orig_group, node1, node2):
105 f3fd2c9d Adeodato Simo
  """gnt-group assign-nodes --force
106 f3fd2c9d Adeodato Simo

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

109 f3fd2c9d Adeodato Simo
  """
110 f3fd2c9d Adeodato Simo
  assert node1 != node2
111 f3fd2c9d Adeodato Simo
  groups = qa_config.get("groups", {})
112 f3fd2c9d Adeodato Simo
  other_group = groups.get("inexistent-groups", ["group1"])[0]
113 f3fd2c9d Adeodato Simo
114 f3fd2c9d Adeodato Simo
  master_node = qa_config.GetMasterNode()["primary"]
115 f3fd2c9d Adeodato Simo
116 f3fd2c9d Adeodato Simo
  def AssertInGroup(group, nodes):
117 f3fd2c9d Adeodato Simo
    real_output = GetCommandOutput(master_node,
118 f3fd2c9d Adeodato Simo
                                   "gnt-node list --no-headers -o group " +
119 f3fd2c9d Adeodato Simo
                                   utils.ShellQuoteArgs(nodes))
120 f3fd2c9d Adeodato Simo
    AssertEqual(real_output.splitlines(), [group] * len(nodes))
121 f3fd2c9d Adeodato Simo
122 f3fd2c9d Adeodato Simo
  AssertInGroup(orig_group, [node1, node2])
123 f3fd2c9d Adeodato Simo
  AssertCommand(["gnt-group", "add", other_group])
124 f3fd2c9d Adeodato Simo
125 f3fd2c9d Adeodato Simo
  try:
126 f3fd2c9d Adeodato Simo
    AssertCommand(["gnt-group", "assign-nodes", other_group, node1, node2])
127 f3fd2c9d Adeodato Simo
    AssertInGroup(other_group, [node1, node2])
128 f3fd2c9d Adeodato Simo
129 f3fd2c9d Adeodato Simo
    # This should fail because moving node1 to orig_group would leave their
130 f3fd2c9d Adeodato Simo
    # common instance split between orig_group and other_group.
131 f3fd2c9d Adeodato Simo
    AssertCommand(["gnt-group", "assign-nodes", orig_group, node1], fail=True)
132 f3fd2c9d Adeodato Simo
    AssertInGroup(other_group, [node1, node2])
133 f3fd2c9d Adeodato Simo
134 f3fd2c9d Adeodato Simo
    AssertCommand(["gnt-group", "assign-nodes", "--force", orig_group, node1])
135 f3fd2c9d Adeodato Simo
    AssertInGroup(orig_group, [node1])
136 f3fd2c9d Adeodato Simo
    AssertInGroup(other_group, [node2])
137 f3fd2c9d Adeodato Simo
138 f3fd2c9d Adeodato Simo
    AssertCommand(["gnt-group", "assign-nodes", orig_group, node2])
139 f3fd2c9d Adeodato Simo
    AssertInGroup(orig_group, [node1, node2])
140 f3fd2c9d Adeodato Simo
  finally:
141 f3fd2c9d Adeodato Simo
    AssertCommand(["gnt-group", "remove", other_group])