Statistics
| Branch: | Tag: | Revision:

root / qa / qa_cluster.py @ 2d6db53a

History | View | Annotate | Download (7.3 kB)

1
#
2
#
3

    
4
# Copyright (C) 2007 Google Inc.
5
#
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful, but
12
# WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
# General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
# 02110-1301, USA.
20

    
21

    
22
"""Cluster related QA tests.
23

24
"""
25

    
26
import tempfile
27

    
28
from ganeti import utils
29

    
30
import qa_config
31
import qa_utils
32
import qa_error
33

    
34
from qa_utils import AssertEqual, StartSSH
35

    
36

    
37
def _RemoveFileFromAllNodes(filename):
38
  """Removes a file from all nodes.
39

40
  """
41
  for node in qa_config.get('nodes'):
42
    cmd = ['rm', '-f', filename]
43
    AssertEqual(StartSSH(node['primary'],
44
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
45

    
46

    
47
def _CheckFileOnAllNodes(filename, content):
48
  """Verifies the content of the given file on all nodes.
49

50
  """
51
  cmd = utils.ShellQuoteArgs(["cat", filename])
52
  for node in qa_config.get('nodes'):
53
    AssertEqual(qa_utils.GetCommandOutput(node['primary'], cmd),
54
                content)
55

    
56

    
57
def TestClusterInit():
58
  """gnt-cluster init"""
59
  master = qa_config.GetMasterNode()
60

    
61
  cmd = ['gnt-cluster', 'init']
62

    
63
  if master.get('secondary', None):
64
    cmd.append('--secondary-ip=%s' % master['secondary'])
65

    
66
  bridge = qa_config.get('bridge', None)
67
  if bridge:
68
    cmd.append('--bridge=%s' % bridge)
69
    cmd.append('--master-netdev=%s' % bridge)
70

    
71
  htype = qa_config.get('enabled-hypervisors', None)
72
  if htype:
73
    cmd.append('--enabled-hypervisors=%s' % htype)
74

    
75
  cmd.append(qa_config.get('name'))
76

    
77
  AssertEqual(StartSSH(master['primary'],
78
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
79

    
80

    
81
def TestClusterRename():
82
  """gnt-cluster rename"""
83
  master = qa_config.GetMasterNode()
84

    
85
  cmd = ['gnt-cluster', 'rename', '-f']
86

    
87
  original_name = qa_config.get('name')
88
  rename_target = qa_config.get('rename', None)
89
  if rename_target is None:
90
    print qa_utils.FormatError('"rename" entry is missing')
91
    return
92

    
93
  cmd_1 = cmd + [rename_target]
94
  cmd_2 = cmd + [original_name]
95

    
96
  cmd_verify = ['gnt-cluster', 'verify']
97

    
98
  AssertEqual(StartSSH(master['primary'],
99
                       utils.ShellQuoteArgs(cmd_1)).wait(), 0)
100

    
101
  AssertEqual(StartSSH(master['primary'],
102
                       utils.ShellQuoteArgs(cmd_verify)).wait(), 0)
103

    
104
  AssertEqual(StartSSH(master['primary'],
105
                       utils.ShellQuoteArgs(cmd_2)).wait(), 0)
106

    
107
  AssertEqual(StartSSH(master['primary'],
108
                       utils.ShellQuoteArgs(cmd_verify)).wait(), 0)
109

    
110

    
111
def TestClusterVerify():
112
  """gnt-cluster verify"""
113
  master = qa_config.GetMasterNode()
114

    
115
  cmd = ['gnt-cluster', 'verify']
116
  AssertEqual(StartSSH(master['primary'],
117
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
118

    
119

    
120
def TestClusterInfo():
121
  """gnt-cluster info"""
122
  master = qa_config.GetMasterNode()
123

    
124
  cmd = ['gnt-cluster', 'info']
125
  AssertEqual(StartSSH(master['primary'],
126
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
127

    
128

    
129
def TestClusterGetmaster():
130
  """gnt-cluster getmaster"""
131
  master = qa_config.GetMasterNode()
132

    
133
  cmd = ['gnt-cluster', 'getmaster']
134
  AssertEqual(StartSSH(master['primary'],
135
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
136

    
137

    
138
def TestClusterVersion():
139
  """gnt-cluster version"""
140
  master = qa_config.GetMasterNode()
141

    
142
  cmd = ['gnt-cluster', 'version']
143
  AssertEqual(StartSSH(master['primary'],
144
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
145

    
146

    
147
def TestClusterBurnin():
148
  """Burnin"""
149
  master = qa_config.GetMasterNode()
150

    
151
  options = qa_config.get('options', {})
152
  disk_template = options.get('burnin-disk-template', 'drbd')
153
  parallel = options.get('burnin-in-parallel', False)
154
  check_inst = options.get('burnin-check-instances', False)
155
  do_rename = options.get('burnin-rename', '')
156

    
157
  # Get as many instances as we need
158
  instances = []
159
  try:
160
    try:
161
      num = qa_config.get('options', {}).get('burnin-instances', 1)
162
      for _ in xrange(0, num):
163
        instances.append(qa_config.AcquireInstance())
164
    except qa_error.OutOfInstancesError:
165
      print "Not enough instances, continuing anyway."
166

    
167
    if len(instances) < 1:
168
      raise qa_error.Error("Burnin needs at least one instance")
169

    
170
    script = qa_utils.UploadFile(master['primary'], '../tools/burnin')
171
    try:
172
      # Run burnin
173
      cmd = [script,
174
             '-p',
175
             '--os=%s' % qa_config.get('os'),
176
             '--disk-size=%s' % ",".join(qa_config.get('disk')),
177
             '--disk-growth=%s' % ",".join(qa_config.get('disk-growth')),
178
             '--disk-template=%s' % disk_template]
179
      if parallel:
180
        cmd.append('--parallel')
181
      if check_inst:
182
        cmd.append('--http-check')
183
      if do_rename:
184
        cmd.append('--rename=%s' % do_rename)
185
      cmd += [inst['name'] for inst in instances]
186
      AssertEqual(StartSSH(master['primary'],
187
                           utils.ShellQuoteArgs(cmd)).wait(), 0)
188
    finally:
189
      cmd = ['rm', '-f', script]
190
      AssertEqual(StartSSH(master['primary'],
191
                           utils.ShellQuoteArgs(cmd)).wait(), 0)
192
  finally:
193
    for inst in instances:
194
      qa_config.ReleaseInstance(inst)
195

    
196

    
197
def TestClusterMasterFailover():
198
  """gnt-cluster masterfailover"""
199
  master = qa_config.GetMasterNode()
200

    
201
  failovermaster = qa_config.AcquireNode(exclude=master)
202
  try:
203
    cmd = ['gnt-cluster', 'masterfailover']
204
    AssertEqual(StartSSH(failovermaster['primary'],
205
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
206

    
207
    cmd = ['gnt-cluster', 'masterfailover']
208
    AssertEqual(StartSSH(master['primary'],
209
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
210
  finally:
211
    qa_config.ReleaseNode(failovermaster)
212

    
213

    
214
def TestClusterCopyfile():
215
  """gnt-cluster copyfile"""
216
  master = qa_config.GetMasterNode()
217

    
218
  uniqueid = utils.NewUUID()
219

    
220
  # Create temporary file
221
  f = tempfile.NamedTemporaryFile()
222
  f.write(uniqueid)
223
  f.flush()
224
  f.seek(0)
225

    
226
  # Upload file to master node
227
  testname = qa_utils.UploadFile(master['primary'], f.name)
228
  try:
229
    # Copy file to all nodes
230
    cmd = ['gnt-cluster', 'copyfile', testname]
231
    AssertEqual(StartSSH(master['primary'],
232
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
233
    _CheckFileOnAllNodes(testname, uniqueid)
234
  finally:
235
    _RemoveFileFromAllNodes(testname)
236

    
237

    
238
def TestClusterCommand():
239
  """gnt-cluster command"""
240
  master = qa_config.GetMasterNode()
241

    
242
  uniqueid = utils.NewUUID()
243
  rfile = "/tmp/gnt%s" % utils.NewUUID()
244
  rcmd = utils.ShellQuoteArgs(['echo', '-n', uniqueid])
245
  cmd = utils.ShellQuoteArgs(['gnt-cluster', 'command',
246
                              "%s >%s" % (rcmd, rfile)])
247

    
248
  try:
249
    AssertEqual(StartSSH(master['primary'], cmd).wait(), 0)
250
    _CheckFileOnAllNodes(rfile, uniqueid)
251
  finally:
252
    _RemoveFileFromAllNodes(rfile)
253

    
254

    
255
def TestClusterDestroy():
256
  """gnt-cluster destroy"""
257
  master = qa_config.GetMasterNode()
258

    
259
  cmd = ['gnt-cluster', 'destroy', '--yes-do-it']
260
  AssertEqual(StartSSH(master['primary'],
261
                       utils.ShellQuoteArgs(cmd)).wait(), 0)