Revision 64760879 test/py/ganeti.config_unittest.py
b/test/py/ganeti.config_unittest.py | ||
---|---|---|
1 | 1 |
#!/usr/bin/python |
2 | 2 |
# |
3 | 3 |
|
4 |
# Copyright (C) 2006, 2007, 2010, 2011, 2012 Google Inc. |
|
4 |
# Copyright (C) 2006, 2007, 2010, 2011, 2012, 2013 Google Inc.
|
|
5 | 5 |
# |
6 | 6 |
# This program is free software; you can redistribute it and/or modify |
7 | 7 |
# it under the terms of the GNU General Public License as published by |
... | ... | |
65 | 65 |
pass |
66 | 66 |
|
67 | 67 |
def _get_object(self): |
68 |
"""Returns a instance of ConfigWriter""" |
|
68 |
"""Returns an instance of ConfigWriter"""
|
|
69 | 69 |
cfg = config.ConfigWriter(cfg_file=self.cfg_file, offline=True, |
70 | 70 |
_getents=_StubGetEntResolver) |
71 | 71 |
return cfg |
... | ... | |
428 | 428 |
finally: |
429 | 429 |
node2.group = orig_group |
430 | 430 |
|
431 |
def _TestVerifyConfigIPolicy(self, ipolicy, ipowner, cfg, isgroup): |
|
432 |
INVALID_KEY = "this_key_cannot_exist" |
|
433 |
|
|
434 |
ipolicy[INVALID_KEY] = None |
|
435 |
# A call to cluster.SimpleFillIPolicy causes different kinds of error |
|
436 |
# depending on the owner (cluster or group) |
|
437 |
if isgroup: |
|
438 |
errs = cfg.VerifyConfig() |
|
439 |
# FIXME: A bug in FillIPolicy (issue 401) makes this test fail, so we |
|
440 |
# invert the assertions for the time being |
|
441 |
self.assertFalse(len(errs) >= 1) |
|
442 |
errstr = "%s has invalid instance policy" % ipowner |
|
443 |
self.assertFalse(_IsErrorInList(errstr, errs)) |
|
444 |
else: |
|
445 |
self.assertRaises(AssertionError, cfg.VerifyConfig) |
|
446 |
del ipolicy[INVALID_KEY] |
|
447 |
errs = cfg.VerifyConfig() |
|
448 |
self.assertFalse(errs) |
|
449 |
|
|
450 |
key = list(constants.IPOLICY_PARAMETERS)[0] |
|
451 |
hasoldv = (key in ipolicy) |
|
452 |
if hasoldv: |
|
453 |
oldv = ipolicy[key] |
|
454 |
ipolicy[key] = "blah" |
|
455 |
errs = cfg.VerifyConfig() |
|
456 |
self.assertTrue(len(errs) >= 1) |
|
457 |
self.assertTrue(_IsErrorInList("%s has invalid instance policy" % ipowner, |
|
458 |
errs)) |
|
459 |
if hasoldv: |
|
460 |
ipolicy[key] = oldv |
|
461 |
else: |
|
462 |
del ipolicy[key] |
|
463 |
|
|
464 |
ispeclist = [ |
|
465 |
(ipolicy[constants.ISPECS_MINMAX][constants.ISPECS_MIN], |
|
466 |
"%s/%s" % (constants.ISPECS_MINMAX, constants.ISPECS_MIN)), |
|
467 |
(ipolicy[constants.ISPECS_MINMAX][constants.ISPECS_MAX], |
|
468 |
"%s/%s" % (constants.ISPECS_MINMAX, constants.ISPECS_MAX)), |
|
469 |
(ipolicy[constants.ISPECS_STD], constants.ISPECS_STD), |
|
470 |
] |
|
471 |
for (ispec, ispecpath) in ispeclist: |
|
472 |
ispec[INVALID_KEY] = None |
|
473 |
errs = cfg.VerifyConfig() |
|
474 |
self.assertTrue(len(errs) >= 1) |
|
475 |
self.assertTrue(_IsErrorInList(("%s has invalid ipolicy/%s" % |
|
476 |
(ipowner, ispecpath)), errs)) |
|
477 |
del ispec[INVALID_KEY] |
|
478 |
errs = cfg.VerifyConfig() |
|
479 |
self.assertFalse(errs) |
|
480 |
|
|
481 |
for par in constants.ISPECS_PARAMETERS: |
|
482 |
hasoldv = par in ispec |
|
483 |
if hasoldv: |
|
484 |
oldv = ispec[par] |
|
485 |
ispec[par] = "blah" |
|
486 |
errs = cfg.VerifyConfig() |
|
487 |
self.assertTrue(len(errs) >= 1) |
|
488 |
self.assertTrue(_IsErrorInList(("%s has invalid ipolicy/%s" % |
|
489 |
(ipowner, ispecpath)), errs)) |
|
490 |
if hasoldv: |
|
491 |
ispec[par] = oldv |
|
492 |
else: |
|
493 |
del ispec[par] |
|
494 |
errs = cfg.VerifyConfig() |
|
495 |
self.assertFalse(errs) |
|
496 |
|
|
497 |
def _TestVerifyConfigGroupIPolicy(self, groupinfo, cfg): |
|
498 |
old_ipolicy = groupinfo.ipolicy |
|
499 |
ipolicy = cfg.GetClusterInfo().SimpleFillIPolicy({}) |
|
500 |
groupinfo.ipolicy = ipolicy |
|
501 |
# Test partial policies |
|
502 |
for key in constants.IPOLICY_ALL_KEYS: |
|
503 |
self.assertTrue(key in ipolicy) |
|
504 |
oldv = ipolicy[key] |
|
505 |
del ipolicy[key] |
|
506 |
errs = cfg.VerifyConfig() |
|
507 |
self.assertFalse(errs) |
|
508 |
ipolicy[key] = oldv |
|
509 |
# Test partial minmax specs |
|
510 |
minmax = ipolicy[constants.ISPECS_MINMAX] |
|
511 |
for ispec_key in minmax.keys(): |
|
512 |
ispec = minmax[ispec_key] |
|
513 |
for par in constants.ISPECS_PARAMETERS: |
|
514 |
oldv = ispec[par] |
|
515 |
del ispec[par] |
|
516 |
errs = cfg.VerifyConfig() |
|
517 |
self.assertFalse(errs) |
|
518 |
ispec[par] = oldv |
|
519 |
groupinfo.ipolicy = old_ipolicy |
|
520 |
|
|
521 |
def _TestVerifyConfigClusterIPolicy(self, ipolicy, cfg): |
|
522 |
# Test partial policies |
|
523 |
for key in constants.IPOLICY_ALL_KEYS: |
|
524 |
self.assertTrue(key in ipolicy) |
|
525 |
oldv = ipolicy[key] |
|
526 |
del ipolicy[key] |
|
527 |
self.assertRaises(AssertionError, cfg.VerifyConfig) |
|
528 |
ipolicy[key] = oldv |
|
529 |
# Test partial minmax specs |
|
530 |
minmax = ipolicy[constants.ISPECS_MINMAX] |
|
531 |
for key in constants.ISPECS_MINMAX_KEYS: |
|
532 |
self.assertTrue(key in minmax) |
|
533 |
oldv = minmax[key] |
|
534 |
del minmax[key] |
|
535 |
self.assertRaises(AssertionError, cfg.VerifyConfig) |
|
536 |
minmax[key] = oldv |
|
537 |
errs = cfg.VerifyConfig() |
|
538 |
self.assertFalse(errs) |
|
539 |
|
|
431 | 540 |
def testVerifyConfig(self): |
432 | 541 |
cfg = self._get_object() |
433 | 542 |
|
... | ... | |
445 | 554 |
errs = cfg.VerifyConfig() |
446 | 555 |
self.assertFalse(errs) |
447 | 556 |
|
557 |
cluster = cfg.GetClusterInfo() |
|
558 |
nodegroup = cfg.GetNodeGroup(cfg.GetNodeGroupList()[0]) |
|
559 |
self._TestVerifyConfigIPolicy(cluster.ipolicy, "cluster", cfg, False) |
|
560 |
self._TestVerifyConfigClusterIPolicy(cluster.ipolicy, cfg) |
|
561 |
self._TestVerifyConfigIPolicy(nodegroup.ipolicy, nodegroup.name, cfg, True) |
|
562 |
self._TestVerifyConfigGroupIPolicy(nodegroup, cfg) |
|
563 |
nodegroup.ipolicy = cluster.SimpleFillIPolicy(nodegroup.ipolicy) |
|
564 |
self._TestVerifyConfigIPolicy(nodegroup.ipolicy, nodegroup.name, cfg, True) |
|
565 |
|
|
448 | 566 |
|
449 | 567 |
def _IsErrorInList(err_str, err_list): |
450 | 568 |
return any(map(lambda e: err_str in e, err_list)) |
Also available in: Unified diff