Statistics
| Branch: | Tag: | Revision:

root / qa / qa_cluster.py @ 6b7d5878

History | View | Annotate | Download (8.9 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 constants
29
from ganeti import bootstrap
30
from ganeti import utils
31

    
32
import qa_config
33
import qa_utils
34
import qa_error
35

    
36
from qa_utils import AssertEqual, AssertNotEqual, StartSSH
37

    
38

    
39
def _RemoveFileFromAllNodes(filename):
40
  """Removes a file from all nodes.
41

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

    
48

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

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

    
58

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

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

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

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

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

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

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

    
82

    
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
def TestClusterVerify():
114
  """gnt-cluster verify"""
115
  master = qa_config.GetMasterNode()
116

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

    
121

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

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

    
130

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

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

    
139

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

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

    
148

    
149
def TestClusterRenewCrypto():
150
  """gnt-cluster renew-crypto"""
151
  master = qa_config.GetMasterNode()
152

    
153
  # Conflicting options
154
  cmd = ["gnt-cluster", "renew-crypto", "--force",
155
         "--new-cluster-certificate", "--new-confd-hmac-key",
156
         "--new-rapi-certificate", "--rapi-certificate=/dev/null"]
157
  AssertNotEqual(StartSSH(master["primary"],
158
                          utils.ShellQuoteArgs(cmd)).wait(), 0)
159

    
160
  # Invalid RAPI certificate
161
  cmd = ["gnt-cluster", "renew-crypto", "--force",
162
         "--rapi-certificate=/dev/null"]
163
  AssertNotEqual(StartSSH(master["primary"],
164
                          utils.ShellQuoteArgs(cmd)).wait(), 0)
165

    
166
  # Custom RAPI certificate
167
  fh = tempfile.NamedTemporaryFile()
168

    
169
  # Ensure certificate doesn't cause "gnt-cluster verify" to complain
170
  validity = constants.SSL_CERT_EXPIRATION_WARN * 3
171

    
172
  bootstrap.GenerateSelfSignedSslCert(fh.name, validity=validity)
173

    
174
  tmpcert = qa_utils.UploadFile(master["primary"], fh.name)
175
  try:
176
    cmd = ["gnt-cluster", "renew-crypto", "--force",
177
           "--rapi-certificate=%s" % tmpcert]
178
    AssertEqual(StartSSH(master["primary"],
179
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
180
  finally:
181
    cmd = ["rm", "-f", tmpcert]
182
    AssertEqual(StartSSH(master["primary"],
183
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
184

    
185
  # Normal case
186
  cmd = ["gnt-cluster", "renew-crypto", "--force",
187
         "--new-cluster-certificate", "--new-confd-hmac-key",
188
         "--new-rapi-certificate"]
189
  AssertEqual(StartSSH(master["primary"],
190
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
191

    
192

    
193
def TestClusterBurnin():
194
  """Burnin"""
195
  master = qa_config.GetMasterNode()
196

    
197
  options = qa_config.get('options', {})
198
  disk_template = options.get('burnin-disk-template', 'drbd')
199
  parallel = options.get('burnin-in-parallel', False)
200
  check_inst = options.get('burnin-check-instances', False)
201
  do_rename = options.get('burnin-rename', '')
202

    
203
  # Get as many instances as we need
204
  instances = []
205
  try:
206
    try:
207
      num = qa_config.get('options', {}).get('burnin-instances', 1)
208
      for _ in range(0, num):
209
        instances.append(qa_config.AcquireInstance())
210
    except qa_error.OutOfInstancesError:
211
      print "Not enough instances, continuing anyway."
212

    
213
    if len(instances) < 1:
214
      raise qa_error.Error("Burnin needs at least one instance")
215

    
216
    script = qa_utils.UploadFile(master['primary'], '../tools/burnin')
217
    try:
218
      # Run burnin
219
      cmd = [script,
220
             '-p',
221
             '--os=%s' % qa_config.get('os'),
222
             '--disk-size=%s' % ",".join(qa_config.get('disk')),
223
             '--disk-growth=%s' % ",".join(qa_config.get('disk-growth')),
224
             '--disk-template=%s' % disk_template]
225
      if parallel:
226
        cmd.append('--parallel')
227
      if check_inst:
228
        cmd.append('--http-check')
229
      if do_rename:
230
        cmd.append('--rename=%s' % do_rename)
231
      cmd += [inst['name'] for inst in instances]
232
      AssertEqual(StartSSH(master['primary'],
233
                           utils.ShellQuoteArgs(cmd)).wait(), 0)
234
    finally:
235
      cmd = ['rm', '-f', script]
236
      AssertEqual(StartSSH(master['primary'],
237
                           utils.ShellQuoteArgs(cmd)).wait(), 0)
238
  finally:
239
    for inst in instances:
240
      qa_config.ReleaseInstance(inst)
241

    
242

    
243
def TestClusterMasterFailover():
244
  """gnt-cluster masterfailover"""
245
  master = qa_config.GetMasterNode()
246

    
247
  failovermaster = qa_config.AcquireNode(exclude=master)
248
  try:
249
    cmd = ['gnt-cluster', 'masterfailover']
250
    AssertEqual(StartSSH(failovermaster['primary'],
251
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
252

    
253
    cmd = ['gnt-cluster', 'masterfailover']
254
    AssertEqual(StartSSH(master['primary'],
255
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
256
  finally:
257
    qa_config.ReleaseNode(failovermaster)
258

    
259

    
260
def TestClusterCopyfile():
261
  """gnt-cluster copyfile"""
262
  master = qa_config.GetMasterNode()
263

    
264
  uniqueid = utils.NewUUID()
265

    
266
  # Create temporary file
267
  f = tempfile.NamedTemporaryFile()
268
  f.write(uniqueid)
269
  f.flush()
270
  f.seek(0)
271

    
272
  # Upload file to master node
273
  testname = qa_utils.UploadFile(master['primary'], f.name)
274
  try:
275
    # Copy file to all nodes
276
    cmd = ['gnt-cluster', 'copyfile', testname]
277
    AssertEqual(StartSSH(master['primary'],
278
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
279
    _CheckFileOnAllNodes(testname, uniqueid)
280
  finally:
281
    _RemoveFileFromAllNodes(testname)
282

    
283

    
284
def TestClusterCommand():
285
  """gnt-cluster command"""
286
  master = qa_config.GetMasterNode()
287

    
288
  uniqueid = utils.NewUUID()
289
  rfile = "/tmp/gnt%s" % utils.NewUUID()
290
  rcmd = utils.ShellQuoteArgs(['echo', '-n', uniqueid])
291
  cmd = utils.ShellQuoteArgs(['gnt-cluster', 'command',
292
                              "%s >%s" % (rcmd, rfile)])
293

    
294
  try:
295
    AssertEqual(StartSSH(master['primary'], cmd).wait(), 0)
296
    _CheckFileOnAllNodes(rfile, uniqueid)
297
  finally:
298
    _RemoveFileFromAllNodes(rfile)
299

    
300

    
301
def TestClusterDestroy():
302
  """gnt-cluster destroy"""
303
  master = qa_config.GetMasterNode()
304

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