Fix an issue with handling invalid section names
Invalid section names in the TOSCA template could cause an unexpected exception that is due to not handling an error properly. This patch is to fix the issue and add a proper unit test to verify the fix. Change-Id: Icbf7c3d0c8a26d8d09c19c68bd58154d4da9cd43 Closes-Bug: #1516826
This commit is contained in:
parent
ffb741201c
commit
9e22adedd6
|
@ -0,0 +1,25 @@
|
|||
tosca_definitions_versions: tosca_simple_yaml_1_0
|
||||
|
||||
descriptions: >
|
||||
TOSCA profile with invalid top-level section names.
|
||||
|
||||
import:
|
||||
- imported.yaml
|
||||
|
||||
topology_templates:
|
||||
|
||||
node_templates:
|
||||
server:
|
||||
type: tosca.nodes.Compute
|
||||
capabilities:
|
||||
host:
|
||||
properties:
|
||||
disk_size: 10 GB
|
||||
num_cpus: 1
|
||||
mem_size: 4096 MB
|
||||
os:
|
||||
properties:
|
||||
architecture: x86_64
|
||||
type: Linux
|
||||
distribution: Ubuntu
|
||||
version: 14.04
|
|
@ -490,6 +490,34 @@ class ToscaTemplateTest(TestCase):
|
|||
exception.ExceptionCollector.assertExceptionMessage(
|
||||
KeyError, err5_msg)
|
||||
|
||||
def test_invalid_section_names(self):
|
||||
tosca_tpl = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
"data/test_invalid_section_names.yaml")
|
||||
self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl,
|
||||
None)
|
||||
err1_msg = _('Template contain(s) unknown field: '
|
||||
'"tosca_definitions_versions", refer to the definition '
|
||||
'to verify valid values.')
|
||||
exception.ExceptionCollector.assertExceptionMessage(
|
||||
exception.UnknownFieldError, err1_msg)
|
||||
|
||||
err2_msg = _('Template contain(s) unknown field: "descriptions", '
|
||||
'refer to the definition to verify valid values.')
|
||||
exception.ExceptionCollector.assertExceptionMessage(
|
||||
exception.UnknownFieldError, err2_msg)
|
||||
|
||||
err3_msg = _('Template contain(s) unknown field: "import", refer to '
|
||||
'the definition to verify valid values.')
|
||||
exception.ExceptionCollector.assertExceptionMessage(
|
||||
exception.UnknownFieldError, err3_msg)
|
||||
|
||||
err4_msg = _('Template contain(s) unknown field: '
|
||||
'"topology_templates", refer to the definition to verify '
|
||||
'valid values.')
|
||||
exception.ExceptionCollector.assertExceptionMessage(
|
||||
exception.UnknownFieldError, err4_msg)
|
||||
|
||||
def test_csar_with_alternate_extenstion(self):
|
||||
tosca_tpl = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
|
|
|
@ -40,19 +40,20 @@ class TopologyTemplate(object):
|
|||
def __init__(self, template, custom_defs,
|
||||
rel_types=None, parsed_params=None):
|
||||
self.tpl = template
|
||||
self.custom_defs = custom_defs
|
||||
self.rel_types = rel_types
|
||||
self.parsed_params = parsed_params
|
||||
self._validate_field()
|
||||
self.description = self._tpl_description()
|
||||
self.inputs = self._inputs()
|
||||
self.relationship_templates = self._relationship_templates()
|
||||
self.nodetemplates = self._nodetemplates()
|
||||
self.outputs = self._outputs()
|
||||
if hasattr(self, 'nodetemplates'):
|
||||
self.graph = ToscaGraph(self.nodetemplates)
|
||||
self.groups = self._groups()
|
||||
self._process_intrinsic_functions()
|
||||
if self.tpl:
|
||||
self.custom_defs = custom_defs
|
||||
self.rel_types = rel_types
|
||||
self.parsed_params = parsed_params
|
||||
self._validate_field()
|
||||
self.description = self._tpl_description()
|
||||
self.inputs = self._inputs()
|
||||
self.relationship_templates = self._relationship_templates()
|
||||
self.nodetemplates = self._nodetemplates()
|
||||
self.outputs = self._outputs()
|
||||
if hasattr(self, 'nodetemplates'):
|
||||
self.graph = ToscaGraph(self.nodetemplates)
|
||||
self.groups = self._groups()
|
||||
self._process_intrinsic_functions()
|
||||
|
||||
def _inputs(self):
|
||||
inputs = []
|
||||
|
|
|
@ -63,11 +63,12 @@ class ToscaTemplate(object):
|
|||
self.relationship_types = self._tpl_relationship_types()
|
||||
self.description = self._tpl_description()
|
||||
self.topology_template = self._topology_template()
|
||||
self.inputs = self._inputs()
|
||||
self.relationship_templates = self._relationship_templates()
|
||||
self.nodetemplates = self._nodetemplates()
|
||||
self.outputs = self._outputs()
|
||||
self.graph = ToscaGraph(self.nodetemplates)
|
||||
if self.topology_template.tpl:
|
||||
self.inputs = self._inputs()
|
||||
self.relationship_templates = self._relationship_templates()
|
||||
self.nodetemplates = self._nodetemplates()
|
||||
self.outputs = self._outputs()
|
||||
self.graph = ToscaGraph(self.nodetemplates)
|
||||
ExceptionCollector.stop()
|
||||
self.verify_template()
|
||||
|
||||
|
@ -199,7 +200,7 @@ class ToscaTemplate(object):
|
|||
if ExceptionCollector.exceptionsCaught():
|
||||
raise ValidationError(
|
||||
message=(_('\nThe input "%(path)s" has failed validation with '
|
||||
'the following errors: \n\n\t')
|
||||
'the following error(s): \n\n\t')
|
||||
% {'path': self.path}) +
|
||||
'\n\t'.join(ExceptionCollector.getExceptionsReport()))
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue