Statistics
| Branch: | Tag: | Revision:

root / qa / qa_cluster.py @ c99a3cc0

History | View | Annotate | Download (6.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 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-verify')
83
def TestClusterVerify():
84
  """gnt-cluster verify"""
85
  master = qa_config.GetMasterNode()
86

    
87
  cmd = ['gnt-cluster', 'verify']
88
  AssertEqual(StartSSH(master['primary'],
89
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
90

    
91

    
92
@qa_utils.DefineHook('cluster-info')
93
def TestClusterInfo():
94
  """gnt-cluster info"""
95
  master = qa_config.GetMasterNode()
96

    
97
  cmd = ['gnt-cluster', 'info']
98
  AssertEqual(StartSSH(master['primary'],
99
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
100

    
101

    
102
@qa_utils.DefineHook('cluster-getmaster')
103
def TestClusterGetmaster():
104
  """gnt-cluster getmaster"""
105
  master = qa_config.GetMasterNode()
106

    
107
  cmd = ['gnt-cluster', 'getmaster']
108
  AssertEqual(StartSSH(master['primary'],
109
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
110

    
111

    
112
@qa_utils.DefineHook('cluster-version')
113
def TestClusterVersion():
114
  """gnt-cluster version"""
115
  master = qa_config.GetMasterNode()
116

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

    
121

    
122
@qa_utils.DefineHook('cluster-burnin')
123
def TestClusterBurnin():
124
  """Burnin"""
125
  master = qa_config.GetMasterNode()
126

    
127
  disk_template = (qa_config.get('options', {}).
128
                   get('burnin-disk-template', 'remote_raid1'))
129

    
130
  # Get as many instances as we need
131
  instances = []
132
  try:
133
    try:
134
      num = qa_config.get('options', {}).get('burnin-instances', 1)
135
      for _ in xrange(0, num):
136
        instances.append(qa_config.AcquireInstance())
137
    except qa_error.OutOfInstancesError:
138
      print "Not enough instances, continuing anyway."
139

    
140
    if len(instances) < 1:
141
      raise qa_error.Error("Burnin needs at least one instance")
142

    
143
    script = qa_utils.UploadFile(master['primary'], '../tools/burnin')
144
    try:
145
      # Run burnin
146
      cmd = [script,
147
             '--os=%s' % qa_config.get('os'),
148
             '--os-size=%s' % qa_config.get('os-size'),
149
             '--swap-size=%s' % qa_config.get('swap-size'),
150
             '--disk-template=%s' % disk_template]
151
      cmd += [inst['name'] for inst in instances]
152
      AssertEqual(StartSSH(master['primary'],
153
                           utils.ShellQuoteArgs(cmd)).wait(), 0)
154
    finally:
155
      cmd = ['rm', '-f', script]
156
      AssertEqual(StartSSH(master['primary'],
157
                           utils.ShellQuoteArgs(cmd)).wait(), 0)
158
  finally:
159
    for inst in instances:
160
      qa_config.ReleaseInstance(inst)
161

    
162

    
163
@qa_utils.DefineHook('cluster-master-failover')
164
def TestClusterMasterFailover():
165
  """gnt-cluster masterfailover"""
166
  master = qa_config.GetMasterNode()
167

    
168
  failovermaster = qa_config.AcquireNode(exclude=master)
169
  try:
170
    cmd = ['gnt-cluster', 'masterfailover']
171
    AssertEqual(StartSSH(failovermaster['primary'],
172
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
173

    
174
    cmd = ['gnt-cluster', 'masterfailover']
175
    AssertEqual(StartSSH(master['primary'],
176
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
177
  finally:
178
    qa_config.ReleaseNode(failovermaster)
179

    
180

    
181
@qa_utils.DefineHook('cluster-copyfile')
182
def TestClusterCopyfile():
183
  """gnt-cluster copyfile"""
184
  master = qa_config.GetMasterNode()
185

    
186
  uniqueid = utils.NewUUID()
187

    
188
  # Create temporary file
189
  f = tempfile.NamedTemporaryFile()
190
  f.write(uniqueid)
191
  f.flush()
192
  f.seek(0)
193

    
194
  # Upload file to master node
195
  testname = qa_utils.UploadFile(master['primary'], f.name)
196
  try:
197
    # Copy file to all nodes
198
    cmd = ['gnt-cluster', 'copyfile', testname]
199
    AssertEqual(StartSSH(master['primary'],
200
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
201
    _CheckFileOnAllNodes(testname, uniqueid)
202
  finally:
203
    _RemoveFileFromAllNodes(testname)
204

    
205

    
206
@qa_utils.DefineHook('cluster-command')
207
def TestClusterCommand():
208
  """gnt-cluster command"""
209
  master = qa_config.GetMasterNode()
210

    
211
  uniqueid = utils.NewUUID()
212
  rfile = "/tmp/gnt%s" % utils.NewUUID()
213
  rcmd = utils.ShellQuoteArgs(['echo', '-n', uniqueid])
214
  cmd = utils.ShellQuoteArgs(['gnt-cluster', 'command',
215
                              "%s >%s" % (rcmd, rfile)])
216

    
217
  try:
218
    AssertEqual(StartSSH(master['primary'], cmd).wait(), 0)
219
    _CheckFileOnAllNodes(rfile, uniqueid)
220
  finally:
221
    _RemoveFileFromAllNodes(rfile)
222

    
223

    
224
@qa_utils.DefineHook('cluster-destroy')
225
def TestClusterDestroy():
226
  """gnt-cluster destroy"""
227
  master = qa_config.GetMasterNode()
228

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