From f416d7ba961edddfd956b556ed6566bf48824bf5 Mon Sep 17 00:00:00 2001 From: shangxdy Date: Fri, 1 Sep 2017 15:16:00 +0800 Subject: Support version of tosca_simple_yaml_1_1 Currently tosca-parser only support tosca_version_1_0, this patch will enable it to support tosca_version_1_1. This requirement is from ONAP, but not need to submit to OpenStack currently JIRA:PARSER-146 Change-Id: If1bc470e3f2d18a606b312425241f27be33b65b4 Signed-off-by: shangxdy --- .../toscaparser/elements/tosca_type_validation.py | 3 ++- .../data/tosca_helloworld_with_version_1_1.yaml | 23 ++++++++++++++++++++++ .../toscaparser/tests/test_toscatpl.py | 11 +++++++++++ .../toscaparser/tests/test_toscatplvalidation.py | 1 + .../tosca-parser/toscaparser/tosca_template.py | 9 ++++++--- 5 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 tosca2heat/tosca-parser/toscaparser/tests/data/tosca_helloworld_with_version_1_1.yaml diff --git a/tosca2heat/tosca-parser/toscaparser/elements/tosca_type_validation.py b/tosca2heat/tosca-parser/toscaparser/elements/tosca_type_validation.py index 45b924b..89a6a03 100644 --- a/tosca2heat/tosca-parser/toscaparser/elements/tosca_type_validation.py +++ b/tosca2heat/tosca-parser/toscaparser/elements/tosca_type_validation.py @@ -29,7 +29,8 @@ class TypeValidation(object): 'data_types', 'artifact_types', 'group_types', 'relationship_types', 'capability_types', 'interface_types', 'policy_types', 'topology_template', 'metadata') - VALID_TEMPLATE_VERSIONS = ['tosca_simple_yaml_1_0'] + VALID_TEMPLATE_VERSIONS = ['tosca_simple_yaml_1_0', + 'tosca_simple_yaml_1_1'] exttools = ExtTools() VALID_TEMPLATE_VERSIONS.extend(exttools.get_versions()) diff --git a/tosca2heat/tosca-parser/toscaparser/tests/data/tosca_helloworld_with_version_1_1.yaml b/tosca2heat/tosca-parser/toscaparser/tests/data/tosca_helloworld_with_version_1_1.yaml new file mode 100644 index 0000000..eeb5f7b --- /dev/null +++ b/tosca2heat/tosca-parser/toscaparser/tests/data/tosca_helloworld_with_version_1_1.yaml @@ -0,0 +1,23 @@ +tosca_definitions_version: tosca_simple_yaml_1_1 + +description: Template for deploying a single server with predefined properties. + +topology_template: + node_templates: + my_server: + type: tosca.nodes.Compute + capabilities: + # Host container properties + host: + properties: + num_cpus: 2 + disk_size: 10 GB + mem_size: 512 MB + # Guest Operating System properties + os: + properties: + # host Operating System image properties + architecture: x86_64 + type: Linux + distribution: RHEL + version: 6.5 diff --git a/tosca2heat/tosca-parser/toscaparser/tests/test_toscatpl.py b/tosca2heat/tosca-parser/toscaparser/tests/test_toscatpl.py index 69dfb46..fd8ee90 100644 --- a/tosca2heat/tosca-parser/toscaparser/tests/test_toscatpl.py +++ b/tosca2heat/tosca-parser/toscaparser/tests/test_toscatpl.py @@ -666,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__)), diff --git a/tosca2heat/tosca-parser/toscaparser/tests/test_toscatplvalidation.py b/tosca2heat/tosca-parser/toscaparser/tests/test_toscatplvalidation.py index 2048a83..a8b1590 100644 --- a/tosca2heat/tosca-parser/toscaparser/tests/test_toscatplvalidation.py +++ b/tosca2heat/tosca-parser/toscaparser/tests/test_toscatplvalidation.py @@ -101,6 +101,7 @@ class ToscaTemplateValidationTest(TestCase): _('The template version "tosca_simple_yaml_1_10 in ' 'custom_types/imported_sample.yaml" is invalid. ' 'Valid versions are "tosca_simple_yaml_1_0, ' + 'tosca_simple_yaml_1_1, ' 'tosca_simple_profile_for_nfv_1_0_0".')) exception.ExceptionCollector.assertExceptionMessage( exception.UnknownFieldError, diff --git a/tosca2heat/tosca-parser/toscaparser/tosca_template.py b/tosca2heat/tosca-parser/toscaparser/tosca_template.py index 3301999..ac534dc 100644 --- a/tosca2heat/tosca-parser/toscaparser/tosca_template.py +++ b/tosca2heat/tosca-parser/toscaparser/tosca_template.py @@ -56,11 +56,13 @@ YAML_LOADER = toscaparser.utils.yamlparser.load_yaml class ToscaTemplate(object): exttools = ExtTools() - VALID_TEMPLATE_VERSIONS = ['tosca_simple_yaml_1_0'] + VALID_TEMPLATE_VERSIONS = ['tosca_simple_yaml_1_0', + 'tosca_simple_yaml_1_1'] VALID_TEMPLATE_VERSIONS.extend(exttools.get_versions()) - ADDITIONAL_SECTIONS = {'tosca_simple_yaml_1_0': SPECIAL_SECTIONS} + ADDITIONAL_SECTIONS = {'tosca_simple_yaml_1_0': SPECIAL_SECTIONS, + 'tosca_simple_yaml_1_1': SPECIAL_SECTIONS} ADDITIONAL_SECTIONS.update(exttools.get_sections()) @@ -272,7 +274,8 @@ class ToscaTemplate(object): what=version, valid_versions=', '. join(self.VALID_TEMPLATE_VERSIONS))) else: - if version != 'tosca_simple_yaml_1_0': + if (version != 'tosca_simple_yaml_1_0' and + version != 'tosca_simple_yaml_1_1'): update_definitions(version) def _get_path(self, path): -- cgit 1.2.3-korg