From: Michael Fritch Date: Wed, 8 Sep 2021 23:16:31 +0000 (-0600) Subject: cephadm: raise error during `pull` failure X-Git-Tag: v16.2.7~67^2~63 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=ea3289f0f69645b138121e6d14fc8bbdfd70b50d;p=ceph.git cephadm: raise error during `pull` failure instead of a traceback to the console Signed-off-by: Michael Fritch (cherry picked from commit d07e72c4b0bdc4d74cf1a0d8826061942f757d08) --- diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 4d6e4ee4499d5..fbf5a81d22ac1 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -3465,12 +3465,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 f65febcb84ad7..16e32833f6364 100644 --- a/src/cephadm/tests/test_cephadm.py +++ b/src/cephadm/tests/test_cephadm.py @@ -1548,3 +1548,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)