Revision 0c2e59ac
b/lib/cmdlib.py | ||
---|---|---|
1116 | 1116 |
(instance.name, msg), errors.ECODE_STATE) |
1117 | 1117 |
|
1118 | 1118 |
|
1119 |
def _ComputeMinMaxSpec(name, ipolicy, value): |
|
1119 |
def _ComputeMinMaxSpec(name, qualifier, ipolicy, value):
|
|
1120 | 1120 |
"""Computes if value is in the desired range. |
1121 | 1121 |
|
1122 | 1122 |
@param name: name of the parameter for which we perform the check |
1123 |
@param qualifier: a qualifier used in the error message (e.g. 'disk/1', |
|
1124 |
not just 'disk') |
|
1123 | 1125 |
@param ipolicy: dictionary containing min, max and std values |
1124 | 1126 |
@param value: actual value that we want to use |
1125 | 1127 |
@return: None or element not meeting the criteria |
... | ... | |
1131 | 1133 |
max_v = ipolicy[constants.ISPECS_MAX].get(name, value) |
1132 | 1134 |
min_v = ipolicy[constants.ISPECS_MIN].get(name, value) |
1133 | 1135 |
if value > max_v or min_v > value: |
1136 |
if qualifier: |
|
1137 |
fqn = "%s/%s" % (name, qualifier) |
|
1138 |
else: |
|
1139 |
fqn = name |
|
1134 | 1140 |
return ("%s value %s is not in range [%s, %s]" % |
1135 |
(name, value, min_v, max_v))
|
|
1141 |
(fqn, value, min_v, max_v))
|
|
1136 | 1142 |
return None |
1137 | 1143 |
|
1138 | 1144 |
|
... | ... | |
1162 | 1168 |
assert disk_count == len(disk_sizes) |
1163 | 1169 |
|
1164 | 1170 |
test_settings = [ |
1165 |
(constants.ISPEC_MEM_SIZE, mem_size), |
|
1166 |
(constants.ISPEC_CPU_COUNT, cpu_count), |
|
1167 |
(constants.ISPEC_DISK_COUNT, disk_count), |
|
1168 |
(constants.ISPEC_NIC_COUNT, nic_count), |
|
1169 |
(constants.ISPEC_SPINDLE_USE, spindle_use), |
|
1170 |
] + map((lambda d: (constants.ISPEC_DISK_SIZE, d)), disk_sizes) |
|
1171 |
(constants.ISPEC_MEM_SIZE, "", mem_size), |
|
1172 |
(constants.ISPEC_CPU_COUNT, "", cpu_count), |
|
1173 |
(constants.ISPEC_DISK_COUNT, "", disk_count), |
|
1174 |
(constants.ISPEC_NIC_COUNT, "", nic_count), |
|
1175 |
(constants.ISPEC_SPINDLE_USE, "", spindle_use), |
|
1176 |
] + [(constants.ISPEC_DISK_SIZE, str(idx), d) |
|
1177 |
for idx, d in enumerate(disk_sizes)] |
|
1171 | 1178 |
|
1172 | 1179 |
return filter(None, |
1173 |
(_compute_fn(name, ipolicy, value) |
|
1174 |
for (name, value) in test_settings)) |
|
1180 |
(_compute_fn(name, qualifier, ipolicy, value)
|
|
1181 |
for (name, qualifier, value) in test_settings))
|
|
1175 | 1182 |
|
1176 | 1183 |
|
1177 | 1184 |
def _ComputeIPolicyInstanceViolation(ipolicy, instance, |
b/test/ganeti.cmdlib_unittest.py | ||
---|---|---|
1 | 1 |
#!/usr/bin/python |
2 | 2 |
# |
3 | 3 |
|
4 |
# Copyright (C) 2008, 2011 Google Inc. |
|
4 |
# Copyright (C) 2008, 2011, 2012 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 |
... | ... | |
586 | 586 |
} |
587 | 587 |
|
588 | 588 |
def testNoneValue(self): |
589 |
self.assertTrue(cmdlib._ComputeMinMaxSpec(constants.ISPEC_MEM_SIZE, |
|
589 |
self.assertTrue(cmdlib._ComputeMinMaxSpec(constants.ISPEC_MEM_SIZE, None,
|
|
590 | 590 |
self.ipolicy, None) is None) |
591 | 591 |
|
592 | 592 |
def testAutoValue(self): |
593 |
self.assertTrue(cmdlib._ComputeMinMaxSpec(constants.ISPEC_MEM_SIZE, |
|
593 |
self.assertTrue(cmdlib._ComputeMinMaxSpec(constants.ISPEC_MEM_SIZE, None,
|
|
594 | 594 |
self.ipolicy, |
595 | 595 |
constants.VALUE_AUTO) is None) |
596 | 596 |
|
597 | 597 |
def testNotDefined(self): |
598 |
self.assertTrue(cmdlib._ComputeMinMaxSpec(constants.ISPEC_NIC_COUNT, |
|
598 |
self.assertTrue(cmdlib._ComputeMinMaxSpec(constants.ISPEC_NIC_COUNT, None,
|
|
599 | 599 |
self.ipolicy, 3) is None) |
600 | 600 |
|
601 | 601 |
def testNoMinDefined(self): |
602 |
self.assertTrue(cmdlib._ComputeMinMaxSpec(constants.ISPEC_DISK_SIZE, |
|
602 |
self.assertTrue(cmdlib._ComputeMinMaxSpec(constants.ISPEC_DISK_SIZE, None,
|
|
603 | 603 |
self.ipolicy, 128) is None) |
604 | 604 |
|
605 | 605 |
def testNoMaxDefined(self): |
606 |
self.assertTrue(cmdlib._ComputeMinMaxSpec(constants.ISPEC_DISK_COUNT, |
|
606 |
self.assertTrue(cmdlib._ComputeMinMaxSpec(constants.ISPEC_DISK_COUNT, None,
|
|
607 | 607 |
self.ipolicy, 16) is None) |
608 | 608 |
|
609 | 609 |
def testOutOfRange(self): |
... | ... | |
613 | 613 |
(constants.ISPEC_DISK_COUNT, 0)): |
614 | 614 |
min_v = self.ipolicy[constants.ISPECS_MIN].get(name, val) |
615 | 615 |
max_v = self.ipolicy[constants.ISPECS_MAX].get(name, val) |
616 |
self.assertEqual(cmdlib._ComputeMinMaxSpec(name, self.ipolicy, val), |
|
616 |
self.assertEqual(cmdlib._ComputeMinMaxSpec(name, None, |
|
617 |
self.ipolicy, val), |
|
617 | 618 |
"%s value %s is not in range [%s, %s]" % |
618 | 619 |
(name, val,min_v, max_v)) |
620 |
self.assertEqual(cmdlib._ComputeMinMaxSpec(name, "1", |
|
621 |
self.ipolicy, val), |
|
622 |
"%s/1 value %s is not in range [%s, %s]" % |
|
623 |
(name, val,min_v, max_v)) |
|
619 | 624 |
|
620 | 625 |
def test(self): |
621 | 626 |
for (name, val) in ((constants.ISPEC_MEM_SIZE, 256), |
... | ... | |
625 | 630 |
(constants.ISPEC_DISK_SIZE, 0), |
626 | 631 |
(constants.ISPEC_DISK_COUNT, 1), |
627 | 632 |
(constants.ISPEC_DISK_COUNT, 5)): |
628 |
self.assertTrue(cmdlib._ComputeMinMaxSpec(name, self.ipolicy, val) |
|
633 |
self.assertTrue(cmdlib._ComputeMinMaxSpec(name, None, self.ipolicy, val)
|
|
629 | 634 |
is None) |
630 | 635 |
|
631 | 636 |
|
Also available in: Unified diff