392 |
392 |
True)
|
393 |
393 |
self._AssertIPolicyIsFull(constants.IPOLICY_DEFAULTS)
|
394 |
394 |
|
|
395 |
def testCheckISpecSyntax(self):
|
|
396 |
par = "my_parameter"
|
|
397 |
for check_std in [True, False]:
|
|
398 |
if check_std:
|
|
399 |
allkeys = constants.IPOLICY_ISPECS
|
|
400 |
else:
|
|
401 |
allkeys = constants.IPOLICY_ISPECS - frozenset([constants.ISPECS_STD])
|
|
402 |
# Only one policy limit
|
|
403 |
for key in allkeys:
|
|
404 |
policy = dict((k, {}) for k in allkeys)
|
|
405 |
policy[key][par] = 11
|
|
406 |
objects.InstancePolicy.CheckISpecSyntax(policy, par, check_std)
|
|
407 |
# Min and max only
|
|
408 |
good_values = [(11, 11), (11, 40), (0, 0)]
|
|
409 |
for (mn, mx) in good_values:
|
|
410 |
policy = dict((k, {}) for k in allkeys)
|
|
411 |
policy[constants.ISPECS_MIN][par] = mn
|
|
412 |
policy[constants.ISPECS_MAX][par] = mx
|
|
413 |
objects.InstancePolicy.CheckISpecSyntax(policy, par, check_std)
|
|
414 |
policy = dict((k, {}) for k in allkeys)
|
|
415 |
policy[constants.ISPECS_MIN][par] = 11
|
|
416 |
policy[constants.ISPECS_MAX][par] = 5
|
|
417 |
self.assertRaises(errors.ConfigurationError,
|
|
418 |
objects.InstancePolicy.CheckISpecSyntax,
|
|
419 |
policy, par, check_std)
|
|
420 |
# Min, std, max
|
|
421 |
good_values = [
|
|
422 |
(11, 11, 11),
|
|
423 |
(11, 11, 40),
|
|
424 |
(11, 40, 40),
|
|
425 |
]
|
|
426 |
for (mn, st, mx) in good_values:
|
|
427 |
policy = {
|
|
428 |
constants.ISPECS_MIN: {par: mn},
|
|
429 |
constants.ISPECS_STD: {par: st},
|
|
430 |
constants.ISPECS_MAX: {par: mx},
|
|
431 |
}
|
|
432 |
objects.InstancePolicy.CheckISpecSyntax(policy, par, True)
|
|
433 |
bad_values = [
|
|
434 |
(11, 11, 5),
|
|
435 |
(40, 11, 11),
|
|
436 |
(11, 80, 40),
|
|
437 |
(11, 5, 40),
|
|
438 |
(11, 5, 5),
|
|
439 |
(40, 40, 11),
|
|
440 |
]
|
|
441 |
for (mn, st, mx) in bad_values:
|
|
442 |
policy = {
|
|
443 |
constants.ISPECS_MIN: {par: mn},
|
|
444 |
constants.ISPECS_STD: {par: st},
|
|
445 |
constants.ISPECS_MAX: {par: mx},
|
|
446 |
}
|
|
447 |
self.assertRaises(errors.ConfigurationError,
|
|
448 |
objects.InstancePolicy.CheckISpecSyntax,
|
|
449 |
policy, par, True)
|
|
450 |
|
|
451 |
def testCheckDiskTemplates(self):
|
|
452 |
invalid = "this_is_not_a_good_template"
|
|
453 |
for dt in constants.DISK_TEMPLATES:
|
|
454 |
objects.InstancePolicy.CheckDiskTemplates([dt])
|
|
455 |
objects.InstancePolicy.CheckDiskTemplates(list(constants.DISK_TEMPLATES))
|
|
456 |
bad_examples = [
|
|
457 |
[invalid],
|
|
458 |
[constants.DT_DRBD8, invalid],
|
|
459 |
list(constants.DISK_TEMPLATES) + [invalid],
|
|
460 |
[],
|
|
461 |
None,
|
|
462 |
]
|
|
463 |
for dtl in bad_examples:
|
|
464 |
self.assertRaises(errors.ConfigurationError,
|
|
465 |
objects.InstancePolicy.CheckDiskTemplates,
|
|
466 |
dtl)
|
|
467 |
|
|
468 |
def testCheckParameterSyntax(self):
|
|
469 |
invalid = "this_key_shouldnt_be_here"
|
|
470 |
for check_std in [True, False]:
|
|
471 |
self.assertRaises(KeyError,
|
|
472 |
objects.InstancePolicy.CheckParameterSyntax,
|
|
473 |
{}, check_std)
|
|
474 |
policy = objects.MakeEmptyIPolicy()
|
|
475 |
policy[invalid] = None
|
|
476 |
self.assertRaises(errors.ConfigurationError,
|
|
477 |
objects.InstancePolicy.CheckParameterSyntax,
|
|
478 |
policy, check_std)
|
|
479 |
for par in constants.IPOLICY_PARAMETERS:
|
|
480 |
policy = objects.MakeEmptyIPolicy()
|
|
481 |
for val in ("blah", None, {}, [42]):
|
|
482 |
policy[par] = val
|
|
483 |
self.assertRaises(errors.ConfigurationError,
|
|
484 |
objects.InstancePolicy.CheckParameterSyntax,
|
|
485 |
policy, check_std)
|
|
486 |
|
395 |
487 |
def testFillIPolicyEmpty(self):
|
396 |
488 |
policy = objects.FillIPolicy(constants.IPOLICY_DEFAULTS, {})
|
397 |
489 |
objects.InstancePolicy.CheckParameterSyntax(policy, True)
|
... | ... | |
418 |
510 |
partial_policies = [
|
419 |
511 |
{constants.IPOLICY_VCPU_RATIO: 3.14},
|
420 |
512 |
{constants.IPOLICY_SPINDLE_RATIO: 2.72},
|
421 |
|
{constants.IPOLICY_DTS: []},
|
422 |
513 |
{constants.IPOLICY_DTS: [constants.DT_FILE]},
|
423 |
514 |
]
|
424 |
515 |
for diff_pol in partial_policies:
|