From 47df1d6a2eee8d88c4d8819ed0e8e982275b874e Mon Sep 17 00:00:00 2001 From: Trinh Nguyen Date: Wed, 7 Mar 2018 01:22:10 +0900 Subject: [PATCH] Fix heat translator bug due to nested_resource_name This patch fix these: - If nested_resource_name is 'SP1_res.yaml' it will create a loop in heat translator and vnf creation will fail. This is a bug of heat translator and this patch is to bypass the loop hole by using a different name than 'SP1_res.yaml'. - Incorrect syntax: ... translate_to_yaml_files_dict() takes exactly 2 arguments (3 given) ... Co-Authored-By: Cong Phuoc Hoang Co-Authored-By: yong sheng gong Co-Authored-By: Trinh Nguyen Change-Id: I60dc0a6d443598264c29fde8a3959d4bd7fba904 Closes-bug: #1753645 --- .../openstack/data/hot_alarm_scale_custom.yaml | 2 +- .../openstack/data/hot_scale_custom.yaml | 2 +- .../vnfm/infra_drivers/openstack/test_openstack.py | 3 --- tacker/tosca/utils.py | 14 ++++++++++++-- .../infra_drivers/openstack/translate_template.py | 8 ++++---- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/tacker/tests/unit/vnfm/infra_drivers/openstack/data/hot_alarm_scale_custom.yaml b/tacker/tests/unit/vnfm/infra_drivers/openstack/data/hot_alarm_scale_custom.yaml index c3e1fa98b..1ef6252bf 100644 --- a/tacker/tests/unit/vnfm/infra_drivers/openstack/data/hot_alarm_scale_custom.yaml +++ b/tacker/tests/unit/vnfm/infra_drivers/openstack/data/hot_alarm_scale_custom.yaml @@ -23,4 +23,4 @@ resources: network: net_mgmt port_security_enabled: false heat_template_version: 2013-05-23 -description: Tacker Scaling template \ No newline at end of file +description: Tacker Scaling template diff --git a/tacker/tests/unit/vnfm/infra_drivers/openstack/data/hot_scale_custom.yaml b/tacker/tests/unit/vnfm/infra_drivers/openstack/data/hot_scale_custom.yaml index cb4198c4b..f51f4e467 100644 --- a/tacker/tests/unit/vnfm/infra_drivers/openstack/data/hot_scale_custom.yaml +++ b/tacker/tests/unit/vnfm/infra_drivers/openstack/data/hot_scale_custom.yaml @@ -22,4 +22,4 @@ resources: network: net_mgmt port_security_enabled: false heat_template_version: 2013-05-23 -description: Tacker Scaling template \ No newline at end of file +description: Tacker Scaling template diff --git a/tacker/tests/unit/vnfm/infra_drivers/openstack/test_openstack.py b/tacker/tests/unit/vnfm/infra_drivers/openstack/test_openstack.py index ae0ea2fcd..9f5d8804a 100644 --- a/tacker/tests/unit/vnfm/infra_drivers/openstack/test_openstack.py +++ b/tacker/tests/unit/vnfm/infra_drivers/openstack/test_openstack.py @@ -17,7 +17,6 @@ import codecs import json import mock import os -import unittest import yaml from tacker import context @@ -393,7 +392,6 @@ class TestOpenStack(base.TestCase): input_params ) - @unittest.skip("Skip and wait for releasing Heat Translator") def test_create_tosca_scale(self): self._test_assert_equal_for_tosca_templates( 'tosca_scale.yaml', @@ -435,7 +433,6 @@ class TestOpenStack(base.TestCase): is_monitor=False ) - @unittest.skip("Skip and wait for releasing Heat Translator") def test_create_tosca_alarm_scale(self): self._test_assert_equal_for_tosca_templates( 'tosca_alarm_scale.yaml', diff --git a/tacker/tosca/utils.py b/tacker/tosca/utils.py index fdaea593d..2893744d0 100644 --- a/tacker/tosca/utils.py +++ b/tacker/tosca/utils.py @@ -19,6 +19,7 @@ import yaml from collections import OrderedDict from oslo_log import log as logging +from oslo_utils import uuidutils from tacker.common import log from tacker.common import utils from tacker.extensions import vnfm @@ -668,6 +669,14 @@ def get_nested_resources_name(template): return nested_resource_name +def get_sub_heat_tmpl_name(template): + for policy in template.policies: + if (policy.type_definition.is_derived_from(SCALING)): + sub_heat_tmpl_name = policy.name + '_' + \ + uuidutils.generate_uuid() + '_res.yaml' + return sub_heat_tmpl_name + + def update_nested_scaling_resources(nested_resources, mgmt_ports, metadata, res_tpl, unsupported_res_prop=None): nested_tpl = dict() @@ -678,8 +687,9 @@ def update_nested_scaling_resources(nested_resources, mgmt_ports, metadata, yamlparser.simple_ordered_parse(nested_resources_yaml) if metadata: for vdu_name, metadata_dict in metadata['vdus'].items(): - nested_resources_dict['resources'][vdu_name]['properties']['metadata'] = \ - metadata_dict + if nested_resources_dict['resources'].get(vdu_name): + nested_resources_dict['resources'][vdu_name]['properties']['metadata'] = \ + metadata_dict add_resources_tpl(nested_resources_dict, res_tpl) for res in nested_resources_dict["resources"].values(): if not res['type'] == HEAT_SOFTWARE_CONFIG: diff --git a/tacker/vnfm/infra_drivers/openstack/translate_template.py b/tacker/vnfm/infra_drivers/openstack/translate_template.py index 27096d7c8..f2b514f3c 100644 --- a/tacker/vnfm/infra_drivers/openstack/translate_template.py +++ b/tacker/vnfm/infra_drivers/openstack/translate_template.py @@ -281,20 +281,20 @@ class TOSCAToHOT(object): monitoring_dict = toscautils.get_vdu_monitoring(tosca) mgmt_ports = toscautils.get_mgmt_ports(tosca) nested_resource_name = toscautils.get_nested_resources_name(tosca) + sub_heat_tmpl_name = toscautils.get_sub_heat_tmpl_name(tosca) res_tpl = toscautils.get_resources_dict(tosca, self.STACK_FLAVOR_EXTRA) toscautils.post_process_template(tosca) scaling_policy_names = toscautils.get_scaling_policy(tosca) try: - translator = tosca_translator.TOSCATranslator(tosca, - parsed_params) + translator = tosca_translator.TOSCATranslator(tosca, parsed_params) heat_template_yaml = translator.translate() if nested_resource_name: sub_heat_template_yaml =\ - translator.translate_to_yaml_files_dict( - nested_resource_name, True) + translator.translate_to_yaml_files_dict(sub_heat_tmpl_name) nested_resource_yaml =\ sub_heat_template_yaml[nested_resource_name] + LOG.debug("nested_resource_yaml: %s", nested_resource_yaml) self.nested_resources[nested_resource_name] =\ nested_resource_yaml