root / test / ganeti.cmdlib_unittest.py @ 9ca8a7c5
History | View | Annotate | Download (14.3 kB)
1 | 6de7c41d | Iustin Pop | #!/usr/bin/python
|
---|---|---|---|
2 | 6de7c41d | Iustin Pop | #
|
3 | 6de7c41d | Iustin Pop | |
4 | ff0d18e6 | Iustin Pop | # Copyright (C) 2008, 2011 Google Inc.
|
5 | 6de7c41d | Iustin Pop | #
|
6 | 6de7c41d | Iustin Pop | # This program is free software; you can redistribute it and/or modify
|
7 | 6de7c41d | Iustin Pop | # it under the terms of the GNU General Public License as published by
|
8 | 6de7c41d | Iustin Pop | # the Free Software Foundation; either version 2 of the License, or
|
9 | 6de7c41d | Iustin Pop | # (at your option) any later version.
|
10 | 6de7c41d | Iustin Pop | #
|
11 | 6de7c41d | Iustin Pop | # This program is distributed in the hope that it will be useful, but
|
12 | 6de7c41d | Iustin Pop | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | 6de7c41d | Iustin Pop | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | 6de7c41d | Iustin Pop | # General Public License for more details.
|
15 | 6de7c41d | Iustin Pop | #
|
16 | 6de7c41d | Iustin Pop | # You should have received a copy of the GNU General Public License
|
17 | 6de7c41d | Iustin Pop | # along with this program; if not, write to the Free Software
|
18 | 6de7c41d | Iustin Pop | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
19 | fd7b69c0 | Michael Hanselmann | # 02110-1301, USA.
|
20 | 6de7c41d | Iustin Pop | |
21 | 6de7c41d | Iustin Pop | |
22 | 6de7c41d | Iustin Pop | """Script for unittesting the cmdlib module"""
|
23 | 6de7c41d | Iustin Pop | |
24 | 6de7c41d | Iustin Pop | |
25 | 6de7c41d | Iustin Pop | import os |
26 | 6de7c41d | Iustin Pop | import unittest |
27 | 6de7c41d | Iustin Pop | import time |
28 | b98bf262 | Michael Hanselmann | import tempfile |
29 | b98bf262 | Michael Hanselmann | import shutil |
30 | 64c7b383 | Michael Hanselmann | import operator |
31 | 6de7c41d | Iustin Pop | |
32 | 83f72637 | Michael Hanselmann | from ganeti import constants |
33 | b8812691 | Iustin Pop | from ganeti import mcpu |
34 | 6de7c41d | Iustin Pop | from ganeti import cmdlib |
35 | b8812691 | Iustin Pop | from ganeti import opcodes |
36 | 6de7c41d | Iustin Pop | from ganeti import errors |
37 | b8812691 | Iustin Pop | from ganeti import utils |
38 | e58f87a9 | Michael Hanselmann | from ganeti import luxi |
39 | 65e183af | Michael Hanselmann | from ganeti import ht |
40 | 8ec505dd | Adeodato Simo | from ganeti import objects |
41 | 170b02b7 | Michael Hanselmann | from ganeti import compat |
42 | 170b02b7 | Michael Hanselmann | from ganeti import rpc |
43 | 0ad1ea40 | Guido Trotter | from ganeti.hypervisor import hv_xen |
44 | 6de7c41d | Iustin Pop | |
45 | 25231ec5 | Michael Hanselmann | import testutils |
46 | bd5f214b | Apollon Oikonomopoulos | import mocks |
47 | 25231ec5 | Michael Hanselmann | |
48 | 6de7c41d | Iustin Pop | |
49 | b98bf262 | Michael Hanselmann | class TestCertVerification(testutils.GanetiTestCase): |
50 | b98bf262 | Michael Hanselmann | def setUp(self): |
51 | b98bf262 | Michael Hanselmann | testutils.GanetiTestCase.setUp(self)
|
52 | b98bf262 | Michael Hanselmann | |
53 | b98bf262 | Michael Hanselmann | self.tmpdir = tempfile.mkdtemp()
|
54 | b98bf262 | Michael Hanselmann | |
55 | b98bf262 | Michael Hanselmann | def tearDown(self): |
56 | b98bf262 | Michael Hanselmann | shutil.rmtree(self.tmpdir)
|
57 | b98bf262 | Michael Hanselmann | |
58 | b98bf262 | Michael Hanselmann | def testVerifyCertificate(self): |
59 | b98bf262 | Michael Hanselmann | cmdlib._VerifyCertificate(self._TestDataFilename("cert1.pem")) |
60 | b98bf262 | Michael Hanselmann | |
61 | b98bf262 | Michael Hanselmann | nonexist_filename = os.path.join(self.tmpdir, "does-not-exist") |
62 | b98bf262 | Michael Hanselmann | |
63 | b98bf262 | Michael Hanselmann | (errcode, msg) = cmdlib._VerifyCertificate(nonexist_filename) |
64 | bf93ae69 | Adeodato Simo | self.assertEqual(errcode, cmdlib.LUClusterVerifyConfig.ETYPE_ERROR)
|
65 | b98bf262 | Michael Hanselmann | |
66 | b98bf262 | Michael Hanselmann | # Try to load non-certificate file
|
67 | 24d70417 | Michael Hanselmann | invalid_cert = self._TestDataFilename("bdev-net.txt") |
68 | b98bf262 | Michael Hanselmann | (errcode, msg) = cmdlib._VerifyCertificate(invalid_cert) |
69 | bf93ae69 | Adeodato Simo | self.assertEqual(errcode, cmdlib.LUClusterVerifyConfig.ETYPE_ERROR)
|
70 | b98bf262 | Michael Hanselmann | |
71 | b98bf262 | Michael Hanselmann | |
72 | b8812691 | Iustin Pop | class TestOpcodeParams(testutils.GanetiTestCase): |
73 | b8812691 | Iustin Pop | def testParamsStructures(self): |
74 | b8812691 | Iustin Pop | for op in sorted(mcpu.Processor.DISPATCH_TABLE): |
75 | b8812691 | Iustin Pop | lu = mcpu.Processor.DISPATCH_TABLE[op] |
76 | b8812691 | Iustin Pop | lu_name = lu.__name__ |
77 | 0bff0b12 | Michael Hanselmann | self.failIf(hasattr(lu, "_OP_REQP"), |
78 | 0bff0b12 | Michael Hanselmann | msg=("LU '%s' has old-style _OP_REQP" % lu_name))
|
79 | 0bff0b12 | Michael Hanselmann | self.failIf(hasattr(lu, "_OP_DEFS"), |
80 | 0bff0b12 | Michael Hanselmann | msg=("LU '%s' has old-style _OP_DEFS" % lu_name))
|
81 | 0bff0b12 | Michael Hanselmann | self.failIf(hasattr(lu, "_OP_PARAMS"), |
82 | 0bff0b12 | Michael Hanselmann | msg=("LU '%s' has old-style _OP_PARAMS" % lu_name))
|
83 | b8812691 | Iustin Pop | |
84 | b8812691 | Iustin Pop | |
85 | bd5f214b | Apollon Oikonomopoulos | class TestIAllocatorChecks(testutils.GanetiTestCase): |
86 | bd5f214b | Apollon Oikonomopoulos | def testFunction(self): |
87 | bd5f214b | Apollon Oikonomopoulos | class TestLU(object): |
88 | bd5f214b | Apollon Oikonomopoulos | def __init__(self, opcode): |
89 | bd5f214b | Apollon Oikonomopoulos | self.cfg = mocks.FakeConfig()
|
90 | bd5f214b | Apollon Oikonomopoulos | self.op = opcode
|
91 | bd5f214b | Apollon Oikonomopoulos | |
92 | ff0d18e6 | Iustin Pop | class OpTest(opcodes.OpCode): |
93 | ff0d18e6 | Iustin Pop | OP_PARAMS = [ |
94 | 197b323b | Michael Hanselmann | ("iallocator", None, ht.NoType, None), |
95 | 197b323b | Michael Hanselmann | ("node", None, ht.NoType, None), |
96 | 65e183af | Michael Hanselmann | ] |
97 | bd5f214b | Apollon Oikonomopoulos | |
98 | bd5f214b | Apollon Oikonomopoulos | default_iallocator = mocks.FakeConfig().GetDefaultIAllocator() |
99 | bd5f214b | Apollon Oikonomopoulos | other_iallocator = default_iallocator + "_not"
|
100 | bd5f214b | Apollon Oikonomopoulos | |
101 | ff0d18e6 | Iustin Pop | op = OpTest() |
102 | bd5f214b | Apollon Oikonomopoulos | lu = TestLU(op) |
103 | bd5f214b | Apollon Oikonomopoulos | |
104 | bd5f214b | Apollon Oikonomopoulos | c_i = lambda: cmdlib._CheckIAllocatorOrNode(lu, "iallocator", "node") |
105 | bd5f214b | Apollon Oikonomopoulos | |
106 | bd5f214b | Apollon Oikonomopoulos | # Neither node nor iallocator given
|
107 | bd5f214b | Apollon Oikonomopoulos | op.iallocator = None
|
108 | bd5f214b | Apollon Oikonomopoulos | op.node = None
|
109 | bd5f214b | Apollon Oikonomopoulos | c_i() |
110 | bd5f214b | Apollon Oikonomopoulos | self.assertEqual(lu.op.iallocator, default_iallocator)
|
111 | bd5f214b | Apollon Oikonomopoulos | self.assertEqual(lu.op.node, None) |
112 | bd5f214b | Apollon Oikonomopoulos | |
113 | bd5f214b | Apollon Oikonomopoulos | # Both, iallocator and node given
|
114 | bd5f214b | Apollon Oikonomopoulos | op.iallocator = "test"
|
115 | bd5f214b | Apollon Oikonomopoulos | op.node = "test"
|
116 | bd5f214b | Apollon Oikonomopoulos | self.assertRaises(errors.OpPrereqError, c_i)
|
117 | bd5f214b | Apollon Oikonomopoulos | |
118 | bd5f214b | Apollon Oikonomopoulos | # Only iallocator given
|
119 | bd5f214b | Apollon Oikonomopoulos | op.iallocator = other_iallocator |
120 | bd5f214b | Apollon Oikonomopoulos | op.node = None
|
121 | bd5f214b | Apollon Oikonomopoulos | c_i() |
122 | bd5f214b | Apollon Oikonomopoulos | self.assertEqual(lu.op.iallocator, other_iallocator)
|
123 | bd5f214b | Apollon Oikonomopoulos | self.assertEqual(lu.op.node, None) |
124 | bd5f214b | Apollon Oikonomopoulos | |
125 | bd5f214b | Apollon Oikonomopoulos | # Only node given
|
126 | bd5f214b | Apollon Oikonomopoulos | op.iallocator = None
|
127 | bd5f214b | Apollon Oikonomopoulos | op.node = "node"
|
128 | bd5f214b | Apollon Oikonomopoulos | c_i() |
129 | bd5f214b | Apollon Oikonomopoulos | self.assertEqual(lu.op.iallocator, None) |
130 | bd5f214b | Apollon Oikonomopoulos | self.assertEqual(lu.op.node, "node") |
131 | bd5f214b | Apollon Oikonomopoulos | |
132 | bd5f214b | Apollon Oikonomopoulos | # No node, iallocator or default iallocator
|
133 | bd5f214b | Apollon Oikonomopoulos | op.iallocator = None
|
134 | bd5f214b | Apollon Oikonomopoulos | op.node = None
|
135 | bd5f214b | Apollon Oikonomopoulos | lu.cfg.GetDefaultIAllocator = lambda: None |
136 | bd5f214b | Apollon Oikonomopoulos | self.assertRaises(errors.OpPrereqError, c_i)
|
137 | bd5f214b | Apollon Oikonomopoulos | |
138 | bd5f214b | Apollon Oikonomopoulos | |
139 | b469eb4d | Iustin Pop | class TestLUTestJqueue(unittest.TestCase): |
140 | e58f87a9 | Michael Hanselmann | def test(self): |
141 | b469eb4d | Iustin Pop | self.assert_(cmdlib.LUTestJqueue._CLIENT_CONNECT_TIMEOUT <
|
142 | e58f87a9 | Michael Hanselmann | (luxi.WFJC_TIMEOUT * 0.75),
|
143 | e58f87a9 | Michael Hanselmann | msg=("Client timeout too high, might not notice bugs"
|
144 | e58f87a9 | Michael Hanselmann | " in WaitForJobChange"))
|
145 | e58f87a9 | Michael Hanselmann | |
146 | e58f87a9 | Michael Hanselmann | |
147 | 83f72637 | Michael Hanselmann | class TestLUQuery(unittest.TestCase): |
148 | 83f72637 | Michael Hanselmann | def test(self): |
149 | 83f72637 | Michael Hanselmann | self.assertEqual(sorted(cmdlib._QUERY_IMPL.keys()), |
150 | abd66bf8 | Michael Hanselmann | sorted(constants.QR_VIA_OP))
|
151 | 83f72637 | Michael Hanselmann | |
152 | abd66bf8 | Michael Hanselmann | assert constants.QR_NODE in constants.QR_VIA_OP |
153 | abd66bf8 | Michael Hanselmann | assert constants.QR_INSTANCE in constants.QR_VIA_OP |
154 | 83f72637 | Michael Hanselmann | |
155 | abd66bf8 | Michael Hanselmann | for i in constants.QR_VIA_OP: |
156 | 83f72637 | Michael Hanselmann | self.assert_(cmdlib._GetQueryImplementation(i))
|
157 | 83f72637 | Michael Hanselmann | |
158 | 83f72637 | Michael Hanselmann | self.assertRaises(errors.OpPrereqError, cmdlib._GetQueryImplementation, "") |
159 | 83f72637 | Michael Hanselmann | self.assertRaises(errors.OpPrereqError, cmdlib._GetQueryImplementation,
|
160 | 83f72637 | Michael Hanselmann | "xyz")
|
161 | 83f72637 | Michael Hanselmann | |
162 | 83f72637 | Michael Hanselmann | |
163 | 934704ae | Iustin Pop | class TestLUGroupAssignNodes(unittest.TestCase): |
164 | 8ec505dd | Adeodato Simo | |
165 | 8ec505dd | Adeodato Simo | def testCheckAssignmentForSplitInstances(self): |
166 | 8ec505dd | Adeodato Simo | node_data = dict((name, objects.Node(name=name, group=group))
|
167 | 8ec505dd | Adeodato Simo | for (name, group) in [("n1a", "g1"), ("n1b", "g1"), |
168 | 8ec505dd | Adeodato Simo | ("n2a", "g2"), ("n2b", "g2"), |
169 | 8ec505dd | Adeodato Simo | ("n3a", "g3"), ("n3b", "g3"), |
170 | 8ec505dd | Adeodato Simo | ("n3c", "g3"), |
171 | 8ec505dd | Adeodato Simo | ]) |
172 | 8ec505dd | Adeodato Simo | |
173 | 8ec505dd | Adeodato Simo | def Instance(name, pnode, snode): |
174 | 8ec505dd | Adeodato Simo | if snode is None: |
175 | 8ec505dd | Adeodato Simo | disks = [] |
176 | 8ec505dd | Adeodato Simo | disk_template = constants.DT_DISKLESS |
177 | 8ec505dd | Adeodato Simo | else:
|
178 | 8ec505dd | Adeodato Simo | disks = [objects.Disk(dev_type=constants.LD_DRBD8, |
179 | 8ec505dd | Adeodato Simo | logical_id=[pnode, snode, 1, 17, 17])] |
180 | 8ec505dd | Adeodato Simo | disk_template = constants.DT_DRBD8 |
181 | 8ec505dd | Adeodato Simo | |
182 | 8ec505dd | Adeodato Simo | return objects.Instance(name=name, primary_node=pnode, disks=disks,
|
183 | 8ec505dd | Adeodato Simo | disk_template=disk_template) |
184 | 8ec505dd | Adeodato Simo | |
185 | 8ec505dd | Adeodato Simo | instance_data = dict((name, Instance(name, pnode, snode))
|
186 | 8ec505dd | Adeodato Simo | for name, pnode, snode in [("inst1a", "n1a", "n1b"), |
187 | 8ec505dd | Adeodato Simo | ("inst1b", "n1b", "n1a"), |
188 | 8ec505dd | Adeodato Simo | ("inst2a", "n2a", "n2b"), |
189 | 8ec505dd | Adeodato Simo | ("inst3a", "n3a", None), |
190 | 8ec505dd | Adeodato Simo | ("inst3b", "n3b", "n1b"), |
191 | 8ec505dd | Adeodato Simo | ("inst3c", "n3b", "n2b"), |
192 | 8ec505dd | Adeodato Simo | ]) |
193 | 8ec505dd | Adeodato Simo | |
194 | 8ec505dd | Adeodato Simo | # Test first with the existing state.
|
195 | 8ec505dd | Adeodato Simo | (new, prev) = \ |
196 | 934704ae | Iustin Pop | cmdlib.LUGroupAssignNodes.CheckAssignmentForSplitInstances([], |
197 | 8ec505dd | Adeodato Simo | node_data, |
198 | 8ec505dd | Adeodato Simo | instance_data) |
199 | 8ec505dd | Adeodato Simo | |
200 | 8ec505dd | Adeodato Simo | self.assertEqual([], new)
|
201 | 8ec505dd | Adeodato Simo | self.assertEqual(set(["inst3b", "inst3c"]), set(prev)) |
202 | 8ec505dd | Adeodato Simo | |
203 | 8ec505dd | Adeodato Simo | # And now some changes.
|
204 | 8ec505dd | Adeodato Simo | (new, prev) = \ |
205 | 934704ae | Iustin Pop | cmdlib.LUGroupAssignNodes.CheckAssignmentForSplitInstances([("n1b",
|
206 | 8ec505dd | Adeodato Simo | "g3")],
|
207 | 8ec505dd | Adeodato Simo | node_data, |
208 | 8ec505dd | Adeodato Simo | instance_data) |
209 | 8ec505dd | Adeodato Simo | |
210 | 8ec505dd | Adeodato Simo | self.assertEqual(set(["inst1a", "inst1b"]), set(new)) |
211 | 8ec505dd | Adeodato Simo | self.assertEqual(set(["inst3c"]), set(prev)) |
212 | 8ec505dd | Adeodato Simo | |
213 | 8ec505dd | Adeodato Simo | |
214 | 64c7b383 | Michael Hanselmann | class TestClusterVerifySsh(unittest.TestCase): |
215 | 64c7b383 | Michael Hanselmann | def testMultipleGroups(self): |
216 | 64c7b383 | Michael Hanselmann | fn = cmdlib.LUClusterVerifyGroup._SelectSshCheckNodes |
217 | 64c7b383 | Michael Hanselmann | mygroupnodes = [ |
218 | 64c7b383 | Michael Hanselmann | objects.Node(name="node20", group="my", offline=False), |
219 | 64c7b383 | Michael Hanselmann | objects.Node(name="node21", group="my", offline=False), |
220 | 64c7b383 | Michael Hanselmann | objects.Node(name="node22", group="my", offline=False), |
221 | 64c7b383 | Michael Hanselmann | objects.Node(name="node23", group="my", offline=False), |
222 | 64c7b383 | Michael Hanselmann | objects.Node(name="node24", group="my", offline=False), |
223 | 64c7b383 | Michael Hanselmann | objects.Node(name="node25", group="my", offline=False), |
224 | 64c7b383 | Michael Hanselmann | objects.Node(name="node26", group="my", offline=True), |
225 | 64c7b383 | Michael Hanselmann | ] |
226 | 64c7b383 | Michael Hanselmann | nodes = [ |
227 | 64c7b383 | Michael Hanselmann | objects.Node(name="node1", group="g1", offline=True), |
228 | 64c7b383 | Michael Hanselmann | objects.Node(name="node2", group="g1", offline=False), |
229 | 64c7b383 | Michael Hanselmann | objects.Node(name="node3", group="g1", offline=False), |
230 | 64c7b383 | Michael Hanselmann | objects.Node(name="node4", group="g1", offline=True), |
231 | 64c7b383 | Michael Hanselmann | objects.Node(name="node5", group="g1", offline=False), |
232 | 64c7b383 | Michael Hanselmann | objects.Node(name="node10", group="xyz", offline=False), |
233 | 64c7b383 | Michael Hanselmann | objects.Node(name="node11", group="xyz", offline=False), |
234 | 64c7b383 | Michael Hanselmann | objects.Node(name="node40", group="alloff", offline=True), |
235 | 64c7b383 | Michael Hanselmann | objects.Node(name="node41", group="alloff", offline=True), |
236 | 64c7b383 | Michael Hanselmann | objects.Node(name="node50", group="aaa", offline=False), |
237 | 64c7b383 | Michael Hanselmann | ] + mygroupnodes |
238 | 64c7b383 | Michael Hanselmann | assert not utils.FindDuplicates(map(operator.attrgetter("name"), nodes)) |
239 | 64c7b383 | Michael Hanselmann | |
240 | 64c7b383 | Michael Hanselmann | (online, perhost) = fn(mygroupnodes, "my", nodes)
|
241 | 64c7b383 | Michael Hanselmann | self.assertEqual(online, ["node%s" % i for i in range(20, 26)]) |
242 | 64c7b383 | Michael Hanselmann | self.assertEqual(set(perhost.keys()), set(online)) |
243 | 64c7b383 | Michael Hanselmann | |
244 | 64c7b383 | Michael Hanselmann | self.assertEqual(perhost, {
|
245 | 64c7b383 | Michael Hanselmann | "node20": ["node10", "node2", "node50"], |
246 | 64c7b383 | Michael Hanselmann | "node21": ["node11", "node3", "node50"], |
247 | 64c7b383 | Michael Hanselmann | "node22": ["node10", "node5", "node50"], |
248 | 64c7b383 | Michael Hanselmann | "node23": ["node11", "node2", "node50"], |
249 | 64c7b383 | Michael Hanselmann | "node24": ["node10", "node3", "node50"], |
250 | 64c7b383 | Michael Hanselmann | "node25": ["node11", "node5", "node50"], |
251 | 64c7b383 | Michael Hanselmann | }) |
252 | 64c7b383 | Michael Hanselmann | |
253 | 64c7b383 | Michael Hanselmann | def testSingleGroup(self): |
254 | 64c7b383 | Michael Hanselmann | fn = cmdlib.LUClusterVerifyGroup._SelectSshCheckNodes |
255 | 64c7b383 | Michael Hanselmann | nodes = [ |
256 | 64c7b383 | Michael Hanselmann | objects.Node(name="node1", group="default", offline=True), |
257 | 64c7b383 | Michael Hanselmann | objects.Node(name="node2", group="default", offline=False), |
258 | 64c7b383 | Michael Hanselmann | objects.Node(name="node3", group="default", offline=False), |
259 | 64c7b383 | Michael Hanselmann | objects.Node(name="node4", group="default", offline=True), |
260 | 64c7b383 | Michael Hanselmann | ] |
261 | 64c7b383 | Michael Hanselmann | assert not utils.FindDuplicates(map(operator.attrgetter("name"), nodes)) |
262 | 64c7b383 | Michael Hanselmann | |
263 | 64c7b383 | Michael Hanselmann | (online, perhost) = fn(nodes, "default", nodes)
|
264 | 64c7b383 | Michael Hanselmann | self.assertEqual(online, ["node2", "node3"]) |
265 | 64c7b383 | Michael Hanselmann | self.assertEqual(set(perhost.keys()), set(online)) |
266 | 64c7b383 | Michael Hanselmann | |
267 | 64c7b383 | Michael Hanselmann | self.assertEqual(perhost, {
|
268 | 64c7b383 | Michael Hanselmann | "node2": [],
|
269 | 64c7b383 | Michael Hanselmann | "node3": [],
|
270 | 64c7b383 | Michael Hanselmann | }) |
271 | 64c7b383 | Michael Hanselmann | |
272 | 64c7b383 | Michael Hanselmann | |
273 | 170b02b7 | Michael Hanselmann | class TestClusterVerifyFiles(unittest.TestCase): |
274 | 170b02b7 | Michael Hanselmann | @staticmethod
|
275 | 170b02b7 | Michael Hanselmann | def _FakeErrorIf(errors, cond, ecode, item, msg, *args, **kwargs): |
276 | eedf99b5 | Andrea Spadaccini | assert ((ecode == constants.CV_ENODEFILECHECK and |
277 | 170b02b7 | Michael Hanselmann | ht.TNonEmptyString(item)) or
|
278 | eedf99b5 | Andrea Spadaccini | (ecode == constants.CV_ECLUSTERFILECHECK and
|
279 | 170b02b7 | Michael Hanselmann | item is None)) |
280 | 170b02b7 | Michael Hanselmann | |
281 | 170b02b7 | Michael Hanselmann | if args:
|
282 | 170b02b7 | Michael Hanselmann | msg = msg % args |
283 | 170b02b7 | Michael Hanselmann | |
284 | 170b02b7 | Michael Hanselmann | if cond:
|
285 | 170b02b7 | Michael Hanselmann | errors.append((item, msg)) |
286 | 170b02b7 | Michael Hanselmann | |
287 | 170b02b7 | Michael Hanselmann | _VerifyFiles = cmdlib.LUClusterVerifyGroup._VerifyFiles |
288 | 170b02b7 | Michael Hanselmann | |
289 | 170b02b7 | Michael Hanselmann | def test(self): |
290 | 170b02b7 | Michael Hanselmann | errors = [] |
291 | 170b02b7 | Michael Hanselmann | master_name = "master.example.com"
|
292 | 170b02b7 | Michael Hanselmann | nodeinfo = [ |
293 | 0ad1ea40 | Guido Trotter | objects.Node(name=master_name, offline=False, vm_capable=True), |
294 | 0ad1ea40 | Guido Trotter | objects.Node(name="node2.example.com", offline=False, vm_capable=True), |
295 | 0ad1ea40 | Guido Trotter | objects.Node(name="node3.example.com", master_candidate=True, |
296 | 0ad1ea40 | Guido Trotter | vm_capable=False),
|
297 | 0ad1ea40 | Guido Trotter | objects.Node(name="node4.example.com", offline=False, vm_capable=True), |
298 | 0ad1ea40 | Guido Trotter | objects.Node(name="nodata.example.com", offline=False, vm_capable=True), |
299 | 170b02b7 | Michael Hanselmann | objects.Node(name="offline.example.com", offline=True), |
300 | 170b02b7 | Michael Hanselmann | ] |
301 | 170b02b7 | Michael Hanselmann | cluster = objects.Cluster(modify_etc_hosts=True,
|
302 | 170b02b7 | Michael Hanselmann | enabled_hypervisors=[constants.HT_XEN_HVM]) |
303 | 170b02b7 | Michael Hanselmann | files_all = set([
|
304 | 170b02b7 | Michael Hanselmann | constants.CLUSTER_DOMAIN_SECRET_FILE, |
305 | 170b02b7 | Michael Hanselmann | constants.RAPI_CERT_FILE, |
306 | 0ad1ea40 | Guido Trotter | constants.RAPI_USERS_FILE, |
307 | 170b02b7 | Michael Hanselmann | ]) |
308 | 0ad1ea40 | Guido Trotter | files_opt = set([
|
309 | 170b02b7 | Michael Hanselmann | constants.RAPI_USERS_FILE, |
310 | 0ad1ea40 | Guido Trotter | hv_xen.XL_CONFIG_FILE, |
311 | 0ad1ea40 | Guido Trotter | constants.VNC_PASSWORD_FILE, |
312 | 170b02b7 | Michael Hanselmann | ]) |
313 | 170b02b7 | Michael Hanselmann | files_mc = set([
|
314 | 170b02b7 | Michael Hanselmann | constants.CLUSTER_CONF_FILE, |
315 | 170b02b7 | Michael Hanselmann | ]) |
316 | 0ad1ea40 | Guido Trotter | files_vm = set([
|
317 | 0ad1ea40 | Guido Trotter | hv_xen.XEND_CONFIG_FILE, |
318 | 0ad1ea40 | Guido Trotter | hv_xen.XL_CONFIG_FILE, |
319 | 0ad1ea40 | Guido Trotter | constants.VNC_PASSWORD_FILE, |
320 | 0ad1ea40 | Guido Trotter | ]) |
321 | 170b02b7 | Michael Hanselmann | nvinfo = { |
322 | 170b02b7 | Michael Hanselmann | master_name: rpc.RpcResult(data=(True, {
|
323 | 170b02b7 | Michael Hanselmann | constants.NV_FILELIST: { |
324 | 170b02b7 | Michael Hanselmann | constants.CLUSTER_CONF_FILE: "82314f897f38b35f9dab2f7c6b1593e0",
|
325 | 170b02b7 | Michael Hanselmann | constants.RAPI_CERT_FILE: "babbce8f387bc082228e544a2146fee4",
|
326 | 170b02b7 | Michael Hanselmann | constants.CLUSTER_DOMAIN_SECRET_FILE: "cds-47b5b3f19202936bb4",
|
327 | 0ad1ea40 | Guido Trotter | hv_xen.XEND_CONFIG_FILE: "b4a8a824ab3cac3d88839a9adeadf310",
|
328 | 0ad1ea40 | Guido Trotter | hv_xen.XL_CONFIG_FILE: "77935cee92afd26d162f9e525e3d49b9"
|
329 | 170b02b7 | Michael Hanselmann | }})), |
330 | 170b02b7 | Michael Hanselmann | "node2.example.com": rpc.RpcResult(data=(True, { |
331 | 170b02b7 | Michael Hanselmann | constants.NV_FILELIST: { |
332 | 170b02b7 | Michael Hanselmann | constants.RAPI_CERT_FILE: "97f0356500e866387f4b84233848cc4a",
|
333 | 0ad1ea40 | Guido Trotter | hv_xen.XEND_CONFIG_FILE: "b4a8a824ab3cac3d88839a9adeadf310",
|
334 | 170b02b7 | Michael Hanselmann | } |
335 | 170b02b7 | Michael Hanselmann | })), |
336 | 170b02b7 | Michael Hanselmann | "node3.example.com": rpc.RpcResult(data=(True, { |
337 | 170b02b7 | Michael Hanselmann | constants.NV_FILELIST: { |
338 | 170b02b7 | Michael Hanselmann | constants.RAPI_CERT_FILE: "97f0356500e866387f4b84233848cc4a",
|
339 | 170b02b7 | Michael Hanselmann | constants.CLUSTER_DOMAIN_SECRET_FILE: "cds-47b5b3f19202936bb4",
|
340 | 170b02b7 | Michael Hanselmann | } |
341 | 170b02b7 | Michael Hanselmann | })), |
342 | 170b02b7 | Michael Hanselmann | "node4.example.com": rpc.RpcResult(data=(True, { |
343 | 170b02b7 | Michael Hanselmann | constants.NV_FILELIST: { |
344 | 170b02b7 | Michael Hanselmann | constants.RAPI_CERT_FILE: "97f0356500e866387f4b84233848cc4a",
|
345 | 170b02b7 | Michael Hanselmann | constants.CLUSTER_CONF_FILE: "conf-a6d4b13e407867f7a7b4f0f232a8f527",
|
346 | 170b02b7 | Michael Hanselmann | constants.CLUSTER_DOMAIN_SECRET_FILE: "cds-47b5b3f19202936bb4",
|
347 | 170b02b7 | Michael Hanselmann | constants.RAPI_USERS_FILE: "rapiusers-ea3271e8d810ef3",
|
348 | 0ad1ea40 | Guido Trotter | hv_xen.XL_CONFIG_FILE: "77935cee92afd26d162f9e525e3d49b9"
|
349 | 170b02b7 | Michael Hanselmann | } |
350 | 170b02b7 | Michael Hanselmann | })), |
351 | 170b02b7 | Michael Hanselmann | "nodata.example.com": rpc.RpcResult(data=(True, {})), |
352 | 170b02b7 | Michael Hanselmann | "offline.example.com": rpc.RpcResult(offline=True), |
353 | 170b02b7 | Michael Hanselmann | } |
354 | 170b02b7 | Michael Hanselmann | assert set(nvinfo.keys()) == set(map(operator.attrgetter("name"), nodeinfo)) |
355 | 170b02b7 | Michael Hanselmann | |
356 | 170b02b7 | Michael Hanselmann | self._VerifyFiles(compat.partial(self._FakeErrorIf, errors), nodeinfo, |
357 | 170b02b7 | Michael Hanselmann | master_name, nvinfo, |
358 | 0ad1ea40 | Guido Trotter | (files_all, files_opt, files_mc, files_vm)) |
359 | 170b02b7 | Michael Hanselmann | self.assertEqual(sorted(errors), sorted([ |
360 | 170b02b7 | Michael Hanselmann | (None, ("File %s found with 2 different checksums (variant 1 on" |
361 | 170b02b7 | Michael Hanselmann | " node2.example.com, node3.example.com, node4.example.com;"
|
362 | 170b02b7 | Michael Hanselmann | " variant 2 on master.example.com)" % constants.RAPI_CERT_FILE)),
|
363 | 170b02b7 | Michael Hanselmann | (None, ("File %s is missing from node(s) node2.example.com" % |
364 | 170b02b7 | Michael Hanselmann | constants.CLUSTER_DOMAIN_SECRET_FILE)), |
365 | 170b02b7 | Michael Hanselmann | (None, ("File %s should not exist on node(s) node4.example.com" % |
366 | 170b02b7 | Michael Hanselmann | constants.CLUSTER_CONF_FILE)), |
367 | 0ad1ea40 | Guido Trotter | (None, ("File %s is missing from node(s) node4.example.com" % |
368 | 0ad1ea40 | Guido Trotter | hv_xen.XEND_CONFIG_FILE)), |
369 | 170b02b7 | Michael Hanselmann | (None, ("File %s is missing from node(s) node3.example.com" % |
370 | 170b02b7 | Michael Hanselmann | constants.CLUSTER_CONF_FILE)), |
371 | 170b02b7 | Michael Hanselmann | (None, ("File %s found with 2 different checksums (variant 1 on" |
372 | 170b02b7 | Michael Hanselmann | " master.example.com; variant 2 on node4.example.com)" %
|
373 | 170b02b7 | Michael Hanselmann | constants.CLUSTER_CONF_FILE)), |
374 | 170b02b7 | Michael Hanselmann | (None, ("File %s is optional, but it must exist on all or no nodes (not" |
375 | 170b02b7 | Michael Hanselmann | " found on master.example.com, node2.example.com,"
|
376 | 170b02b7 | Michael Hanselmann | " node3.example.com)" % constants.RAPI_USERS_FILE)),
|
377 | 0ad1ea40 | Guido Trotter | (None, ("File %s is optional, but it must exist on all or no nodes (not" |
378 | 0ad1ea40 | Guido Trotter | " found on node2.example.com)" % hv_xen.XL_CONFIG_FILE)),
|
379 | 170b02b7 | Michael Hanselmann | ("nodata.example.com", "Node did not return file checksum data"), |
380 | 170b02b7 | Michael Hanselmann | ])) |
381 | 170b02b7 | Michael Hanselmann | |
382 | 170b02b7 | Michael Hanselmann | |
383 | b98bf262 | Michael Hanselmann | if __name__ == "__main__": |
384 | 25231ec5 | Michael Hanselmann | testutils.GanetiTestProgram() |