Statistics
| Branch: | Tag: | Revision:

root / qa / qa_group.py @ 5fa0375e

History | View | Annotate | Download (4.8 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 fe508a9d Michael Hanselmann
def GetDefaultGroup():
37 fe508a9d Michael Hanselmann
  """Returns the default node group.
38 fe508a9d Michael Hanselmann

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

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

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