template validation - fixed bugs

Change-Id: I8000ec2ddd76ab7ad0a541ea1a7a30adb3ba6f42
This commit is contained in:
liathartal 2016-06-15 12:17:38 +00:00
parent 6cae6df79a
commit e308be47dc
5 changed files with 25 additions and 6 deletions

View File

@ -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 |

View File

@ -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})

View File

@ -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])

View File

@ -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.',

View File

@ -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)):