diff --git a/examples/policies/scaling_policy.yaml b/examples/policies/scaling_policy.yaml index 0e0c2114c..3e87a1521 100644 --- a/examples/policies/scaling_policy.yaml +++ b/examples/policies/scaling_policy.yaml @@ -21,3 +21,6 @@ properties: # cluster size to min_size or increase cluster size to max_size # Default False means reject scaling request directly. best_effort: True + + # Number of seconds before allowing the cluster to be resized again. + cooldown: 120 diff --git a/senlin/policies/scaling_policy.py b/senlin/policies/scaling_policy.py index 67a101108..4795830c5 100644 --- a/senlin/policies/scaling_policy.py +++ b/senlin/policies/scaling_policy.py @@ -50,8 +50,10 @@ class ScalingPolicy(base.Policy): _ADJUSTMENT_KEYS = ( ADJUSTMENT_TYPE, ADJUSTMENT_NUMBER, MIN_STEP, BEST_EFFORT, + COOLDOWN, ) = ( 'type', 'number', 'min_step', 'best_effort', + 'cooldown', ) properties_schema = { @@ -88,6 +90,12 @@ class ScalingPolicy(base.Policy): 'cluster will break the size limitation'), default=False, ), + COOLDOWN: schema.Integer( + _('Number of seconds to hold the cluster for cool-down ' + 'before allowing cluster to be resized again.'), + default=0, + ), + } ), } @@ -103,6 +111,7 @@ class ScalingPolicy(base.Policy): self.adjustment_number = adjustment[self.ADJUSTMENT_NUMBER] self.adjustment_min_step = adjustment[self.MIN_STEP] self.best_effort = adjustment[self.BEST_EFFORT] + self.cooldown = adjustment[self.COOLDOWN] def _calculate_adjustment_count(self, current_size): '''Calculate adjustment count based on current_size''' diff --git a/senlin/tests/unit/policies/test_scaling_policy.py b/senlin/tests/unit/policies/test_scaling_policy.py index 3b89d3145..aa485f686 100644 --- a/senlin/tests/unit/policies/test_scaling_policy.py +++ b/senlin/tests/unit/policies/test_scaling_policy.py @@ -38,6 +38,7 @@ class TestScalingPolicy(base.SenlinTestCase): 'number': 1, 'min_step': 1, 'best_effort': False, + 'cooldown': 3, } } } @@ -109,6 +110,7 @@ class TestScalingPolicy(base.SenlinTestCase): self.assertEqual(adjustment['number'], policy.adjustment_number) self.assertEqual(adjustment['min_step'], policy.adjustment_min_step) self.assertEqual(adjustment['best_effort'], policy.best_effort) + self.assertEqual(adjustment['cooldown'], policy.cooldown) def test_policy_init_default_value(self): self.spec['properties']['adjustment'] = {} @@ -121,6 +123,7 @@ class TestScalingPolicy(base.SenlinTestCase): self.assertEqual(1, policy.adjustment_number) self.assertEqual(1, policy.adjustment_min_step) self.assertFalse(policy.best_effort) + self.assertEqual(0, policy.cooldown) def test_calculate_adjustment_count(self): adjustment = self.spec['properties']['adjustment']