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:
parent
fe88383f8f
commit
3c53dc729f
|
@ -216,7 +216,8 @@ class YamlUtils(object):
|
||||||
class TranslationUtils(object):
|
class TranslationUtils(object):
|
||||||
|
|
||||||
@staticmethod
|
@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.
|
'''Verify tosca translation against the given hot specification.
|
||||||
|
|
||||||
inputs:
|
inputs:
|
||||||
|
@ -247,6 +248,12 @@ class TranslationUtils(object):
|
||||||
|
|
||||||
basename = os.path.basename(hot_files[0])
|
basename = os.path.basename(hot_files[0])
|
||||||
output_hot_templates = translate.translate_to_yaml_files_dict(basename)
|
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 = {}
|
output_dict = {}
|
||||||
for output_hot_template_name in output_hot_templates:
|
for output_hot_template_name in output_hot_templates:
|
||||||
output_dict[output_hot_template_name] = \
|
output_dict[output_hot_template_name] = \
|
||||||
|
|
|
@ -46,7 +46,8 @@ class HotTemplate(object):
|
||||||
return yaml.nodes.MappingNode(u'tag:yaml.org,2002:map', nodes)
|
return yaml.nodes.MappingNode(u'tag:yaml.org,2002:map', nodes)
|
||||||
|
|
||||||
def output_to_yaml_files_dict(self, base_filename,
|
def output_to_yaml_files_dict(self, base_filename,
|
||||||
hot_template_version=LATEST):
|
hot_template_version=LATEST,
|
||||||
|
embed_substack_templates=False):
|
||||||
yaml_files_dict = {}
|
yaml_files_dict = {}
|
||||||
base_filename, ext = os.path.splitext(base_filename)
|
base_filename, ext = os.path.splitext(base_filename)
|
||||||
|
|
||||||
|
@ -55,9 +56,9 @@ class HotTemplate(object):
|
||||||
yaml_files_dict.update(
|
yaml_files_dict.update(
|
||||||
resource.extract_substack_templates(base_filename,
|
resource.extract_substack_templates(base_filename,
|
||||||
hot_template_version))
|
hot_template_version))
|
||||||
|
if not embed_substack_templates:
|
||||||
yaml_files_dict[base_filename + ext] = \
|
yaml_files_dict[base_filename + ext] = \
|
||||||
self.output_to_yaml(hot_template_version, False)
|
self.output_to_yaml(hot_template_version, False)
|
||||||
|
|
||||||
return yaml_files_dict
|
return yaml_files_dict
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,8 @@ class TOSCATranslator(object):
|
||||||
|
|
||||||
return yaml_files["output.yaml"]
|
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
|
"""Translate to HOT YAML
|
||||||
|
|
||||||
This method produces a translated output containing main and
|
This method produces a translated output containing main and
|
||||||
|
@ -82,7 +83,7 @@ class TOSCATranslator(object):
|
||||||
self._translate_to_hot_yaml()
|
self._translate_to_hot_yaml()
|
||||||
return self.hot_template.output_to_yaml_files_dict(
|
return self.hot_template.output_to_yaml_files_dict(
|
||||||
base_filename,
|
base_filename,
|
||||||
self.node_translator.hot_template_version)
|
self.node_translator.hot_template_version, nested_resources)
|
||||||
|
|
||||||
def _translate_inputs(self):
|
def _translate_inputs(self):
|
||||||
translator = TranslateInputs(self.tosca.inputs, self.parsed_params,
|
translator = TranslateInputs(self.tosca.inputs, self.parsed_params,
|
||||||
|
|
|
@ -26,14 +26,15 @@ from translator.tests.base import TestCase
|
||||||
|
|
||||||
class ToscaHotTranslationTest(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:
|
if not params:
|
||||||
params = {}
|
params = {}
|
||||||
if not isinstance(hot_files, list):
|
if not isinstance(hot_files, list):
|
||||||
hot_files = [hot_files]
|
hot_files = [hot_files]
|
||||||
diff = TranslationUtils.compare_tosca_translation_with_hot(tosca_file,
|
diff =\
|
||||||
hot_files,
|
TranslationUtils.compare_tosca_translation_with_hot(
|
||||||
params)
|
tosca_file, hot_files, params, nested_resources)
|
||||||
self.assertEqual({}, diff, '<difference> : ' +
|
self.assertEqual({}, diff, '<difference> : ' +
|
||||||
json.dumps(diff, indent=4, separators=(', ', ': ')))
|
json.dumps(diff, indent=4, separators=(', ', ': ')))
|
||||||
|
|
||||||
|
@ -527,6 +528,15 @@ class ToscaHotTranslationTest(TestCase):
|
||||||
params = {}
|
params = {}
|
||||||
self._test_successful_translation(tosca_file, hot_files, 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):
|
def test_translate_unsupported_tosca_type(self):
|
||||||
tosca_file = '../tests/data/test_tosca_unsupported_type.yaml'
|
tosca_file = '../tests/data/test_tosca_unsupported_type.yaml'
|
||||||
tosca_tpl = os.path.normpath(os.path.join(
|
tosca_tpl = os.path.normpath(os.path.join(
|
||||||
|
|
Loading…
Reference in New Issue