root / qa / qa_os.py @ 89e8af70
History | View | Annotate | Download (4.9 kB)
1 |
#
|
---|---|
2 |
#
|
3 |
|
4 |
# Copyright (C) 2007, 2008, 2009, 2010 Google Inc.
|
5 |
#
|
6 |
# This program is free software; you can redistribute it and/or modify
|
7 |
# it under the terms of the GNU General Public License as published by
|
8 |
# the Free Software Foundation; either version 2 of the License, or
|
9 |
# (at your option) any later version.
|
10 |
#
|
11 |
# This program is distributed in the hope that it will be useful, but
|
12 |
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 |
# General Public License for more details.
|
15 |
#
|
16 |
# You should have received a copy of the GNU General Public License
|
17 |
# along with this program; if not, write to the Free Software
|
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 |
# 02110-1301, USA.
|
20 |
|
21 |
|
22 |
"""OS related QA tests.
|
23 |
|
24 |
"""
|
25 |
|
26 |
import os |
27 |
import os.path |
28 |
|
29 |
from ganeti import utils |
30 |
from ganeti import constants |
31 |
|
32 |
import qa_config |
33 |
import qa_utils |
34 |
|
35 |
from qa_utils import AssertEqual, StartSSH |
36 |
|
37 |
|
38 |
_TEMP_OS_NAME = "TEMP-Ganeti-QA-OS"
|
39 |
_TEMP_OS_PATH = os.path.join(constants.OS_SEARCH_PATH[0], _TEMP_OS_NAME)
|
40 |
|
41 |
|
42 |
def TestOsList(): |
43 |
"""gnt-os list"""
|
44 |
master = qa_config.GetMasterNode() |
45 |
|
46 |
cmd = ['gnt-os', 'list'] |
47 |
AssertEqual(StartSSH(master['primary'],
|
48 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
49 |
|
50 |
|
51 |
def TestOsDiagnose(): |
52 |
"""gnt-os diagnose"""
|
53 |
master = qa_config.GetMasterNode() |
54 |
|
55 |
cmd = ['gnt-os', 'diagnose'] |
56 |
AssertEqual(StartSSH(master['primary'],
|
57 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
58 |
|
59 |
|
60 |
def _TestOsModify(hvp_dict, expected_result=0): |
61 |
"""gnt-os modify"""
|
62 |
master = qa_config.GetMasterNode() |
63 |
|
64 |
cmd = ['gnt-os', 'modify'] |
65 |
|
66 |
for hv_name, hv_params in hvp_dict.items(): |
67 |
cmd.append('-H')
|
68 |
options = [] |
69 |
for key, value in hv_params.items(): |
70 |
options.append("%s=%s" % (key, value))
|
71 |
cmd.append('%s:%s' % (hv_name, ','.join(options))) |
72 |
|
73 |
cmd.append(_TEMP_OS_NAME) |
74 |
AssertEqual(StartSSH(master['primary'],
|
75 |
utils.ShellQuoteArgs(cmd)).wait(), expected_result) |
76 |
|
77 |
|
78 |
def _TestOsStates(): |
79 |
"""gnt-os modify, more stuff"""
|
80 |
master = qa_config.GetMasterNode() |
81 |
|
82 |
cmd = ["gnt-os", "modify"] |
83 |
|
84 |
for param in ["hidden", "blacklisted"]: |
85 |
for val in ["yes", "no"]: |
86 |
new_cmd = cmd + ["--%s" % param, val, _TEMP_OS_NAME]
|
87 |
AssertEqual(StartSSH(master["primary"],
|
88 |
utils.ShellQuoteArgs(new_cmd)).wait(), 0)
|
89 |
# check that double-running the command is OK
|
90 |
AssertEqual(StartSSH(master["primary"],
|
91 |
utils.ShellQuoteArgs(new_cmd)).wait(), 0)
|
92 |
|
93 |
|
94 |
def _SetupTempOs(node, dir, valid): |
95 |
"""Creates a temporary OS definition on the given node.
|
96 |
|
97 |
"""
|
98 |
sq = utils.ShellQuoteArgs |
99 |
parts = [sq(["rm", "-rf", dir]), |
100 |
sq(["mkdir", "-p", dir]), |
101 |
sq(["cd", dir]), |
102 |
sq(["ln", "-fs", "/bin/true", "export"]), |
103 |
sq(["ln", "-fs", "/bin/true", "import"]), |
104 |
sq(["ln", "-fs", "/bin/true", "rename"])] |
105 |
|
106 |
if valid:
|
107 |
parts.append(sq(["ln", "-fs", "/bin/true", "create"])) |
108 |
|
109 |
parts.append(sq(["echo", str(constants.OS_API_V10)]) + |
110 |
" >ganeti_api_version")
|
111 |
|
112 |
cmd = ' && '.join(parts)
|
113 |
|
114 |
print qa_utils.FormatInfo("Setting up %s with %s OS definition" % |
115 |
(node["primary"],
|
116 |
["an invalid", "a valid"][int(valid)])) |
117 |
|
118 |
AssertEqual(StartSSH(node['primary'], cmd).wait(), 0) |
119 |
|
120 |
|
121 |
def _RemoveTempOs(node, dir): |
122 |
"""Removes a temporary OS definition.
|
123 |
|
124 |
"""
|
125 |
cmd = ['rm', '-rf', dir] |
126 |
AssertEqual(StartSSH(node['primary'],
|
127 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
128 |
|
129 |
|
130 |
def _TestOs(mode): |
131 |
"""Generic function for OS definition testing
|
132 |
|
133 |
"""
|
134 |
master = qa_config.GetMasterNode() |
135 |
dir = _TEMP_OS_PATH |
136 |
|
137 |
nodes = [] |
138 |
try:
|
139 |
i = 0
|
140 |
for node in qa_config.get('nodes'): |
141 |
nodes.append(node) |
142 |
if mode == 0: |
143 |
valid = False
|
144 |
elif mode == 1: |
145 |
valid = True
|
146 |
else:
|
147 |
valid = bool(i % 2) |
148 |
_SetupTempOs(node, dir, valid)
|
149 |
i += 1
|
150 |
|
151 |
cmd = ['gnt-os', 'diagnose'] |
152 |
result = StartSSH(master['primary'],
|
153 |
utils.ShellQuoteArgs(cmd)).wait() |
154 |
if mode == 1: |
155 |
AssertEqual(result, 0)
|
156 |
else:
|
157 |
AssertEqual(result, 1)
|
158 |
finally:
|
159 |
for node in nodes: |
160 |
_RemoveTempOs(node, dir)
|
161 |
|
162 |
|
163 |
def TestOsValid(): |
164 |
"""Testing valid OS definition"""
|
165 |
return _TestOs(1) |
166 |
|
167 |
|
168 |
def TestOsInvalid(): |
169 |
"""Testing invalid OS definition"""
|
170 |
return _TestOs(0) |
171 |
|
172 |
|
173 |
def TestOsPartiallyValid(): |
174 |
"""Testing partially valid OS definition"""
|
175 |
return _TestOs(2) |
176 |
|
177 |
|
178 |
def TestOsModifyValid(): |
179 |
"""Testing a valid os modify invocation"""
|
180 |
hv_dict = { |
181 |
constants.HT_XEN_PVM: { |
182 |
constants.HV_ROOT_PATH: "/dev/sda5",
|
183 |
}, |
184 |
constants.HT_XEN_HVM: { |
185 |
constants.HV_ACPI: False,
|
186 |
constants.HV_PAE: True,
|
187 |
}, |
188 |
} |
189 |
|
190 |
return _TestOsModify(hv_dict)
|
191 |
|
192 |
|
193 |
def TestOsModifyInvalid(): |
194 |
"""Testing an invalid os modify invocation"""
|
195 |
hv_dict = { |
196 |
"blahblahblubb": {"bar": ""}, |
197 |
} |
198 |
|
199 |
return _TestOsModify(hv_dict, 1) |
200 |
|
201 |
|
202 |
def TestOsStates(): |
203 |
"""Testing OS states"""
|
204 |
|
205 |
return _TestOsStates()
|