X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=tosca2heat%2Ftosca-parser%2Ftoscaparser%2Ftests%2Ftest_toscatpl.py;h=fd8ee90dc44afb48796cb16b939a08e5d947a5ea;hb=f416d7ba961edddfd956b556ed6566bf48824bf5;hp=e229d2faba763e99607d66ff49c3b3b3519b1c63;hpb=f52871b8f5ed66924ae8c715788d0bc09c1518ac;p=parser.git diff --git a/tosca2heat/tosca-parser/toscaparser/tests/test_toscatpl.py b/tosca2heat/tosca-parser/toscaparser/tests/test_toscatpl.py index e229d2f..fd8ee90 100644 --- a/tosca2heat/tosca-parser/toscaparser/tests/test_toscatpl.py +++ b/tosca2heat/tosca-parser/toscaparser/tests/test_toscatpl.py @@ -30,13 +30,15 @@ class ToscaTemplateTest(TestCase): tosca_tpl = os.path.join( os.path.dirname(os.path.abspath(__file__)), "data/tosca_single_instance_wordpress.yaml") - tosca = ToscaTemplate(tosca_tpl) + params = {'db_name': 'my_wordpress', 'db_user': 'my_db_user', + 'db_root_pwd': '12345678'} + tosca = ToscaTemplate(tosca_tpl, parsed_params=params) tosca_elk_tpl = os.path.join( os.path.dirname(os.path.abspath(__file__)), "data/tosca_elk.yaml") tosca_repo_tpl = os.path.join( os.path.dirname(os.path.abspath(__file__)), - "data/tosca_repositories_test_definition.yaml") + "data/repositories/tosca_repositories_test_definition.yaml") def test_version(self): self.assertEqual(self.tosca.version, "tosca_simple_yaml_1_0") @@ -145,8 +147,6 @@ class ToscaTemplateTest(TestCase): wordpress_node.is_derived_from("tosca.nodes.Root")) self.assertFalse( wordpress_node.is_derived_from("tosca.policies.Root")) - self.assertFalse( - wordpress_node.is_derived_from("tosca.groups.Root")) def test_outputs(self): self.assertEqual( @@ -174,14 +174,14 @@ class ToscaTemplateTest(TestCase): self.assertEqual(3, len(interface.inputs)) TestCase.skip(self, 'bug #1440247') wp_db_port = interface.inputs['wp_db_port'] - self.assertTrue(isinstance(wp_db_port, GetProperty)) + self.assertIsInstance(wp_db_port, GetProperty) self.assertEqual('get_property', wp_db_port.name) self.assertEqual(['SELF', 'database_endpoint', 'port'], wp_db_port.args) result = wp_db_port.result() - self.assertTrue(isinstance(result, GetInput)) + self.assertIsInstance(result, GetInput) else: raise AssertionError( 'Unexpected interface: {0}'.format(interface.name)) @@ -200,6 +200,7 @@ class ToscaTemplateTest(TestCase): compute_type = NodeType(tpl.type) self.assertEqual( sorted(['tosca.capabilities.Container', + 'tosca.capabilities.Endpoint.Admin', 'tosca.capabilities.Node', 'tosca.capabilities.OperatingSystem', 'tosca.capabilities.network.Bindable', @@ -215,6 +216,10 @@ class ToscaTemplateTest(TestCase): tosca_tpl = self._load_template('test_no_outputs_in_template.yaml') self.assertEqual(0, len(tosca_tpl.outputs)) + def test_template_file_with_suffix_yml(self): + tosca_tpl = self._load_template('custom_types/wordpress.yml') + self.assertIsNotNone(tosca_tpl) + def test_relationship_interface(self): template = ToscaTemplate(self.tosca_elk_tpl) for node_tpl in template.nodetemplates: @@ -286,7 +291,7 @@ class ToscaTemplateTest(TestCase): """ tosca_tpl = os.path.join( os.path.dirname(os.path.abspath(__file__)), - "data/test_requirements.yaml") + "data/requirements/test_requirements.yaml") tosca = ToscaTemplate(tosca_tpl) for node_tpl in tosca.nodetemplates: if node_tpl.name == 'my_app': @@ -438,14 +443,17 @@ class ToscaTemplateTest(TestCase): tosca_tpl = os.path.join( os.path.dirname(os.path.abspath(__file__)), "data/tosca_single_instance_wordpress.yaml") - tosca = ToscaTemplate(tosca_tpl) + params = {'db_name': 'my_wordpress', 'db_user': 'my_db_user', + 'db_root_pwd': '12345678'} + tosca = ToscaTemplate(tosca_tpl, parsed_params=params) self.assertTrue(tosca.topology_template.custom_defs) def test_local_template_with_url_import(self): tosca_tpl = os.path.join( os.path.dirname(os.path.abspath(__file__)), "data/tosca_single_instance_wordpress_with_url_import.yaml") - tosca = ToscaTemplate(tosca_tpl) + tosca = ToscaTemplate(tosca_tpl, + parsed_params={'db_root_pwd': '123456'}) self.assertTrue(tosca.topology_template.custom_defs) def test_url_template_with_local_relpath_import(self): @@ -506,7 +514,8 @@ class ToscaTemplateTest(TestCase): os.path.dirname(os.path.abspath(__file__)), "data/test_instance_nested_imports.yaml") tosca = ToscaTemplate(tosca_tpl) - expected_custom_types = ['tosca.nodes.WebApplication.WordPress', + expected_custom_types = ['tosca.nodes.SoftwareComponent.Kibana', + 'tosca.nodes.WebApplication.WordPress', 'test_namespace_prefix.Rsyslog', 'Test2ndRsyslogType', 'test_2nd_namespace_prefix.Rsyslog', @@ -567,7 +576,8 @@ class ToscaTemplateTest(TestCase): exception.ExceptionCollector.assertExceptionMessage( exception.UnknownFieldError, err7_msg) - err8_msg = _('\'Node template "server1" was not found.\'') + err8_msg = _('\'Node template "server1" was not found in ' + '"webserver".\'') exception.ExceptionCollector.assertExceptionMessage( KeyError, err8_msg) @@ -576,6 +586,10 @@ class ToscaTemplateTest(TestCase): exception.ExceptionCollector.assertExceptionMessage( exception.MissingRequiredFieldError, err9_msg) + err10_msg = _('Type "tosca.nodes.XYZ" is not a valid type.') + exception.ExceptionCollector.assertExceptionMessage( + exception.InvalidTypeError, err10_msg) + def test_invalid_section_names(self): tosca_tpl = os.path.join( os.path.dirname(os.path.abspath(__file__)), @@ -652,6 +666,17 @@ class ToscaTemplateTest(TestCase): self.assertEqual(tosca.version, "tosca_simple_yaml_1_0") + def test_yaml_dict_tpl_with_version_1_1(self): + test_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/tosca_helloworld_with_version_1_1.yaml") + + yaml_dict_tpl = toscaparser.utils.yamlparser.load_yaml(test_tpl) + + tosca = ToscaTemplate(yaml_dict_tpl=yaml_dict_tpl) + + self.assertEqual(tosca.version, "tosca_simple_yaml_1_1") + def test_yaml_dict_tpl_with_params_and_url_import(self): test_tpl = os.path.join( os.path.dirname(os.path.abspath(__file__)), @@ -673,9 +698,10 @@ class ToscaTemplateTest(TestCase): "data/tosca_single_instance_wordpress.yaml") yaml_dict_tpl = toscaparser.utils.yamlparser.load_yaml(test_tpl) - + params = {'db_name': 'my_wordpress', 'db_user': 'my_db_user', + 'db_root_pwd': '12345678'} self.assertRaises(exception.ValidationError, ToscaTemplate, None, - None, False, yaml_dict_tpl) + params, False, yaml_dict_tpl) err_msg = (_('Relative file name "custom_types/wordpress.yaml" ' 'cannot be used in a pre-parsed input template.')) exception.ExceptionCollector.assertExceptionMessage(ImportError, @@ -706,6 +732,8 @@ class ToscaTemplateTest(TestCase): tosca = ToscaTemplate(tosca_tpl) for policy in tosca.topology_template.policies: + self.assertTrue( + policy.is_derived_from("tosca.policies.Root")) if policy.name == 'my_compute_placement_policy': self.assertEqual('tosca.policies.Placement', policy.type) self.assertEqual(['my_server_1', 'my_server_2'], @@ -726,6 +754,8 @@ class ToscaTemplateTest(TestCase): tosca = ToscaTemplate(tosca_tpl) for policy in tosca.topology_template.policies: + self.assertTrue( + policy.is_derived_from("tosca.policies.Root")) if policy.name == 'my_groups_placement': self.assertEqual('mycompany.mytypes.myScalingPolicy', policy.type) @@ -743,7 +773,7 @@ class ToscaTemplateTest(TestCase): def test_node_filter(self): tosca_tpl = os.path.join( os.path.dirname(os.path.abspath(__file__)), - "data/test_node_filter.yaml") + "data/node_filter/test_node_filter.yaml") ToscaTemplate(tosca_tpl) def test_attributes_inheritance(self): @@ -755,7 +785,7 @@ class ToscaTemplateTest(TestCase): def test_repositories_definition(self): tosca_tpl = os.path.join( os.path.dirname(os.path.abspath(__file__)), - "data/test_repositories_definition.yaml") + "data/repositories/test_repositories_definition.yaml") ToscaTemplate(tosca_tpl) def test_custom_caps_def(self): @@ -815,5 +845,26 @@ class ToscaTemplateTest(TestCase): def test_containers(self): tosca_tpl = os.path.join( os.path.dirname(os.path.abspath(__file__)), - "data/test_containers.yaml") + "data/containers/test_container_docker_mysql.yaml") ToscaTemplate(tosca_tpl, parsed_params={"mysql_root_pwd": "12345678"}) + + def test_endpoint_on_compute(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/test_endpoint_on_compute.yaml") + ToscaTemplate(tosca_tpl) + + def test_nested_dsl_def(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/dsl_definitions/test_nested_dsl_def.yaml") + self.assertIsNotNone(ToscaTemplate(tosca_tpl)) + + def test_multiple_policies(self): + tosca_tpl = os.path.join( + os.path.dirname(os.path.abspath(__file__)), + "data/policies/test_tosca_nfv_multiple_policies.yaml") + tosca = ToscaTemplate(tosca_tpl) + self.assertEqual( + ['ALRM1', 'SP1', 'SP2'], + sorted([policy.name for policy in tosca.policies]))