Statistics
| Branch: | Tag: | Revision:

root / qa / qa_cluster.py @ e42b5307

History | View | Annotate | Download (6.2 kB)

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

    
18

    
19
"""Cluster related QA tests.
20

21
"""
22

    
23
import tempfile
24

    
25
from ganeti import utils
26

    
27
import qa_config
28
import qa_utils
29
import qa_error
30

    
31
from qa_utils import AssertEqual, StartSSH
32

    
33

    
34
def _RemoveFileFromAllNodes(filename):
35
  """Removes a file from all nodes.
36

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

    
43

    
44
def _CheckFileOnAllNodes(filename, content):
45
  """Verifies the content of the given file on all nodes.
46

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

    
53

    
54
@qa_utils.DefineHook('cluster-init')
55
def TestClusterInit():
56
  """gnt-cluster init"""
57
  master = qa_config.GetMasterNode()
58

    
59
  cmd = ['gnt-cluster', 'init']
60

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

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

    
69
  cmd.append(qa_config.get('name'))
70

    
71
  AssertEqual(StartSSH(master['primary'],
72
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
73

    
74

    
75
@qa_utils.DefineHook('cluster-verify')
76
def TestClusterVerify():
77
  """gnt-cluster verify"""
78
  master = qa_config.GetMasterNode()
79

    
80
  cmd = ['gnt-cluster', 'verify']
81
  AssertEqual(StartSSH(master['primary'],
82
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
83

    
84

    
85
@qa_utils.DefineHook('cluster-info')
86
def TestClusterInfo():
87
  """gnt-cluster info"""
88
  master = qa_config.GetMasterNode()
89

    
90
  cmd = ['gnt-cluster', 'info']
91
  AssertEqual(StartSSH(master['primary'],
92
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
93

    
94

    
95
@qa_utils.DefineHook('cluster-getmaster')
96
def TestClusterGetmaster():
97
  """gnt-cluster getmaster"""
98
  master = qa_config.GetMasterNode()
99

    
100
  cmd = ['gnt-cluster', 'getmaster']
101
  AssertEqual(StartSSH(master['primary'],
102
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
103

    
104

    
105
@qa_utils.DefineHook('cluster-version')
106
def TestClusterVersion():
107
  """gnt-cluster version"""
108
  master = qa_config.GetMasterNode()
109

    
110
  cmd = ['gnt-cluster', 'version']
111
  AssertEqual(StartSSH(master['primary'],
112
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
113

    
114

    
115
@qa_utils.DefineHook('cluster-burnin')
116
def TestClusterBurnin():
117
  """Burnin"""
118
  master = qa_config.GetMasterNode()
119

    
120
  # Get as many instances as we need
121
  instances = []
122
  try:
123
    num = qa_config.get('options', {}).get('burnin-instances', 1)
124
    for _ in xrange(0, num):
125
      instances.append(qa_config.AcquireInstance())
126
  except qa_error.OutOfInstancesError:
127
    print "Not enough instances, continuing anyway."
128

    
129
  if len(instances) < 1:
130
    raise qa_error.Error("Burnin needs at least one instance")
131

    
132
  # Run burnin
133
  try:
134
    script = qa_utils.UploadFile(master['primary'], '../tools/burnin')
135
    try:
136
      cmd = [script,
137
             '--os=%s' % qa_config.get('os'),
138
             '--os-size=%s' % qa_config.get('os-size'),
139
             '--swap-size=%s' % qa_config.get('swap-size')]
140
      cmd += [inst['name'] for inst in instances]
141
      AssertEqual(StartSSH(master['primary'],
142
                           utils.ShellQuoteArgs(cmd)).wait(), 0)
143
    finally:
144
      cmd = ['rm', '-f', script]
145
      AssertEqual(StartSSH(master['primary'],
146
                           utils.ShellQuoteArgs(cmd)).wait(), 0)
147
  finally:
148
    for inst in instances:
149
      qa_config.ReleaseInstance(inst)
150

    
151

    
152
@qa_utils.DefineHook('cluster-master-failover')
153
def TestClusterMasterFailover():
154
  """gnt-cluster masterfailover"""
155
  master = qa_config.GetMasterNode()
156

    
157
  failovermaster = qa_config.AcquireNode(exclude=master)
158
  try:
159
    cmd = ['gnt-cluster', 'masterfailover']
160
    AssertEqual(StartSSH(failovermaster['primary'],
161
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
162

    
163
    cmd = ['gnt-cluster', 'masterfailover']
164
    AssertEqual(StartSSH(master['primary'],
165
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
166
  finally:
167
    qa_config.ReleaseNode(failovermaster)
168

    
169

    
170
@qa_utils.DefineHook('cluster-copyfile')
171
def TestClusterCopyfile():
172
  """gnt-cluster copyfile"""
173
  master = qa_config.GetMasterNode()
174

    
175
  uniqueid = utils.NewUUID()
176

    
177
  # Create temporary file
178
  f = tempfile.NamedTemporaryFile()
179
  f.write(uniqueid)
180
  f.flush()
181
  f.seek(0)
182

    
183
  # Upload file to master node
184
  testname = qa_utils.UploadFile(master['primary'], f.name)
185
  try:
186
    # Copy file to all nodes
187
    cmd = ['gnt-cluster', 'copyfile', testname]
188
    AssertEqual(StartSSH(master['primary'],
189
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
190
    _CheckFileOnAllNodes(testname, uniqueid)
191
  finally:
192
    _RemoveFileFromAllNodes(testname)
193

    
194

    
195
@qa_utils.DefineHook('cluster-command')
196
def TestClusterCommand():
197
  """gnt-cluster command"""
198
  master = qa_config.GetMasterNode()
199

    
200
  uniqueid = utils.NewUUID()
201
  rfile = "/tmp/gnt%s" % utils.NewUUID()
202
  rcmd = utils.ShellQuoteArgs(['echo', '-n', uniqueid])
203
  cmd = utils.ShellQuoteArgs(['gnt-cluster', 'command',
204
                              "%s >%s" % (rcmd, rfile)])
205

    
206
  try:
207
    AssertEqual(StartSSH(master['primary'], cmd).wait(), 0)
208
    _CheckFileOnAllNodes(rfile, uniqueid)
209
  finally:
210
    _RemoveFileFromAllNodes(rfile)
211

    
212

    
213
@qa_utils.DefineHook('cluster-destroy')
214
def TestClusterDestroy():
215
  """gnt-cluster destroy"""
216
  master = qa_config.GetMasterNode()
217

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