Merge "Ignore dependency errors with conditions" into stable/newton
This commit is contained in:
commit
1c4b725b85
|
@ -208,6 +208,10 @@ class ResourceDefinitionCore(object):
|
|||
|
||||
def get_resource(res_name):
|
||||
if res_name not in stack:
|
||||
if res_name in stack.t.get(stack.t.RESOURCES):
|
||||
# The resource is conditionally defined, allow dependencies
|
||||
# on it
|
||||
return
|
||||
raise exception.InvalidTemplateReference(resource=res_name,
|
||||
key=self.name)
|
||||
return stack[res_name]
|
||||
|
@ -231,8 +235,9 @@ class ResourceDefinitionCore(object):
|
|||
)
|
||||
return itertools.chain()
|
||||
|
||||
return itertools.chain((get_resource(dep) for dep in explicit_depends),
|
||||
prop_deps, metadata_deps)
|
||||
return itertools.chain(
|
||||
filter(None, (get_resource(dep) for dep in explicit_depends)),
|
||||
prop_deps, metadata_deps)
|
||||
|
||||
def properties(self, schema, context=None):
|
||||
"""Return a Properties object representing the resource properties.
|
||||
|
|
|
@ -1665,6 +1665,25 @@ conditions:
|
|||
|
||||
self.assertEqual(hot_tpl['resources'], empty.t['resources'])
|
||||
|
||||
def test_depends_condition(self):
|
||||
hot_tpl = template_format.parse('''
|
||||
heat_template_version: 2016-10-14
|
||||
resources:
|
||||
one:
|
||||
type: OS::Heat::None
|
||||
two:
|
||||
type: OS::Heat::None
|
||||
condition: False
|
||||
three:
|
||||
type: OS::Heat::None
|
||||
depends_on: two
|
||||
''')
|
||||
|
||||
tmpl = template.Template(hot_tpl)
|
||||
stack = parser.Stack(utils.dummy_context(), 'test_stack', tmpl)
|
||||
stack.validate()
|
||||
self.assertEqual({'one', 'three'}, set(stack.resources))
|
||||
|
||||
|
||||
class HotStackTest(common.HeatTestCase):
|
||||
"""Test stack function when stack was created from HOT template."""
|
||||
|
|
|
@ -35,6 +35,16 @@ resources:
|
|||
type: OS::Heat::TestResource
|
||||
'''
|
||||
|
||||
TEMPLATE_WITH_INVALID_EXPLICIT_DEPEND = '''
|
||||
heat_template_version: 2016-10-14
|
||||
resources:
|
||||
test1:
|
||||
type: OS::Heat::TestResource
|
||||
test3:
|
||||
type: OS::Heat::TestResource
|
||||
depends_on: test2
|
||||
'''
|
||||
|
||||
|
||||
class ResourceDefinitionTest(common.HeatTestCase):
|
||||
|
||||
|
@ -105,8 +115,9 @@ class ResourceDefinitionTest(common.HeatTestCase):
|
|||
self.assertEqual([], list(rsrc.t.dependencies(stack)))
|
||||
|
||||
def test_dependencies_explicit_invalid(self):
|
||||
rd = rsrc_defn.ResourceDefinition('rsrc', 'SomeType', depends=['baz'])
|
||||
stack = {'foo': 'FOO', 'bar': 'BAR'}
|
||||
t = template_format.parse(TEMPLATE_WITH_INVALID_EXPLICIT_DEPEND)
|
||||
stack = utils.parse_stack(t)
|
||||
rd = stack.t.resource_definitions(stack)['test3']
|
||||
self.assertRaises(exception.InvalidTemplateReference,
|
||||
lambda: list(rd.dependencies(stack)))
|
||||
|
||||
|
|
Loading…
Reference in New Issue