Revision 170b02b7 test/ganeti.cmdlib_unittest.py
b/test/ganeti.cmdlib_unittest.py | ||
---|---|---|
38 | 38 |
from ganeti import luxi |
39 | 39 |
from ganeti import ht |
40 | 40 |
from ganeti import objects |
41 |
from ganeti import compat |
|
42 |
from ganeti import rpc |
|
41 | 43 |
|
42 | 44 |
import testutils |
43 | 45 |
import mocks |
... | ... | |
267 | 269 |
}) |
268 | 270 |
|
269 | 271 |
|
272 |
class TestClusterVerifyFiles(unittest.TestCase): |
|
273 |
@staticmethod |
|
274 |
def _FakeErrorIf(errors, cond, ecode, item, msg, *args, **kwargs): |
|
275 |
assert ((ecode == cmdlib.LUClusterVerifyGroup.ENODEFILECHECK and |
|
276 |
ht.TNonEmptyString(item)) or |
|
277 |
(ecode == cmdlib.LUClusterVerifyGroup.ECLUSTERFILECHECK and |
|
278 |
item is None)) |
|
279 |
|
|
280 |
if args: |
|
281 |
msg = msg % args |
|
282 |
|
|
283 |
if cond: |
|
284 |
errors.append((item, msg)) |
|
285 |
|
|
286 |
_VerifyFiles = cmdlib.LUClusterVerifyGroup._VerifyFiles |
|
287 |
|
|
288 |
def test(self): |
|
289 |
errors = [] |
|
290 |
master_name = "master.example.com" |
|
291 |
nodeinfo = [ |
|
292 |
objects.Node(name=master_name, offline=False), |
|
293 |
objects.Node(name="node2.example.com", offline=False), |
|
294 |
objects.Node(name="node3.example.com", master_candidate=True), |
|
295 |
objects.Node(name="node4.example.com", offline=False), |
|
296 |
objects.Node(name="nodata.example.com"), |
|
297 |
objects.Node(name="offline.example.com", offline=True), |
|
298 |
] |
|
299 |
cluster = objects.Cluster(modify_etc_hosts=True, |
|
300 |
enabled_hypervisors=[constants.HT_XEN_HVM]) |
|
301 |
files_all = set([ |
|
302 |
constants.CLUSTER_DOMAIN_SECRET_FILE, |
|
303 |
constants.RAPI_CERT_FILE, |
|
304 |
]) |
|
305 |
files_all_opt = set([ |
|
306 |
constants.RAPI_USERS_FILE, |
|
307 |
]) |
|
308 |
files_mc = set([ |
|
309 |
constants.CLUSTER_CONF_FILE, |
|
310 |
]) |
|
311 |
files_vm = set() |
|
312 |
nvinfo = { |
|
313 |
master_name: rpc.RpcResult(data=(True, { |
|
314 |
constants.NV_FILELIST: { |
|
315 |
constants.CLUSTER_CONF_FILE: "82314f897f38b35f9dab2f7c6b1593e0", |
|
316 |
constants.RAPI_CERT_FILE: "babbce8f387bc082228e544a2146fee4", |
|
317 |
constants.CLUSTER_DOMAIN_SECRET_FILE: "cds-47b5b3f19202936bb4", |
|
318 |
}})), |
|
319 |
"node2.example.com": rpc.RpcResult(data=(True, { |
|
320 |
constants.NV_FILELIST: { |
|
321 |
constants.RAPI_CERT_FILE: "97f0356500e866387f4b84233848cc4a", |
|
322 |
} |
|
323 |
})), |
|
324 |
"node3.example.com": rpc.RpcResult(data=(True, { |
|
325 |
constants.NV_FILELIST: { |
|
326 |
constants.RAPI_CERT_FILE: "97f0356500e866387f4b84233848cc4a", |
|
327 |
constants.CLUSTER_DOMAIN_SECRET_FILE: "cds-47b5b3f19202936bb4", |
|
328 |
} |
|
329 |
})), |
|
330 |
"node4.example.com": rpc.RpcResult(data=(True, { |
|
331 |
constants.NV_FILELIST: { |
|
332 |
constants.RAPI_CERT_FILE: "97f0356500e866387f4b84233848cc4a", |
|
333 |
constants.CLUSTER_CONF_FILE: "conf-a6d4b13e407867f7a7b4f0f232a8f527", |
|
334 |
constants.CLUSTER_DOMAIN_SECRET_FILE: "cds-47b5b3f19202936bb4", |
|
335 |
constants.RAPI_USERS_FILE: "rapiusers-ea3271e8d810ef3", |
|
336 |
} |
|
337 |
})), |
|
338 |
"nodata.example.com": rpc.RpcResult(data=(True, {})), |
|
339 |
"offline.example.com": rpc.RpcResult(offline=True), |
|
340 |
} |
|
341 |
assert set(nvinfo.keys()) == set(map(operator.attrgetter("name"), nodeinfo)) |
|
342 |
|
|
343 |
self._VerifyFiles(compat.partial(self._FakeErrorIf, errors), nodeinfo, |
|
344 |
master_name, nvinfo, |
|
345 |
(files_all, files_all_opt, files_mc, files_vm)) |
|
346 |
self.assertEqual(sorted(errors), sorted([ |
|
347 |
(None, ("File %s found with 2 different checksums (variant 1 on" |
|
348 |
" node2.example.com, node3.example.com, node4.example.com;" |
|
349 |
" variant 2 on master.example.com)" % constants.RAPI_CERT_FILE)), |
|
350 |
(None, ("File %s is missing from node(s) node2.example.com" % |
|
351 |
constants.CLUSTER_DOMAIN_SECRET_FILE)), |
|
352 |
(None, ("File %s should not exist on node(s) node4.example.com" % |
|
353 |
constants.CLUSTER_CONF_FILE)), |
|
354 |
(None, ("File %s is missing from node(s) node3.example.com" % |
|
355 |
constants.CLUSTER_CONF_FILE)), |
|
356 |
(None, ("File %s found with 2 different checksums (variant 1 on" |
|
357 |
" master.example.com; variant 2 on node4.example.com)" % |
|
358 |
constants.CLUSTER_CONF_FILE)), |
|
359 |
(None, ("File %s is optional, but it must exist on all or no nodes (not" |
|
360 |
" found on master.example.com, node2.example.com," |
|
361 |
" node3.example.com)" % constants.RAPI_USERS_FILE)), |
|
362 |
("nodata.example.com", "Node did not return file checksum data"), |
|
363 |
])) |
|
364 |
|
|
365 |
|
|
270 | 366 |
if __name__ == "__main__": |
271 | 367 |
testutils.GanetiTestProgram() |
Also available in: Unified diff