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 <hoangphuocbk2.07@gmail.com>
Co-Authored-By: yong sheng gong <gong.yongsheng@99cloud.net>
Co-Authored-By: Trinh Nguyen <dangtrinhnt@gmail.com>

Change-Id: I60dc0a6d443598264c29fde8a3959d4bd7fba904
Closes-bug: #1753645
This commit is contained in:
Trinh Nguyen 2018-03-07 01:22:10 +09:00 committed by gongysh
parent fb50684adc
commit 47df1d6a2e
5 changed files with 18 additions and 11 deletions

View File

@ -23,4 +23,4 @@ resources:
network: net_mgmt
port_security_enabled: false
heat_template_version: 2013-05-23
description: Tacker Scaling template
description: Tacker Scaling template

View File

@ -22,4 +22,4 @@ resources:
network: net_mgmt
port_security_enabled: false
heat_template_version: 2013-05-23
description: Tacker Scaling template
description: Tacker Scaling template

View File

@ -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',

View File

@ -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:

View File

@ -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