Revision c026664a test/py/ganeti.config_unittest.py
b/test/py/ganeti.config_unittest.py | ||
---|---|---|
439 | 439 |
self.assertFalse(grp1.members) |
440 | 440 |
self.assertEqual(set(grp2.members), set(["node1-uuid", "node2-uuid"])) |
441 | 441 |
|
442 |
def _TestVerifyConfigIPolicy(self, ipolicy, ipowner, cfg, isgroup): |
|
443 |
INVALID_KEY = "this_key_cannot_exist" |
|
444 |
|
|
445 |
ipolicy[INVALID_KEY] = None |
|
446 |
# A call to cluster.SimpleFillIPolicy causes different kinds of error |
|
447 |
# depending on the owner (cluster or group) |
|
448 |
if isgroup: |
|
449 |
errs = cfg.VerifyConfig() |
|
450 |
self.assertTrue(len(errs) >= 1) |
|
451 |
errstr = "%s has invalid instance policy" % ipowner |
|
452 |
self.assertTrue(_IsErrorInList(errstr, errs)) |
|
453 |
else: |
|
454 |
self.assertRaises(AssertionError, cfg.VerifyConfig) |
|
455 |
del ipolicy[INVALID_KEY] |
|
456 |
errs = cfg.VerifyConfig() |
|
457 |
self.assertFalse(errs) |
|
458 |
|
|
459 |
key = list(constants.IPOLICY_PARAMETERS)[0] |
|
460 |
hasoldv = (key in ipolicy) |
|
461 |
if hasoldv: |
|
462 |
oldv = ipolicy[key] |
|
463 |
ipolicy[key] = "blah" |
|
464 |
errs = cfg.VerifyConfig() |
|
465 |
self.assertTrue(len(errs) >= 1) |
|
466 |
self.assertTrue(_IsErrorInList("%s has invalid instance policy" % ipowner, |
|
467 |
errs)) |
|
468 |
if hasoldv: |
|
469 |
ipolicy[key] = oldv |
|
470 |
else: |
|
471 |
del ipolicy[key] |
|
472 |
|
|
473 |
ispeclist = [] |
|
474 |
if constants.ISPECS_MINMAX in ipolicy: |
|
475 |
for k in range(len(ipolicy[constants.ISPECS_MINMAX])): |
|
476 |
ispeclist.extend([ |
|
477 |
(ipolicy[constants.ISPECS_MINMAX][k][constants.ISPECS_MIN], |
|
478 |
"%s[%s]/%s" % (constants.ISPECS_MINMAX, k, constants.ISPECS_MIN)), |
|
479 |
(ipolicy[constants.ISPECS_MINMAX][k][constants.ISPECS_MAX], |
|
480 |
"%s[%s]/%s" % (constants.ISPECS_MINMAX, k, constants.ISPECS_MAX)), |
|
481 |
]) |
|
482 |
if constants.ISPECS_STD in ipolicy: |
|
483 |
ispeclist.append((ipolicy[constants.ISPECS_STD], constants.ISPECS_STD)) |
|
484 |
|
|
485 |
for (ispec, ispecpath) in ispeclist: |
|
486 |
ispec[INVALID_KEY] = None |
|
487 |
errs = cfg.VerifyConfig() |
|
488 |
self.assertTrue(len(errs) >= 1) |
|
489 |
self.assertTrue(_IsErrorInList(("%s has invalid ipolicy/%s" % |
|
490 |
(ipowner, ispecpath)), errs)) |
|
491 |
del ispec[INVALID_KEY] |
|
492 |
errs = cfg.VerifyConfig() |
|
493 |
self.assertFalse(errs) |
|
494 |
|
|
495 |
for par in constants.ISPECS_PARAMETERS: |
|
496 |
hasoldv = par in ispec |
|
497 |
if hasoldv: |
|
498 |
oldv = ispec[par] |
|
499 |
ispec[par] = "blah" |
|
500 |
errs = cfg.VerifyConfig() |
|
501 |
self.assertTrue(len(errs) >= 1) |
|
502 |
self.assertTrue(_IsErrorInList(("%s has invalid ipolicy/%s" % |
|
503 |
(ipowner, ispecpath)), errs)) |
|
504 |
if hasoldv: |
|
505 |
ispec[par] = oldv |
|
506 |
else: |
|
507 |
del ispec[par] |
|
508 |
errs = cfg.VerifyConfig() |
|
509 |
self.assertFalse(errs) |
|
510 |
|
|
511 |
if constants.ISPECS_MINMAX in ipolicy: |
|
512 |
# Test partial minmax specs |
|
513 |
for minmax in ipolicy[constants.ISPECS_MINMAX]: |
|
514 |
for key in constants.ISPECS_MINMAX_KEYS: |
|
515 |
self.assertTrue(key in minmax) |
|
516 |
ispec = minmax[key] |
|
517 |
del minmax[key] |
|
518 |
errs = cfg.VerifyConfig() |
|
519 |
self.assertTrue(len(errs) >= 1) |
|
520 |
self.assertTrue(_IsErrorInList("Missing instance specification", |
|
521 |
errs)) |
|
522 |
minmax[key] = ispec |
|
523 |
for par in constants.ISPECS_PARAMETERS: |
|
524 |
oldv = ispec[par] |
|
525 |
del ispec[par] |
|
526 |
errs = cfg.VerifyConfig() |
|
527 |
self.assertTrue(len(errs) >= 1) |
|
528 |
self.assertTrue(_IsErrorInList("Missing instance specs parameters", |
|
529 |
errs)) |
|
530 |
ispec[par] = oldv |
|
531 |
errs = cfg.VerifyConfig() |
|
532 |
self.assertFalse(errs) |
|
533 |
|
|
534 |
def _TestVerifyConfigGroupIPolicy(self, groupinfo, cfg): |
|
535 |
old_ipolicy = groupinfo.ipolicy |
|
536 |
ipolicy = cfg.GetClusterInfo().SimpleFillIPolicy({}) |
|
537 |
groupinfo.ipolicy = ipolicy |
|
538 |
# Test partial policies |
|
539 |
for key in constants.IPOLICY_ALL_KEYS: |
|
540 |
self.assertTrue(key in ipolicy) |
|
541 |
oldv = ipolicy[key] |
|
542 |
del ipolicy[key] |
|
543 |
errs = cfg.VerifyConfig() |
|
544 |
self.assertFalse(errs) |
|
545 |
ipolicy[key] = oldv |
|
546 |
groupinfo.ipolicy = old_ipolicy |
|
547 |
|
|
548 |
def _TestVerifyConfigClusterIPolicy(self, ipolicy, cfg): |
|
549 |
# Test partial policies |
|
550 |
for key in constants.IPOLICY_ALL_KEYS: |
|
551 |
self.assertTrue(key in ipolicy) |
|
552 |
oldv = ipolicy[key] |
|
553 |
del ipolicy[key] |
|
554 |
self.assertRaises(AssertionError, cfg.VerifyConfig) |
|
555 |
ipolicy[key] = oldv |
|
556 |
errs = cfg.VerifyConfig() |
|
557 |
self.assertFalse(errs) |
|
558 |
# Partial standard specs |
|
559 |
ispec = ipolicy[constants.ISPECS_STD] |
|
560 |
for par in constants.ISPECS_PARAMETERS: |
|
561 |
oldv = ispec[par] |
|
562 |
del ispec[par] |
|
563 |
errs = cfg.VerifyConfig() |
|
564 |
self.assertTrue(len(errs) >= 1) |
|
565 |
self.assertTrue(_IsErrorInList("Missing instance specs parameters", |
|
566 |
errs)) |
|
567 |
ispec[par] = oldv |
|
568 |
errs = cfg.VerifyConfig() |
|
569 |
self.assertFalse(errs) |
|
570 |
|
|
571 |
def testVerifyConfig(self): |
|
572 |
cfg = self._get_object() |
|
573 |
|
|
574 |
errs = cfg.VerifyConfig() |
|
575 |
self.assertFalse(errs) |
|
576 |
|
|
577 |
node = cfg.GetNodeInfo(cfg.GetNodeList()[0]) |
|
578 |
key = list(constants.NDC_GLOBALS)[0] |
|
579 |
node.ndparams[key] = constants.NDC_DEFAULTS[key] |
|
580 |
cfg.Update(node, None) |
|
581 |
errs = cfg.VerifyConfig() |
|
582 |
self.assertTrue(len(errs) >= 1) |
|
583 |
self.assertTrue(_IsErrorInList("has some global parameters set", errs)) |
|
584 |
|
|
585 |
del node.ndparams[key] |
|
586 |
cfg.Update(node, None) |
|
587 |
errs = cfg.VerifyConfig() |
|
588 |
self.assertFalse(errs) |
|
589 |
|
|
590 |
cluster = cfg.GetClusterInfo() |
|
591 |
nodegroup = cfg.GetNodeGroup(cfg.GetNodeGroupList()[0]) |
|
592 |
self._TestVerifyConfigIPolicy(cluster.ipolicy, "cluster", cfg, False) |
|
593 |
self._TestVerifyConfigClusterIPolicy(cluster.ipolicy, cfg) |
|
594 |
self._TestVerifyConfigIPolicy(nodegroup.ipolicy, nodegroup.name, cfg, True) |
|
595 |
self._TestVerifyConfigGroupIPolicy(nodegroup, cfg) |
|
596 |
nodegroup.ipolicy = cluster.SimpleFillIPolicy(nodegroup.ipolicy) |
|
597 |
self._TestVerifyConfigIPolicy(nodegroup.ipolicy, nodegroup.name, cfg, True) |
|
598 |
|
|
599 | 442 |
# Tests for Ssconf helper functions |
600 | 443 |
def testUnlockedGetHvparamsString(self): |
601 | 444 |
hvparams = {"a": "A", "b": "B", "c": "C"} |
Also available in: Unified diff