1 # Copyright (C) 2007 Google Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 """OS related QA tests.
26 from ganeti import utils
27 from ganeti import constants
32 from qa_utils import AssertEqual, StartSSH
35 _TEMP_OS_NAME = "TEMP-Ganeti-QA-OS"
36 _TEMP_OS_PATH = os.path.join(constants.OS_SEARCH_PATH[0], _TEMP_OS_NAME)
39 @qa_utils.DefineHook('os-list')
42 master = qa_config.GetMasterNode()
44 cmd = ['gnt-os', 'list']
45 AssertEqual(StartSSH(master['primary'],
46 utils.ShellQuoteArgs(cmd)).wait(), 0)
49 @qa_utils.DefineHook('os-diagnose')
52 master = qa_config.GetMasterNode()
54 cmd = ['gnt-os', 'diagnose']
55 AssertEqual(StartSSH(master['primary'],
56 utils.ShellQuoteArgs(cmd)).wait(), 0)
59 def _SetupTempOs(node, dir, valid):
60 """Creates a temporary OS definition on the given node.
63 sq = utils.ShellQuoteArgs
64 parts = [sq(["rm", "-rf", dir]),
65 sq(["mkdir", "-p", dir]),
67 sq(["ln", "-fs", "/bin/true", "export"]),
68 sq(["ln", "-fs", "/bin/true", "import"]),
69 sq(["ln", "-fs", "/bin/true", "rename"])]
72 parts.append(sq(["ln", "-fs", "/bin/true", "create"]))
74 parts.append(sq(["echo", str(constants.OS_API_VERSION)]) +
75 " >ganeti_api_version")
77 cmd = ' && '.join(parts)
79 print qa_utils.FormatInfo("Setting up %s with %s OS definition" %
81 ["an invalid", "a valid"][int(valid)]))
83 AssertEqual(StartSSH(node['primary'], cmd).wait(), 0)
86 def _RemoveTempOs(node, dir):
87 """Removes a temporary OS definition.
90 cmd = ['rm', '-rf', dir]
91 AssertEqual(StartSSH(node['primary'],
92 utils.ShellQuoteArgs(cmd)).wait(), 0)
96 """Generic function for OS definition testing
99 master = qa_config.GetMasterNode()
105 for node in qa_config.get('nodes'):
113 _SetupTempOs(node, dir, valid)
116 cmd = ['gnt-os', 'diagnose']
117 result = StartSSH(master['primary'],
118 utils.ShellQuoteArgs(cmd)).wait()
120 AssertEqual(result, 0)
122 AssertEqual(result, 1)
125 _RemoveTempOs(node, dir)
128 @qa_utils.DefineHook('os-valid')
130 """Testing valid OS definition"""
134 @qa_utils.DefineHook('os-invalid')
136 """Testing invalid OS definition"""
140 @qa_utils.DefineHook('os-partially-valid')
141 def TestOsPartiallyValid():
142 """Testing partially valid OS definition"""