1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
5 # http://www.apache.org/licenses/LICENSE-2.0
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
16 from toscaparser.common import exception
17 from toscaparser.imports import ImportsLoader
18 from toscaparser.nodetemplate import NodeTemplate
19 from toscaparser.parameters import Input
20 from toscaparser.parameters import Output
21 from toscaparser.policy import Policy
22 from toscaparser.relationship_template import RelationshipTemplate
23 from toscaparser.repositories import Repository
24 from toscaparser.tests.base import TestCase
25 from toscaparser.topology_template import TopologyTemplate
26 from toscaparser.tosca_template import ToscaTemplate
27 from toscaparser.triggers import Triggers
28 from toscaparser.utils.gettextutils import _
29 import toscaparser.utils.yamlparser
32 class ToscaTemplateValidationTest(TestCase):
34 def test_well_defined_template(self):
35 tpl_path = os.path.join(
36 os.path.dirname(os.path.abspath(__file__)),
37 "data/tosca_single_instance_wordpress.yaml")
38 params = {'db_name': 'my_wordpress', 'db_user': 'my_db_user',
39 'db_root_pwd': '12345678'}
40 self.assertIsNotNone(ToscaTemplate(tpl_path, params))
42 def test_custom_interface_allowed(self):
43 tpl_path = os.path.join(
44 os.path.dirname(os.path.abspath(__file__)),
45 "data/interfaces/test_custom_interface_in_template.yaml")
46 self.assertIsNotNone(ToscaTemplate(tpl_path))
48 def test_custom_interface_invalid_operation(self):
49 tpl_path = os.path.join(
50 os.path.dirname(os.path.abspath(__file__)),
51 "data/interfaces/test_custom_interface_invalid_operation.yaml")
52 self.assertRaises(exception.ValidationError,
53 ToscaTemplate, tpl_path)
54 exception.ExceptionCollector.assertExceptionMessage(
55 exception.UnknownFieldError,
56 _('"interfaces" of template "customInterfaceTest" '
57 'contains unknown field "CustomOp4". '
58 'Refer to the definition to verify valid values.'))
60 def test_first_level_sections(self):
61 tpl_path = os.path.join(
62 os.path.dirname(os.path.abspath(__file__)),
63 "data/test_tosca_top_level_error1.yaml")
64 self.assertRaises(exception.ValidationError, ToscaTemplate, tpl_path)
65 exception.ExceptionCollector.assertExceptionMessage(
66 exception.MissingRequiredFieldError,
67 _('Template is missing required field '
68 '"tosca_definitions_version".'))
70 tpl_path = os.path.join(
71 os.path.dirname(os.path.abspath(__file__)),
72 "data/test_tosca_top_level_error2.yaml")
73 self.assertRaises(exception.ValidationError, ToscaTemplate, tpl_path)
74 exception.ExceptionCollector.assertExceptionMessage(
75 exception.UnknownFieldError,
76 _('Template contains unknown field "node_template". Refer to the '
77 'definition to verify valid values.'))
79 def test_template_with_imports_validation(self):
80 tpl_path = os.path.join(
81 os.path.dirname(os.path.abspath(__file__)),
82 "data/tosca_imports_validation.yaml")
83 self.assertRaises(exception.ValidationError, ToscaTemplate, tpl_path)
84 exception.ExceptionCollector.assertExceptionMessage(
85 exception.UnknownFieldError,
86 _('Template custom_types/imported_sample.yaml contains unknown '
87 'field "descriptions". Refer to the definition'
88 ' to verify valid values.'))
89 exception.ExceptionCollector.assertExceptionMessage(
90 exception.UnknownFieldError,
91 _('Template custom_types/imported_sample.yaml contains unknown '
92 'field "node_typess". Refer to the definition to '
93 'verify valid values.'))
94 exception.ExceptionCollector.assertExceptionMessage(
95 exception.UnknownFieldError,
96 _('Template custom_types/imported_sample.yaml contains unknown '
97 'field "tosca1_definitions_version". Refer to the definition'
98 ' to verify valid values.'))
99 exception.ExceptionCollector.assertExceptionMessage(
100 exception.InvalidTemplateVersion,
101 _('The template version "tosca_simple_yaml_1_10 in '
102 'custom_types/imported_sample.yaml" is invalid. '
103 'Valid versions are "tosca_simple_yaml_1_0, '
104 'tosca_simple_yaml_1_1, '
105 'tosca_simple_profile_for_nfv_1_0_0".'))
106 exception.ExceptionCollector.assertExceptionMessage(
107 exception.UnknownFieldError,
108 _('Template custom_types/imported_sample.yaml contains unknown '
109 'field "policy_types1". Refer to the definition to '
110 'verify valid values.'))
111 exception.ExceptionCollector.assertExceptionMessage(
112 exception.UnknownFieldError,
113 _('Nodetype"tosca.nodes.SoftwareComponent.Logstash" contains '
114 'unknown field "capabilities1". Refer to the definition '
115 'to verify valid values.'))
116 exception.ExceptionCollector.assertExceptionMessage(
117 exception.UnknownFieldError,
118 _('Policy "mycompany.mytypes.myScalingPolicy" contains unknown '
119 'field "derived1_from". Refer to the definition to '
120 'verify valid values.'))
121 exception.ExceptionCollector.assertExceptionMessage(
122 exception.UnknownFieldError,
123 _('Relationshiptype "test.relation.connects" contains unknown '
124 'field "derived_from4". Refer to the definition to '
125 'verify valid values.'))
127 def test_getoperation_IncorrectValue(self):
132 type: tosca.nodes.Compute
136 implementation: scripts/frontend/create.sh
138 implementation: scripts/frontend/configure.sh
140 data_dir: {get_operation_output: [front_end,Standard1,
143 tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet))
144 err = self.assertRaises(ValueError,
145 TopologyTemplate, tpl, None)
146 expectedmessage = _('Enter a valid interface name')
147 self.assertEqual(expectedmessage, err.__str__())
152 type: tosca.nodes.Compute
156 implementation: scripts/frontend/create.sh
158 implementation: scripts/frontend/configure.sh
160 data_dir: {get_operation_output: [front_end1,Standard,
163 tpl2 = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet2))
164 err2 = self.assertRaises(KeyError,
165 TopologyTemplate, tpl2, None)
166 expectedmessage2 = _('\'Node template "front_end1" was not found.\'')
167 self.assertEqual(expectedmessage2, err2.__str__())
172 type: tosca.nodes.Compute
176 implementation: scripts/frontend/create.sh
178 implementation: scripts/frontend/configure.sh
180 data_dir: {get_operation_output: [front_end,Standard,
181 get_target,data_dir]}
183 tpl3 = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet3))
184 err3 = self.assertRaises(ValueError,
185 TopologyTemplate, tpl3, None)
186 expectedmessage3 = _('Enter an operation of Standard interface')
187 self.assertEqual(expectedmessage3, err3.__str__())
192 type: tosca.nodes.Compute
196 implementation: scripts/frontend/create.sh
198 implementation: scripts/frontend/configure.sh
200 data_dir: {get_operation_output: [front_end,Configure,
203 tpl4 = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet4))
204 err4 = self.assertRaises(ValueError,
205 TopologyTemplate, tpl4, None)
206 expectedmessage4 = _('Enter an operation of Configure interface')
207 self.assertEqual(expectedmessage4, err4.__str__())
212 type: tosca.nodes.Compute
216 implementation: scripts/frontend/create.sh
218 implementation: scripts/frontend/configure.sh
220 data_dir: {get_operation_output: [front_end,Standard,
223 tpl5 = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet5))
224 err5 = self.assertRaises(ValueError,
225 TopologyTemplate, tpl5, None)
226 expectedmessage5 = _('Illegal arguments for function'
227 ' "get_operation_output".'
228 ' Expected arguments: "template_name",'
230 '"operation_name","output_variable_name"')
231 self.assertEqual(expectedmessage5, err5.__str__())
233 def test_unsupported_type(self):
237 type: tosca.test.invalidtype
239 size: { get_input: storage_size }
240 snapshot_id: { get_input: storage_snapshot_id }
242 tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet))
243 err = self.assertRaises(exception.UnsupportedTypeError,
244 TopologyTemplate, tpl, None)
245 expectedmessage = _('Type "tosca.test.invalidtype" is valid'
246 ' TOSCA type but not supported at this time.')
247 self.assertEqual(expectedmessage, err.__str__())
249 def test_inputs(self):
254 description: Number of CPUs for the server.
256 - valid_values: [ 1, 2, 4 ]
264 description: Number of CPUs for the server.
266 - valid_values: [ 1, 2, 4 ]
274 description: List of items
279 inputs1 = (toscaparser.utils.yamlparser.
280 simple_parse(tpl_snippet1)['inputs'])
281 name1, attrs1 = list(inputs1.items())[0]
282 inputs2 = (toscaparser.utils.yamlparser.
283 simple_parse(tpl_snippet2)['inputs'])
284 name2, attrs2 = list(inputs2.items())[0]
287 except Exception as err:
288 self.assertEqual(_('Input "cpus" contains unknown field '
289 '"constraint". Refer to the definition to '
290 'verify valid values.'),
292 input2 = Input(name2, attrs2)
293 self.assertTrue(input2.required)
294 toscaparser.utils.yamlparser.simple_parse(tpl_snippet3)['inputs']
296 def _imports_content_test(self, tpl_snippet, path, custom_type_def):
297 imports = (toscaparser.utils.yamlparser.
298 simple_parse(tpl_snippet)['imports'])
299 loader = ImportsLoader(imports, path, custom_type_def)
300 return loader.get_custom_defs()
302 def test_imports_without_templates(self):
305 # omitted here for brevity
307 path = 'toscaparser/tests/data/tosca_elk.yaml'
308 errormsg = _('"imports" keyname is defined without including '
310 err = self.assertRaises(exception.ValidationError,
311 self._imports_content_test,
315 self.assertEqual(errormsg, err.__str__())
317 def test_imports_with_name_without_templates(self):
322 path = 'toscaparser/tests/data/tosca_elk.yaml'
323 errormsg = _('A template file name is not provided with import '
324 'definition "some_definitions".')
325 err = self.assertRaises(exception.ValidationError,
326 self._imports_content_test,
327 tpl_snippet, path, None)
328 self.assertEqual(errormsg, err.__str__())
330 def test_imports_without_import_name(self):
333 - custom_types/paypalpizzastore_nodejs_app.yaml
334 - https://raw.githubusercontent.com/openstack/\
335 tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
337 path = 'toscaparser/tests/data/tosca_elk.yaml'
338 custom_defs = self._imports_content_test(tpl_snippet,
341 self.assertTrue(custom_defs)
343 def test_imports_wth_import_name(self):
346 - some_definitions: custom_types/paypalpizzastore_nodejs_app.yaml
348 file: 'https://raw.githubusercontent.com/openstack/tosca-parser\
349 /master/toscaparser/tests/data/custom_types/wordpress.yaml'
350 namespace_prefix: single_instance_wordpress
352 path = 'toscaparser/tests/data/tosca_elk.yaml'
353 custom_defs = self._imports_content_test(tpl_snippet,
356 self.assertTrue(custom_defs.get("single_instance_wordpress.tosca."
357 "nodes.WebApplication.WordPress"))
359 def test_imports_wth_namespace_prefix(self):
363 file: custom_types/nested_rsyslog.yaml
364 namespace_prefix: testprefix
366 path = 'toscaparser/tests/data/tosca_elk.yaml'
367 custom_defs = self._imports_content_test(tpl_snippet,
370 self.assertTrue(custom_defs.get("testprefix.Rsyslog"))
372 def test_imports_with_no_main_template(self):
375 - some_definitions: https://raw.githubusercontent.com/openstack/\
376 tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
378 file: my_defns/my_typesdefs_n.yaml
380 errormsg = _('Input tosca template is not provided.')
381 err = self.assertRaises(exception.ValidationError,
382 self._imports_content_test,
383 tpl_snippet, None, None)
384 self.assertEqual(errormsg, err.__str__())
386 def test_imports_duplicate_name(self):
389 - some_definitions: https://raw.githubusercontent.com/openstack/\
390 tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
392 file: my_defns/my_typesdefs_n.yaml
394 errormsg = _('Duplicate import name "some_definitions" was found.')
395 path = 'toscaparser/tests/data/tosca_elk.yaml'
396 err = self.assertRaises(exception.ValidationError,
397 self._imports_content_test,
398 tpl_snippet, path, None)
399 self.assertEqual(errormsg, err.__str__())
401 def test_imports_missing_req_field_in_def(self):
405 file1: my_defns/my_typesdefs_n.yaml
406 repository: my_company_repo
407 namespace_uri: http://mycompany.com/ns/tosca/2.0
408 namespace_prefix: mycompany
410 errormsg = _('Import of template "more_definitions" is missing '
411 'required field "file".')
412 path = 'toscaparser/tests/data/tosca_elk.yaml'
413 err = self.assertRaises(exception.MissingRequiredFieldError,
414 self._imports_content_test,
415 tpl_snippet, path, None)
416 self.assertEqual(errormsg, err.__str__())
418 def test_imports_file_with_uri(self):
422 file: https://raw.githubusercontent.com/openstack/\
423 tosca-parser/master/toscaparser/tests/data/custom_types/wordpress.yaml
425 path = 'https://raw.githubusercontent.com/openstack/\
426 tosca-parser/master/toscaparser/tests/data/\
427 tosca_single_instance_wordpress_with_url_import.yaml'
428 custom_defs = self._imports_content_test(tpl_snippet,
431 self.assertTrue(custom_defs.get("tosca.nodes."
432 "WebApplication.WordPress"))
434 def test_imports_file_namespace_fields(self):
438 file: https://raw.githubusercontent.com/openstack/\
439 heat-translator/master/translator/tests/data/custom_types/wordpress.yaml
440 namespace_prefix: mycompany
441 namespace_uri: http://docs.oasis-open.org/tosca/ns/simple/yaml/1.0
443 path = 'toscaparser/tests/data/tosca_elk.yaml'
444 custom_defs = self._imports_content_test(tpl_snippet,
447 self.assertTrue(custom_defs.get("mycompany.tosca.nodes."
448 "WebApplication.WordPress"))
450 def test_imports_file_with_suffix_yml(self):
453 - custom_types/wordpress.yml
455 path = 'toscaparser/tests/data/tosca_elk.yaml'
456 custom_defs = self._imports_content_test(tpl_snippet,
459 self.assertTrue(custom_defs.get("tosca.nodes."
460 "WebApplication.WordPress"))
462 def test_import_error_file_uri(self):
466 file: mycompany.com/ns/tosca/2.0/toscaparser/tests/data\
468 namespace_prefix: mycompany
469 namespace_uri: http://docs.oasis-open.org/tosca/ns/simple/yaml/1.0
471 path = 'toscaparser/tests/data/tosca_elk.yaml'
472 self.assertRaises(ImportError,
473 self._imports_content_test,
474 tpl_snippet, path, None)
476 def test_import_single_line_error(self):
479 - some_definitions: abc.com/tests/data/tosca_elk.yaml
481 errormsg = _('Import "abc.com/tests/data/tosca_elk.yaml" is not '
483 path = 'toscaparser/tests/data/tosca_elk.yaml'
484 err = self.assertRaises(ImportError,
485 self._imports_content_test,
486 tpl_snippet, path, None)
487 self.assertEqual(errormsg, err.__str__())
489 def test_outputs(self):
493 description: IP address of server instance.
494 values: { get_property: [server, private_address] }
496 outputs = (toscaparser.utils.yamlparser.
497 simple_parse(tpl_snippet)['outputs'])
498 name, attrs = list(outputs.items())[0]
499 output = Output(name, attrs)
502 except Exception as err:
504 isinstance(err, exception.MissingRequiredFieldError))
505 self.assertEqual(_('Output "server_address" is missing required '
506 'field "value".'), err.__str__())
511 descriptions: IP address of server instance.
512 value: { get_property: [server, private_address] }
514 outputs = (toscaparser.utils.yamlparser.
515 simple_parse(tpl_snippet)['outputs'])
516 name, attrs = list(outputs.items())[0]
517 output = Output(name, attrs)
520 except Exception as err:
521 self.assertIsInstance(err, exception.UnknownFieldError)
522 self.assertEqual(_('Output "server_address" contains unknown '
523 'field "descriptions". Refer to the definition '
524 'to verify valid values.'),
527 def _repo_content(self, path):
528 repositories = path['repositories']
530 for name, val in repositories.items():
531 reposits = Repository(name, val)
532 reposit.append(reposits)
535 def test_repositories(self):
538 repo_code0: https://raw.githubusercontent.com/nandinivemula/intern
540 description: My project's code Repository in github usercontent.
541 url: https://github.com/nandinivemula/intern
546 description: My Project's code Repository in github.
547 url: https://github.com/nandinivemula/intern
552 tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet))
553 repoobject = self._repo_content(tpl)
554 actualrepo_names = []
555 for repo in repoobject:
557 actualrepo_names.append(repos)
558 reposname = list(tpl.values())
559 reposnames = reposname[0]
560 expected_reponames = list(reposnames.keys())
561 self.assertEqual(expected_reponames, actualrepo_names)
563 def test_repositories_with_missing_required_field(self):
566 repo_code0: https://raw.githubusercontent.com/nandinivemula/intern
568 description: My project's code Repository in github usercontent.
573 description: My Project's code Repository in github.
574 url: https://github.com/nandinivemula/intern
579 tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet))
580 err = self.assertRaises(exception.MissingRequiredFieldError,
581 self._repo_content, tpl)
582 expectedmessage = _('Repository "repo_code1" is missing '
583 'required field "url".')
584 self.assertEqual(expectedmessage, err.__str__())
586 def test_repositories_with_unknown_field(self):
589 repo_code0: https://raw.githubusercontent.com/nandinivemula/intern
591 description: My project's code Repository in github usercontent.
592 url: https://github.com/nandinivemula/intern
597 descripton: My Project's code Repository in github.
598 url: https://github.com/nandinivemula/intern
603 tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet))
604 err = self.assertRaises(exception.UnknownFieldError,
605 self._repo_content, tpl)
606 expectedmessage = _('repositories "repo_code2" contains unknown field'
607 ' "descripton". Refer to the definition to verify'
609 self.assertEqual(expectedmessage, err.__str__())
611 def test_repositories_with_invalid_url(self):
614 repo_code0: https://raw.githubusercontent.com/nandinivemula/intern
616 description: My project's code Repository in github usercontent.
622 description: My Project's code Repository in github.
623 url: https://github.com/nandinivemula/intern
628 tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet))
629 err = self.assertRaises(exception.URLException,
630 self._repo_content, tpl)
631 expectedmessage = _('repsositories "repo_code1" Invalid Url')
632 self.assertEqual(expectedmessage, err.__str__())
634 def test_groups(self):
638 type: tosca.nodes.Compute
641 capability: log_endpoint
644 type: tosca.nodes.DBMS
651 type: tosca.groups.Root
652 members: [ server, mysql_dbms ]
654 tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet))
655 TopologyTemplate(tpl, None)
657 def test_groups_with_missing_required_field(self):
661 type: tosca.nodes.Compute
664 capability: log_endpoint
667 type: tosca.nodes.DBMS
674 members: ['server', 'mysql_dbms']
676 tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet))
677 err = self.assertRaises(exception.MissingRequiredFieldError,
678 TopologyTemplate, tpl, None)
679 expectedmessage = _('Template "webserver_group" is missing '
680 'required field "type".')
681 self.assertEqual(expectedmessage, err.__str__())
683 def test_groups_with_unknown_target(self):
687 type: tosca.nodes.Compute
690 capability: log_endpoint
693 type: tosca.nodes.DBMS
700 type: tosca.groups.Root
701 members: [ serv, mysql_dbms ]
703 tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet))
704 expectedmessage = _('"Target member "serv" is not found in '
706 err = self.assertRaises(exception.InvalidGroupTargetException,
707 TopologyTemplate, tpl, None)
708 self.assertEqual(expectedmessage, err.__str__())
710 def test_groups_with_repeated_targets(self):
714 type: tosca.nodes.Compute
717 capability: log_endpoint
720 type: tosca.nodes.DBMS
727 type: tosca.groups.Root
728 members: [ server, server, mysql_dbms ]
730 tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet))
731 expectedmessage = _('"Member nodes '
732 '"[\'server\', \'server\', \'mysql_dbms\']" '
733 'should be >= 1 and not repeated"')
734 err = self.assertRaises(exception.InvalidGroupTargetException,
735 TopologyTemplate, tpl, None)
736 self.assertEqual(expectedmessage, err.__str__())
738 def test_groups_with_only_one_target(self):
742 type: tosca.nodes.Compute
745 capability: log_endpoint
748 type: tosca.nodes.DBMS
755 type: tosca.groups.Root
758 tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet))
759 expectedmessage = _('"Member nodes "[]" should be >= 1 '
761 err = self.assertRaises(exception.InvalidGroupTargetException,
762 TopologyTemplate, tpl, None)
763 self.assertEqual(expectedmessage, err.__str__())
765 def _custom_types(self):
767 def_file = os.path.join(
768 os.path.dirname(os.path.abspath(__file__)),
769 "data/custom_types/wordpress.yaml")
770 custom_type = toscaparser.utils.yamlparser.load_yaml(def_file)
771 node_types = custom_type['node_types']
772 for name in node_types:
773 defintion = node_types[name]
774 custom_types[name] = defintion
777 def _single_node_template_content_test(self, tpl_snippet):
778 nodetemplates = (toscaparser.utils.yamlparser.
779 simple_ordered_parse(tpl_snippet))['node_templates']
780 name = list(nodetemplates.keys())[0]
781 nodetemplate = NodeTemplate(name, nodetemplates,
782 self._custom_types())
783 nodetemplate.validate()
784 nodetemplate.requirements
785 nodetemplate.get_capabilities_objects()
786 nodetemplate.get_properties_objects()
787 nodetemplate.interfaces
789 def test_node_templates(self):
806 expectedmessage = _('Template "server" is missing required field '
808 err = self.assertRaises(
809 exception.MissingRequiredFieldError,
810 lambda: self._single_node_template_content_test(tpl_snippet))
811 self.assertEqual(expectedmessage, err.__str__())
813 def test_node_template_with_wrong_properties_keyname(self):
814 """Node template keyname 'properties' given as 'propertiessss'."""
818 type: tosca.nodes.DBMS
823 expectedmessage = _('Node template "mysql_dbms" contains unknown '
824 'field "propertiessss". Refer to the definition '
825 'to verify valid values.')
826 err = self.assertRaises(
827 exception.UnknownFieldError,
828 lambda: self._single_node_template_content_test(tpl_snippet))
829 self.assertEqual(expectedmessage, err.__str__())
831 def test_node_template_with_wrong_requirements_keyname(self):
832 """Node template keyname 'requirements' given as 'requirement'."""
836 type: tosca.nodes.DBMS
843 expectedmessage = _('Node template "mysql_dbms" contains unknown '
844 'field "requirement". Refer to the definition to '
845 'verify valid values.')
846 err = self.assertRaises(
847 exception.UnknownFieldError,
848 lambda: self._single_node_template_content_test(tpl_snippet))
849 self.assertEqual(expectedmessage, err.__str__())
851 def test_node_template_with_wrong_interfaces_keyname(self):
852 """Node template keyname 'interfaces' given as 'interfac'."""
856 type: tosca.nodes.DBMS
864 configure: mysql_database_configure.sh
866 expectedmessage = _('Node template "mysql_dbms" contains unknown '
867 'field "interfac". Refer to the definition to '
868 'verify valid values.')
869 err = self.assertRaises(
870 exception.UnknownFieldError,
871 lambda: self._single_node_template_content_test(tpl_snippet))
872 self.assertEqual(expectedmessage, err.__str__())
874 def test_node_template_with_wrong_capabilities_keyname(self):
875 """Node template keyname 'capabilities' given as 'capabilitiis'."""
879 type: tosca.nodes.Database
881 db_name: { get_input: db_name }
882 db_user: { get_input: db_user }
883 db_password: { get_input: db_pwd }
887 port: { get_input: db_port }
889 expectedmessage = _('Node template "mysql_database" contains unknown '
890 'field "capabilitiis". Refer to the definition to '
891 'verify valid values.')
892 err = self.assertRaises(
893 exception.UnknownFieldError,
894 lambda: self._single_node_template_content_test(tpl_snippet))
895 self.assertEqual(expectedmessage, err.__str__())
897 def test_node_template_with_wrong_artifacts_keyname(self):
898 """Node template keyname 'artifacts' given as 'artifactsss'."""
902 type: tosca.nodes.Database
905 implementation: files/my_db_content.txt
906 type: tosca.artifacts.File
908 expectedmessage = _('Node template "mysql_database" contains unknown '
909 'field "artifactsss". Refer to the definition to '
910 'verify valid values.')
911 err = self.assertRaises(
912 exception.UnknownFieldError,
913 lambda: self._single_node_template_content_test(tpl_snippet))
914 self.assertEqual(expectedmessage, err.__str__())
916 def test_node_template_with_multiple_wrong_keynames(self):
917 """Node templates given with multiple wrong keynames."""
921 type: tosca.nodes.DBMS
929 configure: mysql_database_configure.sh
931 expectedmessage = _('Node template "mysql_dbms" contains unknown '
932 'field "propertieees". Refer to the definition to '
933 'verify valid values.')
934 err = self.assertRaises(
935 exception.UnknownFieldError,
936 lambda: self._single_node_template_content_test(tpl_snippet))
937 self.assertEqual(expectedmessage, err.__str__())
942 type: tosca.nodes.Database
944 name: { get_input: db_name }
945 user: { get_input: db_user }
946 password: { get_input: db_pwd }
950 port: { get_input: db_port }
956 configure: mysql_database_configure.sh
959 expectedmessage = _('Node template "mysql_database" contains unknown '
960 'field "capabilitiiiies". Refer to the definition '
961 'to verify valid values.')
962 err = self.assertRaises(
963 exception.UnknownFieldError,
964 lambda: self._single_node_template_content_test(tpl_snippet))
965 self.assertEqual(expectedmessage, err.__str__())
967 def test_node_template_type(self):
971 type: tosca.nodes.Databases
973 db_name: { get_input: db_name }
974 db_user: { get_input: db_user }
975 db_password: { get_input: db_pwd }
979 port: { get_input: db_port }
984 configure: mysql_database_configure.sh
986 expectedmessage = _('Type "tosca.nodes.Databases" is not '
988 err = self.assertRaises(
989 exception.InvalidTypeError,
990 lambda: self._single_node_template_content_test(tpl_snippet))
991 self.assertEqual(expectedmessage, err.__str__())
993 def test_node_template_requirements(self):
997 type: tosca.nodes.WebServer
1002 create: webserver_install.sh
1005 expectedmessage = _('"requirements" of template "webserver" must be '
1007 err = self.assertRaises(
1008 exception.TypeMismatchError,
1009 lambda: self._single_node_template_content_test(tpl_snippet))
1010 self.assertEqual(expectedmessage, err.__str__())
1015 type: tosca.nodes.Database
1017 db_name: { get_input: db_name }
1018 db_user: { get_input: db_user }
1019 db_password: { get_input: db_pwd }
1023 port: { get_input: db_port }
1026 - database_endpoint: mysql_database
1029 configure: mysql_database_configure.sh
1031 expectedmessage = _('"requirements" of template "mysql_database" '
1032 'contains unknown field "database_endpoint". '
1033 'Refer to the definition to verify valid values.')
1034 err = self.assertRaises(
1035 exception.UnknownFieldError,
1036 lambda: self._single_node_template_content_test(tpl_snippet))
1037 self.assertEqual(expectedmessage, err.__str__())
1039 def test_node_template_requirements_with_wrong_node_keyname(self):
1040 """Node template requirements keyname 'node' given as 'nodes'."""
1044 type: tosca.nodes.Database
1050 expectedmessage = _('"requirements" of template "mysql_database" '
1051 'contains unknown field "nodes". Refer to the '
1052 'definition to verify valid values.')
1053 err = self.assertRaises(
1054 exception.UnknownFieldError,
1055 lambda: self._single_node_template_content_test(tpl_snippet))
1056 self.assertEqual(expectedmessage, err.__str__())
1058 def test_node_template_requirements_with_wrong_capability_keyname(self):
1059 """Incorrect node template requirements keyname
1061 Node template requirements keyname 'capability' given as
1067 type: tosca.nodes.Database
1073 capabilityy: log_endpoint
1075 type: tosca.relationships.ConnectsTo
1078 expectedmessage = _('"requirements" of template "mysql_database" '
1079 'contains unknown field "capabilityy". Refer to '
1080 'the definition to verify valid values.')
1081 err = self.assertRaises(
1082 exception.UnknownFieldError,
1083 lambda: self._single_node_template_content_test(tpl_snippet))
1084 self.assertEqual(expectedmessage, err.__str__())
1086 def test_node_template_requirements_with_wrong_relationship_keyname(self):
1087 """Incorrect node template requirements keyname
1089 Node template requirements keyname 'relationship' given as
1095 type: tosca.nodes.Database
1101 capability: log_endpoint
1103 type: tosca.relationships.ConnectsTo
1106 expectedmessage = _('"requirements" of template "mysql_database" '
1107 'contains unknown field "relationshipppp". Refer '
1108 'to the definition to verify valid values.')
1109 err = self.assertRaises(
1110 exception.UnknownFieldError,
1111 lambda: self._single_node_template_content_test(tpl_snippet))
1112 self.assertEqual(expectedmessage, err.__str__())
1114 def test_node_template_requirements_with_wrong_occurrences_keyname(self):
1115 """Incorrect node template requirements keyname
1117 Node template requirements keyname 'occurrences' given as
1123 type: tosca.nodes.Database
1129 capability: log_endpoint
1131 type: tosca.relationships.ConnectsTo
1132 occurences: [0, UNBOUNDED]
1134 expectedmessage = _('"requirements" of template "mysql_database" '
1135 'contains unknown field "occurences". Refer to '
1136 'the definition to verify valid values.')
1137 err = self.assertRaises(
1138 exception.UnknownFieldError,
1139 lambda: self._single_node_template_content_test(tpl_snippet))
1140 self.assertEqual(expectedmessage, err.__str__())
1142 def test_node_template_requirements_with_multiple_wrong_keynames(self):
1143 """Node templates given with multiple wrong requirements keynames."""
1147 type: tosca.nodes.Database
1153 capabilit: log_endpoint
1155 type: tosca.relationships.ConnectsTo
1158 expectedmessage = _('"requirements" of template "mysql_database" '
1159 'contains unknown field "nod". Refer to the '
1160 'definition to verify valid values.')
1161 err = self.assertRaises(
1162 exception.UnknownFieldError,
1163 lambda: self._single_node_template_content_test(tpl_snippet))
1164 self.assertEqual(expectedmessage, err.__str__())
1169 type: tosca.nodes.Database
1175 capabilit: log_endpoint
1177 type: tosca.relationships.ConnectsTo
1180 expectedmessage = _('"requirements" of template "mysql_database" '
1181 'contains unknown field "capabilit". Refer to the '
1182 'definition to verify valid values.')
1183 err = self.assertRaises(
1184 exception.UnknownFieldError,
1185 lambda: self._single_node_template_content_test(tpl_snippet))
1186 self.assertEqual(expectedmessage, err.__str__())
1188 def test_node_template_requirements_invalid_occurrences(self):
1192 type: tosca.nodes.Compute
1195 capability: log_endpoint
1196 occurrences: [0, -1]
1198 expectedmessage = _('Value of property "[0, -1]" is invalid.')
1199 err = self.assertRaises(
1200 exception.InvalidPropertyValueError,
1201 lambda: self._single_node_template_content_test(tpl_snippet))
1202 self.assertEqual(expectedmessage, err.__str__())
1207 type: tosca.nodes.Compute
1210 capability: log_endpoint
1213 expectedmessage = _('"a" is not an integer.')
1214 err = self.assertRaises(
1216 lambda: self._single_node_template_content_test(tpl_snippet))
1217 self.assertEqual(expectedmessage, err.__str__())
1222 type: tosca.nodes.Compute
1225 capability: log_endpoint
1228 expectedmessage = _('"-1" is not a list.')
1229 err = self.assertRaises(
1231 lambda: self._single_node_template_content_test(tpl_snippet))
1232 self.assertEqual(expectedmessage, err.__str__())
1237 type: tosca.nodes.Compute
1240 capability: log_endpoint
1243 expectedmessage = _('Value of property "[5, 1]" is invalid.')
1244 err = self.assertRaises(
1245 exception.InvalidPropertyValueError,
1246 lambda: self._single_node_template_content_test(tpl_snippet))
1247 self.assertEqual(expectedmessage, err.__str__())
1252 type: tosca.nodes.Compute
1255 capability: log_endpoint
1258 expectedmessage = _('Value of property "[0, 0]" is invalid.')
1259 err = self.assertRaises(
1260 exception.InvalidPropertyValueError,
1261 lambda: self._single_node_template_content_test(tpl_snippet))
1262 self.assertEqual(expectedmessage, err.__str__())
1264 def test_node_template_requirements_valid_occurrences(self):
1268 type: tosca.nodes.Compute
1271 capability: log_endpoint
1274 self._single_node_template_content_test(tpl_snippet)
1276 def test_node_template_capabilities(self):
1280 type: tosca.nodes.Database
1282 db_name: { get_input: db_name }
1283 db_user: { get_input: db_user }
1284 db_password: { get_input: db_pwd }
1288 port: { get_input: db_port }
1293 configure: mysql_database_configure.sh
1295 expectedmessage = _('"capabilities" of template "mysql_database" '
1296 'contains unknown field "http_endpoint". Refer to '
1297 'the definition to verify valid values.')
1298 err = self.assertRaises(
1299 exception.UnknownFieldError,
1300 lambda: self._single_node_template_content_test(tpl_snippet))
1301 self.assertEqual(expectedmessage, err.__str__())
1303 def test_node_template_properties(self):
1307 type: tosca.nodes.Compute
1309 os_image: F18_x86_64
1314 num_cpus: { get_input: cpus }
1318 architecture: x86_64
1320 distribution: Fedora
1323 expectedmessage = _('"properties" of template "server" contains '
1324 'unknown field "os_image". Refer to the '
1325 'definition to verify valid values.')
1326 err = self.assertRaises(
1327 exception.UnknownFieldError,
1328 lambda: self._single_node_template_content_test(tpl_snippet))
1329 self.assertEqual(expectedmessage, err.__str__())
1331 def test_node_template_interfaces(self):
1335 type: tosca.nodes.WebApplication.WordPress
1338 - database_endpoint: mysql_database
1341 create: wordpress_install.sh
1343 implementation: wordpress_configure.sh
1345 wp_db_name: { get_property: [ mysql_database, db_name ] }
1346 wp_db_user: { get_property: [ mysql_database, db_user ] }
1347 wp_db_password: { get_property: [ mysql_database, \
1349 wp_db_port: { get_property: [ SELF, \
1350 database_endpoint, port ] }
1352 expectedmessage = _('"interfaces" of template "wordpress" contains '
1353 'unknown field "Standards". Refer to the '
1354 'definition to verify valid values.')
1355 err = self.assertRaises(
1356 exception.UnknownFieldError,
1357 lambda: self._single_node_template_content_test(tpl_snippet))
1358 self.assertEqual(expectedmessage, err.__str__())
1363 type: tosca.nodes.WebApplication.WordPress
1366 - database_endpoint: mysql_database
1369 create: wordpress_install.sh
1371 implementation: wordpress_configure.sh
1373 wp_db_name: { get_property: [ mysql_database, db_name ] }
1374 wp_db_user: { get_property: [ mysql_database, db_user ] }
1375 wp_db_password: { get_property: [ mysql_database, \
1377 wp_db_port: { get_property: [ SELF, \
1378 database_endpoint, port ] }
1380 expectedmessage = _('"interfaces" of template "wordpress" contains '
1381 'unknown field "config". Refer to the definition '
1382 'to verify valid values.')
1383 err = self.assertRaises(
1384 exception.UnknownFieldError,
1385 lambda: self._single_node_template_content_test(tpl_snippet))
1386 self.assertEqual(expectedmessage, err.__str__())
1391 type: tosca.nodes.WebApplication.WordPress
1394 - database_endpoint: mysql_database
1397 create: wordpress_install.sh
1399 implementation: wordpress_configure.sh
1401 wp_db_name: { get_property: [ mysql_database, db_name ] }
1402 wp_db_user: { get_property: [ mysql_database, db_user ] }
1403 wp_db_password: { get_property: [ mysql_database, \
1405 wp_db_port: { get_ref_property: [ database_endpoint, \
1406 database_endpoint, port ] }
1408 expectedmessage = _('"interfaces" of template "wordpress" contains '
1409 'unknown field "input". Refer to the definition '
1410 'to verify valid values.')
1411 err = self.assertRaises(
1412 exception.UnknownFieldError,
1413 lambda: self._single_node_template_content_test(tpl_snippet))
1414 self.assertEqual(expectedmessage, err.__str__())
1416 def test_relationship_template_properties(self):
1418 relationship_templates:
1424 expectedmessage = _('"properties" of template "storage_attachto" is '
1425 'missing required field "[\'location\']".')
1426 rel_template = (toscaparser.utils.yamlparser.
1427 simple_parse(tpl_snippet))['relationship_templates']
1428 name = list(rel_template.keys())[0]
1429 rel_template = RelationshipTemplate(rel_template[name], name)
1430 err = self.assertRaises(exception.MissingRequiredFieldError,
1431 rel_template.validate)
1432 self.assertEqual(expectedmessage, six.text_type(err))
1434 def test_invalid_template_version(self):
1435 tosca_tpl = os.path.join(
1436 os.path.dirname(os.path.abspath(__file__)),
1437 "data/test_invalid_template_version.yaml")
1438 self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl)
1439 valid_versions = ', '.join(ToscaTemplate.VALID_TEMPLATE_VERSIONS)
1440 exception.ExceptionCollector.assertExceptionMessage(
1441 exception.InvalidTemplateVersion,
1442 (_('The template version "tosca_xyz" is invalid. Valid versions '
1443 'are "%s".') % valid_versions))
1445 def test_import_invalid_type(self):
1446 tosca_tpl = os.path.join(
1447 os.path.dirname(os.path.abspath(__file__)),
1448 "data/test_import_invalid_type.yaml")
1449 self.assertRaises(exception.ValidationError, ToscaTemplate, tosca_tpl)
1450 exception.ExceptionCollector.assertExceptionMessage(
1451 exception.UnknownFieldError,
1452 (_("Template {'invalid': 'custom_types/invalid_type.yaml'} "
1453 'contains unknown field "annotation_types". Refer to the '
1454 'definition to verify valid values.')))
1456 def test_node_template_capabilities_properties(self):
1457 # validating capability property values
1461 type: tosca.nodes.WebServer
1467 expectedmessage = _('The value "test" of property "initiator" is '
1468 'not valid. Expected a value from "[source, '
1471 err = self.assertRaises(
1472 exception.ValidationError,
1473 lambda: self._single_node_template_content_test(tpl_snippet))
1474 self.assertEqual(expectedmessage, err.__str__())
1479 type: tosca.nodes.Compute
1484 num_cpus: { get_input: cpus }
1488 architecture: x86_64
1490 distribution: Fedora
1496 default_instances: 5
1498 expectedmessage = _('"properties" of template "server": '
1499 '"default_instances" value is not between '
1500 '"min_instances" and "max_instances".')
1501 err = self.assertRaises(
1502 exception.ValidationError,
1503 lambda: self._single_node_template_content_test(tpl_snippet))
1504 self.assertEqual(expectedmessage, err.__str__())
1506 def test_node_template_objectstorage_without_required_property(self):
1510 type: tosca.nodes.ObjectStorage
1514 expectedmessage = _('"properties" of template "server" is missing '
1515 'required field "[\'name\']".')
1516 err = self.assertRaises(
1517 exception.MissingRequiredFieldError,
1518 lambda: self._single_node_template_content_test(tpl_snippet))
1519 self.assertEqual(expectedmessage, err.__str__())
1521 def test_node_template_objectstorage_with_invalid_scalar_unit(self):
1525 type: tosca.nodes.ObjectStorage
1530 expectedmessage = _('"-1" is not a valid scalar-unit.')
1531 err = self.assertRaises(
1533 lambda: self._single_node_template_content_test(tpl_snippet))
1534 self.assertEqual(expectedmessage, err.__str__())
1536 def test_node_template_objectstorage_with_invalid_scalar_type(self):
1540 type: tosca.nodes.ObjectStorage
1545 expectedmessage = _('"1 XB" is not a valid scalar-unit.')
1546 err = self.assertRaises(
1548 lambda: self._single_node_template_content_test(tpl_snippet))
1549 self.assertEqual(expectedmessage, err.__str__())
1551 def test_special_keywords(self):
1552 """Test special keywords
1554 Test that special keywords, e.g. metadata, which are not part
1555 of specification do not throw any validation error.
1557 tpl_snippet_metadata_map = '''
1560 type: tosca.nodes.Compute
1565 self._single_node_template_content_test(tpl_snippet_metadata_map)
1567 tpl_snippet_metadata_inline = '''
1570 type: tosca.nodes.Compute
1573 self._single_node_template_content_test(tpl_snippet_metadata_inline)
1575 def test_policy_valid_keynames(self):
1578 - servers_placement:
1579 type: tosca.policies.Placement
1580 description: Apply placement policy to servers
1581 metadata: { user1: 1001, user2: 1002 }
1582 targets: [ serv1, serv2 ]
1584 policies = (toscaparser.utils.yamlparser.
1585 simple_parse(tpl_snippet))['policies'][0]
1586 name = list(policies.keys())[0]
1587 Policy(name, policies[name], None, None)
1589 def test_policy_invalid_keyname(self):
1592 - servers_placement:
1593 type: tosca.policies.Placement
1596 policies = (toscaparser.utils.yamlparser.
1597 simple_parse(tpl_snippet))['policies'][0]
1598 name = list(policies.keys())[0]
1600 expectedmessage = _('Policy "servers_placement" contains '
1601 'unknown field "testkey". Refer to the '
1602 'definition to verify valid values.')
1603 err = self.assertRaises(
1604 exception.UnknownFieldError,
1605 lambda: Policy(name, policies[name], None, None))
1606 self.assertEqual(expectedmessage, err.__str__())
1608 def test_policy_trigger_valid_keyname_senlin_resources(self):
1612 description: trigger
1613 event_type: tosca.events.resource.utilization
1615 start_time: "2015-05-07T07:00:00Z"
1616 end_time: "2015-06-07T07:00:00Z"
1618 node: master-container
1620 capability: Container
1622 constraint: { greater_than: 50 }
1627 resize: # Operation name
1629 strategy: LEAST_USED
1630 implementation: Senlin.webhook()
1632 triggers = (toscaparser.utils.yamlparser.
1633 simple_parse(tpl_snippet))['triggers'][0]
1634 name = list(triggers.keys())[0]
1635 Triggers(name, triggers[name])
1637 def test_policy_trigger_valid_keyname_heat_resources(self):
1641 description: trigger
1642 meter_name: cpu_util
1644 constraint: utilization greater_than 60%
1649 comparison_operator: gt
1653 triggers = (toscaparser.utils.yamlparser.
1654 simple_parse(tpl_snippet))['triggers'][0]
1655 name = list(triggers.keys())[0]
1656 Triggers(name, triggers[name])
1658 def test_policy_trigger_invalid_keyname_senlin_resources(self):
1662 description: trigger
1663 event_type: tosca.events.resource.utilization
1665 start_time: "2015-05-07T07:00:00Z"
1666 end_time: "2015-06-07T07:00:00Z"
1668 node: master-container
1670 capability: Container
1672 constraint: utilization greater_than 50%
1677 resize: # Operation name
1679 strategy: LEAST_USED
1680 implementation: Senlin.webhook()
1682 triggers = (toscaparser.utils.yamlparser.
1683 simple_parse(tpl_snippet))['triggers'][0]
1684 name = list(triggers.keys())[0]
1685 expectedmessage = _(
1686 'Triggers "resize_compute" contains unknown field '
1687 '"target_filter1". Refer to the definition '
1688 'to verify valid values.')
1689 err = self.assertRaises(
1690 exception.UnknownFieldError,
1691 lambda: Triggers(name, triggers[name]))
1692 self.assertEqual(expectedmessage, err.__str__())
1694 def test_policy_trigger_invalid_keyname_heat_resources(self):
1698 description: trigger
1699 meter_name: cpu_util
1701 constraint: utilization greater_than 60%
1706 comparison_operator: gt
1710 triggers = (toscaparser.utils.yamlparser.
1711 simple_parse(tpl_snippet))['triggers'][0]
1712 name = list(triggers.keys())[0]
1713 expectedmessage = _(
1714 'Triggers "high_cpu_usage" contains unknown field '
1715 '"metadata1". Refer to the definition '
1716 'to verify valid values.')
1717 err = self.assertRaises(
1718 exception.UnknownFieldError,
1719 lambda: Triggers(name, triggers[name]))
1720 self.assertEqual(expectedmessage, err.__str__())
1722 def test_policy_missing_required_keyname(self):
1725 - servers_placement:
1726 description: test description
1728 policies = (toscaparser.utils.yamlparser.
1729 simple_parse(tpl_snippet))['policies'][0]
1730 name = list(policies.keys())[0]
1732 expectedmessage = _('Template "servers_placement" is missing '
1733 'required field "type".')
1734 err = self.assertRaises(
1735 exception.MissingRequiredFieldError,
1736 lambda: Policy(name, policies[name], None, None))
1737 self.assertEqual(expectedmessage, err.__str__())
1739 def test_credential_datatype(self):
1740 tosca_tpl = os.path.join(
1741 os.path.dirname(os.path.abspath(__file__)),
1742 "data/test_credential_datatype.yaml")
1743 self.assertIsNotNone(ToscaTemplate(tosca_tpl))
1745 def test_invalid_default_value(self):
1746 tpl_path = os.path.join(
1747 os.path.dirname(os.path.abspath(__file__)),
1748 "data/test_invalid_input_defaults.yaml")
1749 self.assertRaises(exception.ValidationError, ToscaTemplate, tpl_path)
1750 exception.ExceptionCollector.assertExceptionMessage(
1751 ValueError, _('"two" is not an integer.'))
1753 def test_invalid_capability(self):
1757 type: tosca.nodes.Compute
1761 architecture: x86_64
1763 tpl = (toscaparser.utils.yamlparser.simple_parse(tpl_snippet))
1764 err = self.assertRaises(exception.UnknownFieldError,
1765 TopologyTemplate, tpl, None)
1766 expectedmessage = _('"capabilities" of template "server" contains '
1767 'unknown field "oss". Refer to the definition '
1768 'to verify valid values.')
1769 self.assertEqual(expectedmessage, err.__str__())
1771 def test_qualified_name(self):
1772 tpl_snippet_full_name = '''
1775 type: tosca.nodes.Compute
1778 toscaparser.utils.yamlparser.simple_parse(
1779 tpl_snippet_full_name))
1780 TopologyTemplate(tpl, None)
1782 tpl_snippet_short_name = '''
1788 toscaparser.utils.yamlparser.simple_parse(
1789 tpl_snippet_short_name))
1790 TopologyTemplate(tpl, None)
1792 tpl_snippet_qualified_name = '''
1798 toscaparser.utils.yamlparser.simple_parse(
1799 tpl_snippet_qualified_name))
1800 TopologyTemplate(tpl, None)
1802 def test_requirements_as_list(self):
1803 """Node template with requirements provided with or without list
1805 Node template requirements are required to be provided as list.
1808 expectedmessage = _('"requirements" of template "my_webserver"'
1809 ' must be of type "list".')
1811 # requirements provided as dictionary
1815 type: tosca.nodes.WebServer
1819 type: tosca.nodes.Compute
1821 err1 = self.assertRaises(
1822 exception.TypeMismatchError,
1823 lambda: self._single_node_template_content_test(tpl_snippet1))
1824 self.assertEqual(expectedmessage, err1.__str__())
1826 # requirements provided as string
1830 type: tosca.nodes.WebServer
1831 requirements: server
1833 type: tosca.nodes.Compute
1835 err2 = self.assertRaises(
1836 exception.TypeMismatchError,
1837 lambda: self._single_node_template_content_test(tpl_snippet2))
1838 self.assertEqual(expectedmessage, err2.__str__())
1840 # requirements provided as list
1844 type: tosca.nodes.WebServer
1848 type: tosca.nodes.Compute
1851 self._single_node_template_content_test(tpl_snippet3))
1853 def test_properties_override_with_flavor_and_image(self):
1854 tpl_path = os.path.join(
1855 os.path.dirname(os.path.abspath(__file__)),
1856 "data/test_normative_type_properties_override.yaml")
1857 self.assertIsNotNone(ToscaTemplate(tpl_path))