From 04be5915de52d399efcfb93f7bcd4c6fed4e22ef Mon Sep 17 00:00:00 2001 From: Adam King Date: Wed, 17 Aug 2022 16:54:54 -0400 Subject: [PATCH] cephadm: return nonzero exit code when applying spec fails in bootstrap This is mostly useful for testing automation, but right now if applying the spec provided with --apply-spec fails, the return code remains zero. We don't want to error out entirely in that case as we still want to print the remaining output (e.g. the dashboard password). Continuing onward and then returning a nonzero code could provide a balance where we still give all the output but still have something to make it easier for those writing automation around bootstrap. Fixes: https://tracker.ceph.com/issues/57173 Signed-off-by: Adam King (cherry picked from commit be17f1d4b30e19aa6039fa5d6a694129cb5f3583) --- src/cephadm/cephadm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 2e551377cfc58..c00083b53e068 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -5427,6 +5427,8 @@ def save_cluster_config(ctx: CephadmContext, uid: int, gid: int, fsid: str) -> N def command_bootstrap(ctx): # type: (CephadmContext) -> int + ctx.error_code = 0 + if not ctx.output_config: ctx.output_config = os.path.join(ctx.output_dir, CEPH_CONF) if not ctx.output_keyring: @@ -5645,6 +5647,7 @@ def command_bootstrap(ctx): out = cli(['orch', 'apply', '-i', '/tmp/spec.yml'], extra_mounts=mounts) logger.info(out) except Exception: + ctx.error_code = -errno.EINVAL logger.info('\nApplying %s to cluster failed!\n' % ctx.apply_spec) save_cluster_config(ctx, uid, gid, fsid) @@ -5670,7 +5673,7 @@ def command_bootstrap(ctx): 'For more information see:\n\n' '\thttps://docs.ceph.com/docs/master/mgr/telemetry/\n') logger.info('Bootstrap complete.') - return 0 + return ctx.error_code ################################## -- 2.39.5