def _test_samples(self, files):
        if files:
            for f in self._get_list_of_sample(files):
                with open(f, 'r') as _f:
                    yaml_dict = None
                    try:
                        yaml_dict = yamlparser.simple_ordered_parse(_f.read())
                    except:  # noqa
                        pass
                    self.assertIsNotNone(yaml_dict,
                                         "Yaml parser failed to parse %s" % f)

                    utils.updateimports(yaml_dict)

                    tosca = None
                    try:
                        tosca = tosca_template.ToscaTemplate(
                            a_file=False, yaml_dict_tpl=yaml_dict)
                    except:  # noqa
                        pass

                    self.assertIsNotNone(tosca,
                                         "Tosca parser failed to parse %s" % f)
                    utils.post_process_template(tosca)
                    hot = None
                    try:
                        hot = tosca_translator.TOSCATranslator(tosca,
                                                               {}).translate()
                    except:  # noqa
                        pass

                    self.assertIsNotNone(
                        hot, "Heat-translator failed to translate %s" % f)
Ejemplo n.º 2
0
    def test_post_process_template(self):
        tosca2 = tosca_template.ToscaTemplate(parsed_params={}, a_file=False,
                          yaml_dict_tpl=self.vnfd_dict)
        toscautils.post_process_template(tosca2)
        invalidNodes = 0
        for nt in tosca2.nodetemplates:
            if (nt.type_definition.is_derived_from(toscautils.MONITORING) or
                nt.type_definition.is_derived_from(toscautils.FAILURE) or
                    nt.type_definition.is_derived_from(toscautils.PLACEMENT)):
                invalidNodes += 1

        self.assertEqual(0, invalidNodes)

        deletedProperties = 0
        if nt.type in toscautils.delpropmap.keys():
            for prop in toscautils.delpropmap[nt.type]:
                for p in nt.get_properties_objects():
                    if prop == p.name:
                        deletedProperties += 1

        self.assertEqual(0, deletedProperties)

        convertedProperties = 0
        if nt.type in toscautils.convert_prop:
            for prop in toscautils.convert_prop[nt.type].keys():
                for p in nt.get_properties_objects():
                    if prop == p.name:
                        convertedProperties += 1

        self.assertEqual(0, convertedProperties)
Ejemplo n.º 3
0
    def test_post_process_template(self):
        tosca2 = tosca_template.ToscaTemplate(parsed_params={}, a_file=False,
                          yaml_dict_tpl=self.vnfd_dict)
        toscautils.post_process_template(tosca2)
        invalidNodes = 0
        for nt in tosca2.nodetemplates:
            if (nt.type_definition.is_derived_from(toscautils.MONITORING) or
                nt.type_definition.is_derived_from(toscautils.FAILURE) or
                    nt.type_definition.is_derived_from(toscautils.PLACEMENT)):
                invalidNodes += 1

        self.assertEqual(0, invalidNodes)

        deletedProperties = 0
        if nt.type in toscautils.delpropmap.keys():
            for prop in toscautils.delpropmap[nt.type]:
                for p in nt.get_properties_objects():
                    if prop == p.name:
                        deletedProperties += 1

        self.assertEqual(0, deletedProperties)

        convertedProperties = 0
        if nt.type in toscautils.convert_prop:
            for prop in toscautils.convert_prop[nt.type].keys():
                for p in nt.get_properties_objects():
                    if prop == p.name:
                        convertedProperties += 1

        self.assertEqual(0, convertedProperties)
Ejemplo n.º 4
0
    def test_post_process_heat_template(self):
        tosca1 = tosca_template.ToscaTemplate(parsed_params={}, a_file=False,
                          yaml_dict_tpl=self.vnfd_dict)
        toscautils.post_process_template(tosca1)
        translator = tosca_translator.TOSCATranslator(tosca1, {})
        heat_template_yaml = translator.translate()
        expected_heat_tpl = _get_template('hot_tosca_openwrt.yaml')
        mgmt_ports = toscautils.get_mgmt_ports(self.tosca)
        heat_tpl = toscautils.post_process_heat_template(
            heat_template_yaml, mgmt_ports, {}, {})

        heatdict = yaml.safe_load(heat_tpl)
        expecteddict = yaml.safe_load(expected_heat_tpl)
        self.assertEqual(expecteddict, heatdict)
Ejemplo n.º 5
0
    def test_post_process_heat_template(self):
        tosca1 = tosca_template.ToscaTemplate(parsed_params={}, a_file=False,
                          yaml_dict_tpl=self.vnfd_dict)
        toscautils.post_process_template(tosca1)
        translator = tosca_translator.TOSCATranslator(tosca1, {})
        heat_template_yaml = translator.translate()
        expected_heat_tpl = _get_template('hot_tosca_openwrt.yaml')
        mgmt_ports = toscautils.get_mgmt_ports(self.tosca)
        heat_tpl = toscautils.post_process_heat_template(
            heat_template_yaml, mgmt_ports, {}, {})

        heatdict = yaml.load(heat_tpl)
        expecteddict = yaml.load(expected_heat_tpl)
        self.assertEqual(expecteddict, heatdict)
