mgr/crash, mgr/status: return negative errno to fix CLI exit code
The crash and status mgr modules return positive errno values (e.g.
errno.EINVAL) on error. However, the ceph CLI (src/ceph.in) only
treats negative return codes as errors:
if ret < 0:
final_ret = -ret
A positive return code falls through and the CLI exits with 0, masking
the error. This causes commands like "ceph crash post" and "ceph crash
info <bad-id>" to return success (rc=0) despite failing, with the
error message only appearing on stderr.
This was observed in the wild and worked around in
a77b47eeeb57, which added a
stderr != "" check to ceph-crash's post_crash() as a mitigation.
Fix the root cause by negating the errno values in both modules,
consistent with the HandleCommandResult convention
(retval: "E.g. 0 or -errno.EINVAL") and the 154 other call sites
across mgr modules that already use negative errno.
Also add error-path tests for the crash module to cover the three
affected commands (info, post, archive).
See-also:
a77b47eeeb5770eeefcf4619ab2105ee7a6a003e
Fixes: https://tracker.ceph.com/issues/75937
Signed-off-by: Kefu Chai <k.chai@proxmox.com>