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