4 # Copyright (C) 2007, 2008, 2009, 2010 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)
79 """gnt-os modify, more stuff"""
80 master = qa_config.GetMasterNode()
82 cmd = ["gnt-os", "modify"]
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)
94 def _SetupTempOs(node, dir, valid):
95 """Creates a temporary OS definition on the given node.
98 sq = utils.ShellQuoteArgs
99 parts = [sq(["rm", "-rf", dir]),
100 sq(["mkdir", "-p", dir]),
102 sq(["ln", "-fs", "/bin/true", "export"]),
103 sq(["ln", "-fs", "/bin/true", "import"]),
104 sq(["ln", "-fs", "/bin/true", "rename"])]
107 parts.append(sq(["ln", "-fs", "/bin/true", "create"]))
109 parts.append(sq(["echo", str(constants.OS_API_V10)]) +
110 " >ganeti_api_version")
112 cmd = ' && '.join(parts)
114 print qa_utils.FormatInfo("Setting up %s with %s OS definition" %
116 ["an invalid", "a valid"][int(valid)]))
118 AssertEqual(StartSSH(node['primary'], cmd).wait(), 0)
121 def _RemoveTempOs(node, dir):
122 """Removes a temporary OS definition.
125 cmd = ['rm', '-rf', dir]
126 AssertEqual(StartSSH(node['primary'],
127 utils.ShellQuoteArgs(cmd)).wait(), 0)
131 """Generic function for OS definition testing
134 master = qa_config.GetMasterNode()
140 for node in qa_config.get('nodes'):
148 _SetupTempOs(node, dir, valid)
151 cmd = ['gnt-os', 'diagnose']
152 result = StartSSH(master['primary'],
153 utils.ShellQuoteArgs(cmd)).wait()
155 AssertEqual(result, 0)
157 AssertEqual(result, 1)
160 _RemoveTempOs(node, dir)
164 """Testing valid OS definition"""
169 """Testing invalid OS definition"""
173 def TestOsPartiallyValid():
174 """Testing partially valid OS definition"""
178 def TestOsModifyValid():
179 """Testing a valid os modify invocation"""
181 constants.HT_XEN_PVM: {
182 constants.HV_ROOT_PATH: "/dev/sda5",
184 constants.HT_XEN_HVM: {
185 constants.HV_ACPI: False,
186 constants.HV_PAE: True,
190 return _TestOsModify(hv_dict)
193 def TestOsModifyInvalid():
194 """Testing an invalid os modify invocation"""
196 "blahblahblubb": {"bar": ""},
199 return _TestOsModify(hv_dict, 1)
203 """Testing OS states"""
205 return _TestOsStates()