]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ansible.git/commitdiff
validate plugin: handle missing exception fields without traceback
authorDan Mick <dan.mick@redhat.com>
Sat, 17 Nov 2018 00:28:54 +0000 (16:28 -0800)
committermergify[bot] <mergify[bot]@users.noreply.github.com>
Mon, 19 Nov 2018 22:01:07 +0000 (22:01 +0000)
"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>
plugins/actions/validate.py

index 620358eae9e5720b6ac99a0a2f5da52f865c4735..2f76619fd3b7103dca14c964612f0325ed93ff3b 100644 (file)
@@ -96,10 +96,15 @@ class ActionModule(ActionBase):
                         notario.validate(host_vars, lvm_bluestore_scenario, defined_keys=True)
 
         except Invalid as error:
-            display.vvvv("Notario Failure: %s" % str(error))
-            msg = "[{}] Validation failed for variable: {}".format(host, error.path[0])
-            display.error(msg)
-            reason = "[{}] Reason: {}".format(host, error.reason)
+            display.vvv("Notario Failure: %s" % str(error))
+            msg = ""
+            if error.path:
+                msg = "[{}] Validation failed for variable: {}".format(host, error.path[0])
+                display.error(msg)
+                reason = "[{}] Reason: {}".format(host, error.reason)
+            else:
+                reason = "[{}] Reason: {}".format(host, str(error))
+            given = ""
             try:
                 if "schema is missing" not in error.message:
                     for i in range(0, len(error.path)):
@@ -108,7 +113,8 @@ class ActionModule(ActionBase):
                                     host, error.path[0])
                         else:
                             given = given + ": {}".format(error.path[i])
-                    display.error(given)
+                    if given:
+                        display.error(given)
                 else:
                     given = ""
                     reason = "[{}] Reason: {}".format(host, error.message)
@@ -116,8 +122,9 @@ class ActionModule(ActionBase):
                 given = ""
             display.error(reason)
             result['failed'] = mode == 'strict'
-            result['msg'] = "\n".join([msg, reason, given])
-            result['stderr_lines'] = msg.split('\n')
+            result['msg'] = "\n".join([s for s in (msg, reason, given) if len(s) > 0])
+            result['stderr_lines'] = result['msg'].split('\n')
+
 
         return result