Ejemplo n.º 6
0
    def _generate_hot_from_tosca(self, vnfd_dict, dev_attrs):
        parsed_params = {}
        if 'param_values' in dev_attrs and dev_attrs['param_values'] != "":
            try:
                parsed_params = yaml.load(dev_attrs['param_values'])
            except Exception as e:
                LOG.debug("Params not Well Formed: %s", str(e))
                raise vnfm.ParamYAMLNotWellFormed(error_msg_details=str(e))

        toscautils.updateimports(vnfd_dict)
        if 'substitution_mappings' in str(vnfd_dict):
            toscautils.check_for_substitution_mappings(vnfd_dict,
                parsed_params)

        try:
            tosca = tosca_template.ToscaTemplate(parsed_params=parsed_params,
                                                 a_file=False,
                                                 yaml_dict_tpl=vnfd_dict)

        except Exception as e:
            LOG.debug("tosca-parser error: %s", str(e))
            raise vnfm.ToscaParserFailed(error_msg_details=str(e))

        metadata = toscautils.get_vdu_metadata(tosca)
        monitoring_dict = toscautils.get_vdu_monitoring(tosca)
        mgmt_ports = toscautils.get_mgmt_ports(tosca)
        res_tpl = toscautils.get_resources_dict(tosca,
                                                self.STACK_FLAVOR_EXTRA)
        toscautils.post_process_template(tosca)
        try:
            translator = tosca_translator.TOSCATranslator(tosca,
                                                          parsed_params)
            heat_template_yaml = translator.translate()
        except Exception as e:
            LOG.debug("heat-translator error: %s", str(e))
            raise vnfm.HeatTranslatorFailed(error_msg_details=str(e))
        heat_template_yaml = toscautils.post_process_heat_template(
            heat_template_yaml, mgmt_ports, metadata,
            res_tpl, self.unsupported_props)

        self.heat_template_yaml = heat_template_yaml
        self.monitoring_dict = monitoring_dict
        self.metadata = metadata
Ejemplo n.º 7
0
        def generate_hot_from_tosca(vnfd_dict):
            parsed_params = {}
            if ('param_values' in dev_attrs and
                    dev_attrs['param_values'] != ""):
                try:
                    parsed_params = yaml.load(dev_attrs['param_values'])
                except Exception as e:
                    LOG.debug("Params not Well Formed: %s", str(e))
                    raise vnfm.ParamYAMLNotWellFormed(
                        error_msg_details=str(e))

            toscautils.updateimports(vnfd_dict)

            try:
                tosca = tosca_template.ToscaTemplate(
                    parsed_params=parsed_params, a_file=False,
                    yaml_dict_tpl=vnfd_dict)

            except Exception as e:
                LOG.debug("tosca-parser error: %s", str(e))
                raise vnfm.ToscaParserFailed(error_msg_details=str(e))

            monitoring_dict = toscautils.get_vdu_monitoring(tosca)
            mgmt_ports = toscautils.get_mgmt_ports(tosca)
            res_tpl = toscautils.get_resources_dict(tosca,
                                                    self.STACK_FLAVOR_EXTRA)
            toscautils.post_process_template(tosca)
            try:
                translator = tosca_translator.TOSCATranslator(tosca,
                                                              parsed_params)
                heat_template_yaml = translator.translate()
            except Exception as e:
                LOG.debug("heat-translator error: %s", str(e))
                raise vnfm.HeatTranslatorFailed(error_msg_details=str(e))
            heat_template_yaml = toscautils.post_process_heat_template(
                heat_template_yaml, mgmt_ports, res_tpl,
                unsupported_res_prop)

            return heat_template_yaml, monitoring_dict
Ejemplo n.º 8
0
        def generate_hot_from_tosca(vnfd_dict):
            parsed_params = {}
            if ('param_values' in dev_attrs and
                    dev_attrs['param_values'] != ""):
                try:
                    parsed_params = yaml.load(dev_attrs['param_values'])
                except Exception as e:
                    LOG.debug("Params not Well Formed: %s", str(e))
                    raise vnfm.ParamYAMLNotWellFormed(
                        error_msg_details=str(e))

            toscautils.updateimports(vnfd_dict)

            try:
                tosca = ToscaTemplate(parsed_params=parsed_params,
                                      a_file=False,
                                      yaml_dict_tpl=vnfd_dict)

            except Exception as e:
                LOG.debug("tosca-parser error: %s", str(e))
                raise vnfm.ToscaParserFailed(error_msg_details=str(e))

            monitoring_dict = toscautils.get_vdu_monitoring(tosca)
            mgmt_ports = toscautils.get_mgmt_ports(tosca)
            res_tpl = toscautils.get_resources_dict(tosca,
                                                    STACK_FLAVOR_EXTRA)
            toscautils.post_process_template(tosca)
            try:
                translator = TOSCATranslator(tosca, parsed_params)
                heat_template_yaml = translator.translate()
            except Exception as e:
                LOG.debug("heat-translator error: %s", str(e))
                raise vnfm.HeatTranslatorFailed(error_msg_details=str(e))
            heat_template_yaml = toscautils.post_process_heat_template(
                heat_template_yaml, mgmt_ports, res_tpl,
                unsupported_res_prop)

            return heat_template_yaml, monitoring_dict