- return (return_status, "Error loading configuration file '"+configuration_file+"': "+code)
- try:
- config = yaml.load(code)
- except yaml.YAMLError, exc:
- error_pos = ""
- if hasattr(exc, 'problem_mark'):
- mark = exc.problem_mark
- error_pos = " at position: (%s:%s)" % (mark.line+1, mark.column+1)
- return (False, "Error loading configuration file '"+configuration_file+"'"+error_pos+": content format error: Failed to parse yaml format")
-
-
- try:
- js_v(config, config_schema)
- except js_e.ValidationError, exc:
- error_pos = ""
- if len(exc.path)>0: error_pos=" at '" + ":".join(map(str, exc.path))+"'"
- return False, "Error loading configuration file '"+configuration_file+"'"+error_pos+": "+exc.message
-
-
- #Check default values tokens
- for k,v in default_tokens.items():
- if k not in config: config[k]=v
- #Check vlan ranges
- if config["network_vlan_range_start"]+10 >= config["network_vlan_range_end"]:
- return False, "Error invalid network_vlan_range less than 10 elements"
-
- except Exception,e:
- return (False, "Error loading configuration file '"+configuration_file+"': "+str(e))
- return (True, config)
+ raise LoadConfigurationException("Error loading configuration file '{}': {}".format(
+ configuration_file, code))
+ config = yaml.load(code)
+ js_v(config, config_schema)
+ # Check default values tokens
+ for k, v in default_tokens.items():
+ if k not in config:
+ config[k] = v
+ # Check vlan ranges
+ if config["network_vlan_range_start"] + 10 >= config["network_vlan_range_end"]:
+ raise LoadConfigurationException(
+ "Error at configuration file '{}'. Invalid network_vlan_range less than 10 elements".format(
+ configuration_file))
+ return config
+ except yaml.YAMLError as exc:
+ error_pos = ""
+ if hasattr(exc, 'problem_mark'):
+ mark = exc.problem_mark
+ error_pos = " at position: ({}:{})".format(mark.line + 1, mark.column + 1)
+ raise LoadConfigurationException("Bad YAML format at configuration file '{}'{}: {}\n"
+ "Use a valid yaml format. Indentation matters, "
+ "and tabs characters are not valid".format(
+ configuration_file, error_pos, exc))
+ except js_e.ValidationError as exc:
+ error_pos = ""
+ if len(exc.path) > 0:
+ error_pos = " at '{}'".format(":".join(map(str, exc.path)))
+ raise LoadConfigurationException("Invalid field at configuration file '{}'{}: {}".format(
+ configuration_file, error_pos, exc))
+
+ # except Exception as e:
+ # raise LoadConfigurationException("Error loading configuration file '{}': {}".format(configuration_file, e))
+