RPC API: Add a WatchRuleNotFound exception
Change-Id: I7abda2fb745b84925edf685b7fced3541d94a8db Signed-off-by: Zane Bitter <zbitter@redhat.com>
This commit is contained in:
parent
805416ebb1
commit
0f902d50e2
|
@ -251,6 +251,7 @@ def map_remote_error(ex):
|
|||
'ResourceNotFound',
|
||||
'ResourceNotAvailable',
|
||||
'PhysicalResourceNotFound',
|
||||
'WatchRuleNotFound',
|
||||
'StackExists',
|
||||
)
|
||||
|
||||
|
|
|
@ -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.")
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue