Revision 0e68bf27
b/lib/cmdlib.py | ||
---|---|---|
1016 | 1016 |
(instance.name, msg), errors.ECODE_STATE) |
1017 | 1017 |
|
1018 | 1018 |
|
1019 |
def _CheckMinMaxSpecs(name, ipolicy, value):
|
|
1020 |
"""Checks if value is in the desired range.
|
|
1019 |
def _ComputeMinMaxSpec(name, ipolicy, value):
|
|
1020 |
"""Computes if value is in the desired range.
|
|
1021 | 1021 |
|
1022 | 1022 |
@param name: name of the parameter for which we perform the check |
1023 | 1023 |
@param ipolicy: dictionary containing min, max and std values |
... | ... | |
1038 | 1038 |
|
1039 | 1039 |
def _ComputeIPolicySpecViolation(ipolicy, mem_size, cpu_count, disk_count, |
1040 | 1040 |
nic_count, disk_sizes, |
1041 |
_check_spec_fn=_CheckMinMaxSpecs):
|
|
1041 |
_compute_fn=_ComputeMinMaxSpec):
|
|
1042 | 1042 |
"""Verifies ipolicy against provided specs. |
1043 | 1043 |
|
1044 | 1044 |
@type ipolicy: dict |
... | ... | |
1053 | 1053 |
@param nic_count: Number of nics used |
1054 | 1054 |
@type disk_sizes: list of ints |
1055 | 1055 |
@param disk_sizes: Disk sizes of used disk (len must match C{disk_count}) |
1056 |
@param _check_spec_fn: The checking function (unittest only)
|
|
1056 |
@param _compute_fn: The compute function (unittest only)
|
|
1057 | 1057 |
@return: A list of violations, or an empty list of no violations are found |
1058 | 1058 |
|
1059 | 1059 |
""" |
... | ... | |
1067 | 1067 |
] + map((lambda d: (constants.ISPEC_DISK_SIZE, d)), disk_sizes) |
1068 | 1068 |
|
1069 | 1069 |
return filter(None, |
1070 |
(_check_spec_fn(name, ipolicy, value)
|
|
1070 |
(_compute_fn(name, ipolicy, value)
|
|
1071 | 1071 |
for (name, value) in test_settings)) |
1072 | 1072 |
|
1073 | 1073 |
|
b/test/ganeti.cmdlib_unittest.py | ||
---|---|---|
570 | 570 |
new, None) |
571 | 571 |
|
572 | 572 |
|
573 |
def _ValidateCheckMinMaxSpec(name, *_):
|
|
573 |
def _ValidateComputeMinMaxSpec(name, *_):
|
|
574 | 574 |
assert name in constants.ISPECS_PARAMETERS |
575 | 575 |
return None |
576 | 576 |
|
... | ... | |
579 | 579 |
def __init__(self, spec): |
580 | 580 |
self.spec = spec |
581 | 581 |
|
582 |
def CheckMinMaxSpec(self, *args):
|
|
582 |
def ComputeMinMaxSpec(self, *args):
|
|
583 | 583 |
return self.spec.pop(0) |
584 | 584 |
|
585 | 585 |
|
586 | 586 |
class TestComputeIPolicySpecViolation(unittest.TestCase): |
587 | 587 |
def test(self): |
588 |
check_fn = _ValidateCheckMinMaxSpec
|
|
588 |
compute_fn = _ValidateComputeMinMaxSpec
|
|
589 | 589 |
ret = cmdlib._ComputeIPolicySpecViolation(NotImplemented, 1024, 1, 1, 1, |
590 |
[1024], _check_spec_fn=check_fn)
|
|
590 |
[1024], _compute_fn=compute_fn)
|
|
591 | 591 |
self.assertEqual(ret, []) |
592 | 592 |
|
593 | 593 |
def testInvalidArguments(self): |
... | ... | |
596 | 596 |
|
597 | 597 |
def testInvalidSpec(self): |
598 | 598 |
spec = _SpecWrapper([None, False, "foo", None, "bar"]) |
599 |
check_fn = spec.CheckMinMaxSpec
|
|
599 |
compute_fn = spec.ComputeMinMaxSpec
|
|
600 | 600 |
ret = cmdlib._ComputeIPolicySpecViolation(NotImplemented, 1024, 1, 1, 1, |
601 |
[1024], _check_spec_fn=check_fn)
|
|
601 |
[1024], _compute_fn=compute_fn)
|
|
602 | 602 |
self.assertEqual(ret, ["foo", "bar"]) |
603 | 603 |
self.assertFalse(spec.spec) |
604 | 604 |
|
Also available in: Unified diff