root / qa / qa_os.py @ c2b05d85
History | View | Annotate | Download (3.4 kB)
1 | c68d1f43 | Michael Hanselmann | #
|
---|---|---|---|
2 | c68d1f43 | Michael Hanselmann | #
|
3 | c68d1f43 | Michael Hanselmann | |
4 | 8947cf2b | Michael Hanselmann | # Copyright (C) 2007 Google Inc.
|
5 | 8947cf2b | Michael Hanselmann | #
|
6 | 8947cf2b | Michael Hanselmann | # This program is free software; you can redistribute it and/or modify
|
7 | 8947cf2b | Michael Hanselmann | # it under the terms of the GNU General Public License as published by
|
8 | 8947cf2b | Michael Hanselmann | # the Free Software Foundation; either version 2 of the License, or
|
9 | 8947cf2b | Michael Hanselmann | # (at your option) any later version.
|
10 | 8947cf2b | Michael Hanselmann | #
|
11 | 8947cf2b | Michael Hanselmann | # This program is distributed in the hope that it will be useful, but
|
12 | 8947cf2b | Michael Hanselmann | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 8947cf2b | Michael Hanselmann | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 8947cf2b | Michael Hanselmann | # General Public License for more details.
|
15 | 8947cf2b | Michael Hanselmann | #
|
16 | 8947cf2b | Michael Hanselmann | # You should have received a copy of the GNU General Public License
|
17 | 8947cf2b | Michael Hanselmann | # along with this program; if not, write to the Free Software
|
18 | 8947cf2b | Michael Hanselmann | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | 8947cf2b | Michael Hanselmann | # 02110-1301, USA.
|
20 | 8947cf2b | Michael Hanselmann | |
21 | 8947cf2b | Michael Hanselmann | |
22 | 8947cf2b | Michael Hanselmann | """OS related QA tests.
|
23 | 8947cf2b | Michael Hanselmann |
|
24 | 8947cf2b | Michael Hanselmann | """
|
25 | 8947cf2b | Michael Hanselmann | |
26 | 8947cf2b | Michael Hanselmann | import os |
27 | 8947cf2b | Michael Hanselmann | import os.path |
28 | 8947cf2b | Michael Hanselmann | |
29 | 8947cf2b | Michael Hanselmann | from ganeti import utils |
30 | 8947cf2b | Michael Hanselmann | from ganeti import constants |
31 | 8947cf2b | Michael Hanselmann | |
32 | 8947cf2b | Michael Hanselmann | import qa_config |
33 | 8947cf2b | Michael Hanselmann | import qa_utils |
34 | 8947cf2b | Michael Hanselmann | |
35 | 8947cf2b | Michael Hanselmann | from qa_utils import AssertEqual, StartSSH |
36 | 8947cf2b | Michael Hanselmann | |
37 | 8947cf2b | Michael Hanselmann | |
38 | 8947cf2b | Michael Hanselmann | _TEMP_OS_NAME = "TEMP-Ganeti-QA-OS"
|
39 | 8947cf2b | Michael Hanselmann | _TEMP_OS_PATH = os.path.join(constants.OS_SEARCH_PATH[0], _TEMP_OS_NAME)
|
40 | 8947cf2b | Michael Hanselmann | |
41 | 8947cf2b | Michael Hanselmann | |
42 | 8947cf2b | Michael Hanselmann | def TestOsList(): |
43 | 8947cf2b | Michael Hanselmann | """gnt-os list"""
|
44 | 8947cf2b | Michael Hanselmann | master = qa_config.GetMasterNode() |
45 | 8947cf2b | Michael Hanselmann | |
46 | 8947cf2b | Michael Hanselmann | cmd = ['gnt-os', 'list'] |
47 | 8947cf2b | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
48 | 8947cf2b | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
49 | 8947cf2b | Michael Hanselmann | |
50 | 8947cf2b | Michael Hanselmann | |
51 | 8947cf2b | Michael Hanselmann | def TestOsDiagnose(): |
52 | 8947cf2b | Michael Hanselmann | """gnt-os diagnose"""
|
53 | 8947cf2b | Michael Hanselmann | master = qa_config.GetMasterNode() |
54 | 8947cf2b | Michael Hanselmann | |
55 | 8947cf2b | Michael Hanselmann | cmd = ['gnt-os', 'diagnose'] |
56 | 8947cf2b | Michael Hanselmann | AssertEqual(StartSSH(master['primary'],
|
57 | 8947cf2b | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
58 | 8947cf2b | Michael Hanselmann | |
59 | 8947cf2b | Michael Hanselmann | |
60 | 8947cf2b | Michael Hanselmann | def _SetupTempOs(node, dir, valid): |
61 | 8947cf2b | Michael Hanselmann | """Creates a temporary OS definition on the given node.
|
62 | 8947cf2b | Michael Hanselmann |
|
63 | 8947cf2b | Michael Hanselmann | """
|
64 | 8947cf2b | Michael Hanselmann | sq = utils.ShellQuoteArgs |
65 | 8947cf2b | Michael Hanselmann | parts = [sq(["rm", "-rf", dir]), |
66 | 8947cf2b | Michael Hanselmann | sq(["mkdir", "-p", dir]), |
67 | 8947cf2b | Michael Hanselmann | sq(["cd", dir]), |
68 | 8947cf2b | Michael Hanselmann | sq(["ln", "-fs", "/bin/true", "export"]), |
69 | 8947cf2b | Michael Hanselmann | sq(["ln", "-fs", "/bin/true", "import"]), |
70 | 8947cf2b | Michael Hanselmann | sq(["ln", "-fs", "/bin/true", "rename"])] |
71 | 8947cf2b | Michael Hanselmann | |
72 | 8947cf2b | Michael Hanselmann | if valid:
|
73 | 8947cf2b | Michael Hanselmann | parts.append(sq(["ln", "-fs", "/bin/true", "create"])) |
74 | 8947cf2b | Michael Hanselmann | |
75 | 8947cf2b | Michael Hanselmann | parts.append(sq(["echo", str(constants.OS_API_VERSION)]) + |
76 | 8947cf2b | Michael Hanselmann | " >ganeti_api_version")
|
77 | 8947cf2b | Michael Hanselmann | |
78 | 8947cf2b | Michael Hanselmann | cmd = ' && '.join(parts)
|
79 | 8947cf2b | Michael Hanselmann | |
80 | dfe11bad | Michael Hanselmann | print qa_utils.FormatInfo("Setting up %s with %s OS definition" % |
81 | dfe11bad | Michael Hanselmann | (node["primary"],
|
82 | dfe11bad | Michael Hanselmann | ["an invalid", "a valid"][int(valid)])) |
83 | 8947cf2b | Michael Hanselmann | |
84 | 8947cf2b | Michael Hanselmann | AssertEqual(StartSSH(node['primary'], cmd).wait(), 0) |
85 | 8947cf2b | Michael Hanselmann | |
86 | 8947cf2b | Michael Hanselmann | |
87 | 8947cf2b | Michael Hanselmann | def _RemoveTempOs(node, dir): |
88 | 8947cf2b | Michael Hanselmann | """Removes a temporary OS definition.
|
89 | 8947cf2b | Michael Hanselmann |
|
90 | 8947cf2b | Michael Hanselmann | """
|
91 | 8947cf2b | Michael Hanselmann | cmd = ['rm', '-rf', dir] |
92 | 8947cf2b | Michael Hanselmann | AssertEqual(StartSSH(node['primary'],
|
93 | 8947cf2b | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait(), 0)
|
94 | 8947cf2b | Michael Hanselmann | |
95 | 8947cf2b | Michael Hanselmann | |
96 | 8947cf2b | Michael Hanselmann | def _TestOs(mode): |
97 | 8947cf2b | Michael Hanselmann | """Generic function for OS definition testing
|
98 | 8947cf2b | Michael Hanselmann |
|
99 | 8947cf2b | Michael Hanselmann | """
|
100 | 8947cf2b | Michael Hanselmann | master = qa_config.GetMasterNode() |
101 | 8947cf2b | Michael Hanselmann | dir = _TEMP_OS_PATH |
102 | 8947cf2b | Michael Hanselmann | |
103 | 8947cf2b | Michael Hanselmann | nodes = [] |
104 | 8947cf2b | Michael Hanselmann | try:
|
105 | 8947cf2b | Michael Hanselmann | i = 0
|
106 | 8947cf2b | Michael Hanselmann | for node in qa_config.get('nodes'): |
107 | 8947cf2b | Michael Hanselmann | nodes.append(node) |
108 | 8947cf2b | Michael Hanselmann | if mode == 0: |
109 | 8947cf2b | Michael Hanselmann | valid = False
|
110 | 8947cf2b | Michael Hanselmann | elif mode == 1: |
111 | 8947cf2b | Michael Hanselmann | valid = True
|
112 | 8947cf2b | Michael Hanselmann | else:
|
113 | 8947cf2b | Michael Hanselmann | valid = bool(i % 2) |
114 | 8947cf2b | Michael Hanselmann | _SetupTempOs(node, dir, valid)
|
115 | 8947cf2b | Michael Hanselmann | i += 1
|
116 | 8947cf2b | Michael Hanselmann | |
117 | 8947cf2b | Michael Hanselmann | cmd = ['gnt-os', 'diagnose'] |
118 | 8947cf2b | Michael Hanselmann | result = StartSSH(master['primary'],
|
119 | 8947cf2b | Michael Hanselmann | utils.ShellQuoteArgs(cmd)).wait() |
120 | 8947cf2b | Michael Hanselmann | if mode == 1: |
121 | 8947cf2b | Michael Hanselmann | AssertEqual(result, 0)
|
122 | 8947cf2b | Michael Hanselmann | else:
|
123 | 8947cf2b | Michael Hanselmann | AssertEqual(result, 1)
|
124 | 8947cf2b | Michael Hanselmann | finally:
|
125 | 8947cf2b | Michael Hanselmann | for node in nodes: |
126 | 8947cf2b | Michael Hanselmann | _RemoveTempOs(node, dir)
|
127 | 8947cf2b | Michael Hanselmann | |
128 | 8947cf2b | Michael Hanselmann | |
129 | 8947cf2b | Michael Hanselmann | def TestOsValid(): |
130 | 8947cf2b | Michael Hanselmann | """Testing valid OS definition"""
|
131 | 8947cf2b | Michael Hanselmann | return _TestOs(1) |
132 | 8947cf2b | Michael Hanselmann | |
133 | 8947cf2b | Michael Hanselmann | |
134 | 8947cf2b | Michael Hanselmann | def TestOsInvalid(): |
135 | 8947cf2b | Michael Hanselmann | """Testing invalid OS definition"""
|
136 | 8947cf2b | Michael Hanselmann | return _TestOs(0) |
137 | 8947cf2b | Michael Hanselmann | |
138 | 8947cf2b | Michael Hanselmann | |
139 | 8947cf2b | Michael Hanselmann | def TestOsPartiallyValid(): |
140 | 8947cf2b | Michael Hanselmann | """Testing partially valid OS definition"""
|
141 | 8947cf2b | Michael Hanselmann | return _TestOs(2) |