Merge "Allow handle_signal to assert which actions are valid"

This commit is contained in:
Jenkins 2014-03-10 07:25:00 +00:00 committed by Gerrit Code Review
commit c186fa7d28
4 changed files with 12 additions and 4 deletions

View File

@ -884,10 +884,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))

View File

@ -948,6 +948,10 @@ class ScalingPolicy(signal_responder.SignalResponder, CooldownMixin):
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'...'})

View File

@ -66,6 +66,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:

View File

@ -112,6 +112,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})