Exemple #1
0
    def validate_topology_highlevel(self, topo_data):
        """
        validate the higher-level components of the topology

        These are not specific to the provider and must be validated separately
        from the items within each resource group

        :param topo_data topology data from the pinfile
        """

        role_path = self._find_role_path("common")
        try:
            sp = "{0}/files/topo-schema.json".format(role_path)
            schema = json.load(open(sp))
        except Exception as e:
            raise LinchpinError("Error with schema: '{0}'"
                                " {1}".format(sp, e))

        document = {'topology': topo_data}
        v = AnyofValidator(schema, error_handler=ValidationErrorHandler)

        if not v.validate(document):
            try:
                err = self._gen_error_msg("", "", v.errors)
                raise TopologyError(err)
            except NotImplementedError:
                # we shouldn't have this issue using cererus >= 1.2, but
                # this is here just in case an older version has to be used
                self.ctx.log_state("There was an error validating your schema,\
                      but we can't seem to format it for you")
                self.ctx.log_state("Here's the raw error data in case you want\
                      to go through it by hand:")
                self.ctx.log_state(v._errors)
    def validate_topology_highlevel(self, topo_data):
        """
        validate the higher-level components of the topology

        These are not specific to the provider and must be validated separately
        from the items within each resource group

        :param topo_data topology data from the pinfile
        """

        pb_path = self._find_playbook_path("layout")
        try:
            sp = "{0}/roles/common/files/topo-schema.json".format(pb_path)
            schema = json.load(open(sp))
        except Exception as e:
            raise LinchpinError("Error with schema: '{0}'"
                                " {1}".format(sp, e))

        document = {'topology': topo_data}
        v = AnyofValidator(schema, error_handler=ValidationErrorHandler)

        if not v.validate(document):
            try:
                err = self._gen_error_msg("", "", v.errors)
                raise TopologyError(err)
            except NotImplementedError as e:
                # we shouldn't have this issue using cererus >= 1.2, but
                # this is here just in case an older version has to be used
                self.ctx.log_state("There was an error validating your schema,\
                      but we can't seem to format it for you")
                self.ctx.log_state("Here's the raw error data in case you want\
                      to go through it by hand:")
                self.ctx.log_state(v._errors)
Exemple #3
0
    def validate_layout(self, layout_data):
        """
        Validate the provided layout against the schema

        :param layout: layout dictionary
        """

        pb_path = self._find_playbook_path("layout")
        try:
            sp = "{0}/roles/common/files/schema.json".format(pb_path)

            schema = json.load(open(sp))
        except Exception as e:
            raise LinchpinError("Error with schema: '{0}' {1}".format(e))

        v = AnyofValidator(schema)

        if not v.validate(layout_data):
            raise SchemaError('Schema validation failed: {0}'.format(v.errors))
    def validate_layout(self, layout_data):
        """
        Validate the provided layout against the schema

        :param layout: layout dictionary
        """

        pb_path = self._find_playbook_path("layout")
        try:
            sp = "{0}/roles/common/files/schema.json".format(pb_path)

            schema = json.load(open(sp))
        except Exception as e:
            raise LinchpinError("Error with schema: '{0}' {1}".format(e))

        v = AnyofValidator(schema)

        if not v.validate(layout_data):
            raise SchemaError('Schema validation failed: {0}'.format(v.errors))
Exemple #5
0
    def validate_resource_group(self, res_grp):
        """
        validate the provided resource group against the schema

        :param res_grp: resource group
        """
        res_grp_type = (res_grp.get('resource_group_type') or
                        res_grp.get('res_group_type'))

        pb_path = self._find_playbook_path(res_grp_type)

        try:
            sp = "{0}/roles/{1}/files/schema.json".format(pb_path,
                                                          res_grp_type)
            schema = json.load(open(sp))
        except Exception as e:
            raise LinchpinError("Error with schema: '{0}'"
                                " {1}".format(sp, e))

        res_defs = res_grp.get('resource_definitions')

        # preload this so it will validate against the schema
        document = {'res_defs': res_defs}
        v = AnyofValidator(schema,
                           error_handler=ValidationErrorHandler)

        if not v.validate(document):
            try:
                err = self._gen_error_msg("", "", v.errors)
                raise SchemaError(err)
            except NotImplementedError as e:
                # we shouldn't have this issue using cererus >= 1.2, but
                # this is here just in case an older version has to be used
                self.ctx.log_state("There was an error validating your schema,\
                      but we can't seem to format it for you")
                self.ctx.log_state("Here's the raw error data in case you want\
                      to go through it by hand:")
                self.ctx.log_state(v._errors)

        return res_grp
    def validate_resource_group(self, res_grp):
        """
        validate the provided resource group against the schema

        :param res_grp: resource group
        """
        res_grp_type = (res_grp.get('resource_group_type') or
                        res_grp.get('res_group_type'))

        pb_path = self._find_playbook_path(res_grp_type)

        try:
            sp = "{0}/roles/{1}/files/schema.json".format(pb_path,
                                                          res_grp_type)
            schema = json.load(open(sp))
        except Exception as e:
            raise LinchpinError("Error with schema: '{0}'"
                                " {1}".format(sp, e))

        res_defs = res_grp.get('resource_definitions')

        # preload this so it will validate against the schema
        document = {'res_defs': res_defs}
        v = AnyofValidator(schema,
                           error_handler=ValidationErrorHandler)

        if not v.validate(document):
            try:
                err = self._gen_error_msg("", "", v.errors)
                raise SchemaError(err)
            except NotImplementedError as e:
                # we shouldn't have this issue using cererus >= 1.2, but
                # this is here just in case an older version has to be used
                self.ctx.log_state("There was an error validating your schema,\
                      but we can't seem to format it for you")
                self.ctx.log_state("Here's the raw error data in case you want\
                      to go through it by hand:")
                self.ctx.log_state(v._errors)

        return res_grp