root / qa / qa_os.py @ 107b0ccb
History | View | Annotate | Download (3.4 kB)
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 |
def TestOsList(): |
40 |
"""gnt-os list"""
|
41 |
master = qa_config.GetMasterNode() |
42 |
|
43 |
cmd = ['gnt-os', 'list'] |
44 |
AssertEqual(StartSSH(master['primary'],
|
45 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
46 |
|
47 |
|
48 |
def TestOsDiagnose(): |
49 |
"""gnt-os diagnose"""
|
50 |
master = qa_config.GetMasterNode() |
51 |
|
52 |
cmd = ['gnt-os', 'diagnose'] |
53 |
AssertEqual(StartSSH(master['primary'],
|
54 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
55 |
|
56 |
|
57 |
def _SetupTempOs(node, dir, valid): |
58 |
"""Creates a temporary OS definition on the given node.
|
59 |
|
60 |
"""
|
61 |
sq = utils.ShellQuoteArgs |
62 |
parts = [sq(["rm", "-rf", dir]), |
63 |
sq(["mkdir", "-p", dir]), |
64 |
sq(["cd", dir]), |
65 |
sq(["ln", "-fs", "/bin/true", "export"]), |
66 |
sq(["ln", "-fs", "/bin/true", "import"]), |
67 |
sq(["ln", "-fs", "/bin/true", "rename"])] |
68 |
|
69 |
if valid:
|
70 |
parts.append(sq(["ln", "-fs", "/bin/true", "create"])) |
71 |
|
72 |
parts.append(sq(["echo", str(constants.OS_API_VERSION)]) + |
73 |
" >ganeti_api_version")
|
74 |
|
75 |
cmd = ' && '.join(parts)
|
76 |
|
77 |
print qa_utils.FormatInfo("Setting up %s with %s OS definition" % |
78 |
(node["primary"],
|
79 |
["an invalid", "a valid"][int(valid)])) |
80 |
|
81 |
AssertEqual(StartSSH(node['primary'], cmd).wait(), 0) |
82 |
|
83 |
|
84 |
def _RemoveTempOs(node, dir): |
85 |
"""Removes a temporary OS definition.
|
86 |
|
87 |
"""
|
88 |
cmd = ['rm', '-rf', dir] |
89 |
AssertEqual(StartSSH(node['primary'],
|
90 |
utils.ShellQuoteArgs(cmd)).wait(), 0)
|
91 |
|
92 |
|
93 |
def _TestOs(mode): |
94 |
"""Generic function for OS definition testing
|
95 |
|
96 |
"""
|
97 |
master = qa_config.GetMasterNode() |
98 |
dir = _TEMP_OS_PATH |
99 |
|
100 |
nodes = [] |
101 |
try:
|
102 |
i = 0
|
103 |
for node in qa_config.get('nodes'): |
104 |
nodes.append(node) |
105 |
if mode == 0: |
106 |
valid = False
|
107 |
elif mode == 1: |
108 |
valid = True
|
109 |
else:
|
110 |
valid = bool(i % 2) |
111 |
_SetupTempOs(node, dir, valid)
|
112 |
i += 1
|
113 |
|
114 |
cmd = ['gnt-os', 'diagnose'] |
115 |
result = StartSSH(master['primary'],
|
116 |
utils.ShellQuoteArgs(cmd)).wait() |
117 |
if mode == 1: |
118 |
AssertEqual(result, 0)
|
119 |
else:
|
120 |
AssertEqual(result, 1)
|
121 |
finally:
|
122 |
for node in nodes: |
123 |
_RemoveTempOs(node, dir)
|
124 |
|
125 |
|
126 |
def TestOsValid(): |
127 |
"""Testing valid OS definition"""
|
128 |
return _TestOs(1) |
129 |
|
130 |
|
131 |
def TestOsInvalid(): |
132 |
"""Testing invalid OS definition"""
|
133 |
return _TestOs(0) |
134 |
|
135 |
|
136 |
def TestOsPartiallyValid(): |
137 |
"""Testing partially valid OS definition"""
|
138 |
return _TestOs(2) |