Statistics
| Branch: | Tag: | Revision:

root / qa / qa_cluster.py @ 9b3939ea

History | View | Annotate | Download (6.3 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
  disk_template = (qa_config.get('options', {}).
121
                   get('burnin-disk-template', 'remote_raid1'))
122

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

    
133
    if len(instances) < 1:
134
      raise qa_error.Error("Burnin needs at least one instance")
135

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

    
155

    
156
@qa_utils.DefineHook('cluster-master-failover')
157
def TestClusterMasterFailover():
158
  """gnt-cluster masterfailover"""
159
  master = qa_config.GetMasterNode()
160

    
161
  failovermaster = qa_config.AcquireNode(exclude=master)
162
  try:
163
    cmd = ['gnt-cluster', 'masterfailover']
164
    AssertEqual(StartSSH(failovermaster['primary'],
165
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
166

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

    
173

    
174
@qa_utils.DefineHook('cluster-copyfile')
175
def TestClusterCopyfile():
176
  """gnt-cluster copyfile"""
177
  master = qa_config.GetMasterNode()
178

    
179
  uniqueid = utils.NewUUID()
180

    
181
  # Create temporary file
182
  f = tempfile.NamedTemporaryFile()
183
  f.write(uniqueid)
184
  f.flush()
185
  f.seek(0)
186

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

    
198

    
199
@qa_utils.DefineHook('cluster-command')
200
def TestClusterCommand():
201
  """gnt-cluster command"""
202
  master = qa_config.GetMasterNode()
203

    
204
  uniqueid = utils.NewUUID()
205
  rfile = "/tmp/gnt%s" % utils.NewUUID()
206
  rcmd = utils.ShellQuoteArgs(['echo', '-n', uniqueid])
207
  cmd = utils.ShellQuoteArgs(['gnt-cluster', 'command',
208
                              "%s >%s" % (rcmd, rfile)])
209

    
210
  try:
211
    AssertEqual(StartSSH(master['primary'], cmd).wait(), 0)
212
    _CheckFileOnAllNodes(rfile, uniqueid)
213
  finally:
214
    _RemoveFileFromAllNodes(rfile)
215

    
216

    
217
@qa_utils.DefineHook('cluster-destroy')
218
def TestClusterDestroy():
219
  """gnt-cluster destroy"""
220
  master = qa_config.GetMasterNode()
221

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