Add new exception for invalid template ref
Hopefully is clearer than a KeyError. Change-Id: Ib387825396ab0286df00aaff3b1b539cd7fc9a77 Fixes: bug #1178011
This commit is contained in:
parent
61090f485e
commit
54225d05d5
|
@ -1,4 +1,4 @@
|
||||||
# vim: tabstop = 4 shiftwidth=4 softtabstop=4
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||||
|
|
||||||
# Copyright 2010 United States Government as represented by the
|
# Copyright 2010 United States Government as represented by the
|
||||||
# Administrator of the National Aeronautics and Space Administration.
|
# Administrator of the National Aeronautics and Space Administration.
|
||||||
|
@ -254,6 +254,7 @@ def map_remote_error(ex):
|
||||||
'WatchRuleNotFound',
|
'WatchRuleNotFound',
|
||||||
'StackExists',
|
'StackExists',
|
||||||
'StackValidationFailed',
|
'StackValidationFailed',
|
||||||
|
'InvalidTemplateReference',
|
||||||
)
|
)
|
||||||
denied_errors = ('Forbidden', 'NotAuthorized')
|
denied_errors = ('Forbidden', 'NotAuthorized')
|
||||||
|
|
||||||
|
|
|
@ -97,6 +97,7 @@ def remote_error(ex):
|
||||||
'InvalidTenant': exc.HTTPForbidden,
|
'InvalidTenant': exc.HTTPForbidden,
|
||||||
'StackExists': exc.HTTPConflict,
|
'StackExists': exc.HTTPConflict,
|
||||||
'StackValidationFailed': exc.HTTPBadRequest,
|
'StackValidationFailed': exc.HTTPBadRequest,
|
||||||
|
'InvalidTemplateReference': exc.HTTPBadRequest,
|
||||||
}
|
}
|
||||||
|
|
||||||
Exc = error_map.get(ex.exc_type, exc.HTTPInternalServerError)
|
Exc = error_map.get(ex.exc_type, exc.HTTPInternalServerError)
|
||||||
|
|
|
@ -196,6 +196,11 @@ class InvalidTemplateAttribute(OpenstackException):
|
||||||
" is incorrect.")
|
" is incorrect.")
|
||||||
|
|
||||||
|
|
||||||
|
class InvalidTemplateReference(OpenstackException):
|
||||||
|
message = _("The specified reference (%(resource)s %(key)s)"
|
||||||
|
" is incorrect.")
|
||||||
|
|
||||||
|
|
||||||
class UserKeyPairMissing(OpenstackException):
|
class UserKeyPairMissing(OpenstackException):
|
||||||
message = _("The Key (%(key_name)s) could not be found.")
|
message = _("The Key (%(key_name)s) could not be found.")
|
||||||
|
|
||||||
|
|
|
@ -262,21 +262,26 @@ class Resource(object):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return '%s "%s"' % (self.__class__.__name__, self.name)
|
return '%s "%s"' % (self.__class__.__name__, self.name)
|
||||||
|
|
||||||
def _add_dependencies(self, deps, fragment):
|
def _add_dependencies(self, deps, head, fragment):
|
||||||
if isinstance(fragment, dict):
|
if isinstance(fragment, dict):
|
||||||
for key, value in fragment.items():
|
for key, value in fragment.items():
|
||||||
if key in ('DependsOn', 'Ref'):
|
if key in ('DependsOn', 'Ref'):
|
||||||
target = self.stack.resources[value]
|
try:
|
||||||
|
target = self.stack.resources[value]
|
||||||
|
except KeyError:
|
||||||
|
raise exception.InvalidTemplateReference(
|
||||||
|
resource=value,
|
||||||
|
key=head)
|
||||||
if key == 'DependsOn' or target.strict_dependency:
|
if key == 'DependsOn' or target.strict_dependency:
|
||||||
deps += (self, target)
|
deps += (self, target)
|
||||||
elif key != 'Fn::GetAtt':
|
elif key != 'Fn::GetAtt':
|
||||||
self._add_dependencies(deps, value)
|
self._add_dependencies(deps, key, value)
|
||||||
elif isinstance(fragment, list):
|
elif isinstance(fragment, list):
|
||||||
for item in fragment:
|
for item in fragment:
|
||||||
self._add_dependencies(deps, item)
|
self._add_dependencies(deps, head, item)
|
||||||
|
|
||||||
def add_dependencies(self, deps):
|
def add_dependencies(self, deps):
|
||||||
self._add_dependencies(deps, self.t)
|
self._add_dependencies(deps, None, self.t)
|
||||||
deps += (self, None)
|
deps += (self, None)
|
||||||
|
|
||||||
def keystone(self):
|
def keystone(self):
|
||||||
|
|
|
@ -390,10 +390,15 @@ Resources:
|
||||||
self.m.VerifyAll()
|
self.m.VerifyAll()
|
||||||
|
|
||||||
def test_network_interface_error(self):
|
def test_network_interface_error(self):
|
||||||
self.assertRaises(
|
real_exception = self.assertRaises(
|
||||||
KeyError,
|
exception.InvalidTemplateReference,
|
||||||
self.create_stack,
|
self.create_stack,
|
||||||
self.test_template_error)
|
self.test_template_error)
|
||||||
|
expected_exception = exception.InvalidTemplateReference(
|
||||||
|
resource='INVALID-REF-IN-TEMPLATE',
|
||||||
|
key='GroupSet')
|
||||||
|
|
||||||
|
self.assertEquals(str(expected_exception), str(real_exception))
|
||||||
|
|
||||||
|
|
||||||
class InternetGatewayTest(VPCTestBase):
|
class InternetGatewayTest(VPCTestBase):
|
||||||
|
|
Loading…
Reference in New Issue