summaryrefslogtreecommitdiffstats
path: root/tosca2heat/tosca-parser/toscaparser/tests/test_topology_template.py
diff options
context:
space:
mode:
authorshangxdy <shang.xiaodong@zte.com.cn>2016-12-02 16:21:21 +0800
committershangxdy <shang.xiaodong@zte.com.cn>2016-12-05 16:43:05 +0800
commitbfa17e5ccf685e3fa5d6661c72397bf3e6953fe4 (patch)
treef7122e7417c868f4260409389b501dc223127d01 /tosca2heat/tosca-parser/toscaparser/tests/test_topology_template.py
parenta618161aad8ebbcf3a613ab3fe1cc4b615542e95 (diff)
Add input validation test case
The required properties without default value in substituted node template which be mapped must be as inputs of nested service template which defines substutition mappings, and the inputs of nested service template which are not in the properties of the substituted node template must provide default values. JIRA:PARSER-113 Change-Id: Idce9ffa7de61f65032fa29f2ccf26c6433c14a40 Signed-off-by: shangxdy <shang.xiaodong@zte.com.cn>
Diffstat (limited to 'tosca2heat/tosca-parser/toscaparser/tests/test_topology_template.py')
-rw-r--r--tosca2heat/tosca-parser/toscaparser/tests/test_topology_template.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/tosca2heat/tosca-parser/toscaparser/tests/test_topology_template.py b/tosca2heat/tosca-parser/toscaparser/tests/test_topology_template.py
index edb834b..6974d52 100644
--- a/tosca2heat/tosca-parser/toscaparser/tests/test_topology_template.py
+++ b/tosca2heat/tosca-parser/toscaparser/tests/test_topology_template.py
@@ -55,6 +55,18 @@ class TopologyTemplateTest(TestCase):
custom_defs.update(self._get_custom_def('capability_types'))
return custom_defs
+ def _get_custom_types(self):
+ custom_types = {}
+ def_file = os.path.join(
+ os.path.dirname(os.path.abspath(__file__)),
+ "data/topology_template/definitions.yaml")
+ custom_type = YAML_LOADER(def_file)
+ node_types = custom_type['node_types']
+ for name in node_types:
+ defintion = node_types[name]
+ custom_types[name] = defintion
+ return custom_types
+
def test_description(self):
expected_desc = 'Template of a database including its hosting stack.'
self.assertEqual(expected_desc, self.topo.description)
@@ -165,6 +177,7 @@ class TopologyTemplateTest(TestCase):
self.assertEqual(
len(system_tosca_template.
nested_tosca_templates_with_topology), 4)
+ self.assertTrue(system_tosca_template.has_nested_templates())
def test_invalid_keyname(self):
tpl_snippet = '''
@@ -205,3 +218,47 @@ class TopologyTemplateTest(TestCase):
lambda: SubstitutionMappings(sub_mappings, None, None,
None, None, None))
self.assertEqual(expected_message, err.__str__())
+
+ def test_invalid_nodetype(self):
+ tpl_snippet = '''
+ substitution_mappings:
+ node_type: example.DatabaseSubsystem1
+ capabilities:
+ database_endpoint: [ db_app, database_endpoint ]
+ requirements:
+ receiver1: [ tran_app, receiver1 ]
+ '''
+ sub_mappings = (toscaparser.utils.yamlparser.
+ simple_parse(tpl_snippet))['substitution_mappings']
+ custom_defs = self._get_custom_types()
+ expected_message = _('Node type "example.DatabaseSubsystem1" '
+ 'is not a valid type.')
+ err = self.assertRaises(
+ exception.InvalidNodeTypeError,
+ lambda: SubstitutionMappings(sub_mappings, None, None,
+ None, None, custom_defs))
+ self.assertEqual(expected_message, err.__str__())
+
+ def test_system_with_input_validation(self):
+ tpl_path0 = os.path.join(
+ os.path.dirname(os.path.abspath(__file__)),
+ "data/topology_template/validate/system_invalid_input.yaml")
+ tpl_path1 = os.path.join(
+ os.path.dirname(os.path.abspath(__file__)),
+ "data/topology_template/validate/"
+ "queuingsubsystem_invalid_input.yaml")
+ errormsg = _('SubstitutionMappings with node_type '
+ 'example.QueuingSubsystem is missing '
+ 'required input definition of input "server_port".')
+
+ # It's invalid in nested template.
+ self.assertRaises(exception.ValidationError,
+ lambda: ToscaTemplate(tpl_path0))
+ exception.ExceptionCollector.assertExceptionMessage(
+ exception.MissingRequiredInputError, errormsg)
+
+ # Subtemplate deploy standaolone is also invalid.
+ self.assertRaises(exception.ValidationError,
+ lambda: ToscaTemplate(tpl_path1))
+ exception.ExceptionCollector.assertExceptionMessage(
+ exception.MissingRequiredInputError, errormsg)