Add extra check for signal during DELETE or SUSPEND

All resources, which have handle_signal, check condition
if action in DELETE or SUSPEND state. Move this check to
Resource class.

Change-Id: Ifa9e97c19cc35c4b2aa40dbed37296d9d4a38d5b
changes/14/166914/4
Peter Razumovsky 8 years ago
parent bb3f40dfb5
commit 664f70383b
  1. 6
      heat/engine/resource.py
  2. 4
      heat/engine/resources/aws/autoscaling/scaling_policy.py
  3. 4
      heat/engine/resources/openstack/heat/ha_restarter.py
  4. 4
      heat/engine/resources/openstack/heat/scaling_policy.py
  5. 5
      heat/tests/generic_resource.py
  6. 13
      heat/tests/test_resource.py

@ -1104,6 +1104,12 @@ class Resource(object):
to implement the signal, the base-class raise an exception if no
handler is implemented.
'''
if self.action in (self.SUSPEND, self.DELETE):
LOG.exception(_LE('Cannot signal resource '
'during %s'), self.action)
ex = Exception(_('Cannot signal resource during %s') % self.action)
raise exception.ResourceFailure(ex, self)
def get_string_details():
if details is None:
return 'No signal details provided'

@ -98,10 +98,6 @@ class AWSScalingPolicy(signal_responder.SignalResponder,
return self.properties[self.ADJUSTMENT_TYPE]
def handle_signal(self, details=None):
if self.action in (self.SUSPEND, self.DELETE):
msg = _('Cannot signal resource during %s') % self.action
raise Exception(msg)
# ceilometer sends details like this:
# {u'alarm_id': ID, u'previous': u'ok', u'current': u'alarm',
# u'reason': u'...'})

@ -71,10 +71,6 @@ class Restarter(signal_responder.SignalResponder):
self.resource_id_set(self._get_user_id())
def handle_signal(self, details=None):
if self.action in (self.SUSPEND, self.DELETE):
msg = _('Cannot signal resource during %s') % self.action
raise Exception(msg)
if details is None:
alarm_state = 'alarm'
else:

@ -107,10 +107,6 @@ class AutoScalingPolicy(signal_responder.SignalResponder,
return ''.join([t.capitalize() for t in adjustment_type.split('_')])
def handle_signal(self, details=None):
if self.action in (self.SUSPEND, self.DELETE):
msg = _('Cannot signal resource during %s') % self.action
raise Exception(msg)
# ceilometer sends details like this:
# {u'alarm_id': ID, u'previous': u'ok', u'current': u'alarm',
# u'reason': u'...'})

@ -14,7 +14,6 @@
from oslo_log import log as logging
import six
from heat.common.i18n import _
from heat.common.i18n import _LW
from heat.engine import attributes
from heat.engine import constraints
@ -139,10 +138,6 @@ class SignalResource(signal_responder.SignalResponder):
self.resource_id_set(self._get_user_id())
def handle_signal(self, details=None):
if self.action in (self.SUSPEND, self.DELETE):
msg = _('Cannot signal resource during %s') % self.action
raise Exception(msg)
LOG.warn(_LW('Signaled resource (Type "%(type)s") %(details)s'),
{'type': self.type(), 'details': details})

@ -123,6 +123,19 @@ class ResourceTest(common.HeatTestCase):
self.assertEqual((res.INIT, res.COMPLETE), res.state)
self.assertEqual('', res.status_reason)
def test_signal_wrong_action_state(self):
snippet = rsrc_defn.ResourceDefinition('res',
'GenericResourceType')
res = resource.Resource('res', snippet, self.stack)
actions = [res.SUSPEND, res.DELETE]
for action in actions:
for status in res.STATUSES:
res.state_set(action, status)
ex = self.assertRaises(exception.ResourceFailure,
res.signal)
self.assertEqual('Exception: Cannot signal resource during '
'%s' % action, six.text_type(ex))
def test_resource_str_repr_stack_id_resource_id(self):
tmpl = rsrc_defn.ResourceDefinition('test_res_str_repr', 'Foo')
res = generic_rsrc.GenericResource('test_res_str_repr', tmpl,

Loading…
Cancel
Save