Should raise error if hook is invalid
If hooks of resource breakpoint are invalid, should raise error message to user, and then user will know what happen and why no pause on updation/creation. Change-Id: I53822ed96fafdd373d20c45cacb5e33ba0306292 Closes-Bug: #1452636
This commit is contained in:
@@ -333,6 +333,10 @@ class InvalidResourceType(HeatException):
|
|||||||
msg_fmt = _("%(message)s")
|
msg_fmt = _("%(message)s")
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidBreakPointHook(HeatException):
|
||||||
|
msg_fmt = _("%(message)s")
|
||||||
|
|
||||||
|
|
||||||
class ResourceNotAvailable(HeatException):
|
class ResourceNotAvailable(HeatException):
|
||||||
msg_fmt = _("The Resource (%(resource_name)s) is not available.")
|
msg_fmt = _("The Resource (%(resource_name)s) is not available.")
|
||||||
|
|
||||||
|
|||||||
@@ -43,14 +43,20 @@ def valid_hook_type(hook):
|
|||||||
|
|
||||||
|
|
||||||
def is_hook_definition(key, value):
|
def is_hook_definition(key, value):
|
||||||
|
is_valid_hook = False
|
||||||
if key == 'hooks':
|
if key == 'hooks':
|
||||||
if isinstance(value, six.string_types):
|
if isinstance(value, six.string_types):
|
||||||
return valid_hook_type(value)
|
is_valid_hook = valid_hook_type(value)
|
||||||
elif isinstance(value, collections.Sequence):
|
elif isinstance(value, collections.Sequence):
|
||||||
return all(valid_hook_type(hook) for hook in value)
|
is_valid_hook = all(valid_hook_type(hook) for hook in value)
|
||||||
else:
|
|
||||||
return False
|
if not is_valid_hook:
|
||||||
return False
|
msg = (_('Invalid hook type "%(value)s" for resource '
|
||||||
|
'breakpoint, acceptable hook types are: %(types)s') %
|
||||||
|
{'value': value, 'types': HOOK_TYPES})
|
||||||
|
raise exception.InvalidBreakPointHook(message=msg)
|
||||||
|
|
||||||
|
return is_valid_hook
|
||||||
|
|
||||||
|
|
||||||
class ResourceInfo(object):
|
class ResourceInfo(object):
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ from oslo_config import cfg
|
|||||||
import six
|
import six
|
||||||
|
|
||||||
from heat.common import environment_format
|
from heat.common import environment_format
|
||||||
|
from heat.common import exception
|
||||||
from heat.engine import environment
|
from heat.engine import environment
|
||||||
from heat.engine import resources
|
from heat.engine import resources
|
||||||
from heat.engine.resources.aws.ec2 import instance
|
from heat.engine.resources.aws.ec2 import instance
|
||||||
@@ -747,6 +748,22 @@ class ResourceRegistryTest(common.HeatTestCase):
|
|||||||
self.assertEqual('pre-create',
|
self.assertEqual('pre-create',
|
||||||
resources['nested']['res']['hooks'])
|
resources['nested']['res']['hooks'])
|
||||||
|
|
||||||
|
def test_load_registry_invalid_hook_type(self):
|
||||||
|
resources = {
|
||||||
|
u'resources': {
|
||||||
|
u'a': {
|
||||||
|
u'hooks': 'invalid-type',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
registry = environment.ResourceRegistry(None, {})
|
||||||
|
msg = ('Invalid hook type "invalid-type" for resource breakpoint, '
|
||||||
|
'acceptable hook types are: (\'pre-create\', \'pre-update\')')
|
||||||
|
ex = self.assertRaises(exception.InvalidBreakPointHook,
|
||||||
|
registry.load, {'resources': resources})
|
||||||
|
self.assertEqual(msg, six.text_type(ex))
|
||||||
|
|
||||||
|
|
||||||
class HookMatchTest(common.HeatTestCase):
|
class HookMatchTest(common.HeatTestCase):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user