From d07e72c4b0bdc4d74cf1a0d8826061942f757d08 Mon Sep 17 00:00:00 2001 From: Michael Fritch Date: Wed, 8 Sep 2021 17:16:31 -0600 Subject: [PATCH] cephadm: raise error during `pull` failure instead of a traceback to the console Signed-off-by: Michael Fritch --- src/cephadm/cephadm | 4 ++-- src/cephadm/tests/test_cephadm.py | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 585c0f3c7802c..337ac90b24b0f 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -3491,12 +3491,12 @@ def _pull_image(ctx, image): return if not any(pattern in err for pattern in ignorelist): - raise RuntimeError('Failed command: %s' % cmd_str) + raise Error('Failed command: %s' % cmd_str) logger.info('`%s` failed transiently. Retrying. waiting %s seconds...' % (cmd_str, sleep_secs)) time.sleep(sleep_secs) - raise RuntimeError('Failed command: %s: maximum retries reached' % cmd_str) + raise Error('Failed command: %s: maximum retries reached' % cmd_str) ################################## diff --git a/src/cephadm/tests/test_cephadm.py b/src/cephadm/tests/test_cephadm.py index 03d872881d376..c4f514699c43b 100644 --- a/src/cephadm/tests/test_cephadm.py +++ b/src/cephadm/tests/test_cephadm.py @@ -1568,3 +1568,29 @@ class TestRmRepo: ctx.container_engine = mock_docker() cd.command_rm_repo(ctx) + + +class TestPull: + + @mock.patch('time.sleep') + @mock.patch('cephadm.call', return_value=('', '', 0)) + @mock.patch('cephadm.get_image_info_from_inspect', return_value={}) + def test_error(self, get_image_info_from_inspect, call, sleep): + ctx = cd.CephadmContext() + ctx.container_engine = mock_podman() + + call.return_value = ('', '', 0) + retval = cd.command_pull(ctx) + assert retval == 0 + + err = 'maximum retries reached' + + call.return_value = ('', 'foobar', 1) + with pytest.raises(cd.Error) as e: + cd.command_pull(ctx) + assert err not in str(e.value) + + call.return_value = ('', 'net/http: TLS handshake timeout', 1) + with pytest.raises(cd.Error) as e: + cd.command_pull(ctx) + assert err in str(e.value) -- 2.39.5