mirror of https://github.com/ceph/ceph-ansible.git
validate plugin: handle missing exception fields without traceback
"missing variable" errors introduced by PR3058 would attempt to be reported, but since the exception contained no "path" definition, would cause a second exception in the Invalid exception handler. Make the exception handler verify that any field it tries to use exists, clean up its message formatting, and reduce the verbose level to see the literal error from notario in case more goes wrong in future. Signed-off-by: Dan Mick <dan.mick@redhat.com>pull/3346/head
parent
10538e9a23
commit
a2349f05ac
|
@ -96,10 +96,15 @@ class ActionModule(ActionBase):
|
||||||
notario.validate(host_vars, lvm_bluestore_scenario, defined_keys=True)
|
notario.validate(host_vars, lvm_bluestore_scenario, defined_keys=True)
|
||||||
|
|
||||||
except Invalid as error:
|
except Invalid as error:
|
||||||
display.vvvv("Notario Failure: %s" % str(error))
|
display.vvv("Notario Failure: %s" % str(error))
|
||||||
|
msg = ""
|
||||||
|
if error.path:
|
||||||
msg = "[{}] Validation failed for variable: {}".format(host, error.path[0])
|
msg = "[{}] Validation failed for variable: {}".format(host, error.path[0])
|
||||||
display.error(msg)
|
display.error(msg)
|
||||||
reason = "[{}] Reason: {}".format(host, error.reason)
|
reason = "[{}] Reason: {}".format(host, error.reason)
|
||||||
|
else:
|
||||||
|
reason = "[{}] Reason: {}".format(host, str(error))
|
||||||
|
given = ""
|
||||||
try:
|
try:
|
||||||
if "schema is missing" not in error.message:
|
if "schema is missing" not in error.message:
|
||||||
for i in range(0, len(error.path)):
|
for i in range(0, len(error.path)):
|
||||||
|
@ -108,6 +113,7 @@ class ActionModule(ActionBase):
|
||||||
host, error.path[0])
|
host, error.path[0])
|
||||||
else:
|
else:
|
||||||
given = given + ": {}".format(error.path[i])
|
given = given + ": {}".format(error.path[i])
|
||||||
|
if given:
|
||||||
display.error(given)
|
display.error(given)
|
||||||
else:
|
else:
|
||||||
given = ""
|
given = ""
|
||||||
|
@ -116,8 +122,9 @@ class ActionModule(ActionBase):
|
||||||
given = ""
|
given = ""
|
||||||
display.error(reason)
|
display.error(reason)
|
||||||
result['failed'] = mode == 'strict'
|
result['failed'] = mode == 'strict'
|
||||||
result['msg'] = "\n".join([msg, reason, given])
|
result['msg'] = "\n".join([s for s in (msg, reason, given) if len(s) > 0])
|
||||||
result['stderr_lines'] = msg.split('\n')
|
result['stderr_lines'] = result['msg'].split('\n')
|
||||||
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue