Statistics
| Branch: | Tag: | Revision:

root / qa / qa_cluster.py @ 7910e7a5

History | View | Annotate | Download (7.3 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
"""Cluster related QA tests.
23 cec9845c Michael Hanselmann

24 cec9845c Michael Hanselmann
"""
25 cec9845c Michael Hanselmann
26 cec9845c Michael Hanselmann
import tempfile
27 cec9845c Michael Hanselmann
28 cec9845c Michael Hanselmann
from ganeti import utils
29 cec9845c Michael Hanselmann
30 cec9845c Michael Hanselmann
import qa_config
31 cec9845c Michael Hanselmann
import qa_utils
32 cec9845c Michael Hanselmann
import qa_error
33 cec9845c Michael Hanselmann
34 cec9845c Michael Hanselmann
from qa_utils import AssertEqual, StartSSH
35 cec9845c Michael Hanselmann
36 cec9845c Michael Hanselmann
37 830da270 Michael Hanselmann
def _RemoveFileFromAllNodes(filename):
38 830da270 Michael Hanselmann
  """Removes a file from all nodes.
39 830da270 Michael Hanselmann

40 830da270 Michael Hanselmann
  """
41 830da270 Michael Hanselmann
  for node in qa_config.get('nodes'):
42 830da270 Michael Hanselmann
    cmd = ['rm', '-f', filename]
43 830da270 Michael Hanselmann
    AssertEqual(StartSSH(node['primary'],
44 830da270 Michael Hanselmann
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
45 830da270 Michael Hanselmann
46 830da270 Michael Hanselmann
47 830da270 Michael Hanselmann
def _CheckFileOnAllNodes(filename, content):
48 830da270 Michael Hanselmann
  """Verifies the content of the given file on all nodes.
49 830da270 Michael Hanselmann

50 830da270 Michael Hanselmann
  """
51 830da270 Michael Hanselmann
  cmd = utils.ShellQuoteArgs(["cat", filename])
52 830da270 Michael Hanselmann
  for node in qa_config.get('nodes'):
53 830da270 Michael Hanselmann
    AssertEqual(qa_utils.GetCommandOutput(node['primary'], cmd),
54 830da270 Michael Hanselmann
                content)
55 830da270 Michael Hanselmann
56 830da270 Michael Hanselmann
57 e42b5307 Michael Hanselmann
@qa_utils.DefineHook('cluster-init')
58 cec9845c Michael Hanselmann
def TestClusterInit():
59 cec9845c Michael Hanselmann
  """gnt-cluster init"""
60 cec9845c Michael Hanselmann
  master = qa_config.GetMasterNode()
61 cec9845c Michael Hanselmann
62 cec9845c Michael Hanselmann
  cmd = ['gnt-cluster', 'init']
63 cec9845c Michael Hanselmann
64 cec9845c Michael Hanselmann
  if master.get('secondary', None):
65 cec9845c Michael Hanselmann
    cmd.append('--secondary-ip=%s' % master['secondary'])
66 cec9845c Michael Hanselmann
67 cec9845c Michael Hanselmann
  bridge = qa_config.get('bridge', None)
68 cec9845c Michael Hanselmann
  if bridge:
69 cec9845c Michael Hanselmann
    cmd.append('--bridge=%s' % bridge)
70 cec9845c Michael Hanselmann
    cmd.append('--master-netdev=%s' % bridge)
71 cec9845c Michael Hanselmann
72 b32f9859 Iustin Pop
  htype = qa_config.get('hypervisor-type', None)
73 b32f9859 Iustin Pop
  if htype:
74 b32f9859 Iustin Pop
    cmd.append('--hypervisor-type=%s' % htype)
75 b32f9859 Iustin Pop
76 cec9845c Michael Hanselmann
  cmd.append(qa_config.get('name'))
77 cec9845c Michael Hanselmann
78 cec9845c Michael Hanselmann
  AssertEqual(StartSSH(master['primary'],
79 cec9845c Michael Hanselmann
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
80 cec9845c Michael Hanselmann
81 cec9845c Michael Hanselmann
82 caea3b32 Iustin Pop
@qa_utils.DefineHook('cluster-rename')
83 caea3b32 Iustin Pop
def TestClusterRename():
84 caea3b32 Iustin Pop
  """gnt-cluster rename"""
85 caea3b32 Iustin Pop
  master = qa_config.GetMasterNode()
86 caea3b32 Iustin Pop
87 caea3b32 Iustin Pop
  cmd = ['gnt-cluster', 'rename', '-f']
88 caea3b32 Iustin Pop
89 caea3b32 Iustin Pop
  original_name = qa_config.get('name')
90 caea3b32 Iustin Pop
  rename_target = qa_config.get('rename', None)
91 caea3b32 Iustin Pop
  if rename_target is None:
92 caea3b32 Iustin Pop
    print qa_utils.FormatError('"rename" entry is missing')
93 caea3b32 Iustin Pop
    return
94 caea3b32 Iustin Pop
95 caea3b32 Iustin Pop
  cmd_1 = cmd + [rename_target]
96 caea3b32 Iustin Pop
  cmd_2 = cmd + [original_name]
97 caea3b32 Iustin Pop
98 caea3b32 Iustin Pop
  cmd_verify = ['gnt-cluster', 'verify']
99 caea3b32 Iustin Pop
100 caea3b32 Iustin Pop
  AssertEqual(StartSSH(master['primary'],
101 caea3b32 Iustin Pop
                       utils.ShellQuoteArgs(cmd_1)).wait(), 0)
102 caea3b32 Iustin Pop
103 caea3b32 Iustin Pop
  AssertEqual(StartSSH(master['primary'],
104 caea3b32 Iustin Pop
                       utils.ShellQuoteArgs(cmd_verify)).wait(), 0)
105 caea3b32 Iustin Pop
106 caea3b32 Iustin Pop
  AssertEqual(StartSSH(master['primary'],
107 caea3b32 Iustin Pop
                       utils.ShellQuoteArgs(cmd_2)).wait(), 0)
108 caea3b32 Iustin Pop
109 caea3b32 Iustin Pop
  AssertEqual(StartSSH(master['primary'],
110 caea3b32 Iustin Pop
                       utils.ShellQuoteArgs(cmd_verify)).wait(), 0)
111 caea3b32 Iustin Pop
112 caea3b32 Iustin Pop
113 e42b5307 Michael Hanselmann
@qa_utils.DefineHook('cluster-verify')
114 cec9845c Michael Hanselmann
def TestClusterVerify():
115 cec9845c Michael Hanselmann
  """gnt-cluster verify"""
116 cec9845c Michael Hanselmann
  master = qa_config.GetMasterNode()
117 cec9845c Michael Hanselmann
118 283f9d4c Michael Hanselmann
  cmd = ['gnt-cluster', 'verify']
119 cec9845c Michael Hanselmann
  AssertEqual(StartSSH(master['primary'],
120 cec9845c Michael Hanselmann
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
121 cec9845c Michael Hanselmann
122 cec9845c Michael Hanselmann
123 e42b5307 Michael Hanselmann
@qa_utils.DefineHook('cluster-info')
124 cec9845c Michael Hanselmann
def TestClusterInfo():
125 cec9845c Michael Hanselmann
  """gnt-cluster info"""
126 283f9d4c Michael Hanselmann
  master = qa_config.GetMasterNode()
127 283f9d4c Michael Hanselmann
128 cec9845c Michael Hanselmann
  cmd = ['gnt-cluster', 'info']
129 283f9d4c Michael Hanselmann
  AssertEqual(StartSSH(master['primary'],
130 283f9d4c Michael Hanselmann
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
131 283f9d4c Michael Hanselmann
132 283f9d4c Michael Hanselmann
133 e42b5307 Michael Hanselmann
@qa_utils.DefineHook('cluster-getmaster')
134 283f9d4c Michael Hanselmann
def TestClusterGetmaster():
135 283f9d4c Michael Hanselmann
  """gnt-cluster getmaster"""
136 cec9845c Michael Hanselmann
  master = qa_config.GetMasterNode()
137 cec9845c Michael Hanselmann
138 283f9d4c Michael Hanselmann
  cmd = ['gnt-cluster', 'getmaster']
139 283f9d4c Michael Hanselmann
  AssertEqual(StartSSH(master['primary'],
140 283f9d4c Michael Hanselmann
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
141 283f9d4c Michael Hanselmann
142 283f9d4c Michael Hanselmann
143 e42b5307 Michael Hanselmann
@qa_utils.DefineHook('cluster-version')
144 283f9d4c Michael Hanselmann
def TestClusterVersion():
145 283f9d4c Michael Hanselmann
  """gnt-cluster version"""
146 283f9d4c Michael Hanselmann
  master = qa_config.GetMasterNode()
147 283f9d4c Michael Hanselmann
148 283f9d4c Michael Hanselmann
  cmd = ['gnt-cluster', 'version']
149 cec9845c Michael Hanselmann
  AssertEqual(StartSSH(master['primary'],
150 cec9845c Michael Hanselmann
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
151 cec9845c Michael Hanselmann
152 cec9845c Michael Hanselmann
153 e42b5307 Michael Hanselmann
@qa_utils.DefineHook('cluster-burnin')
154 cec9845c Michael Hanselmann
def TestClusterBurnin():
155 cec9845c Michael Hanselmann
  """Burnin"""
156 cec9845c Michael Hanselmann
  master = qa_config.GetMasterNode()
157 cec9845c Michael Hanselmann
158 23103544 Michael Hanselmann
  disk_template = (qa_config.get('options', {}).
159 f9193417 Iustin Pop
                   get('burnin-disk-template', 'drbd'))
160 23103544 Michael Hanselmann
161 cec9845c Michael Hanselmann
  # Get as many instances as we need
162 cec9845c Michael Hanselmann
  instances = []
163 cec9845c Michael Hanselmann
  try:
164 23103544 Michael Hanselmann
    try:
165 23103544 Michael Hanselmann
      num = qa_config.get('options', {}).get('burnin-instances', 1)
166 23103544 Michael Hanselmann
      for _ in xrange(0, num):
167 23103544 Michael Hanselmann
        instances.append(qa_config.AcquireInstance())
168 23103544 Michael Hanselmann
    except qa_error.OutOfInstancesError:
169 23103544 Michael Hanselmann
      print "Not enough instances, continuing anyway."
170 cec9845c Michael Hanselmann
171 23103544 Michael Hanselmann
    if len(instances) < 1:
172 23103544 Michael Hanselmann
      raise qa_error.Error("Burnin needs at least one instance")
173 cec9845c Michael Hanselmann
174 cec9845c Michael Hanselmann
    script = qa_utils.UploadFile(master['primary'], '../tools/burnin')
175 cec9845c Michael Hanselmann
    try:
176 23103544 Michael Hanselmann
      # Run burnin
177 cec9845c Michael Hanselmann
      cmd = [script,
178 cec9845c Michael Hanselmann
             '--os=%s' % qa_config.get('os'),
179 cec9845c Michael Hanselmann
             '--os-size=%s' % qa_config.get('os-size'),
180 23103544 Michael Hanselmann
             '--swap-size=%s' % qa_config.get('swap-size'),
181 23103544 Michael Hanselmann
             '--disk-template=%s' % disk_template]
182 cec9845c Michael Hanselmann
      cmd += [inst['name'] for inst in instances]
183 cec9845c Michael Hanselmann
      AssertEqual(StartSSH(master['primary'],
184 cec9845c Michael Hanselmann
                           utils.ShellQuoteArgs(cmd)).wait(), 0)
185 cec9845c Michael Hanselmann
    finally:
186 cec9845c Michael Hanselmann
      cmd = ['rm', '-f', script]
187 cec9845c Michael Hanselmann
      AssertEqual(StartSSH(master['primary'],
188 cec9845c Michael Hanselmann
                           utils.ShellQuoteArgs(cmd)).wait(), 0)
189 cec9845c Michael Hanselmann
  finally:
190 cec9845c Michael Hanselmann
    for inst in instances:
191 cec9845c Michael Hanselmann
      qa_config.ReleaseInstance(inst)
192 cec9845c Michael Hanselmann
193 cec9845c Michael Hanselmann
194 e42b5307 Michael Hanselmann
@qa_utils.DefineHook('cluster-master-failover')
195 cec9845c Michael Hanselmann
def TestClusterMasterFailover():
196 cec9845c Michael Hanselmann
  """gnt-cluster masterfailover"""
197 cec9845c Michael Hanselmann
  master = qa_config.GetMasterNode()
198 cec9845c Michael Hanselmann
199 cec9845c Michael Hanselmann
  failovermaster = qa_config.AcquireNode(exclude=master)
200 cec9845c Michael Hanselmann
  try:
201 cec9845c Michael Hanselmann
    cmd = ['gnt-cluster', 'masterfailover']
202 cec9845c Michael Hanselmann
    AssertEqual(StartSSH(failovermaster['primary'],
203 cec9845c Michael Hanselmann
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
204 cec9845c Michael Hanselmann
205 cec9845c Michael Hanselmann
    cmd = ['gnt-cluster', 'masterfailover']
206 cec9845c Michael Hanselmann
    AssertEqual(StartSSH(master['primary'],
207 cec9845c Michael Hanselmann
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
208 cec9845c Michael Hanselmann
  finally:
209 cec9845c Michael Hanselmann
    qa_config.ReleaseNode(failovermaster)
210 cec9845c Michael Hanselmann
211 cec9845c Michael Hanselmann
212 e42b5307 Michael Hanselmann
@qa_utils.DefineHook('cluster-copyfile')
213 cec9845c Michael Hanselmann
def TestClusterCopyfile():
214 cec9845c Michael Hanselmann
  """gnt-cluster copyfile"""
215 cec9845c Michael Hanselmann
  master = qa_config.GetMasterNode()
216 cec9845c Michael Hanselmann
217 24818e8f Michael Hanselmann
  uniqueid = utils.NewUUID()
218 830da270 Michael Hanselmann
219 cec9845c Michael Hanselmann
  # Create temporary file
220 cec9845c Michael Hanselmann
  f = tempfile.NamedTemporaryFile()
221 830da270 Michael Hanselmann
  f.write(uniqueid)
222 cec9845c Michael Hanselmann
  f.flush()
223 cec9845c Michael Hanselmann
  f.seek(0)
224 cec9845c Michael Hanselmann
225 cec9845c Michael Hanselmann
  # Upload file to master node
226 cec9845c Michael Hanselmann
  testname = qa_utils.UploadFile(master['primary'], f.name)
227 cec9845c Michael Hanselmann
  try:
228 cec9845c Michael Hanselmann
    # Copy file to all nodes
229 cec9845c Michael Hanselmann
    cmd = ['gnt-cluster', 'copyfile', testname]
230 cec9845c Michael Hanselmann
    AssertEqual(StartSSH(master['primary'],
231 cec9845c Michael Hanselmann
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
232 830da270 Michael Hanselmann
    _CheckFileOnAllNodes(testname, uniqueid)
233 cec9845c Michael Hanselmann
  finally:
234 830da270 Michael Hanselmann
    _RemoveFileFromAllNodes(testname)
235 830da270 Michael Hanselmann
236 830da270 Michael Hanselmann
237 e42b5307 Michael Hanselmann
@qa_utils.DefineHook('cluster-command')
238 830da270 Michael Hanselmann
def TestClusterCommand():
239 830da270 Michael Hanselmann
  """gnt-cluster command"""
240 830da270 Michael Hanselmann
  master = qa_config.GetMasterNode()
241 830da270 Michael Hanselmann
242 24818e8f Michael Hanselmann
  uniqueid = utils.NewUUID()
243 24818e8f Michael Hanselmann
  rfile = "/tmp/gnt%s" % utils.NewUUID()
244 830da270 Michael Hanselmann
  rcmd = utils.ShellQuoteArgs(['echo', '-n', uniqueid])
245 830da270 Michael Hanselmann
  cmd = utils.ShellQuoteArgs(['gnt-cluster', 'command',
246 830da270 Michael Hanselmann
                              "%s >%s" % (rcmd, rfile)])
247 830da270 Michael Hanselmann
248 830da270 Michael Hanselmann
  try:
249 830da270 Michael Hanselmann
    AssertEqual(StartSSH(master['primary'], cmd).wait(), 0)
250 830da270 Michael Hanselmann
    _CheckFileOnAllNodes(rfile, uniqueid)
251 830da270 Michael Hanselmann
  finally:
252 830da270 Michael Hanselmann
    _RemoveFileFromAllNodes(rfile)
253 cec9845c Michael Hanselmann
254 cec9845c Michael Hanselmann
255 e42b5307 Michael Hanselmann
@qa_utils.DefineHook('cluster-destroy')
256 cec9845c Michael Hanselmann
def TestClusterDestroy():
257 cec9845c Michael Hanselmann
  """gnt-cluster destroy"""
258 cec9845c Michael Hanselmann
  master = qa_config.GetMasterNode()
259 cec9845c Michael Hanselmann
260 283f9d4c Michael Hanselmann
  cmd = ['gnt-cluster', 'destroy', '--yes-do-it']
261 cec9845c Michael Hanselmann
  AssertEqual(StartSSH(master['primary'],
262 cec9845c Michael Hanselmann
                       utils.ShellQuoteArgs(cmd)).wait(), 0)