Skip to content

Commit 1076450

Browse files
authored
Merge pull request ceph#65599 from bachmanity1/cephadm-support-custom-distro
cephadm: support custom distros by falling back to `ID_LIKE` Reviewed-by: Adam King <[email protected]> Reviewed-by: John Mulligan <[email protected]>
2 parents a700708 + 3532338 commit 1076450

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

src/cephadm/cephadmlib/packagers.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
def get_distro():
2020
# type: () -> Tuple[Optional[str], Optional[str], Optional[str]]
2121
distro = None
22+
distro_like: List[str] = []
2223
distro_version = None
2324
distro_codename = None
2425
with open('/etc/os-release', 'r') as f:
@@ -31,13 +32,34 @@ def get_distro():
3132
val = val[1:-1]
3233
if var == 'ID':
3334
distro = val.lower()
35+
elif var == 'ID_LIKE':
36+
# ID_LIKE can be space-separated or comma-separated
37+
for token in val.replace(',', ' ').split():
38+
distro_like.append(token.strip().lower())
3439
elif var == 'VERSION_ID':
3540
distro_version = val.lower()
3641
elif var == 'VERSION_CODENAME':
3742
distro_codename = val.lower()
43+
44+
if not is_known_distro(distro):
45+
for candidate_distro in distro_like:
46+
if is_known_distro(candidate_distro):
47+
distro = candidate_distro
48+
break
49+
3850
return distro, distro_version, distro_codename
3951

4052

53+
def is_known_distro(distro: Optional[str]) -> bool:
54+
if not distro:
55+
return False
56+
return (
57+
distro in YumDnf.DISTRO_NAMES
58+
or distro in Apt.DISTRO_NAMES
59+
or distro in Zypper.DISTRO_NAMES
60+
)
61+
62+
4163
class Packager(object):
4264
def __init__(
4365
self,

src/cephadm/tests/test_util_funcs.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,54 @@ def test_check_time_sync(call_fn, expected):
517517
""",
518518
("hpec", "33", "hpec nimda"),
519519
),
520+
(
521+
"""# Fallback: unknown distro with comma-separated ID_LIKE
522+
ID="custom-rhel"
523+
ID_LIKE="rhel,centos,fedora"
524+
VERSION_ID="8"
525+
""",
526+
("rhel", "8", None),
527+
),
528+
(
529+
"""# Fallback: unknown distro with space-separated ID_LIKE
530+
ID="custom-rhel"
531+
ID_LIKE="rhel centos fedora"
532+
VERSION_ID="8"
533+
""",
534+
("rhel", "8", None),
535+
),
536+
(
537+
"""# Fallback: picks first known distro from mixed ID_LIKE
538+
ID="custom-distro"
539+
ID_LIKE="unknown-distro,centos,fedora"
540+
VERSION_ID="8"
541+
""",
542+
("centos", "8", None),
543+
),
544+
(
545+
"""# No fallback: unknown distro with unknown ID_LIKE values
546+
ID="unknown-distro"
547+
ID_LIKE="also-unknown another-unknown"
548+
VERSION_ID="1.0"
549+
""",
550+
("unknown-distro", "1.0", None),
551+
),
552+
(
553+
"""# No fallback: unknown distro with empty ID_LIKE
554+
ID="unknown-distro"
555+
ID_LIKE=""
556+
VERSION_ID="1.0"
557+
""",
558+
("unknown-distro", "1.0", None),
559+
),
560+
(
561+
"""# No fallback: known distro stays unchanged
562+
ID="rocky"
563+
ID_LIKE="rhel centos fedora"
564+
VERSION_ID="8.5"
565+
""",
566+
("rocky", "8.5", None),
567+
),
520568
],
521569
)
522570
def test_get_distro(monkeypatch, content, expected):

0 commit comments

Comments
 (0)