Skip to content

Refactor osdetect for rhel family OSes#464

Open
fabi200123 wants to merge 1 commit into
cloudbase:masterfrom
fabi200123:refactor-osdetect
Open

Refactor osdetect for rhel family OSes#464
fabi200123 wants to merge 1 commit into
cloudbase:masterfrom
fabi200123:refactor-osdetect

Conversation

@fabi200123

@fabi200123 fabi200123 commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

This PR refactors the osdetect for the OSes that are RHEL related. It adds a redhat_common.py where the detect_os_from_os_release is defined to return the proper info from /etc/os-release:

    return {
        "os_type": constants.OS_TYPE_LINUX,
        "distribution_name": distribution_name,
        "release_version": version,
        "friendly_release_name": "%s Version %s" % (
            distribution_name, version)}

NOTE: Due to the use of /etc/os-release, which was introduced starting with OSes like RedHat version 7 (e.g. RHEL 7, CentOS 7, OL7), this implementation makes the previous RedHat version 6 OSes to not work with the current logic for detecting OSes.

@fabi200123
fabi200123 marked this pull request as draft July 1, 2026 09:34
@fabi200123
fabi200123 force-pushed the refactor-osdetect branch from bfd6e77 to a4ee503 Compare July 1, 2026 10:37
@fabi200123
fabi200123 marked this pull request as ready for review July 1, 2026 11:14
Comment thread coriolis/osmorphing/osdetect/common.py Outdated
Comment thread coriolis/osmorphing/osdetect/common.py Outdated
Comment thread coriolis/osmorphing/osdetect/common.py Outdated
Comment thread coriolis/osmorphing/osdetect/common.py Outdated
Comment thread coriolis/osmorphing/osdetect/common.py Outdated
Comment thread coriolis/osmorphing/osdetect/common.py Outdated
Comment thread coriolis/osmorphing/osdetect/centos.py Outdated
@fabi200123
fabi200123 force-pushed the refactor-osdetect branch 2 times, most recently from 3a1a592 to cc41923 Compare July 9, 2026 11:37
@fabi200123
fabi200123 marked this pull request as draft July 20, 2026 09:49
@fabi200123
fabi200123 marked this pull request as ready for review July 21, 2026 07:44

"""Shared /etc/os-release parsing for RHEL-family osdetect tools."""

from typing import Dict

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, just for future reference: no need to use Dict from typing, you can declare the type annotation as dict[str, str]

"""Detect a RHEL-family distro from /etc/os-release.

:param os_release: dict populated by ``/etc/os-release`` values, as
returned by ``BaseLinuxOSDetectTools._get_os_release()``.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point, can't we just call get_os_release here and drop the parameter?

Comment thread coriolis/osmorphing/centos.py Outdated
CENTOS_STREAM_DISTRO_IDENTIFIER, CENTOS_DISTRO_IDENTIFIER]
CENTOS_STREAM_DISTRO_IDENTIFIER,
CENTOS_DISTRO_IDENTIFIER,
"CentOS Linux",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably define constants for "CentOS Linux", "AlmaLinux" and "Oracle Linux Server".

@petrutlucian94

Copy link
Copy Markdown
Member

Since we're now dropping RedHat 6 support, the following line should be updated as well:

return cls._version_supported_util(
detected_os_info['release_version'], minimum=6)

@fabi200123
fabi200123 force-pushed the refactor-osdetect branch 2 times, most recently from 25068ed to 4f18bb2 Compare July 23, 2026 13:25


class RedHatOSReleaseMixin:
"""Mixin providing RHEL-family /etc/os-release detection.

@petrutlucian94 petrutlucian94 Jul 23, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why limit the mixin to /etc/os-release parsing? It can be used for any logic that's reused across RHEL derivatives.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point! Updated it

"friendly_release_name": "%s Version %s" % (
distribution_name, version)}
return info
return self._detect_os_from_os_release({"centos", "almalinux"})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we actually need the match_ids filter. without it, it would be able to detect the OS info for any distro that provides /etc/os-release (most modern releases that include systemd).

If we drop the match_ids parameter, _detect_os_from_os_release can become detect_os and it no longer needs to be defined by every RHEL deriviative class.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That being said, there's also the option to move _detect_os_from_os_release to BaseLinuxOSDetectTools and eventually use it for Debian based distros as well, once we drop the support for pre-systemd Debian/Ubuntu releases.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By going this route, we can have a single osdetect class for all RedHat derivatives.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could even have a single LinuxOSDetectUsingOSRelease class for all Linux distros that include /etc/os-release, eventually it would be used for most if not all Linux distros.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants