root / qa / qa_node.py @ 5ae7cd11
History | View | Annotate | Download (8.2 kB)
1 |
#
|
---|---|
2 |
#
|
3 |
|
4 |
# Copyright (C) 2007 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 utils |
23 |
from ganeti import constants |
24 |
|
25 |
import qa_config |
26 |
import qa_error |
27 |
import qa_utils |
28 |
|
29 |
from qa_utils import AssertEqual, AssertNotEqual, StartSSH |
30 |
|
31 |
|
32 |
def _NodeAdd(node, readd=False): |
33 |
master = qa_config.GetMasterNode() |
34 |
|
35 |
if not readd and node.get('_added', False): |
36 |
raise qa_error.Error("Node %s already in cluster" % node['primary']) |
37 |
elif readd and not node.get('_added', False): |
38 |
raise qa_error.Error("Node %s not yet in cluster" % node['primary']) |
39 |
|
40 |
cmd = ['gnt-node', 'add', "--no-ssh-key-check"] |
41 |
if node.get('secondary', None): |
42 |
cmd.append('--secondary-ip=%s' % node['secondary']) |
43 |
if readd:
|
44 |
cmd.append('--readd')
|
45 |
cmd.append(node['primary'])
|
46 |
AssertEqual(StartSSH(master['primary'],
|
47 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
48 |
|
49 |
node['_added'] = True |
50 |
|
51 |
|
52 |
def _NodeRemove(node): |
53 |
master = qa_config.GetMasterNode() |
54 |
|
55 |
cmd = ['gnt-node', 'remove', node['primary']] |
56 |
AssertEqual(StartSSH(master['primary'],
|
57 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
58 |
node['_added'] = False |
59 |
|
60 |
|
61 |
def TestNodeAddAll(): |
62 |
"""Adding all nodes to cluster."""
|
63 |
master = qa_config.GetMasterNode() |
64 |
for node in qa_config.get('nodes'): |
65 |
if node != master:
|
66 |
_NodeAdd(node, readd=False)
|
67 |
|
68 |
|
69 |
def MarkNodeAddedAll(): |
70 |
"""Mark all nodes as added.
|
71 |
|
72 |
This is useful if we don't create the cluster ourselves (in qa).
|
73 |
|
74 |
"""
|
75 |
master = qa_config.GetMasterNode() |
76 |
for node in qa_config.get('nodes'): |
77 |
if node != master:
|
78 |
node['_added'] = True |
79 |
|
80 |
|
81 |
def TestNodeRemoveAll(): |
82 |
"""Removing all nodes from cluster."""
|
83 |
master = qa_config.GetMasterNode() |
84 |
for node in qa_config.get('nodes'): |
85 |
if node != master:
|
86 |
_NodeRemove(node) |
87 |
|
88 |
|
89 |
def TestNodeReadd(node): |
90 |
"""gnt-node add --readd"""
|
91 |
_NodeAdd(node, readd=True)
|
92 |
|
93 |
|
94 |
def TestNodeInfo(): |
95 |
"""gnt-node info"""
|
96 |
master = qa_config.GetMasterNode() |
97 |
|
98 |
cmd = ['gnt-node', 'info'] |
99 |
AssertEqual(StartSSH(master['primary'],
|
100 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
101 |
|
102 |
|
103 |
def TestNodeVolumes(): |
104 |
"""gnt-node volumes"""
|
105 |
master = qa_config.GetMasterNode() |
106 |
|
107 |
cmd = ['gnt-node', 'volumes'] |
108 |
AssertEqual(StartSSH(master['primary'],
|
109 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
110 |
|
111 |
|
112 |
def TestNodeStorage(): |
113 |
"""gnt-node storage"""
|
114 |
master = qa_config.GetMasterNode() |
115 |
|
116 |
for storage_type in constants.VALID_STORAGE_TYPES: |
117 |
# Test simple list
|
118 |
cmd = ["gnt-node", "list-storage", "--storage-type", storage_type] |
119 |
AssertEqual(StartSSH(master["primary"],
|
120 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
121 |
|
122 |
# Test all storage fields
|
123 |
cmd = ["gnt-node", "list-storage", "--storage-type", storage_type, |
124 |
"--output=%s" % ",".join(list(constants.VALID_STORAGE_FIELDS) + |
125 |
[constants.SF_NODE, constants.SF_TYPE])] |
126 |
AssertEqual(StartSSH(master["primary"],
|
127 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
128 |
|
129 |
# Get list of valid storage devices
|
130 |
cmd = ["gnt-node", "list-storage", "--storage-type", storage_type, |
131 |
"--output=node,name,allocatable", "--separator=|", |
132 |
"--no-headers"]
|
133 |
output = qa_utils.GetCommandOutput(master["primary"],
|
134 |
utils.ShellQuoteArgs(cmd)) |
135 |
|
136 |
# Test with up to two devices
|
137 |
testdevcount = 2
|
138 |
|
139 |
for line in output.splitlines()[:testdevcount]: |
140 |
(node_name, st_name, st_allocatable) = line.split("|")
|
141 |
|
142 |
# Dummy modification without any changes
|
143 |
cmd = ["gnt-node", "modify-storage", node_name, storage_type, st_name] |
144 |
AssertEqual(StartSSH(master["primary"],
|
145 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
146 |
|
147 |
# Make sure we end up with the same value as before
|
148 |
if st_allocatable.lower() == "y": |
149 |
test_allocatable = ["no", "yes"] |
150 |
else:
|
151 |
test_allocatable = ["yes", "no"] |
152 |
|
153 |
fail = (constants.SF_ALLOCATABLE not in |
154 |
constants.MODIFIABLE_STORAGE_FIELDS.get(storage_type, [])) |
155 |
|
156 |
if fail:
|
157 |
assert_fn = AssertNotEqual |
158 |
else:
|
159 |
assert_fn = AssertEqual |
160 |
|
161 |
for i in test_allocatable: |
162 |
cmd = ["gnt-node", "modify-storage", "--allocatable", i, |
163 |
node_name, storage_type, st_name] |
164 |
assert_fn(StartSSH(master["primary"],
|
165 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
166 |
|
167 |
# Verify list output
|
168 |
cmd = ["gnt-node", "list-storage", "--storage-type", storage_type, |
169 |
"--output=name,allocatable", "--separator=|", |
170 |
"--no-headers", node_name]
|
171 |
listout = qa_utils.GetCommandOutput(master["primary"],
|
172 |
utils.ShellQuoteArgs(cmd)) |
173 |
for line in listout.splitlines(): |
174 |
(vfy_name, vfy_allocatable) = line.split("|")
|
175 |
if vfy_name == st_name and not fail: |
176 |
AssertEqual(vfy_allocatable, i[0].upper())
|
177 |
else:
|
178 |
AssertEqual(vfy_allocatable, st_allocatable) |
179 |
|
180 |
# Test repair functionality
|
181 |
cmd = ["gnt-node", "repair-storage", node_name, storage_type, st_name] |
182 |
|
183 |
if (constants.SO_FIX_CONSISTENCY in |
184 |
constants.VALID_STORAGE_OPERATIONS.get(storage_type, [])): |
185 |
assert_fn = AssertEqual |
186 |
else:
|
187 |
assert_fn = AssertNotEqual |
188 |
|
189 |
assert_fn(StartSSH(master["primary"],
|
190 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
191 |
|
192 |
|
193 |
def TestNodeFailover(node, node2): |
194 |
"""gnt-node failover"""
|
195 |
master = qa_config.GetMasterNode() |
196 |
|
197 |
if qa_utils.GetNodeInstances(node2, secondaries=False): |
198 |
raise qa_error.UnusableNodeError("Secondary node has at least one" |
199 |
" primary instance. This test requires"
|
200 |
" it to have no primary instances.")
|
201 |
|
202 |
# Fail over to secondary node
|
203 |
cmd = ['gnt-node', 'failover', '-f', node['primary']] |
204 |
AssertEqual(StartSSH(master['primary'],
|
205 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
206 |
|
207 |
# ... and back again.
|
208 |
cmd = ['gnt-node', 'failover', '-f', node2['primary']] |
209 |
AssertEqual(StartSSH(master['primary'],
|
210 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
211 |
|
212 |
|
213 |
def TestNodeEvacuate(node, node2): |
214 |
"""gnt-node evacuate"""
|
215 |
master = qa_config.GetMasterNode() |
216 |
|
217 |
node3 = qa_config.AcquireNode(exclude=[node, node2]) |
218 |
try:
|
219 |
if qa_utils.GetNodeInstances(node3, secondaries=True): |
220 |
raise qa_error.UnusableNodeError("Evacuation node has at least one" |
221 |
" secondary instance. This test requires"
|
222 |
" it to have no secondary instances.")
|
223 |
|
224 |
# Evacuate all secondary instances
|
225 |
cmd = ['gnt-node', 'evacuate', '-f', |
226 |
"--new-secondary=%s" % node3['primary'], node2['primary']] |
227 |
AssertEqual(StartSSH(master['primary'],
|
228 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
229 |
|
230 |
# ... and back again.
|
231 |
cmd = ['gnt-node', 'evacuate', '-f', |
232 |
"--new-secondary=%s" % node2['primary'], node3['primary']] |
233 |
AssertEqual(StartSSH(master['primary'],
|
234 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
235 |
finally:
|
236 |
qa_config.ReleaseNode(node3) |
237 |
|
238 |
|
239 |
def TestNodeModify(node): |
240 |
"""gnt-node modify"""
|
241 |
master = qa_config.GetMasterNode() |
242 |
|
243 |
for flag in ["master-candidate", "drained", "offline"]: |
244 |
for value in ["yes", "no"]: |
245 |
cmd = ["gnt-node", "modify", "--force", |
246 |
"--%s=%s" % (flag, value), node["primary"]] |
247 |
AssertEqual(StartSSH(master["primary"],
|
248 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
249 |
|
250 |
cmd = ["gnt-node", "modify", "--master-candidate=yes", "--auto-promote", |
251 |
node["primary"]]
|
252 |
AssertEqual(StartSSH(master["primary"],
|
253 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|