Raise exception if asg in cooldown

The signal() method of resource class doesn't add
event to event list if the signal can not be performed i.e.
handle_signal raise exception. So it is needed to raise exception
if asg in cooldown. Otherwise the event will be added to event list
in SIGNAL_COMPLETE state, but no action will be performed.

Change-Id: Iebdb6c9231aef90d11428ca6beed150cfba2715f
Closes-Bug: #1486945
This commit is contained in:
Oleksii Chuprykov 2015-08-25 16:03:01 +03:00
parent ddc28808d8
commit a976c63e4e
6 changed files with 25 additions and 5 deletions

View File

@ -302,7 +302,7 @@ class AutoScalingGroup(instgrp.InstanceGroup, cooldown.CooldownMixin):
self.adjust(current_capacity, adjustment_type=EXACT_CAPACITY)
def adjust(self, adjustment, adjustment_type=CHANGE_IN_CAPACITY,
min_adjustment_step=None):
min_adjustment_step=None, signal=False):
"""
Adjust the size of the scaling group if the cooldown permits.
"""
@ -311,7 +311,10 @@ class AutoScalingGroup(instgrp.InstanceGroup, cooldown.CooldownMixin):
"cooldown %(cooldown)s"),
{'name': self.name,
'cooldown': self.properties[self.COOLDOWN]})
return
if signal:
raise resource.NoActionRequired()
else:
return
capacity = grouputils.get_size(self)
lower = self.properties[self.MIN_SIZE]

View File

@ -185,7 +185,8 @@ class AutoScalingPolicy(signal_responder.SignalResponder,
adjustment_type = self._get_adjustement_type()
group.adjust(self.properties[self.SCALING_ADJUSTMENT],
adjustment_type,
self.properties[self.MIN_ADJUSTMENT_STEP])
self.properties[self.MIN_ADJUSTMENT_STEP],
signal=True)
finally:
self._cooldown_timestamp("%s : %s" % (

View File

@ -19,6 +19,7 @@ from heat.common import exception
from heat.common import grouputils
from heat.common import template_format
from heat.engine import function
from heat.engine import resource
from heat.engine import rsrc_defn
from heat.tests.autoscaling import inline_templates
from heat.tests import common
@ -121,6 +122,12 @@ class TestGroupAdjust(common.HeatTestCase):
self.group.adjust(1)
self.assertEqual([], dont_call.call_args_list)
def test_scaling_policy_cooldown_toosoon_with_signal(self):
with mock.patch.object(self.group, '_cooldown_inprogress',
return_value=True):
self.assertRaises(resource.NoActionRequired, self.group.adjust, 1,
signal=True)
def test_scaling_same_capacity(self):
"""Alway resize even if the capacity is the same."""
self.patchobject(grouputils, 'get_size', return_value=3)

View File

@ -116,7 +116,8 @@ class TestAutoScalingPolicy(common.HeatTestCase):
return_value=False) as mock_cip:
pol.handle_signal(details=test)
mock_cip.assert_called_once_with()
group.adjust.assert_called_once_with(1, 'ChangeInCapacity', None)
group.adjust.assert_called_once_with(1, 'ChangeInCapacity', None,
signal=True)
class TestCooldownMixin(common.HeatTestCase):

View File

@ -21,6 +21,7 @@ from heat.common import grouputils
from heat.common import template_format
from heat.engine.clients.os import nova
from heat.engine import function
from heat.engine import resource
from heat.engine import rsrc_defn
from heat.engine import scheduler
from heat.tests.autoscaling import inline_templates
@ -308,6 +309,12 @@ class TestGroupAdjust(common.HeatTestCase):
self.group.adjust(1)
self.assertEqual([], dont_call.call_args_list)
def test_scaling_policy_cooldown_toosoon_with_signal(self):
with mock.patch.object(self.group, '_cooldown_inprogress',
return_value=True):
self.assertRaises(resource.NoActionRequired, self.group.adjust, 1,
signal=True)
def test_scaling_same_capacity(self):
"""Alway resize even if the capacity is the same."""
self.patchobject(grouputils, 'get_size', return_value=3)

View File

@ -121,7 +121,8 @@ class TestAutoScalingPolicy(common.HeatTestCase):
return_value=False) as mock_cip:
pol.handle_signal(details=test)
mock_cip.assert_called_once_with()
group.adjust.assert_called_once_with(1, 'ChangeInCapacity', None)
group.adjust.assert_called_once_with(1, 'ChangeInCapacity', None,
signal=True)
class TestCooldownMixin(common.HeatTestCase):