def set_template(self, path, parsed_params=None):
        """
    set_template is the method that will parse the tosca template and return the
    object topology object.

    :params: path, parsed_params
    :type: string, dictionary
    :return: template
    :raises: Exception

    | parsed_params: dictionary containing the input to change
    | path: local or remote path to the file to parse (it needs to be reachable.)
    """
        self.path = path
        isfile = False
        if os.path.isfile(self.path):
            logger.debug("check if the input file is local")
            isfile = True
            #return ToscaTemplate(self.path, parsed_params, isfile)
        else:
            try:
                toscaparser.utils.urlutils.UrlUtils.validate_url(self.path)
                logger.debug("check if the input is a valid url")
                isfile = False
            except Exception as e:
                logger.error(
                    "the input file doesn't exist or cannot be reached")
                raise Exception("Cannot find input file {}".format(e))

        template = ToscaTemplate(self.path, parsed_params, isfile)
        Validator.validation(template)

        return template
    def set_template(self, path, parsed_params=None):
        """
    set_template is the method that will parse the tosca template and return the
    object topology object.

    :params: path, parsed_params
    :type: string, dictionary
    :return: template
    :raises: Exception

    | parsed_params: dictionary containing the input to change
    | path: local or remote path to the file to parse (it needs to be reachable.)
    """
        self.path = path
        isfile = False
        if os.path.isfile(self.path):
            logger.debug("check if the input file is local")
            isfile = True
            #return ToscaTemplate(self.path, parsed_params, isfile)
        else:
            try:
                toscaparser.utils.urlutils.UrlUtils.validate_url(self.path)
                logger.debug("check if the input is a valid url")
                isfile = False
            except Exception as e:
                logger.error(
                    "the input file doesn't exist or cannot be reached")
                raise Exception("Cannot find input file {}".format(e))

        try:
            template = ToscaTemplate(self.path, parsed_params, isfile)
        except AttributeError as e:
            logger.error(
                "error happened: {}, This might be due to the wrong type in the TOSCA template, check if all the type exist or that the import section is correct."
                .format(e))
            raise Exception(
                "An error occured while parsing, This might be due to the a wrong type in the TOSCA template, check if all the types exist, or that the import section is correct."
            )

        Validator.validation(template)

        #    raise Exception("an error happened most likely with the policy, check if import section is right")

        return template
Esempio n. 3
0
 def test_bad_validation_raises_error(self):
     with self.assertRaises(MultiError):
         validator.validation(self.bad_tpl)
Esempio n. 4
0
 def test_good_validation_returns_good(self):
     good_tpl = ToscaTemplate("tests/templates/good_tosca.yaml")
     msg = "ToscaTemplate passed compatibility validation"
     self.assertTrue(msg in validator.validation(good_tpl))