Statistics
| Branch: | Tag: | Revision:

root / qa / qa_cluster.py @ 7910e7a5

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
@qa_utils.DefineHook('cluster-init')
58
def TestClusterInit():
59
  """gnt-cluster init"""
60
  master = qa_config.GetMasterNode()
61

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

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

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

    
72
  htype = qa_config.get('hypervisor-type', None)
73
  if htype:
74
    cmd.append('--hypervisor-type=%s' % htype)
75

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

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

    
81

    
82
@qa_utils.DefineHook('cluster-rename')
83
def TestClusterRename():
84
  """gnt-cluster rename"""
85
  master = qa_config.GetMasterNode()
86

    
87
  cmd = ['gnt-cluster', 'rename', '-f']
88

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

    
95
  cmd_1 = cmd + [rename_target]
96
  cmd_2 = cmd + [original_name]
97

    
98
  cmd_verify = ['gnt-cluster', 'verify']
99

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

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

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

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

    
112

    
113
@qa_utils.DefineHook('cluster-verify')
114
def TestClusterVerify():
115
  """gnt-cluster verify"""
116
  master = qa_config.GetMasterNode()
117

    
118
  cmd = ['gnt-cluster', 'verify']
119
  AssertEqual(StartSSH(master['primary'],
120
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
121

    
122

    
123
@qa_utils.DefineHook('cluster-info')
124
def TestClusterInfo():
125
  """gnt-cluster info"""
126
  master = qa_config.GetMasterNode()
127

    
128
  cmd = ['gnt-cluster', 'info']
129
  AssertEqual(StartSSH(master['primary'],
130
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
131

    
132

    
133
@qa_utils.DefineHook('cluster-getmaster')
134
def TestClusterGetmaster():
135
  """gnt-cluster getmaster"""
136
  master = qa_config.GetMasterNode()
137

    
138
  cmd = ['gnt-cluster', 'getmaster']
139
  AssertEqual(StartSSH(master['primary'],
140
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
141

    
142

    
143
@qa_utils.DefineHook('cluster-version')
144
def TestClusterVersion():
145
  """gnt-cluster version"""
146
  master = qa_config.GetMasterNode()
147

    
148
  cmd = ['gnt-cluster', 'version']
149
  AssertEqual(StartSSH(master['primary'],
150
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
151

    
152

    
153
@qa_utils.DefineHook('cluster-burnin')
154
def TestClusterBurnin():
155
  """Burnin"""
156
  master = qa_config.GetMasterNode()
157

    
158
  disk_template = (qa_config.get('options', {}).
159
                   get('burnin-disk-template', 'drbd'))
160

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

    
171
    if len(instances) < 1:
172
      raise qa_error.Error("Burnin needs at least one instance")
173

    
174
    script = qa_utils.UploadFile(master['primary'], '../tools/burnin')
175
    try:
176
      # Run burnin
177
      cmd = [script,
178
             '--os=%s' % qa_config.get('os'),
179
             '--os-size=%s' % qa_config.get('os-size'),
180
             '--swap-size=%s' % qa_config.get('swap-size'),
181
             '--disk-template=%s' % disk_template]
182
      cmd += [inst['name'] for inst in instances]
183
      AssertEqual(StartSSH(master['primary'],
184
                           utils.ShellQuoteArgs(cmd)).wait(), 0)
185
    finally:
186
      cmd = ['rm', '-f', script]
187
      AssertEqual(StartSSH(master['primary'],
188
                           utils.ShellQuoteArgs(cmd)).wait(), 0)
189
  finally:
190
    for inst in instances:
191
      qa_config.ReleaseInstance(inst)
192

    
193

    
194
@qa_utils.DefineHook('cluster-master-failover')
195
def TestClusterMasterFailover():
196
  """gnt-cluster masterfailover"""
197
  master = qa_config.GetMasterNode()
198

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

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

    
211

    
212
@qa_utils.DefineHook('cluster-copyfile')
213
def TestClusterCopyfile():
214
  """gnt-cluster copyfile"""
215
  master = qa_config.GetMasterNode()
216

    
217
  uniqueid = utils.NewUUID()
218

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

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

    
236

    
237
@qa_utils.DefineHook('cluster-command')
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
@qa_utils.DefineHook('cluster-destroy')
256
def TestClusterDestroy():
257
  """gnt-cluster destroy"""
258
  master = qa_config.GetMasterNode()
259

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