diff --git a/heat/api/aws/exception.py b/heat/api/aws/exception.py index 727e104e83..14c8258af0 100644 --- a/heat/api/aws/exception.py +++ b/heat/api/aws/exception.py @@ -251,6 +251,7 @@ def map_remote_error(ex): 'ResourceNotFound', 'ResourceNotAvailable', 'PhysicalResourceNotFound', + 'WatchRuleNotFound', 'StackExists', ) diff --git a/heat/common/exception.py b/heat/common/exception.py index 0b6e7b18b4..2d9aceeb3d 100644 --- a/heat/common/exception.py +++ b/heat/common/exception.py @@ -228,3 +228,7 @@ class ResourceNotAvailable(OpenstackException): class PhysicalResourceNotFound(OpenstackException): message = _("The Resource (%(resource_id)s) could not be found.") + + +class WatchRuleNotFound(OpenstackException): + message = _("The Watch Rule (%(watch_name)s) could not be found.") diff --git a/heat/engine/watchrule.py b/heat/engine/watchrule.py index 8d91e9312f..c29fa8f75e 100644 --- a/heat/engine/watchrule.py +++ b/heat/engine/watchrule.py @@ -15,6 +15,7 @@ import datetime +from heat.common import exception from heat.openstack.common import log as logging from heat.openstack.common import timeutils from heat.engine import timestamp @@ -70,7 +71,7 @@ class WatchRule(object): logger.warn('WatchRule.load (%s) db error %s' % (watch_name, str(ex))) if watch is None: - raise AttributeError('Unknown watch name %s' % watch_name) + raise exception.WatchRuleNotFound(watch_name=watch_name) else: return cls(context=context, watch_name=watch.name, @@ -251,8 +252,8 @@ class WatchRule(object): if not self.rule['MetricName'] in data: logger.warn('new data has incorrect metric:%s' % (self.rule['MetricName'])) - raise AttributeError('MetricName %s missing' % - self.rule['MetricName']) + raise ValueError('MetricName %s missing' % + self.rule['MetricName']) watch_data = { 'data': data, @@ -269,7 +270,7 @@ class WatchRule(object): ''' if state not in self.WATCH_STATES: - raise AttributeError('Unknown watch state %s' % state) + raise ValueError('Unknown watch state %s' % state) if state != self.state: if self.rule_action(state): diff --git a/heat/tests/test_engine_service.py b/heat/tests/test_engine_service.py index ac235d127f..bd544a51d0 100644 --- a/heat/tests/test_engine_service.py +++ b/heat/tests/test_engine_service.py @@ -720,8 +720,7 @@ class stackServiceTest(unittest.TestCase): result = self.man.show_watch(self.ctx, watch_name="HttpFailureAlarm") self.assertEqual(1, len(result)) - # watch_name="nonexistent" should raise an AttributeError - self.assertRaises(AttributeError, + self.assertRaises(exception.WatchRuleNotFound, self.man.show_watch, self.ctx, watch_name="nonexistent") @@ -834,7 +833,7 @@ class stackServiceTest(unittest.TestCase): self.assertNotEqual(db_ret, None) for state in ["HGJHGJHG", "1234", "!\*(&%"]: - self.assertRaises(AttributeError, + self.assertRaises(ValueError, self.man.set_watch_state, self.ctx, watch_name="OverrideAlarm2", state=state) @@ -843,8 +842,7 @@ class stackServiceTest(unittest.TestCase): db_api.watch_rule_delete(self.ctx, "OverrideAlarm2") def test_set_watch_state_noexist(self): - # watch_name="nonexistent" should raise an AttributeError state = watchrule.WatchRule.ALARM # State valid - self.assertRaises(AttributeError, + self.assertRaises(exception.WatchRuleNotFound, self.man.set_watch_state, self.ctx, watch_name="nonexistent", state=state)