diff --git a/doc/source/tempolate_validation_status_code.rst b/doc/source/tempolate_validation_status_code.rst index 02e174980..cfb69d35e 100644 --- a/doc/source/tempolate_validation_status_code.rst +++ b/doc/source/tempolate_validation_status_code.rst @@ -22,6 +22,8 @@ The following describes all the possible status code and their messages: +------------------+---------------------------------------------------------+-------------------------------+ | 3 | template_id does not appear in the definition block | content | +------------------+---------------------------------------------------------+-------------------------------+ +| 4 | Syntax error: [error message] | syntax | ++------------------+---------------------------------------------------------+-------------------------------+ | 20 | definitions section must contain entities field | syntax | +------------------+---------------------------------------------------------+-------------------------------+ | 21 | definitions section is a mandatory section | syntax | diff --git a/vitrage/api_handler/apis.py b/vitrage/api_handler/apis.py index 9e8b3f735..35592a487 100644 --- a/vitrage/api_handler/apis.py +++ b/vitrage/api_handler/apis.py @@ -213,8 +213,8 @@ class TemplateApis(object): self._add_result(path, self.OK_MSG, 'Template validation', - status_msgs[4], - 4, + status_msgs[0], + 0, results) return json.dumps({'results': results}) diff --git a/vitrage/evaluator/template_validation/base.py b/vitrage/evaluator/template_validation/base.py index 909c99616..51be36872 100644 --- a/vitrage/evaluator/template_validation/base.py +++ b/vitrage/evaluator/template_validation/base.py @@ -25,5 +25,7 @@ def get_correct_result(description): return Result(description, True, 0, status_msgs[0]) -def get_fault_result(description, code): +def get_fault_result(description, code, msg=None): + if msg: + return Result(description, False, code, msg) return Result(description, False, code, status_msgs[code]) diff --git a/vitrage/evaluator/template_validation/status_messages.py b/vitrage/evaluator/template_validation/status_messages.py index c862958f4..975fa3c79 100644 --- a/vitrage/evaluator/template_validation/status_messages.py +++ b/vitrage/evaluator/template_validation/status_messages.py @@ -22,6 +22,7 @@ status_msgs = { 1: 'template_id field contains incorrect string value.', 2: 'Duplicate template_id definition.', 3: 'template_id does not appear in the definition block.', + 4: 'Syntax error: %s', # definitions section 20-39 20: 'definitions section must contain entities field.', diff --git a/vitrage/evaluator/template_validation/template_syntax_validator.py b/vitrage/evaluator/template_validation/template_syntax_validator.py index 12e4be970..89e420993 100644 --- a/vitrage/evaluator/template_validation/template_syntax_validator.py +++ b/vitrage/evaluator/template_validation/template_syntax_validator.py @@ -236,14 +236,28 @@ def _validate_dict_schema(schema, value): try: schema(value) except Error as e: - status_code = int(str(e).split(' ')[0].strip()) - LOG.error('%s error code: %s' % (status_msgs[status_code], - status_code)) + + status_code = _get_status_code(e) + if status_code: + msg = status_msgs[status_code] + else: + # General syntax error + status_code = 4 + msg = status_msgs[4] % e + + LOG.error('%s error code: %s' % (msg, status_code)) return get_fault_result(RESULT_DESCRIPTION, status_code) return get_correct_result(RESULT_DESCRIPTION) +def _get_status_code(e): + prefix = str(e).split(' ')[0].strip() + if prefix.isdigit(): + return int(prefix) + return None + + def _validate_template_id_value(msg=None): def f(v): if re.match("_*[a-zA-Z]+\\w*", str(v)):