Statistics
| Branch: | Tag: | Revision:

root / qa / qa_instance.py @ 283f9d4c

History | View | Annotate | Download (5 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
"""Instance related QA tests.
20

21
"""
22

    
23
from ganeti import utils
24
from ganeti import constants
25

    
26
import qa_config
27
import qa_utils
28

    
29
from qa_utils import AssertEqual, StartSSH
30

    
31

    
32
def _GetGenericAddParameters():
33
  return ['--os-size=%s' % qa_config.get('os-size'),
34
          '--swap-size=%s' % qa_config.get('swap-size'),
35
          '--memory=%s' % qa_config.get('mem')]
36

    
37

    
38
def _DiskTest(node, args):
39
  master = qa_config.GetMasterNode()
40

    
41
  instance = qa_config.AcquireInstance()
42
  try:
43
    cmd = (['gnt-instance', 'add',
44
            '--os-type=%s' % qa_config.get('os'),
45
            '--node=%s' % node['primary']] +
46
           _GetGenericAddParameters())
47
    if args:
48
      cmd += args
49
    cmd.append(instance['name'])
50

    
51
    AssertEqual(StartSSH(master['primary'],
52
                         utils.ShellQuoteArgs(cmd)).wait(), 0)
53
    return instance
54
  except:
55
    qa_config.ReleaseInstance(instance)
56
    raise
57

    
58

    
59
def TestInstanceAddWithPlainDisk(node):
60
  """gnt-instance add -t plain"""
61
  return _DiskTest(node, ['--disk-template=plain'])
62

    
63

    
64
def TestInstanceAddWithLocalMirrorDisk(node):
65
  """gnt-instance add -t local_raid1"""
66
  return _DiskTest(node, ['--disk-template=local_raid1'])
67

    
68

    
69
def TestInstanceAddWithRemoteRaidDisk(node, node2):
70
  """gnt-instance add -t remote_raid1"""
71
  return _DiskTest(node,
72
                   ['--disk-template=remote_raid1',
73
                    '--secondary-node=%s' % node2['primary']])
74

    
75

    
76
def TestInstanceRemove(instance):
77
  """gnt-instance remove"""
78
  master = qa_config.GetMasterNode()
79

    
80
  cmd = ['gnt-instance', 'remove', '-f', instance['name']]
81
  AssertEqual(StartSSH(master['primary'],
82
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
83

    
84
  qa_config.ReleaseInstance(instance)
85

    
86

    
87
def TestInstanceStartup(instance):
88
  """gnt-instance startup"""
89
  master = qa_config.GetMasterNode()
90

    
91
  cmd = ['gnt-instance', 'startup', instance['name']]
92
  AssertEqual(StartSSH(master['primary'],
93
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
94

    
95

    
96
def TestInstanceShutdown(instance):
97
  """gnt-instance shutdown"""
98
  master = qa_config.GetMasterNode()
99

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

    
104

    
105
def TestInstanceReinstall(instance):
106
  """gnt-instance reinstall"""
107
  master = qa_config.GetMasterNode()
108

    
109
  cmd = ['gnt-instance', 'reinstall', '-f', instance['name']]
110
  AssertEqual(StartSSH(master['primary'],
111
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
112

    
113

    
114
def TestInstanceFailover(instance):
115
  """gnt-instance failover"""
116
  master = qa_config.GetMasterNode()
117

    
118
  cmd = ['gnt-instance', 'failover', '--force', instance['name']]
119
  AssertEqual(StartSSH(master['primary'],
120
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
121

    
122

    
123
def TestInstanceInfo(instance):
124
  """gnt-instance info"""
125
  master = qa_config.GetMasterNode()
126

    
127
  cmd = ['gnt-instance', 'info', instance['name']]
128
  AssertEqual(StartSSH(master['primary'],
129
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
130

    
131

    
132
def TestInstanceList():
133
  """gnt-instance list"""
134
  master = qa_config.GetMasterNode()
135

    
136
  cmd = ['gnt-instance', 'list']
137
  AssertEqual(StartSSH(master['primary'],
138
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
139

    
140

    
141
def TestInstanceExport(instance, node):
142
  """gnt-backup export"""
143
  master = qa_config.GetMasterNode()
144

    
145
  cmd = ['gnt-backup', 'export', '-n', node['primary'], instance['name']]
146
  AssertEqual(StartSSH(master['primary'],
147
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
148

    
149
  return qa_utils.ResolveInstanceName(instance)
150

    
151

    
152
def TestInstanceImport(node, newinst, expnode, name):
153
  """gnt-backup import"""
154
  master = qa_config.GetMasterNode()
155

    
156
  cmd = (['gnt-backup', 'import',
157
          '--disk-template=plain',
158
          '--no-ip-check',
159
          '--src-node=%s' % expnode['primary'],
160
          '--src-dir=%s/%s' % (constants.EXPORT_DIR, name),
161
          '--node=%s' % node['primary']] +
162
         _GetGenericAddParameters())
163
  cmd.append(newinst['name'])
164
  AssertEqual(StartSSH(master['primary'],
165
                       utils.ShellQuoteArgs(cmd)).wait(), 0)
166

    
167

    
168
def TestBackupList(expnode):
169
  """gnt-backup list"""
170
  master = qa_config.GetMasterNode()
171

    
172
  cmd = ['gnt-backup', 'list', '--nodes=%s' % expnode['primary']]
173
  AssertEqual(StartSSH(master['primary'],
174
                       utils.ShellQuoteArgs(cmd)).wait(), 0)