(config)
return errors
Function used to validate a whole yaml configuration file. Will check if there are both the init_config and
    the instances sections. And will parse using the _parse_for_config_blocks function
Function used to validate a whole yaml configuration file. Will check if there are both the init_config and
    the instances sections. And will parse using the _parse_for_config_blocks function
Function used to validate a whole yaml configuration file . Will check if there are both the init_config and the instances sections . And will parse using the _parse_for_config_blocks function
def validate_config(config):
    """Function used to validate a whole yaml configuration file. Will check if there are both the init_config and
    the instances sections. And will parse using the _parse_for_config_blocks function
    """
    errors = []
    blocks = []  # This will store ConfigBlocks as a tree
    config_lines = config.split('\n')

    init_config_line = -1
    instances_line = -1
    for i, line in enumerate(config_lines):
        if line.startswith("init_config:"):
            init_config_line = i
            if line != "init_config:":
                errors.append(ValidatorError("Expected no data after ':'", i, SEVERITY_WARNING))
        if line.startswith("instances:"):
            instances_line = i
            if line != "instances:":
                errors.append(ValidatorError("Expected no data after ':'", i, SEVERITY_WARNING))

    if init_config_line == -1:
        errors.append(ValidatorError("Missing `init_config` section", None))
        return errors

    if instances_line == -1:
        errors.append(ValidatorError("Missing `instances` section", None))
        return errors

    # parse init_config data
    blocks.append(_parse_init_config(config_lines, init_config_line, errors))

    # parse instances data
    instances_end = get_end_of_part(config_lines, instances_line)
    if instances_end is None:
        errors.append(ValidatorError("Malformed file, cannot find end of part 'instances'", instances_line))
        return errors
    blocks.append(_parse_for_config_blocks(config_lines, instances_line + 1, instances_end, errors))

    _check_no_duplicate_names(blocks, errors)
    _validate_blocks(blocks, errors)
    return errors
def validate_config ( config ) : errors = [ ] blocks = [ ] # This will store ConfigBlocks as a tree config_lines = config . split ( '\n' ) init_config_line = - 1 instances_line = - 1 for i , line in enumerate ( config_lines ) : if line . startswith ( "init_config:" ) : init_config_line = i if line != "init_config:" : errors . append ( ValidatorError ( "Expected no data after ':'" , i , SEVERITY_WARNING ) ) if line . startswith ( "instances:" ) : instances_line = i if line != "instances:" : errors . append ( ValidatorError ( "Expected no data after ':'" , i , SEVERITY_WARNING ) ) if init_config_line == - 1 : errors . append ( ValidatorError ( "Missing `init_config` section" , None ) ) return errors if instances_line == - 1 : errors . append ( ValidatorError ( "Missing `instances` section" , None ) ) return errors # parse init_config data blocks . append ( _parse_init_config ( config_lines , init_config_line , errors ) ) # parse instances data instances_end = get_end_of_part ( config_lines , instances_line ) if instances_end is None : errors . append ( ValidatorError ( "Malformed file, cannot find end of part 'instances'" , instances_line ) ) return errors blocks . append ( _parse_for_config_blocks ( config_lines , instances_line + 1 , instances_end , errors ) ) _check_no_duplicate_names ( blocks , errors ) _validate_blocks ( blocks , errors ) return errors