Merge "Set max_size to cfg.CONF.max_nodes_per_cluster if -1."

This commit is contained in:
Jenkins 2016-12-15 02:11:22 +00:00 committed by Gerrit Code Review
commit 9f2a2ca8c2
3 changed files with 40 additions and 3 deletions

View File

@ -10,6 +10,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslo_config import cfg
from senlin.common import constraints
from senlin.common import consts
from senlin.common.i18n import _
@ -21,6 +23,9 @@ from senlin.objects import node as no
from senlin.policies import base
CONF = cfg.CONF
class ScalingPolicy(base.Policy):
"""Policy for changing the size of a cluster.
@ -182,6 +187,9 @@ class ScalingPolicy(base.Policy):
# Check size constraints
cluster = co.Cluster.get(action.context, cluster_id)
max_size = cluster.max_size
if max_size == -1:
max_size = cfg.CONF.max_nodes_per_cluster
if action.action == consts.CLUSTER_SCALE_IN:
if self.best_effort:
count = min(count, current - cluster.min_size)
@ -189,7 +197,7 @@ class ScalingPolicy(base.Policy):
strict=not self.best_effort)
else:
if self.best_effort:
count = min(count, cluster.max_size - current)
count = min(count, max_size - current)
result = su.check_size_params(cluster, current + count,
strict=not self.best_effort)

View File

@ -85,7 +85,7 @@ def create_profile(context, profile_id):
return objects.Profile.create(context, values)
def create_cluster(context, cluster_id, profile_id):
def create_cluster(context, cluster_id, profile_id, **kwargs):
values = {
'id': cluster_id,
'profile_id': profile_id,
@ -99,7 +99,7 @@ def create_cluster(context, cluster_id, profile_id):
'user': context.user,
'project': context.project,
}
values.update(kwargs)
return objects.Cluster.create(context, values)

View File

@ -21,6 +21,7 @@ from senlin.tests.unit.common import utils
PROFILE_ID = 'aa5f86b8-e52b-4f2b-828a-4c14c770938d'
CLUSTER_ID = '2c5139a6-24ba-4a6f-bd53-a268f61536de'
CLUSTER_NOMAXSIZE_ID = 'e470c11d-910d-491b-a7c3-93b047a6108d'
class TestScalingPolicy(base.SenlinTestCase):
@ -45,6 +46,9 @@ class TestScalingPolicy(base.SenlinTestCase):
self.profile = utils.create_profile(self.context, PROFILE_ID)
self.cluster = utils.create_cluster(self.context, CLUSTER_ID,
PROFILE_ID)
self.cluster_no_maxsize = utils. \
create_cluster(self.context, CLUSTER_NOMAXSIZE_ID,
PROFILE_ID, max_size=-1)
def _create_nodes(self, count):
NODE_IDS = [
@ -192,6 +196,31 @@ class TestScalingPolicy(base.SenlinTestCase):
}
action.data.update.assert_called_with(pd)
@mock.patch.object(sp.ScalingPolicy, '_calculate_adjustment_count')
@mock.patch.object(no.Node, 'count_by_cluster')
def test_pre_op_pass_check_effort(self, mock_currentcount,
mock_adjustmentcount):
# Cluster with maxsize and best_effert is False
action = mock.Mock()
action.context = self.context
action.action = consts.CLUSTER_SCALE_OUT
action.inputs = {}
mock_adjustmentcount.return_value = 1
mock_currentcount.return_value = 2
policy = sp.ScalingPolicy('test-policy', self.spec)
policy.event = consts.CLUSTER_SCALE_OUT
policy.best_effort = True
policy.pre_op(self.cluster_no_maxsize['id'], action)
pd = {
'creation': {
'count': 1,
},
'reason': 'Scaling request validated.',
'status': pb.CHECK_OK,
}
action.data.update.assert_called_with(pd)
action.store.assert_called_with(self.context)
def test_pre_op_fail_negative_count(self):
self._create_nodes(3)
action = mock.Mock()