4 # Copyright (C) 2007, 2008, 2009, 2010, 2011 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 AssertCommand
38 _TEMP_OS_NAME = "TEMP-Ganeti-QA-OS"
39 _TEMP_OS_PATH = os.path.join(constants.OS_SEARCH_PATH[0], _TEMP_OS_NAME)
44 AssertCommand(["gnt-os", "list"])
49 AssertCommand(["gnt-os", "diagnose"])
52 def _TestOsModify(hvp_dict, fail=False):
54 cmd = ['gnt-os', 'modify']
56 for hv_name, hv_params in hvp_dict.items():
59 for key, value in hv_params.items():
60 options.append("%s=%s" % (key, value))
61 cmd.append('%s:%s' % (hv_name, ','.join(options)))
63 cmd.append(_TEMP_OS_NAME)
64 AssertCommand(cmd, fail=fail)
68 """gnt-os modify, more stuff"""
69 cmd = ["gnt-os", "modify"]
71 for param in ["hidden", "blacklisted"]:
72 for val in ["yes", "no"]:
73 new_cmd = cmd + ["--%s" % param, val, _TEMP_OS_NAME]
74 AssertCommand(new_cmd)
75 # check that double-running the command is OK
76 AssertCommand(new_cmd)
79 def _SetupTempOs(node, dirname, valid):
80 """Creates a temporary OS definition on the given node.
83 sq = utils.ShellQuoteArgs
84 parts = [sq(["rm", "-rf", dirname]),
85 sq(["mkdir", "-p", dirname]),
87 sq(["ln", "-fs", "/bin/true", "export"]),
88 sq(["ln", "-fs", "/bin/true", "import"]),
89 sq(["ln", "-fs", "/bin/true", "rename"])]
92 parts.append(sq(["ln", "-fs", "/bin/true", "create"]))
94 parts.append(sq(["echo", str(constants.OS_API_V10)]) +
95 " >ganeti_api_version")
97 cmd = ' && '.join(parts)
99 print qa_utils.FormatInfo("Setting up %s with %s OS definition" %
101 ["an invalid", "a valid"][int(valid)]))
103 AssertCommand(cmd, node=node)
106 def _RemoveTempOs(node, dirname):
107 """Removes a temporary OS definition.
110 AssertCommand(["rm", "-rf", dirname], node=node)
114 """Generic function for OS definition testing
117 dirname = _TEMP_OS_PATH
121 for i, node in enumerate(qa_config.get("nodes")):
129 _SetupTempOs(node, dirname, valid)
131 AssertCommand(["gnt-os", "diagnose"], fail=not mode==1)
134 _RemoveTempOs(node, dirname)
138 """Testing valid OS definition"""
143 """Testing invalid OS definition"""
147 def TestOsPartiallyValid():
148 """Testing partially valid OS definition"""
152 def TestOsModifyValid():
153 """Testing a valid os modify invocation"""
155 constants.HT_XEN_PVM: {
156 constants.HV_ROOT_PATH: "/dev/sda5",
158 constants.HT_XEN_HVM: {
159 constants.HV_ACPI: False,
160 constants.HV_PAE: True,
164 return _TestOsModify(hv_dict)
167 def TestOsModifyInvalid():
168 """Testing an invalid os modify invocation"""
170 "blahblahblubb": {"bar": ""},
173 return _TestOsModify(hv_dict, fail=True)
177 """Testing OS states"""
179 return _TestOsStates()