Refactor osdetect for rhel family OSes#464
Conversation
bfd6e77 to
a4ee503
Compare
3a1a592 to
cc41923
Compare
|
|
||
| """Shared /etc/os-release parsing for RHEL-family osdetect tools.""" | ||
|
|
||
| from typing import Dict |
There was a problem hiding this comment.
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()``. |
There was a problem hiding this comment.
At this point, can't we just call get_os_release here and drop the parameter?
| CENTOS_STREAM_DISTRO_IDENTIFIER, CENTOS_DISTRO_IDENTIFIER] | ||
| CENTOS_STREAM_DISTRO_IDENTIFIER, | ||
| CENTOS_DISTRO_IDENTIFIER, | ||
| "CentOS Linux", |
There was a problem hiding this comment.
We should probably define constants for "CentOS Linux", "AlmaLinux" and "Oracle Linux Server".
|
Since we're now dropping RedHat 6 support, the following line should be updated as well: coriolis/coriolis/osmorphing/redhat.py Lines 36 to 37 in e7cc804 |
25068ed to
4f18bb2
Compare
|
|
||
|
|
||
| class RedHatOSReleaseMixin: | ||
| """Mixin providing RHEL-family /etc/os-release detection. |
There was a problem hiding this comment.
Why limit the mixin to /etc/os-release parsing? It can be used for any logic that's reused across RHEL derivatives.
There was a problem hiding this comment.
Fair point! Updated it
4f18bb2 to
119d1bc
Compare
| "friendly_release_name": "%s Version %s" % ( | ||
| distribution_name, version)} | ||
| return info | ||
| return self._detect_os_from_os_release({"centos", "almalinux"}) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
By going this route, we can have a single osdetect class for all RedHat derivatives.
There was a problem hiding this comment.
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.
This PR refactors the osdetect for the OSes that are RHEL related. It adds a
redhat_common.pywhere thedetect_os_from_os_releaseis defined to return the proper info from/etc/os-release:NOTE: Due to the use of
/etc/os-release, which was introduced starting with OSes likeRedHat version 7(e.g. RHEL 7, CentOS 7, OL7), this implementation makes the previousRedHat version 6OSes to not work with the current logic for detecting OSes.