root / qa / qa_cluster.py @ 30989e69
History | View | Annotate | Download (6.3 kB)
1 | cec9845c | Michael Hanselmann | # Copyright (C) 2007 Google Inc.
|
---|---|---|---|
2 | cec9845c | Michael Hanselmann | #
|
3 | cec9845c | Michael Hanselmann | # This program is free software; you can redistribute it and/or modify
|
4 | cec9845c | Michael Hanselmann | # it under the terms of the GNU General Public License as published by
|
5 | cec9845c | Michael Hanselmann | # the Free Software Foundation; either version 2 of the License, or
|
6 | cec9845c | Michael Hanselmann | # (at your option) any later version.
|
7 | cec9845c | Michael Hanselmann | #
|
8 | cec9845c | Michael Hanselmann | # This program is distributed in the hope that it will be useful, but
|
9 | cec9845c | Michael Hanselmann | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
10 | cec9845c | Michael Hanselmann | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11 | cec9845c | Michael Hanselmann | # General Public License for more details.
|
12 | cec9845c | Michael Hanselmann | #
|
13 | cec9845c | Michael Hanselmann | # You should have received a copy of the GNU General Public License
|
14 | cec9845c | Michael Hanselmann | # along with this program; if not, write to the Free Software
|
15 | cec9845c | Michael Hanselmann | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
16 | cec9845c | Michael Hanselmann | # 02110-1301, USA.
|
17 | cec9845c | Michael Hanselmann | |
18 | cec9845c | Michael Hanselmann | |
19 | cec9845c | Michael Hanselmann | """Cluster related QA tests.
|
20 | cec9845c | Michael Hanselmann |
|
21 | cec9845c | Michael Hanselmann | """
|
22 | cec9845c | Michael Hanselmann | |
23 | cec9845c | Michael Hanselmann | import tempfile |
24 | cec9845c | Michael Hanselmann | |
25 | cec9845c | Michael Hanselmann | from ganeti import utils |
26 | cec9845c | Michael Hanselmann | |
27 | cec9845c | Michael Hanselmann | import qa_config |
28 | cec9845c | Michael Hanselmann | import qa_utils |
29 | cec9845c | Michael Hanselmann | import qa_error |
30 | cec9845c | Michael Hanselmann | |
31 | cec9845c | Michael Hanselmann | from qa_utils import AssertEqual, StartSSH |
32 | cec9845c | Michael Hanselmann | |
33 | cec9845c | Michael Hanselmann | |
34 | 830da270 | Michael Hanselmann | def _RemoveFileFromAllNodes(filename): |
35 | 830da270 | Michael Hanselmann | """Removes a file from all nodes.
|
36 | 830da270 | Michael Hanselmann |
|
37 | 830da270 | Michael Hanselmann | """
|
38 | 830da270 | Michael Hanselmann | for node in qa_config.get('nodes'): |
39 | 830da270 | Michael Hanselmann | cmd = ['rm', '-f', filename] |
40 | 830da270 | Michael Hanselmann | AssertEqual(StartSSH(node['primary'],
|
41 | 830da270 | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
42 | 830da270 | Michael Hanselmann | |
43 | 830da270 | Michael Hanselmann | |
44 | 830da270 | Michael Hanselmann | def _CheckFileOnAllNodes(filename, content): |
45 | 830da270 | Michael Hanselmann | """Verifies the content of the given file on all nodes.
|
46 | 830da270 | Michael Hanselmann |
|
47 | 830da270 | Michael Hanselmann | """
|
48 | 830da270 | Michael Hanselmann | cmd = utils.ShellQuoteArgs(["cat", filename])
|
49 | 830da270 | Michael Hanselmann | for node in qa_config.get('nodes'): |
50 | 830da270 | Michael Hanselmann | AssertEqual(qa_utils.GetCommandOutput(node['primary'], cmd),
|
51 | 830da270 | Michael Hanselmann | content) |
52 | 830da270 | Michael Hanselmann | |
53 | 830da270 | Michael Hanselmann | |
54 | e42b5307 | Michael Hanselmann | @qa_utils.DefineHook('cluster-init') |
55 | cec9845c | Michael Hanselmann | def TestClusterInit(): |
56 | cec9845c | Michael Hanselmann | """gnt-cluster init"""
|
57 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
58 | cec9845c | Michael Hanselmann | |
59 | cec9845c | Michael Hanselmann | cmd = ['gnt-cluster', 'init'] |
60 | cec9845c | Michael Hanselmann | |
61 | cec9845c | Michael Hanselmann | if master.get('secondary', None): |
62 | cec9845c | Michael Hanselmann | cmd.append('--secondary-ip=%s' % master['secondary']) |
63 | cec9845c | Michael Hanselmann | |
64 | cec9845c | Michael Hanselmann | bridge = qa_config.get('bridge', None) |
65 | cec9845c | Michael Hanselmann | if bridge:
|
66 | cec9845c | Michael Hanselmann | cmd.append('--bridge=%s' % bridge)
|
67 | cec9845c | Michael Hanselmann | cmd.append('--master-netdev=%s' % bridge)
|
68 | cec9845c | Michael Hanselmann | |
69 | cec9845c | Michael Hanselmann | cmd.append(qa_config.get('name'))
|
70 | cec9845c | Michael Hanselmann | |
71 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
72 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
73 | cec9845c | Michael Hanselmann | |
74 | cec9845c | Michael Hanselmann | |
75 | e42b5307 | Michael Hanselmann | @qa_utils.DefineHook('cluster-verify') |
76 | cec9845c | Michael Hanselmann | def TestClusterVerify(): |
77 | cec9845c | Michael Hanselmann | """gnt-cluster verify"""
|
78 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
79 | cec9845c | Michael Hanselmann | |
80 | 283f9d4c | Michael Hanselmann | cmd = ['gnt-cluster', 'verify'] |
81 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
82 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
83 | cec9845c | Michael Hanselmann | |
84 | cec9845c | Michael Hanselmann | |
85 | e42b5307 | Michael Hanselmann | @qa_utils.DefineHook('cluster-info') |
86 | cec9845c | Michael Hanselmann | def TestClusterInfo(): |
87 | cec9845c | Michael Hanselmann | """gnt-cluster info"""
|
88 | 283f9d4c | Michael Hanselmann | master = qa_config.GetMasterNode() |
89 | 283f9d4c | Michael Hanselmann | |
90 | cec9845c | Michael Hanselmann | cmd = ['gnt-cluster', 'info'] |
91 | 283f9d4c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
92 | 283f9d4c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
93 | 283f9d4c | Michael Hanselmann | |
94 | 283f9d4c | Michael Hanselmann | |
95 | e42b5307 | Michael Hanselmann | @qa_utils.DefineHook('cluster-getmaster') |
96 | 283f9d4c | Michael Hanselmann | def TestClusterGetmaster(): |
97 | 283f9d4c | Michael Hanselmann | """gnt-cluster getmaster"""
|
98 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
99 | cec9845c | Michael Hanselmann | |
100 | 283f9d4c | Michael Hanselmann | cmd = ['gnt-cluster', 'getmaster'] |
101 | 283f9d4c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
102 | 283f9d4c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
103 | 283f9d4c | Michael Hanselmann | |
104 | 283f9d4c | Michael Hanselmann | |
105 | e42b5307 | Michael Hanselmann | @qa_utils.DefineHook('cluster-version') |
106 | 283f9d4c | Michael Hanselmann | def TestClusterVersion(): |
107 | 283f9d4c | Michael Hanselmann | """gnt-cluster version"""
|
108 | 283f9d4c | Michael Hanselmann | master = qa_config.GetMasterNode() |
109 | 283f9d4c | Michael Hanselmann | |
110 | 283f9d4c | Michael Hanselmann | cmd = ['gnt-cluster', 'version'] |
111 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
112 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
113 | cec9845c | Michael Hanselmann | |
114 | cec9845c | Michael Hanselmann | |
115 | e42b5307 | Michael Hanselmann | @qa_utils.DefineHook('cluster-burnin') |
116 | cec9845c | Michael Hanselmann | def TestClusterBurnin(): |
117 | cec9845c | Michael Hanselmann | """Burnin"""
|
118 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
119 | cec9845c | Michael Hanselmann | |
120 | 23103544 | Michael Hanselmann | disk_template = (qa_config.get('options', {}).
|
121 | 23103544 | Michael Hanselmann | get('burnin-disk-template', 'remote_raid1')) |
122 | 23103544 | Michael Hanselmann | |
123 | cec9845c | Michael Hanselmann | # Get as many instances as we need
|
124 | cec9845c | Michael Hanselmann | instances = [] |
125 | cec9845c | Michael Hanselmann | try:
|
126 | 23103544 | Michael Hanselmann | try:
|
127 | 23103544 | Michael Hanselmann | num = qa_config.get('options', {}).get('burnin-instances', 1) |
128 | 23103544 | Michael Hanselmann | for _ in xrange(0, num): |
129 | 23103544 | Michael Hanselmann | instances.append(qa_config.AcquireInstance()) |
130 | 23103544 | Michael Hanselmann | except qa_error.OutOfInstancesError:
|
131 | 23103544 | Michael Hanselmann | print "Not enough instances, continuing anyway." |
132 | cec9845c | Michael Hanselmann | |
133 | 23103544 | Michael Hanselmann | if len(instances) < 1: |
134 | 23103544 | Michael Hanselmann | raise qa_error.Error("Burnin needs at least one instance") |
135 | cec9845c | Michael Hanselmann | |
136 | cec9845c | Michael Hanselmann | script = qa_utils.UploadFile(master['primary'], '../tools/burnin') |
137 | cec9845c | Michael Hanselmann | try:
|
138 | 23103544 | Michael Hanselmann | # Run burnin
|
139 | cec9845c | Michael Hanselmann | cmd = [script, |
140 | cec9845c | Michael Hanselmann | '--os=%s' % qa_config.get('os'), |
141 | cec9845c | Michael Hanselmann | '--os-size=%s' % qa_config.get('os-size'), |
142 | 23103544 | Michael Hanselmann | '--swap-size=%s' % qa_config.get('swap-size'), |
143 | 23103544 | Michael Hanselmann | '--disk-template=%s' % disk_template]
|
144 | cec9845c | Michael Hanselmann | cmd += [inst['name'] for inst in instances] |
145 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
146 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
147 | cec9845c | Michael Hanselmann | finally:
|
148 | cec9845c | Michael Hanselmann | cmd = ['rm', '-f', script] |
149 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
150 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
151 | cec9845c | Michael Hanselmann | finally:
|
152 | cec9845c | Michael Hanselmann | for inst in instances: |
153 | cec9845c | Michael Hanselmann | qa_config.ReleaseInstance(inst) |
154 | cec9845c | Michael Hanselmann | |
155 | cec9845c | Michael Hanselmann | |
156 | e42b5307 | Michael Hanselmann | @qa_utils.DefineHook('cluster-master-failover') |
157 | cec9845c | Michael Hanselmann | def TestClusterMasterFailover(): |
158 | cec9845c | Michael Hanselmann | """gnt-cluster masterfailover"""
|
159 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
160 | cec9845c | Michael Hanselmann | |
161 | cec9845c | Michael Hanselmann | failovermaster = qa_config.AcquireNode(exclude=master) |
162 | cec9845c | Michael Hanselmann | try:
|
163 | cec9845c | Michael Hanselmann | cmd = ['gnt-cluster', 'masterfailover'] |
164 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(failovermaster['primary'],
|
165 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
166 | cec9845c | Michael Hanselmann | |
167 | cec9845c | Michael Hanselmann | cmd = ['gnt-cluster', 'masterfailover'] |
168 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
169 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
170 | cec9845c | Michael Hanselmann | finally:
|
171 | cec9845c | Michael Hanselmann | qa_config.ReleaseNode(failovermaster) |
172 | cec9845c | Michael Hanselmann | |
173 | cec9845c | Michael Hanselmann | |
174 | e42b5307 | Michael Hanselmann | @qa_utils.DefineHook('cluster-copyfile') |
175 | cec9845c | Michael Hanselmann | def TestClusterCopyfile(): |
176 | cec9845c | Michael Hanselmann | """gnt-cluster copyfile"""
|
177 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
178 | cec9845c | Michael Hanselmann | |
179 | 24818e8f | Michael Hanselmann | uniqueid = utils.NewUUID() |
180 | 830da270 | Michael Hanselmann | |
181 | cec9845c | Michael Hanselmann | # Create temporary file
|
182 | cec9845c | Michael Hanselmann | f = tempfile.NamedTemporaryFile() |
183 | 830da270 | Michael Hanselmann | f.write(uniqueid) |
184 | cec9845c | Michael Hanselmann | f.flush() |
185 | cec9845c | Michael Hanselmann | f.seek(0)
|
186 | cec9845c | Michael Hanselmann | |
187 | cec9845c | Michael Hanselmann | # Upload file to master node
|
188 | cec9845c | Michael Hanselmann | testname = qa_utils.UploadFile(master['primary'], f.name)
|
189 | cec9845c | Michael Hanselmann | try:
|
190 | cec9845c | Michael Hanselmann | # Copy file to all nodes
|
191 | cec9845c | Michael Hanselmann | cmd = ['gnt-cluster', 'copyfile', testname] |
192 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
193 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
194 | 830da270 | Michael Hanselmann | _CheckFileOnAllNodes(testname, uniqueid) |
195 | cec9845c | Michael Hanselmann | finally:
|
196 | 830da270 | Michael Hanselmann | _RemoveFileFromAllNodes(testname) |
197 | 830da270 | Michael Hanselmann | |
198 | 830da270 | Michael Hanselmann | |
199 | e42b5307 | Michael Hanselmann | @qa_utils.DefineHook('cluster-command') |
200 | 830da270 | Michael Hanselmann | def TestClusterCommand(): |
201 | 830da270 | Michael Hanselmann | """gnt-cluster command"""
|
202 | 830da270 | Michael Hanselmann | master = qa_config.GetMasterNode() |
203 | 830da270 | Michael Hanselmann | |
204 | 24818e8f | Michael Hanselmann | uniqueid = utils.NewUUID() |
205 | 24818e8f | Michael Hanselmann | rfile = "/tmp/gnt%s" % utils.NewUUID()
|
206 | 830da270 | Michael Hanselmann | rcmd = utils.ShellQuoteArgs(['echo', '-n', uniqueid]) |
207 | 830da270 | Michael Hanselmann | cmd = utils.ShellQuoteArgs(['gnt-cluster', 'command', |
208 | 830da270 | Michael Hanselmann | "%s >%s" % (rcmd, rfile)])
|
209 | 830da270 | Michael Hanselmann | |
210 | 830da270 | Michael Hanselmann | try:
|
211 | 830da270 | Michael Hanselmann | AssertEqual(StartSSH(master['primary'], cmd).wait(), 0) |
212 | 830da270 | Michael Hanselmann | _CheckFileOnAllNodes(rfile, uniqueid) |
213 | 830da270 | Michael Hanselmann | finally:
|
214 | 830da270 | Michael Hanselmann | _RemoveFileFromAllNodes(rfile) |
215 | cec9845c | Michael Hanselmann | |
216 | cec9845c | Michael Hanselmann | |
217 | e42b5307 | Michael Hanselmann | @qa_utils.DefineHook('cluster-destroy') |
218 | cec9845c | Michael Hanselmann | def TestClusterDestroy(): |
219 | cec9845c | Michael Hanselmann | """gnt-cluster destroy"""
|
220 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
221 | cec9845c | Michael Hanselmann | |
222 | 283f9d4c | Michael Hanselmann | cmd = ['gnt-cluster', 'destroy', '--yes-do-it'] |
223 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
224 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0) |