From: Melissa Li Date: Wed, 23 Mar 2022 15:38:37 +0000 (-0400) Subject: cephadm: show error message if private registry credentials not provided X-Git-Tag: v16.2.8~20^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=5fd3b523e8661ba267077dc3dea5656fcf76fd31;p=ceph.git cephadm: show error message if private registry credentials not provided Raise UnauthorizedRegistryError in `_pull_image` if user tries to pull from a private registry without authentication, handle error in `command_bootstrap`, `commond_adopt`, `command_pull` Fixes: https://tracker.ceph.com/issues/55015 Signed-off-by: Melissa Li (cherry picked from commit 4de0803ba893abf341ab634d1382208370de7c98) --- diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 37e91f2c40cd..c9223f821428 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -252,6 +252,10 @@ class Error(Exception): class TimeoutExpired(Error): pass + +class UnauthorizedRegistryError(Error): + pass + ################################## @@ -3698,7 +3702,12 @@ def command_version(ctx): def command_pull(ctx): # type: (CephadmContext) -> int - _pull_image(ctx, ctx.image, ctx.insecure) + try: + _pull_image(ctx, ctx.image, ctx.insecure) + except UnauthorizedRegistryError: + err_str = 'Failed to pull container image. Check that host(s) are logged into the registry' + logger.debug(f'Pulling image for `command_pull` failed: {err_str}') + raise Error(err_str) return command_inspect_image(ctx) @@ -3726,6 +3735,9 @@ def _pull_image(ctx, image, insecure=False): if not ret: return + if 'unauthorized' in err: + raise UnauthorizedRegistryError() + if not any(pattern in err for pattern in ignorelist): raise Error('Failed command: %s' % cmd_str) @@ -4535,7 +4547,12 @@ def command_bootstrap(ctx): config = prepare_bootstrap_config(ctx, fsid, addr_arg, ctx.image) if not ctx.skip_pull: - _pull_image(ctx, ctx.image) + try: + _pull_image(ctx, ctx.image) + except UnauthorizedRegistryError: + err_str = 'Failed to pull container image. Check that correct registry credentials are provided in bootstrap by --registry-url, --registry-username, --registry-password, or supply --registry-json with credentials' + logger.debug(f'Pulling image for bootstrap on {hostname} failed: {err_str}') + raise Error(err_str) image_ver = CephContainer(ctx, ctx.image, 'ceph', ['--version']).run().strip() logger.info(f'Ceph version: {image_ver}') @@ -5561,7 +5578,12 @@ def command_adopt(ctx): # type: (CephadmContext) -> None if not ctx.skip_pull: - _pull_image(ctx, ctx.image) + try: + _pull_image(ctx, ctx.image) + except UnauthorizedRegistryError: + err_str = 'Failed to pull container image. Host may not be logged into container registry. Try `cephadm registry-login --registry-url --registry-username --registry-password ` or supply login info via a json file with `cephadm registry-login --registry-json `' + logger.debug(f'Pulling image for `command_adopt` failed: {err_str}') + raise Error(err_str) (daemon_type, daemon_id) = ctx.name.split('.', 1)