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)
42 @qa_utils.DefineHook('os-list')
45 master = qa_config.GetMasterNode()
47 cmd = ['gnt-os', 'list']
48 AssertEqual(StartSSH(master['primary'],
49 utils.ShellQuoteArgs(cmd)).wait(), 0)
52 @qa_utils.DefineHook('os-diagnose')
55 master = qa_config.GetMasterNode()
57 cmd = ['gnt-os', 'diagnose']
58 AssertEqual(StartSSH(master['primary'],
59 utils.ShellQuoteArgs(cmd)).wait(), 0)
62 def _SetupTempOs(node, dir, valid):
63 """Creates a temporary OS definition on the given node.
66 sq = utils.ShellQuoteArgs
67 parts = [sq(["rm", "-rf", dir]),
68 sq(["mkdir", "-p", dir]),
70 sq(["ln", "-fs", "/bin/true", "export"]),
71 sq(["ln", "-fs", "/bin/true", "import"]),
72 sq(["ln", "-fs", "/bin/true", "rename"])]
75 parts.append(sq(["ln", "-fs", "/bin/true", "create"]))
77 parts.append(sq(["echo", str(constants.OS_API_VERSION)]) +
78 " >ganeti_api_version")
80 cmd = ' && '.join(parts)
82 print qa_utils.FormatInfo("Setting up %s with %s OS definition" %
84 ["an invalid", "a valid"][int(valid)]))
86 AssertEqual(StartSSH(node['primary'], cmd).wait(), 0)
89 def _RemoveTempOs(node, dir):
90 """Removes a temporary OS definition.
93 cmd = ['rm', '-rf', dir]
94 AssertEqual(StartSSH(node['primary'],
95 utils.ShellQuoteArgs(cmd)).wait(), 0)
99 """Generic function for OS definition testing
102 master = qa_config.GetMasterNode()
108 for node in qa_config.get('nodes'):
116 _SetupTempOs(node, dir, valid)
119 cmd = ['gnt-os', 'diagnose']
120 result = StartSSH(master['primary'],
121 utils.ShellQuoteArgs(cmd)).wait()
123 AssertEqual(result, 0)
125 AssertEqual(result, 1)
128 _RemoveTempOs(node, dir)
131 @qa_utils.DefineHook('os-valid')
133 """Testing valid OS definition"""
137 @qa_utils.DefineHook('os-invalid')
139 """Testing invalid OS definition"""
143 @qa_utils.DefineHook('os-partially-valid')
144 def TestOsPartiallyValid():
145 """Testing partially valid OS definition"""