Statistics
| Branch: | Tag: | Revision:

root / qa / qa_cluster.py @ 06fcbaf1

History | View | Annotate | Download (9.5 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
  # Create RAPI credentials
83
  rapi_user = qa_config.get("rapi-user", default=None)
84
  rapi_pass = qa_config.get("rapi-pass", default=None)
85

    
86
  if rapi_user and rapi_pass:
87
    cmds = []
88

    
89
    cred_string = "%s %s write" % (rapi_user, rapi_pass)
90
    cmds.append(("echo %s >> %s" %
91
                 (utils.ShellQuote(cred_string),
92
                  utils.ShellQuote(constants.RAPI_USERS_FILE))))
93
    cmds.append("%s stop-master" % constants.DAEMON_UTIL)
94
    cmds.append("%s start-master" % constants.DAEMON_UTIL)
95
    AssertEqual(StartSSH(master['primary'], ' && '.join(cmds)).wait(), 0)
96

    
97

    
98
def TestClusterRename():
99
  """gnt-cluster rename"""
100
  master = qa_config.GetMasterNode()
101

    
102
  cmd = ['gnt-cluster', 'rename', '-f']
103

    
104
  original_name = qa_config.get('name')
105
  rename_target = qa_config.get('rename', None)
106
  if rename_target is None:
107
    print qa_utils.FormatError('"rename" entry is missing')
108
    return
109

    
110
  cmd_1 = cmd + [rename_target]
111
  cmd_2 = cmd + [original_name]
112

    
113
  cmd_verify = ['gnt-cluster', 'verify']
114

    
115
  AssertEqual(StartSSH(master['primary'],
116
                       utils.ShellQuoteArgs(cmd_1)).wait(), 0)
117

    
118
  AssertEqual(StartSSH(master['primary'],
119
                       utils.ShellQuoteArgs(cmd_verify)).wait(), 0)
120

    
121
  AssertEqual(StartSSH(master['primary'],
122
                       utils.ShellQuoteArgs(cmd_2)).wait(), 0)
123

    
124
  AssertEqual(StartSSH(master['primary'],
125
                       utils.ShellQuoteArgs(cmd_verify)).wait(), 0)
126

    
127

    
128
def TestClusterVerify():
129
  """gnt-cluster verify"""
130
  master = qa_config.GetMasterNode()
131

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

    
136

    
137
def TestClusterInfo():
138
  """gnt-cluster info"""
139
  master = qa_config.GetMasterNode()
140

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

    
145

    
146
def TestClusterGetmaster():
147
  """gnt-cluster getmaster"""
148
  master = qa_config.GetMasterNode()
149

    
150
  cmd = ['gnt-cluster', 'getmaster']
151
  AssertEqual(StartSSH(master['primary'],
152
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
153

    
154

    
155
def TestClusterVersion():
156
  """gnt-cluster version"""
157
  master = qa_config.GetMasterNode()
158

    
159
  cmd = ['gnt-cluster', 'version']
160
  AssertEqual(StartSSH(master['primary'],
161
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
162

    
163

    
164
def TestClusterRenewCrypto():
165
  """gnt-cluster renew-crypto"""
166
  master = qa_config.GetMasterNode()
167

    
168
  # Conflicting options
169
  cmd = ["gnt-cluster", "renew-crypto", "--force",
170
         "--new-cluster-certificate", "--new-confd-hmac-key",
171
         "--new-rapi-certificate", "--rapi-certificate=/dev/null"]
172
  AssertNotEqual(StartSSH(master["primary"],
173
                          utils.ShellQuoteArgs(cmd)).wait(), 0)
174

    
175
  # Invalid RAPI certificate
176
  cmd = ["gnt-cluster", "renew-crypto", "--force",
177
         "--rapi-certificate=/dev/null"]
178
  AssertNotEqual(StartSSH(master["primary"],
179
                          utils.ShellQuoteArgs(cmd)).wait(), 0)
180

    
181
  # Custom RAPI certificate
182
  fh = tempfile.NamedTemporaryFile()
183

    
184
  # Ensure certificate doesn't cause "gnt-cluster verify" to complain
185
  validity = constants.SSL_CERT_EXPIRATION_WARN * 3
186

    
187
  bootstrap.GenerateSelfSignedSslCert(fh.name, validity=validity)
188

    
189
  tmpcert = qa_utils.UploadFile(master["primary"], fh.name)
190
  try:
191
    cmd = ["gnt-cluster", "renew-crypto", "--force",
192
           "--rapi-certificate=%s" % tmpcert]
193
    AssertEqual(StartSSH(master["primary"],
194
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
195
  finally:
196
    cmd = ["rm", "-f", tmpcert]
197
    AssertEqual(StartSSH(master["primary"],
198
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
199

    
200
  # Normal case
201
  cmd = ["gnt-cluster", "renew-crypto", "--force",
202
         "--new-cluster-certificate", "--new-confd-hmac-key",
203
         "--new-rapi-certificate"]
204
  AssertEqual(StartSSH(master["primary"],
205
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
206

    
207

    
208
def TestClusterBurnin():
209
  """Burnin"""
210
  master = qa_config.GetMasterNode()
211

    
212
  options = qa_config.get('options', {})
213
  disk_template = options.get('burnin-disk-template', 'drbd')
214
  parallel = options.get('burnin-in-parallel', False)
215
  check_inst = options.get('burnin-check-instances', False)
216
  do_rename = options.get('burnin-rename', '')
217

    
218
  # Get as many instances as we need
219
  instances = []
220
  try:
221
    try:
222
      num = qa_config.get('options', {}).get('burnin-instances', 1)
223
      for _ in range(0, num):
224
        instances.append(qa_config.AcquireInstance())
225
    except qa_error.OutOfInstancesError:
226
      print "Not enough instances, continuing anyway."
227

    
228
    if len(instances) < 1:
229
      raise qa_error.Error("Burnin needs at least one instance")
230

    
231
    script = qa_utils.UploadFile(master['primary'], '../tools/burnin')
232
    try:
233
      # Run burnin
234
      cmd = [script,
235
             '-p',
236
             '--os=%s' % qa_config.get('os'),
237
             '--disk-size=%s' % ",".join(qa_config.get('disk')),
238
             '--disk-growth=%s' % ",".join(qa_config.get('disk-growth')),
239
             '--disk-template=%s' % disk_template]
240
      if parallel:
241
        cmd.append('--parallel')
242
      if check_inst:
243
        cmd.append('--http-check')
244
      if do_rename:
245
        cmd.append('--rename=%s' % do_rename)
246
      cmd += [inst['name'] for inst in instances]
247
      AssertEqual(StartSSH(master['primary'],
248
                           utils.ShellQuoteArgs(cmd)).wait(), 0)
249
    finally:
250
      cmd = ['rm', '-f', script]
251
      AssertEqual(StartSSH(master['primary'],
252
                           utils.ShellQuoteArgs(cmd)).wait(), 0)
253
  finally:
254
    for inst in instances:
255
      qa_config.ReleaseInstance(inst)
256

    
257

    
258
def TestClusterMasterFailover():
259
  """gnt-cluster masterfailover"""
260
  master = qa_config.GetMasterNode()
261

    
262
  failovermaster = qa_config.AcquireNode(exclude=master)
263
  try:
264
    cmd = ['gnt-cluster', 'masterfailover']
265
    AssertEqual(StartSSH(failovermaster['primary'],
266
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
267

    
268
    cmd = ['gnt-cluster', 'masterfailover']
269
    AssertEqual(StartSSH(master['primary'],
270
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
271
  finally:
272
    qa_config.ReleaseNode(failovermaster)
273

    
274

    
275
def TestClusterCopyfile():
276
  """gnt-cluster copyfile"""
277
  master = qa_config.GetMasterNode()
278

    
279
  uniqueid = utils.NewUUID()
280

    
281
  # Create temporary file
282
  f = tempfile.NamedTemporaryFile()
283
  f.write(uniqueid)
284
  f.flush()
285
  f.seek(0)
286

    
287
  # Upload file to master node
288
  testname = qa_utils.UploadFile(master['primary'], f.name)
289
  try:
290
    # Copy file to all nodes
291
    cmd = ['gnt-cluster', 'copyfile', testname]
292
    AssertEqual(StartSSH(master['primary'],
293
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
294
    _CheckFileOnAllNodes(testname, uniqueid)
295
  finally:
296
    _RemoveFileFromAllNodes(testname)
297

    
298

    
299
def TestClusterCommand():
300
  """gnt-cluster command"""
301
  master = qa_config.GetMasterNode()
302

    
303
  uniqueid = utils.NewUUID()
304
  rfile = "/tmp/gnt%s" % utils.NewUUID()
305
  rcmd = utils.ShellQuoteArgs(['echo', '-n', uniqueid])
306
  cmd = utils.ShellQuoteArgs(['gnt-cluster', 'command',
307
                              "%s >%s" % (rcmd, rfile)])
308

    
309
  try:
310
    AssertEqual(StartSSH(master['primary'], cmd).wait(), 0)
311
    _CheckFileOnAllNodes(rfile, uniqueid)
312
  finally:
313
    _RemoveFileFromAllNodes(rfile)
314

    
315

    
316
def TestClusterDestroy():
317
  """gnt-cluster destroy"""
318
  master = qa_config.GetMasterNode()
319

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