Enforce max_nodes_per_cluster in check_size_params

Change-Id: I04c2c2784c736f62aa011c8054481c75b04e780e
Related-bug: #1631823
This commit is contained in:
lvdongbing 2016-10-10 03:26:27 -04:00
parent c0e8ca7c3b
commit ba178cef36
2 changed files with 26 additions and 0 deletions

View File

@ -17,6 +17,7 @@ Utilities for scaling actions and related policies.
import math
import random
from oslo_config import cfg
from oslo_log import log as logging
from senlin.common import consts
@ -109,8 +110,14 @@ def check_size_params(cluster=None, desired=None, min_size=None, max_size=None,
the checking.
"""
max_nodes_per_cluster = cfg.CONF.max_nodes_per_cluster
if desired is not None:
# recalculate/validate desired based on strict setting
if desired > max_nodes_per_cluster:
v = {'d': desired, 'm': max_nodes_per_cluster}
return _("The target capacity (%(d)s) is greater than the "
"maximum number of nodes allowed per cluster "
"(%(m)s).") % v
if (min_size is not None and desired < min_size):
v = {'d': desired, 'm': min_size}
return _("The target capacity (%(d)s) is less than "
@ -154,6 +161,11 @@ def check_size_params(cluster=None, desired=None, min_size=None, max_size=None,
"current desired_capacity (%(d)s) of the cluster.") % v
if max_size is not None:
if max_size > max_nodes_per_cluster:
v = {'m': max_size, 'mc': max_nodes_per_cluster}
return _("The specified max_size (%(m)s) is greater than the "
"maximum number of nodes allowed per cluster "
"(%(mc)s).") % v
if (min_size is None and cluster is not None and
max_size >= 0 and max_size < cluster.min_size):
v = {'m': max_size, 'n': cluster.min_size}

View File

@ -12,6 +12,8 @@
import mock
from oslo_config import cfg
from senlin.common import consts
from senlin.common.i18n import _
from senlin.common import scaleutils as su
@ -331,6 +333,14 @@ class CheckSizeParamsTest(base.SenlinTestCase):
desired=None, min_size=None, max_size=14, strict=True,
result='The specified max_size (14) is less than the current '
'desired_capacity (15) of the cluster.')),
('101_x_x_x', dict(
desired=101, min_size=None, max_size=None, strict=True,
result='The target capacity (101) is greater than the '
'maximum number of nodes allowed per cluster (100).')),
('x_x_101_x', dict(
desired=None, min_size=None, max_size=101, strict=True,
result='The specified max_size (101) is greater than the '
'maximum number of nodes allowed per cluster (100).')),
# The following are okay cases
('5_x10_x_x', dict(
desired=5, min_size=None, max_size=None, strict=False,
@ -382,6 +392,10 @@ class CheckSizeParamsTest(base.SenlinTestCase):
result=None)),
]
def setUp(self):
super(CheckSizeParamsTest, self).setUp()
cfg.CONF.set_override('max_nodes_per_cluster', 100, enforce_type=True)
def test_check_size_params(self):
cluster = mock.Mock()
cluster.min_size = 10