]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: support custom distros by falling back to ID_LIKE 65696/head
authorbachmanity1 <bachmanity138@gmail.com>
Fri, 19 Sep 2025 07:52:15 +0000 (16:52 +0900)
committerAdam King <adking@redhat.com>
Fri, 26 Sep 2025 14:24:25 +0000 (10:24 -0400)
This change enables cephadm to work on custom or derivative distributions
that are based on supported distros without requiring code changes for
each new custom/derivative distro.

Signed-off-by: bachmanity1 <bachmanity138@gmail.com>
(cherry picked from commit 35323380403eebe69ad8650a2036afa87569d1a2)

src/cephadm/cephadmlib/packagers.py
src/cephadm/tests/test_util_funcs.py

index df015771650b5595f1af357ebc1bf70b4be5daae..a353fbe79a08ddffcd7e0ce30906ed4697084719 100644 (file)
@@ -19,6 +19,7 @@ logger = logging.getLogger()
 def get_distro():
     # type: () -> Tuple[Optional[str], Optional[str], Optional[str]]
     distro = None
+    distro_like: List[str] = []
     distro_version = None
     distro_codename = None
     with open('/etc/os-release', 'r') as f:
@@ -31,13 +32,34 @@ def get_distro():
                 val = val[1:-1]
             if var == 'ID':
                 distro = val.lower()
+            elif var == 'ID_LIKE':
+                # ID_LIKE can be space-separated or comma-separated
+                for token in val.replace(',', ' ').split():
+                    distro_like.append(token.strip().lower())
             elif var == 'VERSION_ID':
                 distro_version = val.lower()
             elif var == 'VERSION_CODENAME':
                 distro_codename = val.lower()
+
+    if not is_known_distro(distro):
+        for candidate_distro in distro_like:
+            if is_known_distro(candidate_distro):
+                distro = candidate_distro
+                break
+
     return distro, distro_version, distro_codename
 
 
+def is_known_distro(distro: Optional[str]) -> bool:
+    if not distro:
+        return False
+    return (
+        distro in YumDnf.DISTRO_NAMES
+        or distro in Apt.DISTRO_NAMES
+        or distro in Zypper.DISTRO_NAMES
+    )
+
+
 class Packager(object):
     def __init__(
         self,
index d2aa39aca4bf8f3ce235f09ee5ed23603de55825..e5b88fcf83989a106df99da6d143cfc42f653ba7 100644 (file)
@@ -517,6 +517,54 @@ VERSION_CODENAME=hpec nimda
             """,
             ("hpec", "33", "hpec nimda"),
         ),
+        (
+            """# Fallback: unknown distro with comma-separated ID_LIKE
+ID="custom-rhel"
+ID_LIKE="rhel,centos,fedora"
+VERSION_ID="8"
+            """,
+            ("rhel", "8", None),
+        ),
+        (
+            """# Fallback: unknown distro with space-separated ID_LIKE
+ID="custom-rhel"
+ID_LIKE="rhel centos fedora"
+VERSION_ID="8"
+            """,
+            ("rhel", "8", None),
+        ),
+        (
+            """# Fallback: picks first known distro from mixed ID_LIKE
+ID="custom-distro"
+ID_LIKE="unknown-distro,centos,fedora"
+VERSION_ID="8"
+            """,
+            ("centos", "8", None),
+        ),
+        (
+            """# No fallback: unknown distro with unknown ID_LIKE values
+ID="unknown-distro"
+ID_LIKE="also-unknown another-unknown"
+VERSION_ID="1.0"
+            """,
+            ("unknown-distro", "1.0", None),
+        ),
+        (
+            """# No fallback: unknown distro with empty ID_LIKE
+ID="unknown-distro"
+ID_LIKE=""
+VERSION_ID="1.0"
+            """,
+            ("unknown-distro", "1.0", None),
+        ),
+        (
+            """# No fallback: known distro stays unchanged
+ID="rocky"
+ID_LIKE="rhel centos fedora"
+VERSION_ID="8.5"
+            """,
+            ("rocky", "8.5", None),
+        ),
     ],
 )
 def test_get_distro(monkeypatch, content, expected):