4 # Copyright (C) 2007 Google Inc.
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.
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.
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
22 """OS related QA tests.
29 from ganeti import utils
30 from ganeti import constants
35 from qa_utils import AssertEqual, StartSSH
38 _TEMP_OS_NAME = "TEMP-Ganeti-QA-OS"
39 _TEMP_OS_PATH = os.path.join(constants.OS_SEARCH_PATH[0], _TEMP_OS_NAME)
44 master = qa_config.GetMasterNode()
46 cmd = ['gnt-os', 'list']
47 AssertEqual(StartSSH(master['primary'],
48 utils.ShellQuoteArgs(cmd)).wait(), 0)
53 master = qa_config.GetMasterNode()
55 cmd = ['gnt-os', 'diagnose']
56 AssertEqual(StartSSH(master['primary'],
57 utils.ShellQuoteArgs(cmd)).wait(), 0)
60 def _TestOsModify(hvp_dict, expected_result=0):
62 master = qa_config.GetMasterNode()
64 cmd = ['gnt-os', 'modify']
66 for hv_name, hv_params in hvp_dict.items():
69 for key, value in hv_params.items():
70 options.append("%s=%s" % (key, value))
71 cmd.append('%s:%s' % (hv_name, ','.join(options)))
73 cmd.append(_TEMP_OS_NAME)
74 AssertEqual(StartSSH(master['primary'],
75 utils.ShellQuoteArgs(cmd)).wait(), expected_result)
78 def _SetupTempOs(node, dir, valid):
79 """Creates a temporary OS definition on the given node.
82 sq = utils.ShellQuoteArgs
83 parts = [sq(["rm", "-rf", dir]),
84 sq(["mkdir", "-p", dir]),
86 sq(["ln", "-fs", "/bin/true", "export"]),
87 sq(["ln", "-fs", "/bin/true", "import"]),
88 sq(["ln", "-fs", "/bin/true", "rename"])]
91 parts.append(sq(["ln", "-fs", "/bin/true", "create"]))
93 parts.append(sq(["echo", str(constants.OS_API_V10)]) +
94 " >ganeti_api_version")
96 cmd = ' && '.join(parts)
98 print qa_utils.FormatInfo("Setting up %s with %s OS definition" %
100 ["an invalid", "a valid"][int(valid)]))
102 AssertEqual(StartSSH(node['primary'], cmd).wait(), 0)
105 def _RemoveTempOs(node, dir):
106 """Removes a temporary OS definition.
109 cmd = ['rm', '-rf', dir]
110 AssertEqual(StartSSH(node['primary'],
111 utils.ShellQuoteArgs(cmd)).wait(), 0)
115 """Generic function for OS definition testing
118 master = qa_config.GetMasterNode()
124 for node in qa_config.get('nodes'):
132 _SetupTempOs(node, dir, valid)
135 cmd = ['gnt-os', 'diagnose']
136 result = StartSSH(master['primary'],
137 utils.ShellQuoteArgs(cmd)).wait()
139 AssertEqual(result, 0)
141 AssertEqual(result, 1)
144 _RemoveTempOs(node, dir)
148 """Testing valid OS definition"""
153 """Testing invalid OS definition"""
157 def TestOsPartiallyValid():
158 """Testing partially valid OS definition"""
162 def TestOsModifyValid():
163 """Testing a valid os modify invocation"""
165 constants.HT_XEN_PVM: {
166 constants.HV_ROOT_PATH: "/dev/sda5",
168 constants.HT_XEN_HVM: {
169 constants.HV_ACPI: False,
170 constants.HV_PAE: True,
174 return _TestOsModify(hv_dict)
177 def TestOsModifyInvalid():
178 """Testing an invalid os modify invocation"""
180 "blahblahblubb": {"bar": ""},
183 return _TestOsModify(hv_dict, 1)