Raise NotFound() when group member does not exist
Raise NotFound() exception with proper message when fetching atrribitutes for a member, that is not in the nested stack. Change-Id: I8969893781439ef5e87ea9f815d7f22e23be3e78 Closes-Bug: #1723315
This commit is contained in:
parent
8b2136451d
commit
48fcaf3fb2
heat
@ -14,6 +14,7 @@
|
||||
import six
|
||||
|
||||
from heat.common import exception
|
||||
from heat.common.i18n import _
|
||||
|
||||
|
||||
def get_size(group, include_failed=False):
|
||||
@ -69,7 +70,7 @@ def get_member_names(group):
|
||||
return [r.name for r in get_members(group)]
|
||||
|
||||
|
||||
def get_resource(stack, resource_name, use_indices, key):
|
||||
def get_resource(stack, resource_name, use_indices, key=None):
|
||||
nested_stack = stack.nested()
|
||||
if not nested_stack:
|
||||
return None
|
||||
@ -79,18 +80,20 @@ def get_resource(stack, resource_name, use_indices, key):
|
||||
else:
|
||||
return nested_stack[resource_name]
|
||||
except (IndexError, KeyError):
|
||||
raise exception.InvalidTemplateAttribute(resource=stack.name,
|
||||
key=key)
|
||||
raise exception.NotFound(_("Member '%(mem)s' not found "
|
||||
"in group resource '%(grp)s'.")
|
||||
% {'mem': resource_name,
|
||||
'grp': stack.name})
|
||||
|
||||
|
||||
def get_rsrc_attr(stack, key, use_indices, resource_name, *attr_path):
|
||||
resource = get_resource(stack, resource_name, use_indices, key)
|
||||
resource = get_resource(stack, resource_name, use_indices)
|
||||
if resource:
|
||||
return resource.FnGetAtt(*attr_path)
|
||||
|
||||
|
||||
def get_rsrc_id(stack, key, use_indices, resource_name):
|
||||
resource = get_resource(stack, resource_name, use_indices, key)
|
||||
resource = get_resource(stack, resource_name, use_indices)
|
||||
if resource:
|
||||
return resource.FnGetRefId()
|
||||
|
||||
|
@ -462,7 +462,7 @@ class HeatScalingGroupAttrTest(common.HeatTestCase):
|
||||
mock_members.return_value = members
|
||||
self.assertEqual(output[0], self.group.FnGetAtt('resource.0', 'Bar'))
|
||||
self.assertEqual(output[1], self.group.FnGetAtt('resource.1.Bar'))
|
||||
self.assertRaises(exception.InvalidTemplateAttribute,
|
||||
self.assertRaises(exception.NotFound,
|
||||
self.group.FnGetAtt, 'resource.2')
|
||||
|
||||
|
||||
|
@ -865,8 +865,10 @@ class ResourceGroupAttrTest(common.HeatTestCase):
|
||||
resg = self._create_dummy_stack()
|
||||
self.assertEqual("ID-0", resg.FnGetAtt('resource.0'))
|
||||
self.assertEqual("ID-1", resg.FnGetAtt('resource.1'))
|
||||
self.assertRaises(exception.InvalidTemplateAttribute, resg.FnGetAtt,
|
||||
'resource.2')
|
||||
ex = self.assertRaises(exception.NotFound, resg.FnGetAtt,
|
||||
'resource.2')
|
||||
self.assertIn("Member '2' not found in group resource 'group1'.",
|
||||
six.text_type(ex))
|
||||
|
||||
@mock.patch.object(grouputils, 'get_rsrc_id')
|
||||
def test_get_attribute(self, mock_get_rsrc_id):
|
||||
|
Loading…
x
Reference in New Issue
Block a user