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