burnin: don't try to grow diskless instances
[ganeti-local] / qa / qa_os.py
1 # Copyright (C) 2007 Google Inc.
2 #
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.
7 #
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.
12 #
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
16 # 02110-1301, USA.
17
18
19 """OS related QA tests.
20
21 """
22
23 import os
24 import os.path
25
26 from ganeti import utils
27 from ganeti import constants
28
29 import qa_config
30 import qa_utils
31
32 from qa_utils import AssertEqual, StartSSH
33
34
35 _TEMP_OS_NAME = "TEMP-Ganeti-QA-OS"
36 _TEMP_OS_PATH = os.path.join(constants.OS_SEARCH_PATH[0], _TEMP_OS_NAME)
37
38
39 @qa_utils.DefineHook('os-list')
40 def TestOsList():
41   """gnt-os list"""
42   master = qa_config.GetMasterNode()
43
44   cmd = ['gnt-os', 'list']
45   AssertEqual(StartSSH(master['primary'],
46                        utils.ShellQuoteArgs(cmd)).wait(), 0)
47
48
49 @qa_utils.DefineHook('os-diagnose')
50 def TestOsDiagnose():
51   """gnt-os diagnose"""
52   master = qa_config.GetMasterNode()
53
54   cmd = ['gnt-os', 'diagnose']
55   AssertEqual(StartSSH(master['primary'],
56                        utils.ShellQuoteArgs(cmd)).wait(), 0)
57
58
59 def _SetupTempOs(node, dir, valid):
60   """Creates a temporary OS definition on the given node.
61
62   """
63   sq = utils.ShellQuoteArgs
64   parts = [sq(["rm", "-rf", dir]),
65            sq(["mkdir", "-p", dir]),
66            sq(["cd", dir]),
67            sq(["ln", "-fs", "/bin/true", "export"]),
68            sq(["ln", "-fs", "/bin/true", "import"]),
69            sq(["ln", "-fs", "/bin/true", "rename"])]
70
71   if valid:
72     parts.append(sq(["ln", "-fs", "/bin/true", "create"]))
73
74   parts.append(sq(["echo", str(constants.OS_API_VERSION)]) +
75                " >ganeti_api_version")
76
77   cmd = ' && '.join(parts)
78
79   print qa_utils.FormatInfo("Setting up %s with %s OS definition" %
80                             (node["primary"],
81                              ["an invalid", "a valid"][int(valid)]))
82
83   AssertEqual(StartSSH(node['primary'], cmd).wait(), 0)
84
85
86 def _RemoveTempOs(node, dir):
87   """Removes a temporary OS definition.
88
89   """
90   cmd = ['rm', '-rf', dir]
91   AssertEqual(StartSSH(node['primary'],
92                        utils.ShellQuoteArgs(cmd)).wait(), 0)
93
94
95 def _TestOs(mode):
96   """Generic function for OS definition testing
97
98   """
99   master = qa_config.GetMasterNode()
100   dir = _TEMP_OS_PATH
101
102   nodes = []
103   try:
104     i = 0
105     for node in qa_config.get('nodes'):
106       nodes.append(node)
107       if mode == 0:
108         valid = False
109       elif mode == 1:
110         valid = True
111       else:
112         valid = bool(i % 2)
113       _SetupTempOs(node, dir, valid)
114       i += 1
115
116     cmd = ['gnt-os', 'diagnose']
117     result = StartSSH(master['primary'],
118                       utils.ShellQuoteArgs(cmd)).wait()
119     if mode == 1:
120       AssertEqual(result, 0)
121     else:
122       AssertEqual(result, 1)
123   finally:
124     for node in nodes:
125       _RemoveTempOs(node, dir)
126
127
128 @qa_utils.DefineHook('os-valid')
129 def TestOsValid():
130   """Testing valid OS definition"""
131   return _TestOs(1)
132
133
134 @qa_utils.DefineHook('os-invalid')
135 def TestOsInvalid():
136   """Testing invalid OS definition"""
137   return _TestOs(0)
138
139
140 @qa_utils.DefineHook('os-partially-valid')
141 def TestOsPartiallyValid():
142   """Testing partially valid OS definition"""
143   return _TestOs(2)