]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: make extract_uid_gid errors more readable 44293/head
authorSebastian Wagner <sewagner@redhat.com>
Mon, 13 Dec 2021 11:54:22 +0000 (12:54 +0100)
committerSebastian Wagner <sewagner@redhat.com>
Tue, 14 Dec 2021 13:13:15 +0000 (14:13 +0100)
Avoid dumping a traceback

Signed-off-by: Sebastian Wagner <sewagner@redhat.com>
src/cephadm/cephadm
src/cephadm/tests/test_cephadm.py

index f262bb1b7f6cfc20e96f9b7fe2ae848b50cc6815..74de67bd592a6a7a4017c540681b5a6151733988 100755 (executable)
@@ -1462,6 +1462,9 @@ def call_throws(
         **kwargs: Any) -> Tuple[str, str, int]:
     out, err, ret = call(ctx, command, desc, verbosity, timeout, **kwargs)
     if ret:
+        for s in (out, err):
+            if s.strip() and len(s.splitlines()) <= 2:  # readable message?
+                raise RuntimeError(f'Failed command: {" ".join(command)}: {s}')
         raise RuntimeError('Failed command: %s' % ' '.join(command))
     return out, err, ret
 
@@ -2631,6 +2634,8 @@ def extract_uid_gid(ctx, img='', file_path='/var/lib/ceph'):
     else:
         paths = file_path
 
+    ex: Optional[Tuple[str, RuntimeError]] = None
+
     for fp in paths:
         try:
             out = CephContainer(
@@ -2641,8 +2646,11 @@ def extract_uid_gid(ctx, img='', file_path='/var/lib/ceph'):
             ).run()
             uid, gid = out.split(' ')
             return int(uid), int(gid)
-        except RuntimeError:
-            pass
+        except RuntimeError as e:
+            ex = (fp, e)
+    if ex:
+        raise Error(f'Failed to extract uid/gid for path {ex[0]}: {ex[1]}')
+
     raise RuntimeError('uid/gid not found')
 
 
index df0f932248cc4c497282c57969dd30b439dd7fd1..94cf3827fe782bc3f068aa3f210e06396249c9c4 100644 (file)
@@ -540,6 +540,16 @@ docker.io/ceph/daemon-base:octopus
             infer_config(ctx)
             assert ctx.config == result
 
+    @mock.patch('cephadm.call')
+    def test_extract_uid_gid_fail(self, _call):
+        err = """Error: container_linux.go:370: starting container process caused: process_linux.go:459: container init caused: process_linux.go:422: setting cgroup config for procHooks process caused: Unit libpod-056038e1126191fba41d8a037275136f2d7aeec9710b9ee
+ff792c06d8544b983.scope not found.: OCI runtime error"""
+        _call.return_value = ('', err, 127)
+        ctx = cd.CephadmContext()
+        ctx.container_engine = mock_podman()
+        with pytest.raises(cd.Error, match='OCI'):
+            cd.extract_uid_gid(ctx)
+
 
 class TestCustomContainer(unittest.TestCase):
     cc: cd.CustomContainer