Get rid of Template.validate_condition_definitions()

Following on from the deprecation of validate_resource_definitions() from
the Template interface, also remove validate_condition_definitions(). The
definitions will be validated when calling Template.conditions(), which
now occurs when loading the resource definitions, so it will still happen
during Stack.validate().

Since this interface is new and has never appeared in a release, we have no
need to go through a deprecation process.

Change-Id: I4dc36433c1aca776c2151205ed26a0f5241a750a
This commit is contained in:
Zane Bitter 2016-09-02 18:08:14 -04:00 committed by huangtianhua
parent 9bd13adeea
commit 1744d6758d
4 changed files with 14 additions and 27 deletions

View File

@ -782,9 +782,6 @@ class Stack(collections.Mapping):
parameter_groups = param_groups.ParameterGroups(self.t)
parameter_groups.validate()
# Validate condition definition of conditions section
self.t.validate_condition_definitions(self)
# Continue to call this function, since old third-party Template
# plugins may depend on it being called to validate the resource
# definitions before actually generating them.

View File

@ -255,10 +255,6 @@ class Template(collections.Mapping):
"""
pass
def validate_condition_definitions(self, stack):
"""Check conditions section."""
pass
def conditions(self, stack):
"""Return a dictionary of resolved conditions."""
return {}

View File

@ -81,18 +81,7 @@ class CommonTemplate(template.Template):
six.string_types,
'string', name, data)
def validate_condition_definitions(self, stack):
"""Check conditions section."""
resolved_cds = self.resolve_conditions(stack)
if resolved_cds:
for cd_key, cd_value in six.iteritems(resolved_cds):
if not isinstance(cd_value, bool):
raise exception.InvalidConditionDefinition(
cd=cd_key,
definition=cd_value)
def resolve_conditions(self, stack):
def _resolve_conditions(self, stack):
cd_snippet = self.get_condition_definitions()
result = {}
for cd_key, cd_value in six.iteritems(cd_snippet):
@ -135,7 +124,15 @@ class CommonTemplate(template.Template):
def conditions(self, stack):
if self._conditions is None:
self._conditions = self.resolve_conditions(stack)
resolved_cds = self._resolve_conditions(stack)
if resolved_cds:
for cd_key, cd_value in six.iteritems(resolved_cds):
if not isinstance(cd_value, bool):
raise exception.InvalidConditionDefinition(
cd=cd_key,
definition=cd_value)
self._conditions = resolved_cds
return self._conditions

View File

@ -137,9 +137,6 @@ class TestTemplatePluginManager(common.HeatTestCase):
param_defaults=None):
pass
def validate_condition_definitions(self, stack):
pass
def resource_definitions(self, stack):
pass
@ -326,7 +323,7 @@ class TestTemplateConditionParser(common.HeatTestCase):
stk = stack.Stack(self.ctx, 'test_condition_with_get_attr_func', tmpl,
resolve_data=False)
ex = self.assertRaises(exception.InvalidConditionFunction,
tmpl.resolve_conditions, stk)
tmpl._resolve_conditions, stk)
self.assertIn('The function is not supported in condition: get_attr',
six.text_type(ex))
@ -335,7 +332,7 @@ class TestTemplateConditionParser(common.HeatTestCase):
stk = stack.Stack(self.ctx, 'test_condition_with_get_attr_func', tmpl,
resolve_data=False)
ex = self.assertRaises(exception.InvalidConditionFunction,
tmpl.resolve_conditions, stk)
tmpl._resolve_conditions, stk)
self.assertIn('The function is not supported in condition: '
'get_resource', six.text_type(ex))
@ -344,7 +341,7 @@ class TestTemplateConditionParser(common.HeatTestCase):
stk = stack.Stack(self.ctx, 'test_condition_with_get_attr_func', tmpl,
resolve_data=False)
ex = self.assertRaises(exception.InvalidConditionFunction,
tmpl.resolve_conditions, stk)
tmpl._resolve_conditions, stk)
self.assertIn('The function is not supported in condition: get_attr',
six.text_type(ex))
@ -365,7 +362,7 @@ class TestTemplateConditionParser(common.HeatTestCase):
stk = stack.Stack(self.ctx, 'test_condition_not_boolean', tmpl)
ex = self.assertRaises(exception.InvalidConditionDefinition,
tmpl.validate_condition_definitions, stk)
tmpl.conditions, stk)
self.assertIn('The definition of condition (prod_env) is invalid',
six.text_type(ex))