Move Resource exceptions to common module (5)

It is convenient to have all exceptions in exception module.
Also it is reduces namespace cluttering of resource module and decreases
the number of dependencies in other modules (we do not need to import resource
in some cases for now).
NoActionRequired exception is moved in this patch.

Change-Id: Idf9bfaa8a51dd6ea679a0148c712529e3c3b072a
This commit is contained in:
Oleksii Chuprykov 2015-09-02 18:11:39 +03:00
parent f1b2d9add5
commit 5120f096d7
9 changed files with 15 additions and 20 deletions

View File

@ -519,3 +519,7 @@ class SIGHUPInterrupt(HeatException):
class ResourceTypeUnavailable(HeatException):
msg_fmt = _("Service %(service_name)s does not have required endpoint in "
"service catalog for the resource type %(resource_type)s")
class NoActionRequired(Exception):
pass

View File

@ -57,10 +57,6 @@ def _register_class(resource_type, resource_class):
resources.global_env().register_class(resource_type, resource_class)
class NoActionRequired(Exception):
pass
@six.python_2_unicode_compatible
class Resource(object):
ACTIONS = (
@ -1533,7 +1529,7 @@ class Resource(object):
else:
reason_string = get_string_details()
self._add_event('SIGNAL', self.status, reason_string)
except NoActionRequired:
except exception.NoActionRequired:
# Don't log an event as it just spams the user.
pass
except Exception as ex:

View File

@ -312,7 +312,7 @@ class AutoScalingGroup(instgrp.InstanceGroup, cooldown.CooldownMixin):
{'name': self.name,
'cooldown': self.properties[self.COOLDOWN]})
if signal:
raise resource.NoActionRequired()
raise exception.NoActionRequired()
else:
return

View File

@ -160,13 +160,13 @@ class AutoScalingPolicy(signal_responder.SignalResponder,
{'name': self.name, 'state': alarm_state})
if alarm_state != 'alarm':
raise resource.NoActionRequired()
raise exception.NoActionRequired()
if self._cooldown_inprogress():
LOG.info(_LI("%(name)s NOT performing scaling action, "
"cooldown %(cooldown)s"),
{'name': self.name,
'cooldown': self.properties[self.COOLDOWN]})
raise resource.NoActionRequired()
raise exception.NoActionRequired()
asgn_id = self.properties[self.AUTO_SCALING_GROUP_NAME]
group = self.stack.resource_by_refid(asgn_id)

View File

@ -19,7 +19,6 @@ from heat.common import exception
from heat.common import grouputils
from heat.common import template_format
from heat.engine import function
from heat.engine import resource
from heat.engine import rsrc_defn
from heat.tests.autoscaling import inline_templates
from heat.tests import common
@ -125,7 +124,7 @@ class TestGroupAdjust(common.HeatTestCase):
def test_scaling_policy_cooldown_toosoon_with_signal(self):
with mock.patch.object(self.group, '_cooldown_inprogress',
return_value=True):
self.assertRaises(resource.NoActionRequired, self.group.adjust, 1,
self.assertRaises(exception.NoActionRequired, self.group.adjust, 1,
signal=True)
def test_scaling_same_capacity(self):

View File

@ -19,7 +19,6 @@ import six
from heat.common import exception
from heat.common import template_format
from heat.engine import resource
from heat.engine import scheduler
from heat.tests.autoscaling import inline_templates
from heat.tests import common
@ -84,7 +83,7 @@ class TestAutoScalingPolicy(common.HeatTestCase):
test = {'current': 'not_an_alarm'}
with mock.patch.object(pol, '_cooldown_inprogress',
side_effect=AssertionError()) as dont_call:
self.assertRaises(resource.NoActionRequired,
self.assertRaises(exception.NoActionRequired,
pol.handle_signal, details=test)
self.assertEqual([], dont_call.call_args_list)
@ -99,7 +98,7 @@ class TestAutoScalingPolicy(common.HeatTestCase):
side_effect=AssertionError) as dont_call:
with mock.patch.object(pol, '_cooldown_inprogress',
return_value=True) as mock_cip:
self.assertRaises(resource.NoActionRequired,
self.assertRaises(exception.NoActionRequired,
pol.handle_signal, details=test)
mock_cip.assert_called_once_with()
self.assertEqual([], dont_call.call_args_list)

View File

@ -21,7 +21,6 @@ from heat.common import grouputils
from heat.common import template_format
from heat.engine.clients.os import nova
from heat.engine import function
from heat.engine import resource
from heat.engine import rsrc_defn
from heat.engine import scheduler
from heat.tests.autoscaling import inline_templates
@ -312,7 +311,7 @@ class TestGroupAdjust(common.HeatTestCase):
def test_scaling_policy_cooldown_toosoon_with_signal(self):
with mock.patch.object(self.group, '_cooldown_inprogress',
return_value=True):
self.assertRaises(resource.NoActionRequired, self.group.adjust, 1,
self.assertRaises(exception.NoActionRequired, self.group.adjust, 1,
signal=True)
def test_scaling_same_capacity(self):

View File

@ -19,7 +19,6 @@ import six
from heat.common import exception
from heat.common import template_format
from heat.engine import resource
from heat.engine import scheduler
from heat.tests.autoscaling import inline_templates
from heat.tests import common
@ -89,7 +88,7 @@ class TestAutoScalingPolicy(common.HeatTestCase):
test = {'current': 'not_an_alarm'}
with mock.patch.object(pol, '_cooldown_inprogress',
side_effect=AssertionError()) as dont_call:
self.assertRaises(resource.NoActionRequired,
self.assertRaises(exception.NoActionRequired,
pol.handle_signal, details=test)
self.assertEqual([], dont_call.call_args_list)
@ -104,7 +103,7 @@ class TestAutoScalingPolicy(common.HeatTestCase):
side_effect=AssertionError) as dont_call:
with mock.patch.object(pol, '_cooldown_inprogress',
return_value=True) as mock_cip:
self.assertRaises(resource.NoActionRequired,
self.assertRaises(exception.NoActionRequired,
pol.handle_signal, details=test)
mock_cip.assert_called_once_with()
self.assertEqual([], dont_call.call_args_list)

View File

@ -21,7 +21,6 @@ from six.moves.urllib import parse as urlparse
from heat.common import exception
from heat.common import template_format
from heat.engine import resource
from heat.engine import scheduler
from heat.engine import stack as parser
from heat.engine import template
@ -521,7 +520,7 @@ class SignalTest(common.HeatTestCase):
self.m.StubOutWithMock(generic_resource.SignalResource,
'handle_signal')
generic_resource.SignalResource.handle_signal(test_d).AndRaise(
resource.NoActionRequired())
exception.NoActionRequired())
# _add_event should not be called.
self.m.StubOutWithMock(generic_resource.SignalResource,