From 8a3ef73d02c61e21bd65240b8612314c668615fe Mon Sep 17 00:00:00 2001 From: Patrick Seidensal Date: Thu, 30 Jul 2020 11:37:46 +0200 Subject: [PATCH] cephadm: fix custom alertmanager When alertmanager image has been customized and does not have a /etc/alertmanager directory, the uid/gid extraction fails. This change assumes that instead the /etc/prometheus directory exists and can be used to extract the uid and gid. Signed-off-by: Patrick Seidensal (cherry picked from commit d218de4cde8d37f7f69a2a2a9474c0ac9afca41d) --- src/cephadm/cephadm | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 62ba1528d3e7c..829f56bb9e8c8 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -1840,18 +1840,28 @@ def get_container(fsid, daemon_type, daemon_id, def extract_uid_gid(img='', file_path='/var/lib/ceph'): - # type: (str, str) -> Tuple[int, int] + # type: (str, Union[str, Iterabe[str]]) -> Tuple[int, int] if not img: img = args.image - out = CephContainer( - image=img, - entrypoint='stat', - args=['-c', '%u %g', file_path] - ).run() - (uid, gid) = out.split(' ') - return int(uid), int(gid) + if isinstance(file_path, str): + paths = [file_path] + else: + paths = file_path + + for fp in paths: + try: + out = CephContainer( + image=img, + entrypoint='stat', + args=['-c', '%u %g', fp] + ).run() + uid, gid = out.split(' ') + return int(uid), int(gid) + except RuntimeError: + pass + raise RuntimeError('uid/gid not found') def deploy_daemon(fsid, daemon_type, daemon_id, c, uid, gid, @@ -3055,7 +3065,7 @@ def extract_uid_gid_monitoring(daemon_type): elif daemon_type == 'grafana': uid, gid = extract_uid_gid(file_path='/var/lib/grafana') elif daemon_type == 'alertmanager': - uid, gid = extract_uid_gid(file_path='/etc/alertmanager') + uid, gid = extract_uid_gid(file_path=['/etc/alertmanager', '/etc/prometheus']) else: raise Error("{} not implemented yet".format(daemon_type)) return uid, gid -- 2.39.5