]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ansible.git/commitdiff
ceph-volume: if --report fails to load json, fail with better info
authorAndrew Schoen <aschoen@redhat.com>
Tue, 2 Oct 2018 18:50:01 +0000 (13:50 -0500)
committerSébastien Han <seb@redhat.com>
Tue, 9 Oct 2018 14:09:50 +0000 (10:09 -0400)
This handles the case gracefully where --report does not return any JSON
because a validator might have failed.

Signed-off-by: Andrew Schoen <aschoen@redhat.com>
library/ceph_volume.py

index f05bab57c5da2b5d4139a8d7b564e287c711cc01..2d281b1b85c6238c3c6d52583d647480ce9565d8 100644 (file)
@@ -285,7 +285,18 @@ def batch(module):
     report_cmd.extend(report_flags)
 
     rc, out, err = module.run_command(report_cmd, encoding=None)
-    report_result = json.loads(out)
+    try:
+        report_result = json.loads(out)
+    except ValueError:
+        result = dict(
+            cmd=report_cmd,
+            stdout=out.rstrip(b"\r\n"),
+            stderr=err.rstrip(b"\r\n"),
+            rc=rc,
+            changed=True,
+        )
+        module.fail_json(msg='non-zero return code', **result)
+
     if not report:
         rc, out, err = module.run_command(cmd, encoding=None)
     else: