Fix: nested resources cannot be given out

In Tacker, we now are fixing Tacker scaling to fully leverage heat-translator.
To make a best fit, Tacker need to have nested resources from heat-translator.
Heat-translator already provided this by using translate_to_yaml_dict().
Unfortunately, this method always return to the main heat yaml file not to
nested yaml file.

Change-Id: I7144d9926141dc4fc70f3a3c73c7fd41e2ff288c
This commit is contained in:
doantungbk 2017-06-05 09:23:10 -07:00
parent fe88383f8f
commit 3c53dc729f
4 changed files with 30 additions and 11 deletions

View File

@ -216,7 +216,8 @@ class YamlUtils(object):
class TranslationUtils(object):
@staticmethod
def compare_tosca_translation_with_hot(tosca_file, hot_files, params):
def compare_tosca_translation_with_hot(tosca_file, hot_files, params,
nested_resources=False):
'''Verify tosca translation against the given hot specification.
inputs:
@ -247,6 +248,12 @@ class TranslationUtils(object):
basename = os.path.basename(hot_files[0])
output_hot_templates = translate.translate_to_yaml_files_dict(basename)
if nested_resources:
basename = os.path.basename(hot_files[0])
output_hot_templates =\
translate.translate_to_yaml_files_dict(basename, True)
output_dict = {}
for output_hot_template_name in output_hot_templates:
output_dict[output_hot_template_name] = \

View File

@ -46,7 +46,8 @@ class HotTemplate(object):
return yaml.nodes.MappingNode(u'tag:yaml.org,2002:map', nodes)
def output_to_yaml_files_dict(self, base_filename,
hot_template_version=LATEST):
hot_template_version=LATEST,
embed_substack_templates=False):
yaml_files_dict = {}
base_filename, ext = os.path.splitext(base_filename)
@ -55,9 +56,9 @@ class HotTemplate(object):
yaml_files_dict.update(
resource.extract_substack_templates(base_filename,
hot_template_version))
yaml_files_dict[base_filename + ext] = \
self.output_to_yaml(hot_template_version, False)
if not embed_substack_templates:
yaml_files_dict[base_filename + ext] = \
self.output_to_yaml(hot_template_version, False)
return yaml_files_dict

View File

@ -71,7 +71,8 @@ class TOSCATranslator(object):
return yaml_files["output.yaml"]
def translate_to_yaml_files_dict(self, base_filename):
def translate_to_yaml_files_dict(self, base_filename,
nested_resources=False):
"""Translate to HOT YAML
This method produces a translated output containing main and
@ -82,7 +83,7 @@ class TOSCATranslator(object):
self._translate_to_hot_yaml()
return self.hot_template.output_to_yaml_files_dict(
base_filename,
self.node_translator.hot_template_version)
self.node_translator.hot_template_version, nested_resources)
def _translate_inputs(self):
translator = TranslateInputs(self.tosca.inputs, self.parsed_params,

View File

@ -26,14 +26,15 @@ from translator.tests.base import TestCase
class ToscaHotTranslationTest(TestCase):
def _test_successful_translation(self, tosca_file, hot_files, params=None):
def _test_successful_translation(self, tosca_file, hot_files, params=None,
nested_resources=False):
if not params:
params = {}
if not isinstance(hot_files, list):
hot_files = [hot_files]
diff = TranslationUtils.compare_tosca_translation_with_hot(tosca_file,
hot_files,
params)
diff =\
TranslationUtils.compare_tosca_translation_with_hot(
tosca_file, hot_files, params, nested_resources)
self.assertEqual({}, diff, '<difference> : ' +
json.dumps(diff, indent=4, separators=(', ', ': ')))
@ -527,6 +528,15 @@ class ToscaHotTranslationTest(TestCase):
params = {}
self._test_successful_translation(tosca_file, hot_files, params)
def test_hot_translate_scaling_nested_plate(self):
tosca_file = '../tests/data/autoscaling/tosca_autoscaling.yaml'
hot_files = [
'../tests/data/hot_output/autoscaling/asg_res.yaml'
]
params = {}
self._test_successful_translation(tosca_file, hot_files, params,
nested_resources=True)
def test_translate_unsupported_tosca_type(self):
tosca_file = '../tests/data/test_tosca_unsupported_type.yaml'
tosca_tpl = os.path.normpath(os.path.join(