Revision 41044e04 test/py/ganeti.cli_unittest.py
b/test/py/ganeti.cli_unittest.py | ||
---|---|---|
1184 | 1184 |
# Policies are big, and we want to see the difference in case of an error |
1185 | 1185 |
self.maxDiff = None |
1186 | 1186 |
|
1187 |
def _RecursiveCheckMergedDicts(self, default_pol, diff_pol, merged_pol): |
|
1187 |
def _RecursiveCheckMergedDicts(self, default_pol, diff_pol, merged_pol, |
|
1188 |
merge_minmax=False): |
|
1188 | 1189 |
self.assertTrue(type(default_pol) is dict) |
1189 | 1190 |
self.assertTrue(type(diff_pol) is dict) |
1190 | 1191 |
self.assertTrue(type(merged_pol) is dict) |
... | ... | |
1194 | 1195 |
if key in diff_pol: |
1195 | 1196 |
if type(val) is dict: |
1196 | 1197 |
self._RecursiveCheckMergedDicts(default_pol[key], diff_pol[key], val) |
1198 |
elif (merge_minmax and key == "minmax" and type(val) is list and |
|
1199 |
len(val) == 1): |
|
1200 |
self.assertEqual(len(default_pol[key]), 1) |
|
1201 |
self.assertEqual(len(diff_pol[key]), 1) |
|
1202 |
self._RecursiveCheckMergedDicts(default_pol[key][0], |
|
1203 |
diff_pol[key][0], val[0]) |
|
1197 | 1204 |
else: |
1198 | 1205 |
self.assertEqual(val, diff_pol[key]) |
1199 | 1206 |
else: |
... | ... | |
1214 | 1221 |
self.assertEqual(pol0, constants.IPOLICY_DEFAULTS) |
1215 | 1222 |
|
1216 | 1223 |
exp_pol1 = { |
1217 |
constants.ISPECS_MINMAX: { |
|
1218 |
constants.ISPECS_MIN: { |
|
1219 |
constants.ISPEC_CPU_COUNT: 2, |
|
1220 |
constants.ISPEC_DISK_COUNT: 1, |
|
1221 |
}, |
|
1222 |
constants.ISPECS_MAX: { |
|
1223 |
constants.ISPEC_MEM_SIZE: 12*1024, |
|
1224 |
constants.ISPEC_DISK_COUNT: 2, |
|
1224 |
constants.ISPECS_MINMAX: [ |
|
1225 |
{ |
|
1226 |
constants.ISPECS_MIN: { |
|
1227 |
constants.ISPEC_CPU_COUNT: 2, |
|
1228 |
constants.ISPEC_DISK_COUNT: 1, |
|
1229 |
}, |
|
1230 |
constants.ISPECS_MAX: { |
|
1231 |
constants.ISPEC_MEM_SIZE: 12*1024, |
|
1232 |
constants.ISPEC_DISK_COUNT: 2, |
|
1233 |
}, |
|
1225 | 1234 |
}, |
1226 |
},
|
|
1235 |
],
|
|
1227 | 1236 |
constants.ISPECS_STD: { |
1228 | 1237 |
constants.ISPEC_CPU_COUNT: 2, |
1229 | 1238 |
constants.ISPEC_DISK_COUNT: 2, |
... | ... | |
1242 | 1251 |
fill_all=True |
1243 | 1252 |
) |
1244 | 1253 |
self._RecursiveCheckMergedDicts(constants.IPOLICY_DEFAULTS, |
1245 |
exp_pol1, pol1) |
|
1254 |
exp_pol1, pol1, merge_minmax=True)
|
|
1246 | 1255 |
|
1247 | 1256 |
exp_pol2 = { |
1248 |
constants.ISPECS_MINMAX: { |
|
1249 |
constants.ISPECS_MIN: { |
|
1250 |
constants.ISPEC_DISK_SIZE: 512, |
|
1251 |
constants.ISPEC_NIC_COUNT: 2, |
|
1257 |
constants.ISPECS_MINMAX: [ |
|
1258 |
{ |
|
1259 |
constants.ISPECS_MIN: { |
|
1260 |
constants.ISPEC_DISK_SIZE: 512, |
|
1261 |
constants.ISPEC_NIC_COUNT: 2, |
|
1262 |
}, |
|
1263 |
constants.ISPECS_MAX: { |
|
1264 |
constants.ISPEC_NIC_COUNT: 3, |
|
1265 |
}, |
|
1252 | 1266 |
}, |
1253 |
constants.ISPECS_MAX: { |
|
1254 |
constants.ISPEC_NIC_COUNT: 3, |
|
1255 |
}, |
|
1256 |
}, |
|
1267 |
], |
|
1257 | 1268 |
constants.ISPECS_STD: { |
1258 | 1269 |
constants.ISPEC_CPU_COUNT: 2, |
1259 | 1270 |
constants.ISPEC_NIC_COUNT: 3, |
... | ... | |
1273 | 1284 |
fill_all=True |
1274 | 1285 |
) |
1275 | 1286 |
self._RecursiveCheckMergedDicts(constants.IPOLICY_DEFAULTS, |
1276 |
exp_pol2, pol2) |
|
1287 |
exp_pol2, pol2, merge_minmax=True)
|
|
1277 | 1288 |
|
1278 | 1289 |
for fill_all in [False, True]: |
1279 | 1290 |
exp_pol3 = { |
... | ... | |
1294 | 1305 |
) |
1295 | 1306 |
if fill_all: |
1296 | 1307 |
self._RecursiveCheckMergedDicts(constants.IPOLICY_DEFAULTS, |
1297 |
exp_pol3, pol3) |
|
1308 |
exp_pol3, pol3, merge_minmax=True)
|
|
1298 | 1309 |
else: |
1299 | 1310 |
self.assertEqual(pol3, exp_pol3) |
1300 | 1311 |
|
... | ... | |
1384 | 1395 |
broken_mmspecs[key]["invalid_key"] = None |
1385 | 1396 |
self._TestInvalidISpecs(broken_mmspecs, None) |
1386 | 1397 |
del broken_mmspecs[key]["invalid_key"] |
1398 |
broken_mmspecs["invalid_key"] = None |
|
1399 |
self._TestInvalidISpecs(broken_mmspecs, None) |
|
1400 |
del broken_mmspecs["invalid_key"] |
|
1387 | 1401 |
assert broken_mmspecs == good_mmspecs |
1388 | 1402 |
|
1389 | 1403 |
good_stdspecs = constants.IPOLICY_DEFAULTS[constants.ISPECS_STD] |
... | ... | |
1437 | 1451 |
minmax_ispecs = {} |
1438 | 1452 |
for (key, spec) in exp_minmax.items(): |
1439 | 1453 |
minmax_ispecs[key] = self._ConvertSpecToStrings(spec) |
1440 |
exp_ipol[constants.ISPECS_MINMAX] = exp_minmax
|
|
1454 |
exp_ipol[constants.ISPECS_MINMAX] = [exp_minmax]
|
|
1441 | 1455 |
else: |
1442 | 1456 |
minmax_ispecs = None |
1443 | 1457 |
if exp_std is not None: |
... | ... | |
1527 | 1541 |
policies = [ |
1528 | 1542 |
{}, |
1529 | 1543 |
{"std": {}}, |
1530 |
{"minmax": {}}, |
|
1531 |
{"minmax": { |
|
1544 |
{"minmax": []}, |
|
1545 |
{"minmax": [{}]}, |
|
1546 |
{"minmax": [{ |
|
1532 | 1547 |
"min": {}, |
1533 | 1548 |
"max": {}, |
1534 |
}}, |
|
1535 |
{"minmax": { |
|
1549 |
}]},
|
|
1550 |
{"minmax": [{
|
|
1536 | 1551 |
"min": self._SPECS1, |
1537 | 1552 |
"max": {}, |
1538 |
}}, |
|
1553 |
}]},
|
|
1539 | 1554 |
] |
1540 | 1555 |
for pol in policies: |
1541 | 1556 |
self._CheckPrintIPolicyCommand(pol, False, "") |
... | ... | |
1544 | 1559 |
cases = [ |
1545 | 1560 |
({"std": self._SPECS1}, |
1546 | 1561 |
" %s %s" % (cli.IPOLICY_STD_SPECS_STR, self._SPECS1_STR)), |
1547 |
({"minmax": { |
|
1562 |
({"minmax": [{
|
|
1548 | 1563 |
"min": self._SPECS1, |
1549 | 1564 |
"max": self._SPECS2, |
1550 |
}}, |
|
1565 |
}]},
|
|
1551 | 1566 |
" %s min:%s/max:%s" % (cli.IPOLICY_BOUNDS_SPECS_STR, |
1552 | 1567 |
self._SPECS1_STR, self._SPECS2_STR)), |
1553 | 1568 |
] |
Also available in: Unified diff