]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: fix custom alertmanager
authorPatrick Seidensal <pseidensal@suse.com>
Thu, 30 Jul 2020 09:37:46 +0000 (11:37 +0200)
committerSebastian Wagner <sebastian.wagner@suse.com>
Fri, 21 Aug 2020 11:04:01 +0000 (13:04 +0200)
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 <pseidensal@suse.com>
(cherry picked from commit d218de4cde8d37f7f69a2a2a9474c0ac9afca41d)

src/cephadm/cephadm

index 62ba1528d3e7ce3747a121d2c500c157b88dca8f..829f56bb9e8c8c243ba8bdcaaa619808955d69d9 100755 (executable)
@@ -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