Merge "Get the dependency graph directly from functions"

This commit is contained in:
Jenkins 2014-06-03 05:53:11 +00:00 committed by Gerrit Code Review
commit 0678d6c68c
3 changed files with 6 additions and 43 deletions

View File

@ -12,7 +12,6 @@
# under the License.
import base64
import copy
from datetime import datetime
import six
@ -283,39 +282,9 @@ class Resource(object):
str(self.stack))
return '%s "%s"' % (self.__class__.__name__, self.name)
def _add_dependencies(self, deps, path, fragment):
if isinstance(fragment, dict):
for key, value in fragment.items():
if key in ('DependsOn', 'Ref', 'Fn::GetAtt', 'get_attr',
'get_resource'):
if key in ('Fn::GetAtt', 'get_attr'):
res_name = value[0]
res_list = [res_name]
elif key == 'DependsOn' and isinstance(value, list):
res_list = value
else:
res_list = [value]
for res in res_list:
try:
target = self.stack[res]
except KeyError:
if (key != 'Ref' or
res not in self.stack.parameters):
raise exception.InvalidTemplateReference(
resource=res,
key=path)
else:
if key == 'DependsOn' or target.strict_dependency:
deps += (self, target)
else:
self._add_dependencies(deps, '%s.%s' % (path, key), value)
elif isinstance(fragment, list):
for index, item in enumerate(fragment):
self._add_dependencies(deps, '%s[%d]' % (path, index), item)
def add_dependencies(self, deps):
self._add_dependencies(deps, self.name, copy.deepcopy(dict(self.t)))
for dep in self.t.dependencies(self.stack):
deps += (self, dep)
deps += (self, None)
def required_by(self):

View File

@ -993,9 +993,8 @@ class ResourceDependenciesTest(HeatTestCase):
}
})
stack = parser.Stack(utils.dummy_context(), 'test', tmpl)
ex = self.assertRaises(exception.InvalidTemplateReference,
stack.validate)
self.assertIn('"baz" (in bar.Properties.Foo)', str(ex))
self.assertRaises(exception.StackValidationFailed,
stack.validate)
def test_hot_ref_fail(self):
tmpl = template.Template({

View File

@ -654,15 +654,10 @@ Resources:
self.m.VerifyAll()
def test_network_interface_error(self):
real_exception = self.assertRaises(
exception.InvalidTemplateReference,
self.assertRaises(
exception.StackValidationFailed,
self.create_stack,
self.test_template_error)
expected_exception = exception.InvalidTemplateReference(
resource='INVALID-REF-IN-TEMPLATE',
key='the_nic.Properties.GroupSet[0]')
self.assertEqual(str(expected_exception), str(real_exception))
class InternetGatewayTest(VPCTestBase):