From: Zane Bitter Date: Tue, 3 Sep 2013 10:04:13 +0000 (+0200) Subject: Add unit tests for Resource dependency inference X-Git-Tag: 2014.1~81^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=f2acd0e6147b71f4fa989a0ce44c6cb59ce5eb78;p=openstack-build%2Fheat-build.git Add unit tests for Resource dependency inference Change-Id: Idd05c880913081dccfbcbb1f26a528705e5ec924 --- diff --git a/heat/tests/test_resource.py b/heat/tests/test_resource.py index 7cb19198..345f9030 100644 --- a/heat/tests/test_resource.py +++ b/heat/tests/test_resource.py @@ -15,9 +15,11 @@ import itertools from heat.common import exception +from heat.engine import dependencies from heat.engine import parser from heat.engine import resource from heat.engine import scheduler +from heat.engine import template from heat.engine import environment from heat.openstack.common import uuidutils import heat.db.api as db_api @@ -565,6 +567,183 @@ class ResourceTest(HeatTestCase): ) +class ResourceDependenciesTest(HeatTestCase): + def setUp(self): + super(ResourceDependenciesTest, self).setUp() + utils.setup_dummy_db() + + resource._register_class('GenericResourceType', + generic_rsrc.GenericResource) + resource._register_class('ResourceWithPropsType', + generic_rsrc.ResourceWithProps) + + self.deps = dependencies.Dependencies() + + def test_no_deps(self): + tmpl = template.Template({ + 'Resources': { + 'foo': {'Type': 'GenericResourceType'}, + } + }) + stack = parser.Stack(None, 'test', tmpl) + + res = stack['foo'] + res.add_dependencies(self.deps) + graph = self.deps.graph() + + self.assertIn(res, graph) + + def test_ref(self): + tmpl = template.Template({ + 'Resources': { + 'foo': {'Type': 'GenericResourceType'}, + 'bar': { + 'Type': 'ResourceWithPropsType', + 'Properties': { + 'Foo': {'Ref': 'foo'}, + } + } + } + }) + stack = parser.Stack(None, 'test', tmpl) + + res = stack['bar'] + res.add_dependencies(self.deps) + graph = self.deps.graph() + + self.assertIn(res, graph) + self.assertIn(stack['foo'], graph[res]) + + def test_ref_nested_dict(self): + tmpl = template.Template({ + 'Resources': { + 'foo': {'Type': 'GenericResourceType'}, + 'bar': { + 'Type': 'ResourceWithPropsType', + 'Properties': { + 'Foo': {'Fn::Base64': {'Ref': 'foo'}}, + } + } + } + }) + stack = parser.Stack(None, 'test', tmpl) + + res = stack['bar'] + res.add_dependencies(self.deps) + graph = self.deps.graph() + + self.assertIn(res, graph) + self.assertIn(stack['foo'], graph[res]) + + def test_ref_nested_deep(self): + tmpl = template.Template({ + 'Resources': { + 'foo': {'Type': 'GenericResourceType'}, + 'bar': { + 'Type': 'ResourceWithPropsType', + 'Properties': { + 'Foo': {'Fn::Join': [",", ["blarg", + {'Ref': 'foo'}, + "wibble"]]}, + } + } + } + }) + stack = parser.Stack(None, 'test', tmpl) + + res = stack['bar'] + res.add_dependencies(self.deps) + graph = self.deps.graph() + + self.assertIn(res, graph) + self.assertIn(stack['foo'], graph[res]) + + def test_getatt(self): + tmpl = template.Template({ + 'Resources': { + 'foo': {'Type': 'GenericResourceType'}, + 'bar': { + 'Type': 'ResourceWithPropsType', + 'Properties': { + 'Foo': {'Fn::GetAtt': ['foo', 'bar']}, + } + } + } + }) + stack = parser.Stack(None, 'test', tmpl) + + res = stack['bar'] + res.add_dependencies(self.deps) + graph = self.deps.graph() + + self.assertIn(res, graph) + self.assertIn(stack['foo'], graph[res]) + + def test_getatt_nested_dict(self): + tmpl = template.Template({ + 'Resources': { + 'foo': {'Type': 'GenericResourceType'}, + 'bar': { + 'Type': 'ResourceWithPropsType', + 'Properties': { + 'Foo': {'Fn::Base64': {'Fn::GetAtt': ['foo', 'bar']}}, + } + } + } + }) + stack = parser.Stack(None, 'test', tmpl) + + res = stack['bar'] + res.add_dependencies(self.deps) + graph = self.deps.graph() + + self.assertIn(res, graph) + self.assertIn(stack['foo'], graph[res]) + + def test_getatt_nested_deep(self): + tmpl = template.Template({ + 'Resources': { + 'foo': {'Type': 'GenericResourceType'}, + 'bar': { + 'Type': 'ResourceWithPropsType', + 'Properties': { + 'Foo': {'Fn::Join': [",", ["blarg", + {'Fn::GetAtt': ['foo', + 'bar']}, + "wibble"]]}, + } + } + } + }) + stack = parser.Stack(None, 'test', tmpl) + + res = stack['bar'] + res.add_dependencies(self.deps) + graph = self.deps.graph() + + self.assertIn(res, graph) + self.assertIn(stack['foo'], graph[res]) + + def test_dependson(self): + tmpl = template.Template({ + 'Resources': { + 'foo': {'Type': 'GenericResourceType'}, + 'bar': { + 'Type': 'GenericResourceType', + 'DependsOn': 'foo', + } + } + }) + stack = parser.Stack(None, 'test', tmpl) + + res = stack['bar'] + res.add_dependencies(self.deps) + graph = self.deps.graph() + + self.assertIn(res, graph) + self.assertIn(stack['foo'], graph[res]) + + class MetadataTest(HeatTestCase): def setUp(self): super(MetadataTest, self).setUp()