def _validate_topology(self, topology): """ Validate the provided topology against the schema ;param topology: topology dictionary """ res_grps = topology.get('resource_groups') resources = [] for group in res_grps: res_grp_type = (group.get('resource_group_type') or group.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 = group.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 cerberus >= 1.2, but # this is here just in case an older version has to be used print("There was an error validating your schema, but we\ can't seem to format it for you") print("Here's the raw error data in case you want to go\ through it by hand:") print(v._errors) resources.append(group) return resources
def _validate_layout(self, layout): """ 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(sp, e)) v = AnyofValidator(schema) if not v.validate(layout): 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 """ # the layout schema is in the 'common' role role_path = self._find_role_path("common") try: sp = "{0}/files/schema.json".format(role_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_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_topology(self, topology): """ Validate the provided topology against the schema ;param topology: topology dictionary """ res_grps = topology.get('resource_groups') resources = [] for group in res_grps: res_grp_type = (group.get('resource_group_type') or group.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 = group.get('resource_definitions') # preload this so it will validate against the schema document = {'res_defs': res_defs} v = Validator(schema) if not v.validate(document): raise SchemaError('Schema validation failed:' ' {0}'.format(v.errors)) resources.append(group) return resources