Commit 3ca0d42c authored by Tomas Krizek's avatar Tomas Krizek

respdiff/cfg: check fields in criteria/field_weights

parent 4f309b75
......@@ -11,6 +11,12 @@ import os
import dns.inet
'timeout', 'malformed', 'opcode', 'qcase', 'qname', 'qtype', 'question', 'rcode',
'flags', 'answertypes', 'answerrrsigs', 'answer', 'authority', 'additional',
'edns', 'nsid']
def ipaddr_check(addr):
Verify that string addr can be parsed as a IP address and return it.
......@@ -119,6 +125,28 @@ def cfg2dict_check_diff(cdict):
def cfg2dict_check_fields(cdict):
"""Check if all fields are known and that all have a weight assigned"""
def get_unknown_fields(fields):
return [field for field in fields if field not in ALL_FIELDS]
unknown_criteria = get_unknown_fields(cdict['diff']['criteria'])
if unknown_criteria:
raise ValueError('[diff] criteria: unknown fields: {}'.format(
', '.join(['"{}"'.format(field) for field in unknown_criteria])))
unknown_field_weights = get_unknown_fields(cdict['report']['field_weights'])
if unknown_field_weights:
raise ValueError('[report] field_weights: unknown fields: {}'.format(
', '.join(['"{}"'.format(field) for field in unknown_field_weights])))
missing_field_weights = [
field for field in ALL_FIELDS if field not in cdict['report']['field_weights']]
if missing_field_weights:
raise ValueError('[report] field_weights: missing fields: {}'.format(
', '.join(['"{}"'.format(field) for field in missing_field_weights])))
def read_cfg(filename):
Read config file, convert values, validate data and return dict[section][key] = value.
......@@ -149,6 +177,9 @@ def read_cfg(filename):
# check existence of undefined extra sections
cfg2dict_check_sect(cfgfmt_servers, parser)
# check fields (criteria, field_weights)
except Exception as exc:
logging.critical('Failed to parse config: %s', exc)
raise ValueError(exc)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment