root / qa / qa_node.py @ 8e1db003
History | View | Annotate | Download (6.8 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 TestNodeRemoveAll(): |
70 |
"""Removing all nodes from cluster."""
|
71 |
master = qa_config.GetMasterNode() |
72 |
for node in qa_config.get('nodes'): |
73 |
if node != master:
|
74 |
_NodeRemove(node) |
75 |
|
76 |
|
77 |
def TestNodeReadd(node): |
78 |
"""gnt-node add --readd"""
|
79 |
_NodeAdd(node, readd=True)
|
80 |
|
81 |
|
82 |
def TestNodeInfo(): |
83 |
"""gnt-node info"""
|
84 |
master = qa_config.GetMasterNode() |
85 |
|
86 |
cmd = ['gnt-node', 'info'] |
87 |
AssertEqual(StartSSH(master['primary'],
|
88 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
89 |
|
90 |
|
91 |
def TestNodeVolumes(): |
92 |
"""gnt-node volumes"""
|
93 |
master = qa_config.GetMasterNode() |
94 |
|
95 |
cmd = ['gnt-node', 'volumes'] |
96 |
AssertEqual(StartSSH(master['primary'],
|
97 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
98 |
|
99 |
|
100 |
def TestNodeStorage(): |
101 |
"""gnt-node storage"""
|
102 |
master = qa_config.GetMasterNode() |
103 |
|
104 |
for storage_type in constants.VALID_STORAGE_TYPES: |
105 |
# Test simple list
|
106 |
cmd = ["gnt-node", "list-storage", "--storage-type", storage_type] |
107 |
AssertEqual(StartSSH(master["primary"],
|
108 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
109 |
|
110 |
# Test all storage fields
|
111 |
cmd = ["gnt-node", "list-storage", "--storage-type", storage_type, |
112 |
"--output=%s" % ",".join(list(constants.VALID_STORAGE_FIELDS) + |
113 |
[constants.SF_NODE, constants.SF_TYPE])] |
114 |
AssertEqual(StartSSH(master["primary"],
|
115 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
116 |
|
117 |
# Get list of valid storage devices
|
118 |
cmd = ["gnt-node", "list-storage", "--storage-type", storage_type, |
119 |
"--output=node,name,allocatable", "--separator=|", |
120 |
"--no-headers"]
|
121 |
output = qa_utils.GetCommandOutput(master["primary"],
|
122 |
utils.ShellQuoteArgs(cmd)) |
123 |
|
124 |
# Test with up to two devices
|
125 |
testdevcount = 2
|
126 |
|
127 |
for line in output.splitlines()[:testdevcount]: |
128 |
(node_name, st_name, st_allocatable) = line.split("|")
|
129 |
|
130 |
# Dummy modification without any changes
|
131 |
cmd = ["gnt-node", "modify-storage", node_name, storage_type, st_name] |
132 |
AssertEqual(StartSSH(master["primary"],
|
133 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
134 |
|
135 |
# Make sure we end up with the same value as before
|
136 |
if st_allocatable.lower() == "y": |
137 |
test_allocatable = ["no", "yes"] |
138 |
else:
|
139 |
test_allocatable = ["yes", "no"] |
140 |
|
141 |
if (constants.SF_ALLOCATABLE in |
142 |
constants.MODIFIABLE_STORAGE_FIELDS.get(storage_type, [])): |
143 |
assert_fn = AssertEqual |
144 |
else:
|
145 |
assert_fn = AssertNotEqual |
146 |
|
147 |
for i in test_allocatable: |
148 |
cmd = ["gnt-node", "modify-storage", "--allocatable", i, |
149 |
node_name, storage_type, st_name] |
150 |
assert_fn(StartSSH(master["primary"],
|
151 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
152 |
|
153 |
# Test repair functionality
|
154 |
cmd = ["gnt-node", "repair-storage", node_name, storage_type, st_name] |
155 |
|
156 |
if (constants.SO_FIX_CONSISTENCY in |
157 |
constants.VALID_STORAGE_OPERATIONS.get(storage_type, [])): |
158 |
assert_fn = AssertEqual |
159 |
else:
|
160 |
assert_fn = AssertNotEqual |
161 |
|
162 |
assert_fn(StartSSH(master["primary"],
|
163 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
164 |
|
165 |
|
166 |
def TestNodeFailover(node, node2): |
167 |
"""gnt-node failover"""
|
168 |
master = qa_config.GetMasterNode() |
169 |
|
170 |
if qa_utils.GetNodeInstances(node2, secondaries=False): |
171 |
raise qa_error.UnusableNodeError("Secondary node has at least one" |
172 |
" primary instance. This test requires"
|
173 |
" it to have no primary instances.")
|
174 |
|
175 |
# Fail over to secondary node
|
176 |
cmd = ['gnt-node', 'failover', '-f', node['primary']] |
177 |
AssertEqual(StartSSH(master['primary'],
|
178 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
179 |
|
180 |
# ... and back again.
|
181 |
cmd = ['gnt-node', 'failover', '-f', node2['primary']] |
182 |
AssertEqual(StartSSH(master['primary'],
|
183 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
184 |
|
185 |
|
186 |
def TestNodeEvacuate(node, node2): |
187 |
"""gnt-node evacuate"""
|
188 |
master = qa_config.GetMasterNode() |
189 |
|
190 |
node3 = qa_config.AcquireNode(exclude=[node, node2]) |
191 |
try:
|
192 |
if qa_utils.GetNodeInstances(node3, secondaries=True): |
193 |
raise qa_error.UnusableNodeError("Evacuation node has at least one" |
194 |
" secondary instance. This test requires"
|
195 |
" it to have no secondary instances.")
|
196 |
|
197 |
# Evacuate all secondary instances
|
198 |
cmd = ['gnt-node', 'evacuate', '-f', |
199 |
"--new-secondary=%s" % node3['primary'], node2['primary']] |
200 |
AssertEqual(StartSSH(master['primary'],
|
201 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
202 |
|
203 |
# ... and back again.
|
204 |
cmd = ['gnt-node', 'evacuate', '-f', |
205 |
"--new-secondary=%s" % node2['primary'], node3['primary']] |
206 |
AssertEqual(StartSSH(master['primary'],
|
207 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
208 |
finally:
|
209 |
qa_config.ReleaseNode(node3) |