Revision d2d3935a test/py/ganeti.cli_unittest.py
b/test/py/ganeti.cli_unittest.py | ||
---|---|---|
1332 | 1332 |
allowed_values=[allowedv]) |
1333 | 1333 |
self.assertEqual(pol1, exp_pol1) |
1334 | 1334 |
|
1335 |
@staticmethod |
|
1336 |
def _ConvertSpecToStrings(spec): |
|
1337 |
ret = {} |
|
1338 |
for (par, val) in spec.items(): |
|
1339 |
ret[par] = str(val) |
|
1340 |
return ret |
|
1341 |
|
|
1342 |
def _CheckNewStyleSpecsCall(self, exp_ipolicy, minmax_ispecs, std_ispecs, |
|
1343 |
group_ipolicy, fill_all): |
|
1344 |
ipolicy = cli.CreateIPolicyFromOpts(minmax_ispecs=minmax_ispecs, |
|
1345 |
std_ispecs=std_ispecs, |
|
1346 |
group_ipolicy=group_ipolicy, |
|
1347 |
fill_all=fill_all) |
|
1348 |
self.assertEqual(ipolicy, exp_ipolicy) |
|
1349 |
|
|
1350 |
def _TestFullISpecsInner(self, skel_exp_ipol, exp_minmax, exp_std, |
|
1351 |
group_ipolicy, fill_all): |
|
1352 |
exp_ipol = skel_exp_ipol.copy() |
|
1353 |
if exp_minmax is not None: |
|
1354 |
minmax_ispecs = {} |
|
1355 |
for (key, spec) in exp_minmax.items(): |
|
1356 |
minmax_ispecs[key] = self._ConvertSpecToStrings(spec) |
|
1357 |
exp_ipol[constants.ISPECS_MINMAX] = exp_minmax |
|
1358 |
else: |
|
1359 |
minmax_ispecs = None |
|
1360 |
if constants.ISPECS_MINMAX not in exp_ipol: |
|
1361 |
empty_minmax = dict((k, {}) for k in constants.ISPECS_MINMAX_KEYS) |
|
1362 |
exp_ipol[constants.ISPECS_MINMAX] = empty_minmax |
|
1363 |
if exp_std is not None: |
|
1364 |
std_ispecs = self._ConvertSpecToStrings(exp_std) |
|
1365 |
exp_ipol[constants.ISPECS_STD] = exp_std |
|
1366 |
else: |
|
1367 |
std_ispecs = None |
|
1368 |
if constants.ISPECS_STD not in exp_ipol: |
|
1369 |
exp_ipol[constants.ISPECS_STD] = {} |
|
1370 |
|
|
1371 |
self._CheckNewStyleSpecsCall(exp_ipol, minmax_ispecs, std_ispecs, |
|
1372 |
group_ipolicy, fill_all) |
|
1373 |
if minmax_ispecs: |
|
1374 |
for (key, spec) in minmax_ispecs.items(): |
|
1375 |
for par in [constants.ISPEC_MEM_SIZE, constants.ISPEC_DISK_SIZE]: |
|
1376 |
if par in spec: |
|
1377 |
spec[par] += "m" |
|
1378 |
self._CheckNewStyleSpecsCall(exp_ipol, minmax_ispecs, std_ispecs, |
|
1379 |
group_ipolicy, fill_all) |
|
1380 |
if std_ispecs: |
|
1381 |
for par in [constants.ISPEC_MEM_SIZE, constants.ISPEC_DISK_SIZE]: |
|
1382 |
if par in std_ispecs: |
|
1383 |
std_ispecs[par] += "m" |
|
1384 |
self._CheckNewStyleSpecsCall(exp_ipol, minmax_ispecs, std_ispecs, |
|
1385 |
group_ipolicy, fill_all) |
|
1386 |
|
|
1387 |
def testFullISpecs(self): |
|
1388 |
exp_minmax1 = { |
|
1389 |
constants.ISPECS_MIN: { |
|
1390 |
constants.ISPEC_MEM_SIZE: 512, |
|
1391 |
constants.ISPEC_CPU_COUNT: 2, |
|
1392 |
constants.ISPEC_DISK_COUNT: 2, |
|
1393 |
constants.ISPEC_DISK_SIZE: 512, |
|
1394 |
constants.ISPEC_NIC_COUNT: 2, |
|
1395 |
constants.ISPEC_SPINDLE_USE: 2, |
|
1396 |
}, |
|
1397 |
constants.ISPECS_MAX: { |
|
1398 |
constants.ISPEC_MEM_SIZE: 768*1024, |
|
1399 |
constants.ISPEC_CPU_COUNT: 7, |
|
1400 |
constants.ISPEC_DISK_COUNT: 6, |
|
1401 |
constants.ISPEC_DISK_SIZE: 2048*1024, |
|
1402 |
constants.ISPEC_NIC_COUNT: 3, |
|
1403 |
constants.ISPEC_SPINDLE_USE: 1, |
|
1404 |
}, |
|
1405 |
} |
|
1406 |
exp_std1 = { |
|
1407 |
constants.ISPEC_MEM_SIZE: 768*1024, |
|
1408 |
constants.ISPEC_CPU_COUNT: 7, |
|
1409 |
constants.ISPEC_DISK_COUNT: 6, |
|
1410 |
constants.ISPEC_DISK_SIZE: 2048*1024, |
|
1411 |
constants.ISPEC_NIC_COUNT: 3, |
|
1412 |
constants.ISPEC_SPINDLE_USE: 1, |
|
1413 |
} |
|
1414 |
for fill_all in [False, True]: |
|
1415 |
if fill_all: |
|
1416 |
skel_ipolicy = constants.IPOLICY_DEFAULTS |
|
1417 |
else: |
|
1418 |
skel_ipolicy = {} |
|
1419 |
self._TestFullISpecsInner(skel_ipolicy, exp_minmax1, exp_std1, |
|
1420 |
False, fill_all) |
|
1421 |
self._TestFullISpecsInner(skel_ipolicy, None, exp_std1, |
|
1422 |
False, fill_all) |
|
1423 |
self._TestFullISpecsInner(skel_ipolicy, exp_minmax1, None, |
|
1424 |
False, fill_all) |
|
1335 | 1425 |
|
1336 | 1426 |
if __name__ == "__main__": |
1337 | 1427 |
testutils.GanetiTestProgram() |
Also available in: Unified diff