root / qa / qa_node.py @ f8c9fa5c
History | View | Annotate | Download (7 kB)
1 | c68d1f43 | Michael Hanselmann | #
|
---|---|---|---|
2 | c68d1f43 | Michael Hanselmann | #
|
3 | c68d1f43 | Michael Hanselmann | |
4 | cec9845c | Michael Hanselmann | # Copyright (C) 2007 Google Inc.
|
5 | cec9845c | Michael Hanselmann | #
|
6 | cec9845c | Michael Hanselmann | # This program is free software; you can redistribute it and/or modify
|
7 | cec9845c | Michael Hanselmann | # it under the terms of the GNU General Public License as published by
|
8 | cec9845c | Michael Hanselmann | # the Free Software Foundation; either version 2 of the License, or
|
9 | cec9845c | Michael Hanselmann | # (at your option) any later version.
|
10 | cec9845c | Michael Hanselmann | #
|
11 | cec9845c | Michael Hanselmann | # This program is distributed in the hope that it will be useful, but
|
12 | cec9845c | Michael Hanselmann | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | cec9845c | Michael Hanselmann | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | cec9845c | Michael Hanselmann | # General Public License for more details.
|
15 | cec9845c | Michael Hanselmann | #
|
16 | cec9845c | Michael Hanselmann | # You should have received a copy of the GNU General Public License
|
17 | cec9845c | Michael Hanselmann | # along with this program; if not, write to the Free Software
|
18 | cec9845c | Michael Hanselmann | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | cec9845c | Michael Hanselmann | # 02110-1301, USA.
|
20 | cec9845c | Michael Hanselmann | |
21 | cec9845c | Michael Hanselmann | |
22 | cec9845c | Michael Hanselmann | from ganeti import utils |
23 | 8e1db003 | Michael Hanselmann | from ganeti import constants |
24 | cec9845c | Michael Hanselmann | |
25 | cec9845c | Michael Hanselmann | import qa_config |
26 | cec9845c | Michael Hanselmann | import qa_error |
27 | 4b62db14 | Michael Hanselmann | import qa_utils |
28 | cec9845c | Michael Hanselmann | |
29 | 8e1db003 | Michael Hanselmann | from qa_utils import AssertEqual, AssertNotEqual, StartSSH |
30 | cec9845c | Michael Hanselmann | |
31 | cec9845c | Michael Hanselmann | |
32 | e7c6e02b | Michael Hanselmann | def _NodeAdd(node, readd=False): |
33 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
34 | cec9845c | Michael Hanselmann | |
35 | e7c6e02b | Michael Hanselmann | if not readd and node.get('_added', False): |
36 | cec9845c | Michael Hanselmann | raise qa_error.Error("Node %s already in cluster" % node['primary']) |
37 | e7c6e02b | Michael Hanselmann | elif readd and not node.get('_added', False): |
38 | 102b115b | Michael Hanselmann | raise qa_error.Error("Node %s not yet in cluster" % node['primary']) |
39 | cec9845c | Michael Hanselmann | |
40 | 28a90aff | Michael Hanselmann | cmd = ['gnt-node', 'add', "--no-ssh-key-check"] |
41 | cec9845c | Michael Hanselmann | if node.get('secondary', None): |
42 | cec9845c | Michael Hanselmann | cmd.append('--secondary-ip=%s' % node['secondary']) |
43 | e7c6e02b | Michael Hanselmann | if readd:
|
44 | e7c6e02b | Michael Hanselmann | cmd.append('--readd')
|
45 | cec9845c | Michael Hanselmann | cmd.append(node['primary'])
|
46 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
47 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
48 | cec9845c | Michael Hanselmann | |
49 | cec9845c | Michael Hanselmann | node['_added'] = True |
50 | cec9845c | Michael Hanselmann | |
51 | cec9845c | Michael Hanselmann | |
52 | cec9845c | Michael Hanselmann | def _NodeRemove(node): |
53 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
54 | cec9845c | Michael Hanselmann | |
55 | cec9845c | Michael Hanselmann | cmd = ['gnt-node', 'remove', node['primary']] |
56 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
57 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
58 | cec9845c | Michael Hanselmann | node['_added'] = False |
59 | cec9845c | Michael Hanselmann | |
60 | cec9845c | Michael Hanselmann | |
61 | cec9845c | Michael Hanselmann | def TestNodeAddAll(): |
62 | cec9845c | Michael Hanselmann | """Adding all nodes to cluster."""
|
63 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
64 | cec9845c | Michael Hanselmann | for node in qa_config.get('nodes'): |
65 | cec9845c | Michael Hanselmann | if node != master:
|
66 | e7c6e02b | Michael Hanselmann | _NodeAdd(node, readd=False)
|
67 | cec9845c | Michael Hanselmann | |
68 | cec9845c | Michael Hanselmann | |
69 | 8e671b7c | Iustin Pop | def MarkNodeAddedAll(): |
70 | 8e671b7c | Iustin Pop | """Mark all nodes as added.
|
71 | 8e671b7c | Iustin Pop |
|
72 | 8e671b7c | Iustin Pop | This is useful if we don't create the cluster ourselves (in qa).
|
73 | 8e671b7c | Iustin Pop |
|
74 | 8e671b7c | Iustin Pop | """
|
75 | 8e671b7c | Iustin Pop | master = qa_config.GetMasterNode() |
76 | 8e671b7c | Iustin Pop | for node in qa_config.get('nodes'): |
77 | 8e671b7c | Iustin Pop | if node != master:
|
78 | 8e671b7c | Iustin Pop | node['_added'] = True |
79 | 8e671b7c | Iustin Pop | |
80 | 8e671b7c | Iustin Pop | |
81 | cec9845c | Michael Hanselmann | def TestNodeRemoveAll(): |
82 | cec9845c | Michael Hanselmann | """Removing all nodes from cluster."""
|
83 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
84 | cec9845c | Michael Hanselmann | for node in qa_config.get('nodes'): |
85 | cec9845c | Michael Hanselmann | if node != master:
|
86 | cec9845c | Michael Hanselmann | _NodeRemove(node) |
87 | cec9845c | Michael Hanselmann | |
88 | cec9845c | Michael Hanselmann | |
89 | e7c6e02b | Michael Hanselmann | def TestNodeReadd(node): |
90 | e7c6e02b | Michael Hanselmann | """gnt-node add --readd"""
|
91 | e7c6e02b | Michael Hanselmann | _NodeAdd(node, readd=True)
|
92 | e7c6e02b | Michael Hanselmann | |
93 | e7c6e02b | Michael Hanselmann | |
94 | cec9845c | Michael Hanselmann | def TestNodeInfo(): |
95 | cec9845c | Michael Hanselmann | """gnt-node info"""
|
96 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
97 | cec9845c | Michael Hanselmann | |
98 | cec9845c | Michael Hanselmann | cmd = ['gnt-node', 'info'] |
99 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
100 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
101 | cec9845c | Michael Hanselmann | |
102 | cec9845c | Michael Hanselmann | |
103 | cec9845c | Michael Hanselmann | def TestNodeVolumes(): |
104 | cec9845c | Michael Hanselmann | """gnt-node volumes"""
|
105 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
106 | cec9845c | Michael Hanselmann | |
107 | cec9845c | Michael Hanselmann | cmd = ['gnt-node', 'volumes'] |
108 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
109 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
110 | 4b62db14 | Michael Hanselmann | |
111 | 4b62db14 | Michael Hanselmann | |
112 | 8e1db003 | Michael Hanselmann | def TestNodeStorage(): |
113 | 8e1db003 | Michael Hanselmann | """gnt-node storage"""
|
114 | 8e1db003 | Michael Hanselmann | master = qa_config.GetMasterNode() |
115 | 8e1db003 | Michael Hanselmann | |
116 | 8e1db003 | Michael Hanselmann | for storage_type in constants.VALID_STORAGE_TYPES: |
117 | 8e1db003 | Michael Hanselmann | # Test simple list
|
118 | 8e1db003 | Michael Hanselmann | cmd = ["gnt-node", "list-storage", "--storage-type", storage_type] |
119 | 8e1db003 | Michael Hanselmann | AssertEqual(StartSSH(master["primary"],
|
120 | 8e1db003 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
121 | 8e1db003 | Michael Hanselmann | |
122 | 8e1db003 | Michael Hanselmann | # Test all storage fields
|
123 | 8e1db003 | Michael Hanselmann | cmd = ["gnt-node", "list-storage", "--storage-type", storage_type, |
124 | 8e1db003 | Michael Hanselmann | "--output=%s" % ",".join(list(constants.VALID_STORAGE_FIELDS) + |
125 | 8e1db003 | Michael Hanselmann | [constants.SF_NODE, constants.SF_TYPE])] |
126 | 8e1db003 | Michael Hanselmann | AssertEqual(StartSSH(master["primary"],
|
127 | 8e1db003 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
128 | 8e1db003 | Michael Hanselmann | |
129 | 8e1db003 | Michael Hanselmann | # Get list of valid storage devices
|
130 | 8e1db003 | Michael Hanselmann | cmd = ["gnt-node", "list-storage", "--storage-type", storage_type, |
131 | 8e1db003 | Michael Hanselmann | "--output=node,name,allocatable", "--separator=|", |
132 | 8e1db003 | Michael Hanselmann | "--no-headers"]
|
133 | 8e1db003 | Michael Hanselmann | output = qa_utils.GetCommandOutput(master["primary"],
|
134 | 8e1db003 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)) |
135 | 8e1db003 | Michael Hanselmann | |
136 | 8e1db003 | Michael Hanselmann | # Test with up to two devices
|
137 | 8e1db003 | Michael Hanselmann | testdevcount = 2
|
138 | 8e1db003 | Michael Hanselmann | |
139 | 8e1db003 | Michael Hanselmann | for line in output.splitlines()[:testdevcount]: |
140 | 8e1db003 | Michael Hanselmann | (node_name, st_name, st_allocatable) = line.split("|")
|
141 | 8e1db003 | Michael Hanselmann | |
142 | 8e1db003 | Michael Hanselmann | # Dummy modification without any changes
|
143 | 8e1db003 | Michael Hanselmann | cmd = ["gnt-node", "modify-storage", node_name, storage_type, st_name] |
144 | 8e1db003 | Michael Hanselmann | AssertEqual(StartSSH(master["primary"],
|
145 | 8e1db003 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
146 | 8e1db003 | Michael Hanselmann | |
147 | 8e1db003 | Michael Hanselmann | # Make sure we end up with the same value as before
|
148 | 8e1db003 | Michael Hanselmann | if st_allocatable.lower() == "y": |
149 | 8e1db003 | Michael Hanselmann | test_allocatable = ["no", "yes"] |
150 | 8e1db003 | Michael Hanselmann | else:
|
151 | 8e1db003 | Michael Hanselmann | test_allocatable = ["yes", "no"] |
152 | 8e1db003 | Michael Hanselmann | |
153 | 8e1db003 | Michael Hanselmann | if (constants.SF_ALLOCATABLE in |
154 | 8e1db003 | Michael Hanselmann | constants.MODIFIABLE_STORAGE_FIELDS.get(storage_type, [])): |
155 | 8e1db003 | Michael Hanselmann | assert_fn = AssertEqual |
156 | 8e1db003 | Michael Hanselmann | else:
|
157 | 8e1db003 | Michael Hanselmann | assert_fn = AssertNotEqual |
158 | 8e1db003 | Michael Hanselmann | |
159 | 8e1db003 | Michael Hanselmann | for i in test_allocatable: |
160 | 8e1db003 | Michael Hanselmann | cmd = ["gnt-node", "modify-storage", "--allocatable", i, |
161 | 8e1db003 | Michael Hanselmann | node_name, storage_type, st_name] |
162 | 8e1db003 | Michael Hanselmann | assert_fn(StartSSH(master["primary"],
|
163 | 8e1db003 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
164 | 8e1db003 | Michael Hanselmann | |
165 | 8e1db003 | Michael Hanselmann | # Test repair functionality
|
166 | 8e1db003 | Michael Hanselmann | cmd = ["gnt-node", "repair-storage", node_name, storage_type, st_name] |
167 | 8e1db003 | Michael Hanselmann | |
168 | 8e1db003 | Michael Hanselmann | if (constants.SO_FIX_CONSISTENCY in |
169 | 8e1db003 | Michael Hanselmann | constants.VALID_STORAGE_OPERATIONS.get(storage_type, [])): |
170 | 8e1db003 | Michael Hanselmann | assert_fn = AssertEqual |
171 | 8e1db003 | Michael Hanselmann | else:
|
172 | 8e1db003 | Michael Hanselmann | assert_fn = AssertNotEqual |
173 | 8e1db003 | Michael Hanselmann | |
174 | 8e1db003 | Michael Hanselmann | assert_fn(StartSSH(master["primary"],
|
175 | 8e1db003 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
176 | 8e1db003 | Michael Hanselmann | |
177 | 8e1db003 | Michael Hanselmann | |
178 | 4b62db14 | Michael Hanselmann | def TestNodeFailover(node, node2): |
179 | 4b62db14 | Michael Hanselmann | """gnt-node failover"""
|
180 | 4b62db14 | Michael Hanselmann | master = qa_config.GetMasterNode() |
181 | 4b62db14 | Michael Hanselmann | |
182 | d7e49c13 | Michael Hanselmann | if qa_utils.GetNodeInstances(node2, secondaries=False): |
183 | f4bc1f2c | Michael Hanselmann | raise qa_error.UnusableNodeError("Secondary node has at least one" |
184 | f4bc1f2c | Michael Hanselmann | " primary instance. This test requires"
|
185 | f4bc1f2c | Michael Hanselmann | " it to have no primary instances.")
|
186 | 4b62db14 | Michael Hanselmann | |
187 | 4b62db14 | Michael Hanselmann | # Fail over to secondary node
|
188 | 4b62db14 | Michael Hanselmann | cmd = ['gnt-node', 'failover', '-f', node['primary']] |
189 | 4b62db14 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
190 | 4b62db14 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
191 | 4b62db14 | Michael Hanselmann | |
192 | 4b62db14 | Michael Hanselmann | # ... and back again.
|
193 | 4b62db14 | Michael Hanselmann | cmd = ['gnt-node', 'failover', '-f', node2['primary']] |
194 | 4b62db14 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
195 | 4b62db14 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
196 | 4b62db14 | Michael Hanselmann | |
197 | 4b62db14 | Michael Hanselmann | |
198 | 4b62db14 | Michael Hanselmann | def TestNodeEvacuate(node, node2): |
199 | 4b62db14 | Michael Hanselmann | """gnt-node evacuate"""
|
200 | 4b62db14 | Michael Hanselmann | master = qa_config.GetMasterNode() |
201 | 4b62db14 | Michael Hanselmann | |
202 | 4b62db14 | Michael Hanselmann | node3 = qa_config.AcquireNode(exclude=[node, node2]) |
203 | 4b62db14 | Michael Hanselmann | try:
|
204 | d7e49c13 | Michael Hanselmann | if qa_utils.GetNodeInstances(node3, secondaries=True): |
205 | f4bc1f2c | Michael Hanselmann | raise qa_error.UnusableNodeError("Evacuation node has at least one" |
206 | f4bc1f2c | Michael Hanselmann | " secondary instance. This test requires"
|
207 | f4bc1f2c | Michael Hanselmann | " it to have no secondary instances.")
|
208 | 4b62db14 | Michael Hanselmann | |
209 | 4b62db14 | Michael Hanselmann | # Evacuate all secondary instances
|
210 | aca55e15 | Michael Hanselmann | cmd = ['gnt-node', 'evacuate', '-f', |
211 | aca55e15 | Michael Hanselmann | "--new-secondary=%s" % node3['primary'], node2['primary']] |
212 | 4b62db14 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
213 | 4b62db14 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
214 | 4b62db14 | Michael Hanselmann | |
215 | 4b62db14 | Michael Hanselmann | # ... and back again.
|
216 | aca55e15 | Michael Hanselmann | cmd = ['gnt-node', 'evacuate', '-f', |
217 | aca55e15 | Michael Hanselmann | "--new-secondary=%s" % node2['primary'], node3['primary']] |
218 | 4b62db14 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
219 | 4b62db14 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
220 | 4b62db14 | Michael Hanselmann | finally:
|
221 | 4b62db14 | Michael Hanselmann | qa_config.ReleaseNode(node3) |