root / qa / qa_os.py @ fca11dec
History | View | Annotate | Download (4.3 kB)
1 |
#
|
---|---|
2 |
#
|
3 |
|
4 |
# Copyright (C) 2007 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 _SetupTempOs(node, dir, valid): |
79 |
"""Creates a temporary OS definition on the given node.
|
80 |
|
81 |
"""
|
82 |
sq = utils.ShellQuoteArgs |
83 |
parts = [sq(["rm", "-rf", dir]), |
84 |
sq(["mkdir", "-p", dir]), |
85 |
sq(["cd", dir]), |
86 |
sq(["ln", "-fs", "/bin/true", "export"]), |
87 |
sq(["ln", "-fs", "/bin/true", "import"]), |
88 |
sq(["ln", "-fs", "/bin/true", "rename"])] |
89 |
|
90 |
if valid:
|
91 |
parts.append(sq(["ln", "-fs", "/bin/true", "create"])) |
92 |
|
93 |
parts.append(sq(["echo", str(constants.OS_API_V10)]) + |
94 |
" >ganeti_api_version")
|
95 |
|
96 |
cmd = ' && '.join(parts)
|
97 |
|
98 |
print qa_utils.FormatInfo("Setting up %s with %s OS definition" % |
99 |
(node["primary"],
|
100 |
["an invalid", "a valid"][int(valid)])) |
101 |
|
102 |
AssertEqual(StartSSH(node['primary'], cmd).wait(), 0) |
103 |
|
104 |
|
105 |
def _RemoveTempOs(node, dir): |
106 |
"""Removes a temporary OS definition.
|
107 |
|
108 |
"""
|
109 |
cmd = ['rm', '-rf', dir] |
110 |
AssertEqual(StartSSH(node['primary'],
|
111 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
112 |
|
113 |
|
114 |
def _TestOs(mode): |
115 |
"""Generic function for OS definition testing
|
116 |
|
117 |
"""
|
118 |
master = qa_config.GetMasterNode() |
119 |
dir = _TEMP_OS_PATH |
120 |
|
121 |
nodes = [] |
122 |
try:
|
123 |
i = 0
|
124 |
for node in qa_config.get('nodes'): |
125 |
nodes.append(node) |
126 |
if mode == 0: |
127 |
valid = False
|
128 |
elif mode == 1: |
129 |
valid = True
|
130 |
else:
|
131 |
valid = bool(i % 2) |
132 |
_SetupTempOs(node, dir, valid)
|
133 |
i += 1
|
134 |
|
135 |
cmd = ['gnt-os', 'diagnose'] |
136 |
result = StartSSH(master['primary'],
|
137 |
utils.ShellQuoteArgs(cmd)).wait() |
138 |
if mode == 1: |
139 |
AssertEqual(result, 0)
|
140 |
else:
|
141 |
AssertEqual(result, 1)
|
142 |
finally:
|
143 |
for node in nodes: |
144 |
_RemoveTempOs(node, dir)
|
145 |
|
146 |
|
147 |
def TestOsValid(): |
148 |
"""Testing valid OS definition"""
|
149 |
return _TestOs(1) |
150 |
|
151 |
|
152 |
def TestOsInvalid(): |
153 |
"""Testing invalid OS definition"""
|
154 |
return _TestOs(0) |
155 |
|
156 |
|
157 |
def TestOsPartiallyValid(): |
158 |
"""Testing partially valid OS definition"""
|
159 |
return _TestOs(2) |
160 |
|
161 |
|
162 |
def TestOsModifyValid(): |
163 |
"""Testing a valid os modify invocation"""
|
164 |
hv_dict = { |
165 |
constants.HT_XEN_PVM: { |
166 |
constants.HV_ROOT_PATH: "/dev/sda5",
|
167 |
}, |
168 |
constants.HT_XEN_HVM: { |
169 |
constants.HV_ACPI: False,
|
170 |
constants.HV_PAE: True,
|
171 |
}, |
172 |
} |
173 |
|
174 |
return _TestOsModify(hv_dict)
|
175 |
|
176 |
|
177 |
def TestOsModifyInvalid(): |
178 |
"""Testing an invalid os modify invocation"""
|
179 |
hv_dict = { |
180 |
"blahblahblubb": {"bar": ""}, |
181 |
} |
182 |
|
183 |
return _TestOsModify(hv_dict, 1) |