Commit 0e68bf27 authored by René Nussbaumer's avatar René Nussbaumer
Browse files

cmdlib: Rename _CheckMinMaxSpecs to _ComputeMinMaxSpec



This is to reflect the fact that _Check functions do raise Op*Error
which is not the case for _CheckMinMaxSpec.
Signed-off-by: default avatarRené Nussbaumer <rn@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent 89e8508e
...@@ -1016,8 +1016,8 @@ def _CheckInstanceState(lu, instance, req_states, msg=None): ...@@ -1016,8 +1016,8 @@ def _CheckInstanceState(lu, instance, req_states, msg=None):
(instance.name, msg), errors.ECODE_STATE) (instance.name, msg), errors.ECODE_STATE)
   
   
def _CheckMinMaxSpecs(name, ipolicy, value): def _ComputeMinMaxSpec(name, ipolicy, value):
"""Checks if value is in the desired range. """Computes if value is in the desired range.
   
@param name: name of the parameter for which we perform the check @param name: name of the parameter for which we perform the check
@param ipolicy: dictionary containing min, max and std values @param ipolicy: dictionary containing min, max and std values
...@@ -1038,7 +1038,7 @@ def _CheckMinMaxSpecs(name, ipolicy, value): ...@@ -1038,7 +1038,7 @@ def _CheckMinMaxSpecs(name, ipolicy, value):
   
def _ComputeIPolicySpecViolation(ipolicy, mem_size, cpu_count, disk_count, def _ComputeIPolicySpecViolation(ipolicy, mem_size, cpu_count, disk_count,
nic_count, disk_sizes, nic_count, disk_sizes,
_check_spec_fn=_CheckMinMaxSpecs): _compute_fn=_ComputeMinMaxSpec):
"""Verifies ipolicy against provided specs. """Verifies ipolicy against provided specs.
   
@type ipolicy: dict @type ipolicy: dict
...@@ -1053,7 +1053,7 @@ def _ComputeIPolicySpecViolation(ipolicy, mem_size, cpu_count, disk_count, ...@@ -1053,7 +1053,7 @@ def _ComputeIPolicySpecViolation(ipolicy, mem_size, cpu_count, disk_count,
@param nic_count: Number of nics used @param nic_count: Number of nics used
@type disk_sizes: list of ints @type disk_sizes: list of ints
@param disk_sizes: Disk sizes of used disk (len must match C{disk_count}) @param disk_sizes: Disk sizes of used disk (len must match C{disk_count})
@param _check_spec_fn: The checking function (unittest only) @param _compute_fn: The compute function (unittest only)
@return: A list of violations, or an empty list of no violations are found @return: A list of violations, or an empty list of no violations are found
   
""" """
...@@ -1067,7 +1067,7 @@ def _ComputeIPolicySpecViolation(ipolicy, mem_size, cpu_count, disk_count, ...@@ -1067,7 +1067,7 @@ def _ComputeIPolicySpecViolation(ipolicy, mem_size, cpu_count, disk_count,
] + map((lambda d: (constants.ISPEC_DISK_SIZE, d)), disk_sizes) ] + map((lambda d: (constants.ISPEC_DISK_SIZE, d)), disk_sizes)
   
return filter(None, return filter(None,
(_check_spec_fn(name, ipolicy, value) (_compute_fn(name, ipolicy, value)
for (name, value) in test_settings)) for (name, value) in test_settings))
   
   
......
...@@ -570,7 +570,7 @@ class TestDiskStateHelper(unittest.TestCase): ...@@ -570,7 +570,7 @@ class TestDiskStateHelper(unittest.TestCase):
new, None) new, None)
def _ValidateCheckMinMaxSpec(name, *_): def _ValidateComputeMinMaxSpec(name, *_):
assert name in constants.ISPECS_PARAMETERS assert name in constants.ISPECS_PARAMETERS
return None return None
...@@ -579,15 +579,15 @@ class _SpecWrapper: ...@@ -579,15 +579,15 @@ class _SpecWrapper:
def __init__(self, spec): def __init__(self, spec):
self.spec = spec self.spec = spec
def CheckMinMaxSpec(self, *args): def ComputeMinMaxSpec(self, *args):
return self.spec.pop(0) return self.spec.pop(0)
class TestComputeIPolicySpecViolation(unittest.TestCase): class TestComputeIPolicySpecViolation(unittest.TestCase):
def test(self): def test(self):
check_fn = _ValidateCheckMinMaxSpec compute_fn = _ValidateComputeMinMaxSpec
ret = cmdlib._ComputeIPolicySpecViolation(NotImplemented, 1024, 1, 1, 1, ret = cmdlib._ComputeIPolicySpecViolation(NotImplemented, 1024, 1, 1, 1,
[1024], _check_spec_fn=check_fn) [1024], _compute_fn=compute_fn)
self.assertEqual(ret, []) self.assertEqual(ret, [])
def testInvalidArguments(self): def testInvalidArguments(self):
...@@ -596,9 +596,9 @@ class TestComputeIPolicySpecViolation(unittest.TestCase): ...@@ -596,9 +596,9 @@ class TestComputeIPolicySpecViolation(unittest.TestCase):
def testInvalidSpec(self): def testInvalidSpec(self):
spec = _SpecWrapper([None, False, "foo", None, "bar"]) spec = _SpecWrapper([None, False, "foo", None, "bar"])
check_fn = spec.CheckMinMaxSpec compute_fn = spec.ComputeMinMaxSpec
ret = cmdlib._ComputeIPolicySpecViolation(NotImplemented, 1024, 1, 1, 1, ret = cmdlib._ComputeIPolicySpecViolation(NotImplemented, 1024, 1, 1, 1,
[1024], _check_spec_fn=check_fn) [1024], _compute_fn=compute_fn)
self.assertEqual(ret, ["foo", "bar"]) self.assertEqual(ret, ["foo", "bar"])
self.assertFalse(spec.spec) self.assertFalse(spec.spec)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment