ceph-volume: if --report fails to load json, fail with better info

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>
pull/3206/head
Andrew Schoen 2018-10-02 13:50:01 -05:00 committed by Sébastien Han
parent a68c680225
commit a63ca220e6
1 changed files with 12 additions and 1 deletions

View File

@ -285,7 +285,18 @@ def batch(module):
report_cmd.extend(report_flags)
rc, out, err = module.run_command(report_cmd, encoding=None)
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: