root / qa / qa_cluster.py @ e8ae0c20
History | View | Annotate | Download (4.9 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 | cec9845c | Michael Hanselmann | def TestClusterInit(): |
35 | cec9845c | Michael Hanselmann | """gnt-cluster init"""
|
36 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
37 | cec9845c | Michael Hanselmann | |
38 | cec9845c | Michael Hanselmann | cmd = ['gnt-cluster', 'init'] |
39 | cec9845c | Michael Hanselmann | |
40 | cec9845c | Michael Hanselmann | if master.get('secondary', None): |
41 | cec9845c | Michael Hanselmann | cmd.append('--secondary-ip=%s' % master['secondary']) |
42 | cec9845c | Michael Hanselmann | |
43 | cec9845c | Michael Hanselmann | bridge = qa_config.get('bridge', None) |
44 | cec9845c | Michael Hanselmann | if bridge:
|
45 | cec9845c | Michael Hanselmann | cmd.append('--bridge=%s' % bridge)
|
46 | cec9845c | Michael Hanselmann | cmd.append('--master-netdev=%s' % bridge)
|
47 | cec9845c | Michael Hanselmann | |
48 | cec9845c | Michael Hanselmann | cmd.append(qa_config.get('name'))
|
49 | cec9845c | Michael Hanselmann | |
50 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
51 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
52 | cec9845c | Michael Hanselmann | |
53 | cec9845c | Michael Hanselmann | |
54 | cec9845c | Michael Hanselmann | def TestClusterVerify(): |
55 | cec9845c | Michael Hanselmann | """gnt-cluster verify"""
|
56 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
57 | cec9845c | Michael Hanselmann | |
58 | 283f9d4c | Michael Hanselmann | cmd = ['gnt-cluster', 'verify'] |
59 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
60 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
61 | cec9845c | Michael Hanselmann | |
62 | cec9845c | Michael Hanselmann | |
63 | cec9845c | Michael Hanselmann | def TestClusterInfo(): |
64 | cec9845c | Michael Hanselmann | """gnt-cluster info"""
|
65 | 283f9d4c | Michael Hanselmann | master = qa_config.GetMasterNode() |
66 | 283f9d4c | Michael Hanselmann | |
67 | cec9845c | Michael Hanselmann | cmd = ['gnt-cluster', 'info'] |
68 | 283f9d4c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
69 | 283f9d4c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
70 | 283f9d4c | Michael Hanselmann | |
71 | 283f9d4c | Michael Hanselmann | |
72 | 283f9d4c | Michael Hanselmann | def TestClusterGetmaster(): |
73 | 283f9d4c | Michael Hanselmann | """gnt-cluster getmaster"""
|
74 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
75 | cec9845c | Michael Hanselmann | |
76 | 283f9d4c | Michael Hanselmann | cmd = ['gnt-cluster', 'getmaster'] |
77 | 283f9d4c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
78 | 283f9d4c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
79 | 283f9d4c | Michael Hanselmann | |
80 | 283f9d4c | Michael Hanselmann | |
81 | 283f9d4c | Michael Hanselmann | def TestClusterVersion(): |
82 | 283f9d4c | Michael Hanselmann | """gnt-cluster version"""
|
83 | 283f9d4c | Michael Hanselmann | master = qa_config.GetMasterNode() |
84 | 283f9d4c | Michael Hanselmann | |
85 | 283f9d4c | Michael Hanselmann | cmd = ['gnt-cluster', 'version'] |
86 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
87 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
88 | cec9845c | Michael Hanselmann | |
89 | cec9845c | Michael Hanselmann | |
90 | cec9845c | Michael Hanselmann | def TestClusterBurnin(): |
91 | cec9845c | Michael Hanselmann | """Burnin"""
|
92 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
93 | cec9845c | Michael Hanselmann | |
94 | cec9845c | Michael Hanselmann | # Get as many instances as we need
|
95 | cec9845c | Michael Hanselmann | instances = [] |
96 | cec9845c | Michael Hanselmann | try:
|
97 | cec9845c | Michael Hanselmann | num = qa_config.get('options', {}).get('burnin-instances', 1) |
98 | cec9845c | Michael Hanselmann | for _ in xrange(0, num): |
99 | cec9845c | Michael Hanselmann | instances.append(qa_config.AcquireInstance()) |
100 | cec9845c | Michael Hanselmann | except qa_error.OutOfInstancesError:
|
101 | cec9845c | Michael Hanselmann | print "Not enough instances, continuing anyway." |
102 | cec9845c | Michael Hanselmann | |
103 | cec9845c | Michael Hanselmann | if len(instances) < 1: |
104 | cec9845c | Michael Hanselmann | raise qa_error.Error("Burnin needs at least one instance") |
105 | cec9845c | Michael Hanselmann | |
106 | cec9845c | Michael Hanselmann | # Run burnin
|
107 | cec9845c | Michael Hanselmann | try:
|
108 | cec9845c | Michael Hanselmann | script = qa_utils.UploadFile(master['primary'], '../tools/burnin') |
109 | cec9845c | Michael Hanselmann | try:
|
110 | cec9845c | Michael Hanselmann | cmd = [script, |
111 | cec9845c | Michael Hanselmann | '--os=%s' % qa_config.get('os'), |
112 | cec9845c | Michael Hanselmann | '--os-size=%s' % qa_config.get('os-size'), |
113 | cec9845c | Michael Hanselmann | '--swap-size=%s' % qa_config.get('swap-size')] |
114 | cec9845c | Michael Hanselmann | cmd += [inst['name'] for inst in instances] |
115 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
116 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
117 | cec9845c | Michael Hanselmann | finally:
|
118 | cec9845c | Michael Hanselmann | cmd = ['rm', '-f', script] |
119 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
120 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
121 | cec9845c | Michael Hanselmann | finally:
|
122 | cec9845c | Michael Hanselmann | for inst in instances: |
123 | cec9845c | Michael Hanselmann | qa_config.ReleaseInstance(inst) |
124 | cec9845c | Michael Hanselmann | |
125 | cec9845c | Michael Hanselmann | |
126 | cec9845c | Michael Hanselmann | def TestClusterMasterFailover(): |
127 | cec9845c | Michael Hanselmann | """gnt-cluster masterfailover"""
|
128 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
129 | cec9845c | Michael Hanselmann | |
130 | cec9845c | Michael Hanselmann | failovermaster = qa_config.AcquireNode(exclude=master) |
131 | cec9845c | Michael Hanselmann | try:
|
132 | cec9845c | Michael Hanselmann | cmd = ['gnt-cluster', 'masterfailover'] |
133 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(failovermaster['primary'],
|
134 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
135 | cec9845c | Michael Hanselmann | |
136 | cec9845c | Michael Hanselmann | cmd = ['gnt-cluster', 'masterfailover'] |
137 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
138 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
139 | cec9845c | Michael Hanselmann | finally:
|
140 | cec9845c | Michael Hanselmann | qa_config.ReleaseNode(failovermaster) |
141 | cec9845c | Michael Hanselmann | |
142 | cec9845c | Michael Hanselmann | |
143 | cec9845c | Michael Hanselmann | def TestClusterCopyfile(): |
144 | cec9845c | Michael Hanselmann | """gnt-cluster copyfile"""
|
145 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
146 | cec9845c | Michael Hanselmann | |
147 | cec9845c | Michael Hanselmann | # Create temporary file
|
148 | cec9845c | Michael Hanselmann | f = tempfile.NamedTemporaryFile() |
149 | cec9845c | Michael Hanselmann | f.write("I'm a testfile.\n")
|
150 | cec9845c | Michael Hanselmann | f.flush() |
151 | cec9845c | Michael Hanselmann | f.seek(0)
|
152 | cec9845c | Michael Hanselmann | |
153 | cec9845c | Michael Hanselmann | # Upload file to master node
|
154 | cec9845c | Michael Hanselmann | testname = qa_utils.UploadFile(master['primary'], f.name)
|
155 | cec9845c | Michael Hanselmann | try:
|
156 | cec9845c | Michael Hanselmann | # Copy file to all nodes
|
157 | cec9845c | Michael Hanselmann | cmd = ['gnt-cluster', 'copyfile', testname] |
158 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
159 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
160 | cec9845c | Michael Hanselmann | finally:
|
161 | cec9845c | Michael Hanselmann | # Remove file from all nodes
|
162 | cec9845c | Michael Hanselmann | for node in qa_config.get('nodes'): |
163 | cec9845c | Michael Hanselmann | cmd = ['rm', '-f', testname] |
164 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(node['primary'],
|
165 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
166 | cec9845c | Michael Hanselmann | |
167 | cec9845c | Michael Hanselmann | |
168 | cec9845c | Michael Hanselmann | def TestClusterDestroy(): |
169 | cec9845c | Michael Hanselmann | """gnt-cluster destroy"""
|
170 | cec9845c | Michael Hanselmann | master = qa_config.GetMasterNode() |
171 | cec9845c | Michael Hanselmann | |
172 | 283f9d4c | Michael Hanselmann | cmd = ['gnt-cluster', 'destroy', '--yes-do-it'] |
173 | cec9845c | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
174 | cec9845c | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0) |