Beispiel #1
0
    def compare_tosca_translation_with_hot(tosca_file, hot_files, params):
        '''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.output_to_yaml_files_dict(basename)
        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)