Exemple #1
0
    def compare_tosca_translation_with_hot(tosca_file, hot_files, params,
                                           nested_resources=False):
        '''Verify tosca translation against the given hot specification.

        inputs:
        tosca_file: relative local path or URL to the tosca input file
        hot_file: relative path to expected hot output
        params: dictionary of parameter name value pairs

        Returns as a dictionary the difference between the HOT translation
        of the given tosca_file and the given hot_file.
        '''

        from toscaparser.tosca_template import ToscaTemplate
        from translator.hot.tosca_translator import TOSCATranslator

        tosca_tpl = os.path.normpath(os.path.join(
            os.path.dirname(os.path.abspath(__file__)), tosca_file))
        a_file = os.path.isfile(tosca_tpl)
        if not a_file:
            tosca_tpl = tosca_file

        expected_hot_templates = []
        for hot_file in hot_files:
            expected_hot_templates.append(os.path.join(
                os.path.dirname(os.path.abspath(__file__)), hot_file))

        tosca = ToscaTemplate(tosca_tpl, params, a_file)
        translate = TOSCATranslator(tosca, params)

        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] = \
                toscaparser.utils.yamlparser.simple_parse(
                    output_hot_templates[output_hot_template_name])

        expected_output_dict = {}
        for expected_hot_template in expected_hot_templates:
            expected_output_dict[os.path.basename(expected_hot_template)] = \
                YamlUtils.get_dict(expected_hot_template)

        return CompareUtils.diff_dicts(expected_output_dict, output_dict)
Exemple #2
0
 def generate_heat_template(self, tosca_template_str):
     if tosca_template_str is None:
         raise ValueError('Must provide tosca_template_str parameter')
     tosca = self.tosca_parser_service.parse_tosca_str(tosca_template_str)
     heat_translator = TOSCATranslator(tosca, {})
     # heat translator returns translated heat in a dict
     translation_dict_key = 'main_hot'
     heat_translations = heat_translator.translate_to_yaml_files_dict(
         translation_dict_key)
     heat_result = heat_translations[translation_dict_key]
     return heat_result
Exemple #3
0
 def generate_heat_template(self, tosca_template_str, template_path=None):
     if tosca_template_str is None:
         raise ValueError('Must provide tosca_template_str parameter')
     tosca = self.tosca_parser_service.parse_tosca_str(
         tosca_template_str, template_path=template_path)
     heat_translator = TOSCATranslator(tosca, {})
     # heat translator returns translated heat in a dict
     translation_dict_key = 'main_hot'
     heat_translations = heat_translator.translate_to_yaml_files_dict(
         translation_dict_key)
     heat_result = heat_translations[translation_dict_key]
     logger.debug('Translated Heat: {0}'.format(heat_result))
     return heat_result