]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: raise error during `pull` failure
authorMichael Fritch <mfritch@suse.com>
Wed, 8 Sep 2021 23:16:31 +0000 (17:16 -0600)
committerSebastian Wagner <sewagner@redhat.com>
Tue, 2 Nov 2021 09:01:18 +0000 (10:01 +0100)
instead of a traceback to the console

Signed-off-by: Michael Fritch <mfritch@suse.com>
(cherry picked from commit d07e72c4b0bdc4d74cf1a0d8826061942f757d08)

src/cephadm/cephadm
src/cephadm/tests/test_cephadm.py

index 4d6e4ee4499d51cd50beb56bfb0792807fbb8d8a..fbf5a81d22ac1f14cb4a54920a0b3c4f2575accc 100755 (executable)
@@ -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)
 
 ##################################
 
index f65febcb84ad7a48bf09c6615d982bbaf56be18a..16e32833f636458330a53533d419387e29e43ba7 100644 (file)
@@ -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)