root / qa / qa_cluster.py @ cec9845c
History | View | Annotate | Download (4.4 kB)
1 |
# Copyright (C) 2007 Google Inc.
|
---|---|
2 |
#
|
3 |
# This program is free software; you can redistribute it and/or modify
|
4 |
# it under the terms of the GNU General Public License as published by
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
6 |
# (at your option) any later version.
|
7 |
#
|
8 |
# This program is distributed in the hope that it will be useful, but
|
9 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11 |
# General Public License for more details.
|
12 |
#
|
13 |
# You should have received a copy of the GNU General Public License
|
14 |
# along with this program; if not, write to the Free Software
|
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
16 |
# 02110-1301, USA.
|
17 |
|
18 |
|
19 |
"""Cluster related QA tests.
|
20 |
|
21 |
"""
|
22 |
|
23 |
import tempfile |
24 |
|
25 |
from ganeti import utils |
26 |
|
27 |
import qa_config |
28 |
import qa_utils |
29 |
import qa_error |
30 |
|
31 |
from qa_utils import AssertEqual, StartSSH |
32 |
|
33 |
|
34 |
def TestClusterInit(): |
35 |
"""gnt-cluster init"""
|
36 |
master = qa_config.GetMasterNode() |
37 |
|
38 |
cmd = ['gnt-cluster', 'init'] |
39 |
|
40 |
if master.get('secondary', None): |
41 |
cmd.append('--secondary-ip=%s' % master['secondary']) |
42 |
|
43 |
bridge = qa_config.get('bridge', None) |
44 |
if bridge:
|
45 |
cmd.append('--bridge=%s' % bridge)
|
46 |
cmd.append('--master-netdev=%s' % bridge)
|
47 |
|
48 |
cmd.append(qa_config.get('name'))
|
49 |
|
50 |
AssertEqual(StartSSH(master['primary'],
|
51 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
52 |
|
53 |
|
54 |
def TestClusterVerify(): |
55 |
"""gnt-cluster verify"""
|
56 |
cmd = ['gnt-cluster', 'verify'] |
57 |
master = qa_config.GetMasterNode() |
58 |
|
59 |
AssertEqual(StartSSH(master['primary'],
|
60 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
61 |
|
62 |
|
63 |
def TestClusterInfo(): |
64 |
"""gnt-cluster info"""
|
65 |
cmd = ['gnt-cluster', 'info'] |
66 |
master = qa_config.GetMasterNode() |
67 |
|
68 |
AssertEqual(StartSSH(master['primary'],
|
69 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
70 |
|
71 |
|
72 |
def TestClusterBurnin(): |
73 |
"""Burnin"""
|
74 |
master = qa_config.GetMasterNode() |
75 |
|
76 |
# Get as many instances as we need
|
77 |
instances = [] |
78 |
try:
|
79 |
num = qa_config.get('options', {}).get('burnin-instances', 1) |
80 |
for _ in xrange(0, num): |
81 |
instances.append(qa_config.AcquireInstance()) |
82 |
except qa_error.OutOfInstancesError:
|
83 |
print "Not enough instances, continuing anyway." |
84 |
|
85 |
if len(instances) < 1: |
86 |
raise qa_error.Error("Burnin needs at least one instance") |
87 |
|
88 |
# Run burnin
|
89 |
try:
|
90 |
script = qa_utils.UploadFile(master['primary'], '../tools/burnin') |
91 |
try:
|
92 |
cmd = [script, |
93 |
'--os=%s' % qa_config.get('os'), |
94 |
'--os-size=%s' % qa_config.get('os-size'), |
95 |
'--swap-size=%s' % qa_config.get('swap-size')] |
96 |
cmd += [inst['name'] for inst in instances] |
97 |
AssertEqual(StartSSH(master['primary'],
|
98 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
99 |
finally:
|
100 |
cmd = ['rm', '-f', script] |
101 |
AssertEqual(StartSSH(master['primary'],
|
102 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
103 |
finally:
|
104 |
for inst in instances: |
105 |
qa_config.ReleaseInstance(inst) |
106 |
|
107 |
|
108 |
def TestClusterMasterFailover(): |
109 |
"""gnt-cluster masterfailover"""
|
110 |
master = qa_config.GetMasterNode() |
111 |
|
112 |
failovermaster = qa_config.AcquireNode(exclude=master) |
113 |
try:
|
114 |
cmd = ['gnt-cluster', 'masterfailover'] |
115 |
AssertEqual(StartSSH(failovermaster['primary'],
|
116 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
117 |
|
118 |
cmd = ['gnt-cluster', 'masterfailover'] |
119 |
AssertEqual(StartSSH(master['primary'],
|
120 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
121 |
finally:
|
122 |
qa_config.ReleaseNode(failovermaster) |
123 |
|
124 |
|
125 |
def TestClusterCopyfile(): |
126 |
"""gnt-cluster copyfile"""
|
127 |
master = qa_config.GetMasterNode() |
128 |
|
129 |
# Create temporary file
|
130 |
f = tempfile.NamedTemporaryFile() |
131 |
f.write("I'm a testfile.\n")
|
132 |
f.flush() |
133 |
f.seek(0)
|
134 |
|
135 |
# Upload file to master node
|
136 |
testname = qa_utils.UploadFile(master['primary'], f.name)
|
137 |
try:
|
138 |
# Copy file to all nodes
|
139 |
cmd = ['gnt-cluster', 'copyfile', testname] |
140 |
AssertEqual(StartSSH(master['primary'],
|
141 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
142 |
finally:
|
143 |
# Remove file from all nodes
|
144 |
for node in qa_config.get('nodes'): |
145 |
cmd = ['rm', '-f', testname] |
146 |
AssertEqual(StartSSH(node['primary'],
|
147 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
148 |
|
149 |
|
150 |
def TestClusterDestroy(): |
151 |
"""gnt-cluster destroy"""
|
152 |
cmd = ['gnt-cluster', 'destroy', '--yes-do-it'] |
153 |
master = qa_config.GetMasterNode() |
154 |
|
155 |
AssertEqual(StartSSH(master['primary'],
|
156 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|