Revision 62fed51b test/py/ganeti.objects_unittest.py

b/test/py/ganeti.objects_unittest.py
428 428
    self._AssertIPolicyIsFull(constants.IPOLICY_DEFAULTS)
429 429

  
430 430
  def testCheckISpecSyntax(self):
431
    incomplete_ipolicies = [
432
      {
433
         constants.ISPECS_MINMAX: {},
434
         constants.ISPECS_STD: NotImplemented,
435
         },
436
      {
437
        constants.ISPECS_MINMAX: {
438
          constants.ISPECS_MIN: NotImplemented,
439
          },
440
        constants.ISPECS_STD: NotImplemented,
441
        },
442
      {
443
        constants.ISPECS_MINMAX: {
444
          constants.ISPECS_MAX: NotImplemented,
445
          },
446
        constants.ISPECS_STD: NotImplemented,
447
        },
448
      {
449
        constants.ISPECS_MINMAX: {
450
          constants.ISPECS_MIN: NotImplemented,
451
          constants.ISPECS_MAX: NotImplemented,
452
          },
453
        },
454
      ]
455
    for ipol in incomplete_ipolicies:
456
      self.assertRaises(errors.ConfigurationError,
457
                        objects.InstancePolicy.CheckISpecSyntax,
458
                        ipol, True)
459

  
460
  def testCheckISpecParamSyntax(self):
431 461
    par = "my_parameter"
432 462
    for check_std in [True, False]:
433 463
      # Only one policy limit
434 464
      for key in constants.ISPECS_MINMAX_KEYS:
435 465
        minmax = dict((k, {}) for k in constants.ISPECS_MINMAX_KEYS)
436 466
        minmax[key][par] = 11
437
        objects.InstancePolicy.CheckISpecSyntax(minmax, {}, par, check_std)
467
        objects.InstancePolicy._CheckISpecParamSyntax(minmax, {}, par,
468
                                                      check_std)
438 469
      if check_std:
439 470
        minmax = dict((k, {}) for k in constants.ISPECS_MINMAX_KEYS)
440 471
        stdspec = {par: 11}
441
        objects.InstancePolicy.CheckISpecSyntax(minmax, stdspec, par, check_std)
472
        objects.InstancePolicy._CheckISpecParamSyntax(minmax, stdspec, par,
473
                                                      check_std)
442 474

  
443 475
      # Min and max only
444 476
      good_values = [(11, 11), (11, 40), (0, 0)]
......
446 478
        minmax = dict((k, {}) for k in constants.ISPECS_MINMAX_KEYS)
447 479
        minmax[constants.ISPECS_MIN][par] = mn
448 480
        minmax[constants.ISPECS_MAX][par] = mx
449
        objects.InstancePolicy.CheckISpecSyntax(minmax, {}, par, check_std)
481
        objects.InstancePolicy._CheckISpecParamSyntax(minmax, {}, par,
482
                                                     check_std)
450 483
      minmax = dict((k, {}) for k in constants.ISPECS_MINMAX_KEYS)
451 484
      minmax[constants.ISPECS_MIN][par] = 11
452 485
      minmax[constants.ISPECS_MAX][par] = 5
453 486
      self.assertRaises(errors.ConfigurationError,
454
                        objects.InstancePolicy.CheckISpecSyntax,
487
                        objects.InstancePolicy._CheckISpecParamSyntax,
455 488
                        minmax, {}, par, check_std)
456 489
    # Min, std, max
457 490
    good_values = [
......
465 498
        constants.ISPECS_MAX: {par: mx},
466 499
        }
467 500
      stdspec = {par: st}
468
      objects.InstancePolicy.CheckISpecSyntax(minmax, stdspec, par, True)
501
      objects.InstancePolicy._CheckISpecParamSyntax(minmax, stdspec, par, True)
469 502
    bad_values = [
470 503
      (11, 11,  5),
471 504
      (40, 11, 11),
......
481 514
        }
482 515
      stdspec = {par: st}
483 516
      self.assertRaises(errors.ConfigurationError,
484
                        objects.InstancePolicy.CheckISpecSyntax,
517
                        objects.InstancePolicy._CheckISpecParamSyntax,
485 518
                        minmax, stdspec, par, True)
486 519

  
487 520
  def testCheckDiskTemplates(self):

Also available in: Unified diff