root / qa / qa_instance.py @ 5d640672
History | View | Annotate | Download (4.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 |
"""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 TestInstanceFailover(instance): |
106 |
"""gnt-instance failover"""
|
107 |
master = qa_config.GetMasterNode() |
108 |
|
109 |
cmd = ['gnt-instance', 'failover', '--force', instance['name']] |
110 |
AssertEqual(StartSSH(master['primary'],
|
111 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
112 |
|
113 |
|
114 |
def TestInstanceInfo(instance): |
115 |
"""gnt-instance info"""
|
116 |
master = qa_config.GetMasterNode() |
117 |
|
118 |
cmd = ['gnt-instance', 'info', instance['name']] |
119 |
AssertEqual(StartSSH(master['primary'],
|
120 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
121 |
|
122 |
|
123 |
def TestInstanceExport(instance, node): |
124 |
"""gnt-backup export"""
|
125 |
master = qa_config.GetMasterNode() |
126 |
|
127 |
cmd = ['gnt-backup', 'export', '-n', node['primary'], instance['name']] |
128 |
AssertEqual(StartSSH(master['primary'],
|
129 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
130 |
|
131 |
return qa_utils.ResolveInstanceName(instance)
|
132 |
|
133 |
|
134 |
def TestInstanceImport(node, newinst, expnode, name): |
135 |
"""gnt-backup import"""
|
136 |
master = qa_config.GetMasterNode() |
137 |
|
138 |
cmd = (['gnt-backup', 'import', |
139 |
'--disk-template=plain',
|
140 |
'--no-ip-check',
|
141 |
'--src-node=%s' % expnode['primary'], |
142 |
'--src-dir=%s/%s' % (constants.EXPORT_DIR, name),
|
143 |
'--node=%s' % node['primary']] + |
144 |
_GetGenericAddParameters()) |
145 |
cmd.append(newinst['name'])
|
146 |
AssertEqual(StartSSH(master['primary'],
|
147 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|