Merge "Get the dependency graph directly from functions"
This commit is contained in:
commit
0678d6c68c
@ -12,7 +12,6 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
import copy
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import six
|
import six
|
||||||
@ -283,39 +282,9 @@ class Resource(object):
|
|||||||
str(self.stack))
|
str(self.stack))
|
||||||
return '%s "%s"' % (self.__class__.__name__, self.name)
|
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):
|
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)
|
deps += (self, None)
|
||||||
|
|
||||||
def required_by(self):
|
def required_by(self):
|
||||||
|
@ -993,9 +993,8 @@ class ResourceDependenciesTest(HeatTestCase):
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
stack = parser.Stack(utils.dummy_context(), 'test', tmpl)
|
stack = parser.Stack(utils.dummy_context(), 'test', tmpl)
|
||||||
ex = self.assertRaises(exception.InvalidTemplateReference,
|
self.assertRaises(exception.StackValidationFailed,
|
||||||
stack.validate)
|
stack.validate)
|
||||||
self.assertIn('"baz" (in bar.Properties.Foo)', str(ex))
|
|
||||||
|
|
||||||
def test_hot_ref_fail(self):
|
def test_hot_ref_fail(self):
|
||||||
tmpl = template.Template({
|
tmpl = template.Template({
|
||||||
|
@ -654,15 +654,10 @@ Resources:
|
|||||||
self.m.VerifyAll()
|
self.m.VerifyAll()
|
||||||
|
|
||||||
def test_network_interface_error(self):
|
def test_network_interface_error(self):
|
||||||
real_exception = self.assertRaises(
|
self.assertRaises(
|
||||||
exception.InvalidTemplateReference,
|
exception.StackValidationFailed,
|
||||||
self.create_stack,
|
self.create_stack,
|
||||||
self.test_template_error)
|
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):
|
class InternetGatewayTest(VPCTestBase):
|
||||||
|
Loading…
Reference in New Issue
Block a user