Statistics
| Branch: | Tag: | Revision:

root / qa / qa_cluster.py @ 283f9d4c

History | View | Annotate | Download (4.9 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 TestClusterInit():
35
  """gnt-cluster init"""
36
  master = qa_config.GetMasterNode()
37

    
38
  cmd = ['gnt-cluster', 'init']
39

    
40
  if master.get('secondary', None):
41
    cmd.append('--secondary-ip=%s' % master['secondary'])
42

    
43
  bridge = qa_config.get('bridge', None)
44
  if bridge:
45
    cmd.append('--bridge=%s' % bridge)
46
    cmd.append('--master-netdev=%s' % bridge)
47

    
48
  cmd.append(qa_config.get('name'))
49

    
50
  AssertEqual(StartSSH(master['primary'],
51
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
52

    
53

    
54
def TestClusterVerify():
55
  """gnt-cluster verify"""
56
  master = qa_config.GetMasterNode()
57

    
58
  cmd = ['gnt-cluster', 'verify']
59
  AssertEqual(StartSSH(master['primary'],
60
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
61

    
62

    
63
def TestClusterInfo():
64
  """gnt-cluster info"""
65
  master = qa_config.GetMasterNode()
66

    
67
  cmd = ['gnt-cluster', 'info']
68
  AssertEqual(StartSSH(master['primary'],
69
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
70

    
71

    
72
def TestClusterGetmaster():
73
  """gnt-cluster getmaster"""
74
  master = qa_config.GetMasterNode()
75

    
76
  cmd = ['gnt-cluster', 'getmaster']
77
  AssertEqual(StartSSH(master['primary'],
78
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
79

    
80

    
81
def TestClusterVersion():
82
  """gnt-cluster version"""
83
  master = qa_config.GetMasterNode()
84

    
85
  cmd = ['gnt-cluster', 'version']
86
  AssertEqual(StartSSH(master['primary'],
87
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
88

    
89

    
90
def TestClusterBurnin():
91
  """Burnin"""
92
  master = qa_config.GetMasterNode()
93

    
94
  # Get as many instances as we need
95
  instances = []
96
  try:
97
    num = qa_config.get('options', {}).get('burnin-instances', 1)
98
    for _ in xrange(0, num):
99
      instances.append(qa_config.AcquireInstance())
100
  except qa_error.OutOfInstancesError:
101
    print "Not enough instances, continuing anyway."
102

    
103
  if len(instances) < 1:
104
    raise qa_error.Error("Burnin needs at least one instance")
105

    
106
  # Run burnin
107
  try:
108
    script = qa_utils.UploadFile(master['primary'], '../tools/burnin')
109
    try:
110
      cmd = [script,
111
             '--os=%s' % qa_config.get('os'),
112
             '--os-size=%s' % qa_config.get('os-size'),
113
             '--swap-size=%s' % qa_config.get('swap-size')]
114
      cmd += [inst['name'] for inst in instances]
115
      AssertEqual(StartSSH(master['primary'],
116
                           utils.ShellQuoteArgs(cmd)).wait(), 0)
117
    finally:
118
      cmd = ['rm', '-f', script]
119
      AssertEqual(StartSSH(master['primary'],
120
                           utils.ShellQuoteArgs(cmd)).wait(), 0)
121
  finally:
122
    for inst in instances:
123
      qa_config.ReleaseInstance(inst)
124

    
125

    
126
def TestClusterMasterFailover():
127
  """gnt-cluster masterfailover"""
128
  master = qa_config.GetMasterNode()
129

    
130
  failovermaster = qa_config.AcquireNode(exclude=master)
131
  try:
132
    cmd = ['gnt-cluster', 'masterfailover']
133
    AssertEqual(StartSSH(failovermaster['primary'],
134
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
135

    
136
    cmd = ['gnt-cluster', 'masterfailover']
137
    AssertEqual(StartSSH(master['primary'],
138
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
139
  finally:
140
    qa_config.ReleaseNode(failovermaster)
141

    
142

    
143
def TestClusterCopyfile():
144
  """gnt-cluster copyfile"""
145
  master = qa_config.GetMasterNode()
146

    
147
  # Create temporary file
148
  f = tempfile.NamedTemporaryFile()
149
  f.write("I'm a testfile.\n")
150
  f.flush()
151
  f.seek(0)
152

    
153
  # Upload file to master node
154
  testname = qa_utils.UploadFile(master['primary'], f.name)
155
  try:
156
    # Copy file to all nodes
157
    cmd = ['gnt-cluster', 'copyfile', testname]
158
    AssertEqual(StartSSH(master['primary'],
159
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
160
  finally:
161
    # Remove file from all nodes
162
    for node in qa_config.get('nodes'):
163
      cmd = ['rm', '-f', testname]
164
      AssertEqual(StartSSH(node['primary'],
165
                           utils.ShellQuoteArgs(cmd)).wait(), 0)
166

    
167

    
168
def TestClusterDestroy():
169
  """gnt-cluster destroy"""
170
  master = qa_config.GetMasterNode()
171

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