Revision 2f4b4f78 qa/qa_node.py
b/qa/qa_node.py | ||
---|---|---|
26 | 26 |
import qa_error |
27 | 27 |
import qa_utils |
28 | 28 |
|
29 |
from qa_utils import AssertEqual, AssertNotEqual, StartSSH
|
|
29 |
from qa_utils import AssertCommand
|
|
30 | 30 |
|
31 | 31 |
|
32 | 32 |
def _NodeAdd(node, readd=False): |
33 |
master = qa_config.GetMasterNode() |
|
34 |
|
|
35 | 33 |
if not readd and node.get('_added', False): |
36 | 34 |
raise qa_error.Error("Node %s already in cluster" % node['primary']) |
37 | 35 |
elif readd and not node.get('_added', False): |
... | ... | |
43 | 41 |
if readd: |
44 | 42 |
cmd.append('--readd') |
45 | 43 |
cmd.append(node['primary']) |
46 |
AssertEqual(StartSSH(master['primary'], |
|
47 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
|
44 |
|
|
45 |
AssertCommand(cmd)
|
|
48 | 46 |
|
49 | 47 |
node['_added'] = True |
50 | 48 |
|
51 | 49 |
|
52 | 50 |
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) |
|
51 |
AssertCommand(["gnt-node", "remove", node["primary"]]) |
|
58 | 52 |
node['_added'] = False |
59 | 53 |
|
60 | 54 |
|
... | ... | |
93 | 87 |
|
94 | 88 |
def TestNodeInfo(): |
95 | 89 |
"""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) |
|
90 |
AssertCommand(["gnt-node", "info"]) |
|
101 | 91 |
|
102 | 92 |
|
103 | 93 |
def TestNodeVolumes(): |
104 | 94 |
"""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) |
|
95 |
AssertCommand(["gnt-node", "volumes"]) |
|
110 | 96 |
|
111 | 97 |
|
112 | 98 |
def TestNodeStorage(): |
... | ... | |
115 | 101 |
|
116 | 102 |
for storage_type in constants.VALID_STORAGE_TYPES: |
117 | 103 |
# Test simple list |
118 |
cmd = ["gnt-node", "list-storage", "--storage-type", storage_type] |
|
119 |
AssertEqual(StartSSH(master["primary"], |
|
120 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
104 |
AssertCommand(["gnt-node", "list-storage", "--storage-type", storage_type]) |
|
121 | 105 |
|
122 | 106 |
# Test all storage fields |
123 | 107 |
cmd = ["gnt-node", "list-storage", "--storage-type", storage_type, |
124 | 108 |
"--output=%s" % ",".join(list(constants.VALID_STORAGE_FIELDS) + |
125 | 109 |
[constants.SF_NODE, constants.SF_TYPE])] |
126 |
AssertEqual(StartSSH(master["primary"], |
|
127 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
110 |
AssertCommand(cmd) |
|
128 | 111 |
|
129 | 112 |
# Get list of valid storage devices |
130 | 113 |
cmd = ["gnt-node", "list-storage", "--storage-type", storage_type, |
... | ... | |
141 | 124 |
|
142 | 125 |
# Dummy modification without any changes |
143 | 126 |
cmd = ["gnt-node", "modify-storage", node_name, storage_type, st_name] |
144 |
AssertEqual(StartSSH(master["primary"], |
|
145 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
127 |
AssertCommand(cmd) |
|
146 | 128 |
|
147 | 129 |
# Make sure we end up with the same value as before |
148 | 130 |
if st_allocatable.lower() == "y": |
... | ... | |
150 | 132 |
else: |
151 | 133 |
test_allocatable = ["yes", "no"] |
152 | 134 |
|
153 |
if (constants.SF_ALLOCATABLE in |
|
154 |
constants.MODIFIABLE_STORAGE_FIELDS.get(storage_type, [])): |
|
155 |
assert_fn = AssertEqual |
|
156 |
else: |
|
157 |
assert_fn = AssertNotEqual |
|
135 |
fail = (constants.SF_ALLOCATABLE not in |
|
136 |
constants.MODIFIABLE_STORAGE_FIELDS.get(storage_type, [])) |
|
158 | 137 |
|
159 | 138 |
for i in test_allocatable: |
160 |
cmd = ["gnt-node", "modify-storage", "--allocatable", i, |
|
161 |
node_name, storage_type, st_name] |
|
162 |
assert_fn(StartSSH(master["primary"], |
|
163 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
139 |
AssertCommand(["gnt-node", "modify-storage", "--allocatable", i, |
|
140 |
node_name, storage_type, st_name], fail=fail) |
|
164 | 141 |
|
165 | 142 |
# Test repair functionality |
166 |
cmd = ["gnt-node", "repair-storage", node_name, storage_type, st_name] |
|
167 |
|
|
168 |
if (constants.SO_FIX_CONSISTENCY in |
|
169 |
constants.VALID_STORAGE_OPERATIONS.get(storage_type, [])): |
|
170 |
assert_fn = AssertEqual |
|
171 |
else: |
|
172 |
assert_fn = AssertNotEqual |
|
173 |
|
|
174 |
assert_fn(StartSSH(master["primary"], |
|
175 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
143 |
fail = (constants.SO_FIX_CONSISTENCY not in |
|
144 |
constants.VALID_STORAGE_OPERATIONS.get(storage_type, [])) |
|
145 |
AssertCommand(["gnt-node", "repair-storage", node_name, |
|
146 |
storage_type, st_name], fail=fail) |
|
176 | 147 |
|
177 | 148 |
|
178 | 149 |
def TestNodeFailover(node, node2): |
179 | 150 |
"""gnt-node failover""" |
180 |
master = qa_config.GetMasterNode() |
|
181 |
|
|
182 | 151 |
if qa_utils.GetNodeInstances(node2, secondaries=False): |
183 | 152 |
raise qa_error.UnusableNodeError("Secondary node has at least one" |
184 | 153 |
" primary instance. This test requires" |
185 | 154 |
" it to have no primary instances.") |
186 | 155 |
|
187 | 156 |
# Fail over to secondary node |
188 |
cmd = ['gnt-node', 'failover', '-f', node['primary']] |
|
189 |
AssertEqual(StartSSH(master['primary'], |
|
190 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
157 |
AssertCommand(["gnt-node", "failover", "-f", node["primary"]]) |
|
191 | 158 |
|
192 | 159 |
# ... and back again. |
193 |
cmd = ['gnt-node', 'failover', '-f', node2['primary']] |
|
194 |
AssertEqual(StartSSH(master['primary'], |
|
195 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
160 |
AssertCommand(["gnt-node", "failover", "-f", node2["primary"]]) |
|
196 | 161 |
|
197 | 162 |
|
198 | 163 |
def TestNodeEvacuate(node, node2): |
199 | 164 |
"""gnt-node evacuate""" |
200 |
master = qa_config.GetMasterNode() |
|
201 |
|
|
202 | 165 |
node3 = qa_config.AcquireNode(exclude=[node, node2]) |
203 | 166 |
try: |
204 | 167 |
if qa_utils.GetNodeInstances(node3, secondaries=True): |
... | ... | |
207 | 170 |
" it to have no secondary instances.") |
208 | 171 |
|
209 | 172 |
# Evacuate all secondary instances |
210 |
cmd = ['gnt-node', 'evacuate', '-f', |
|
211 |
"--new-secondary=%s" % node3['primary'], node2['primary']] |
|
212 |
AssertEqual(StartSSH(master['primary'], |
|
213 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
173 |
AssertCommand(["gnt-node", "evacuate", "-f", |
|
174 |
"--new-secondary=%s" % node3["primary"], node2["primary"]]) |
|
214 | 175 |
|
215 | 176 |
# ... and back again. |
216 |
cmd = ['gnt-node', 'evacuate', '-f', |
|
217 |
"--new-secondary=%s" % node2['primary'], node3['primary']] |
|
218 |
AssertEqual(StartSSH(master['primary'], |
|
219 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
177 |
AssertCommand(["gnt-node", "evacuate", "-f", |
|
178 |
"--new-secondary=%s" % node2["primary"], node3["primary"]]) |
|
220 | 179 |
finally: |
221 | 180 |
qa_config.ReleaseNode(node3) |
222 | 181 |
|
223 | 182 |
|
224 | 183 |
def TestNodeModify(node): |
225 | 184 |
"""gnt-node modify""" |
226 |
master = qa_config.GetMasterNode() |
|
227 |
|
|
228 | 185 |
for flag in ["master-candidate", "drained", "offline"]: |
229 | 186 |
for value in ["yes", "no"]: |
230 |
cmd = ["gnt-node", "modify", "--force", |
|
231 |
"--%s=%s" % (flag, value), node["primary"]] |
|
232 |
AssertEqual(StartSSH(master["primary"], |
|
233 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
234 |
|
|
235 |
cmd = ["gnt-node", "modify", "--master-candidate=yes", "--auto-promote", |
|
236 |
node["primary"]] |
|
237 |
AssertEqual(StartSSH(master["primary"], |
|
238 |
utils.ShellQuoteArgs(cmd)).wait(), 0) |
|
187 |
AssertCommand(["gnt-node", "modify", "--force", |
|
188 |
"--%s=%s" % (flag, value), node["primary"]]) |
|
189 |
|
|
190 |
AssertCommand(["gnt-node", "modify", "--master-candidate=yes", |
|
191 |
"--auto-promote", node["primary"]]) |
Also available in: Unified diff