From d44094173645232ec70dea1a6ac75a7a7882d552 Mon Sep 17 00:00:00 2001 From: Steve Baker Date: Tue, 4 Mar 2014 09:38:08 +1300 Subject: [PATCH] Allow handle_signal to assert which actions are valid This retains the current behaviour for InstanceGroup and Restarter while allowing other resources to apply different policies about what actions are allowed when a signal is received. This is needed by SoftwareDeployment, which can legitimately receive signals during SUSPEND and DELETE. Change-Id: I6f694451669b6c9b60b9fbd3ad77d0fc111bbb5a Closes-Bug: #1286920 --- heat/engine/resource.py | 4 ---- heat/engine/resources/autoscaling.py | 4 ++++ heat/engine/resources/instance.py | 4 ++++ heat/tests/generic_resource.py | 4 ++++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/heat/engine/resource.py b/heat/engine/resource.py index 0edeb887c..cbfd221a2 100644 --- a/heat/engine/resource.py +++ b/heat/engine/resource.py @@ -885,10 +885,6 @@ class Resource(object): return 'Unknown' try: - if self.action in (self.SUSPEND, self.DELETE): - msg = _('Cannot signal resource during %s') % self.action - raise Exception(msg) - if not callable(getattr(self, 'handle_signal', None)): msg = (_('Resource %s is not able to receive a signal') % str(self)) diff --git a/heat/engine/resources/autoscaling.py b/heat/engine/resources/autoscaling.py index bcc6a4112..386d69b47 100644 --- a/heat/engine/resources/autoscaling.py +++ b/heat/engine/resources/autoscaling.py @@ -943,6 +943,10 @@ class ScalingPolicy(signal_responder.SignalResponder, CooldownMixin): self.context) 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'...'}) diff --git a/heat/engine/resources/instance.py b/heat/engine/resources/instance.py index 999c2d449..61b127df1 100644 --- a/heat/engine/resources/instance.py +++ b/heat/engine/resources/instance.py @@ -67,6 +67,10 @@ 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: diff --git a/heat/tests/generic_resource.py b/heat/tests/generic_resource.py index 9519434f5..dad8f1674 100644 --- a/heat/tests/generic_resource.py +++ b/heat/tests/generic_resource.py @@ -96,6 +96,10 @@ 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) + logger.warning(_('Signaled resource (Type "%(type)s") %(details)s') % {'type': self.type(), 'details': details})