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
This commit is contained in:
parent
bb3f40dfb5
commit
664f70383b
@ -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…
Reference in New Issue
Block a user