Don't check alarm state when signaled

Scaling policies(alarm_url) are normally expected to be
used with 'alarm_actions' of Alarm resource plugins by
the template author. However, we should not check for the
alarm state before proceeding on handling the signal.
This would provide flexibility to use these policies with
other alarm actions like 'insufficient_data_actions',
if required.

Change-Id: I733f986c9ac151f76aa997d26e9b9cf8afd9f6c9
Closes-Bug: #1598044
This commit is contained in:
rabi 2016-07-07 09:46:32 +05:30 committed by Rabi Mishra
parent 7538c6d888
commit fe4f250826
3 changed files with 12 additions and 36 deletions

View File

@ -143,14 +143,19 @@ class AutoScalingPolicy(signal_responder.SignalResponder,
self.context)
def handle_signal(self, details=None):
# ceilometer sends details like this:
# {u'alarm_id': ID, u'previous': u'ok', u'current': u'alarm',
# u'reason': u'...'})
# in this policy we currently assume that this gets called
# only when there is an alarm. But the template writer can
# put the policy in all the alarm notifiers (nodata, and ok).
# Template author can use scaling policy with any of the actions
# of an alarm (i.e alarm_actions, insufficient_data_actions) and
# it would be actioned irrespective of the alarm state. It's
# fair to assume that the alarm state would be the appropriate one.
# The responsibility of using a scaling policy with desired actions
# lies with the template author, though this is normally expected to
# be used with 'alarm_actions'.
#
# our watchrule has upper case states so lower() them all.
# We also assume that the alarm state is 'alarm' when 'details' is None
# or no 'current'/'state' key in 'details'. Watchrule has upper case
# states, so we lower() them. This is only used for logging the alarm
# state.
if details is None:
alarm_state = 'alarm'
else:
@ -160,9 +165,6 @@ class AutoScalingPolicy(signal_responder.SignalResponder,
LOG.info(_LI('Alarm %(name)s, new state %(state)s'),
{'name': self.name, 'state': alarm_state})
if alarm_state != 'alarm':
raise exception.NoActionRequired()
asgn_id = self.properties[self.AUTO_SCALING_GROUP_NAME]
group = self.stack.resource_by_refid(asgn_id)

View File

@ -106,19 +106,6 @@ class TestAutoScalingPolicy(common.HeatTestCase):
mock_fin_scaling.assert_called_once_with('change_in_capacity : 1',
size_changed=True)
def test_scaling_policy_not_alarm_state(self):
"""If the details don't have 'alarm' then don't progress."""
t = template_format.parse(as_template)
stack = utils.parse_stack(t, params=as_params)
pol = self.create_scaling_policy(t, stack, 'my-policy')
test = {'current': 'not_an_alarm'}
with mock.patch.object(pol, '_is_scaling_allowed',
side_effect=AssertionError()) as dont_call:
self.assertRaises(exception.NoActionRequired,
pol.handle_signal, details=test)
self.assertEqual([], dont_call.call_args_list)
def test_scaling_policy_cooldown_toosoon(self):
"""If _is_scaling_allowed() returns False don't progress."""
t = template_format.parse(as_template)

View File

@ -112,19 +112,6 @@ class TestAutoScalingPolicy(common.HeatTestCase):
mock_fin_scaling.assert_called_once_with('ChangeInCapacity : 1',
size_changed=True)
def test_scaling_policy_not_alarm_state(self):
"""If the details don't have 'alarm' then don't progress."""
t = template_format.parse(as_template)
stack = utils.parse_stack(t, params=as_params)
pol = self.create_scaling_policy(t, stack, 'WebServerScaleUpPolicy')
test = {'current': 'not_an_alarm'}
with mock.patch.object(pol, '_is_scaling_allowed',
side_effect=AssertionError()) as dont_call:
self.assertRaises(exception.NoActionRequired,
pol.handle_signal, details=test)
self.assertEqual([], dont_call.call_args_list)
def test_scaling_policy_cooldown_toosoon(self):
"""If _is_scaling_allowed() returns False don't progress."""
t = template_format.parse(as_template)