**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
else:
paths = file_path
+ ex: Optional[Tuple[str, RuntimeError]] = None
+
for fp in paths:
try:
out = CephContainer(
).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')
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