-
Notifications
You must be signed in to change notification settings - Fork 68
Refactor osdetect for rhel family OSes #464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fabi200123
wants to merge
1
commit into
cloudbase:master
Choose a base branch
from
fabi200123:refactor-osdetect
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+312
−226
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,46 +1,17 @@ | ||
| # Copyright 2020 Cloudbase Solutions Srl | ||
| # All Rights Reserved. | ||
|
|
||
| import re | ||
|
|
||
| from coriolis import constants | ||
| from coriolis.osmorphing.osdetect import base | ||
| from oslo_log import log as logging | ||
| from coriolis.osmorphing.osdetect import redhat_common | ||
|
|
||
|
|
||
| LOG = logging.getLogger(__name__) | ||
| CENTOS_DISTRO_IDENTIFIER = "CentOS" | ||
| CENTOS_STREAM_DISTRO_IDENTIFIER = "CentOS Stream" | ||
| ALMA_IDENTIFIER = "AlmaLinux" | ||
| CENTOS_DISTRO_IDENTIFIER = redhat_common.CENTOS_DISTRO_IDENTIFIER | ||
| CENTOS_STREAM_DISTRO_IDENTIFIER = redhat_common.CENTOS_STREAM_DISTRO_IDENTIFIER | ||
|
|
||
|
|
||
| class CentOSOSDetectTools(base.BaseLinuxOSDetectTools): | ||
|
|
||
| def detect_os(self): | ||
| info = {} | ||
| redhat_release_path = "etc/redhat-release" | ||
| if self._test_path(redhat_release_path): | ||
| release_info = self._read_file( | ||
| redhat_release_path).decode().splitlines() | ||
| if release_info: | ||
| m = re.match(r"^(.*) release ([0-9]+(\.[0-9]+)*)( \(.*\))?.*$", | ||
| release_info[0].strip()) | ||
| if m: | ||
| distro, version, _, _ = m.groups() | ||
| if (CENTOS_DISTRO_IDENTIFIER not in distro and | ||
| ALMA_IDENTIFIER not in distro): | ||
| LOG.debug( | ||
| "Distro does not appear to be a CentOS or Alma: " | ||
| f"{distro}") | ||
| return {} | ||
|
|
||
| distribution_name = CENTOS_DISTRO_IDENTIFIER | ||
| if CENTOS_STREAM_DISTRO_IDENTIFIER in distro: | ||
| distribution_name = CENTOS_STREAM_DISTRO_IDENTIFIER | ||
| info = { | ||
| "os_type": constants.OS_TYPE_LINUX, | ||
| "distribution_name": distribution_name, | ||
| "release_version": version, | ||
| "friendly_release_name": "%s Version %s" % ( | ||
| distribution_name, version)} | ||
| return info | ||
| return redhat_common.detect_os_from_os_release( | ||
| self._get_os_release(), | ||
| match_ids={"centos", "almalinux"}) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,16 @@ | ||
| # Copyright 2020 Cloudbase Solutions Srl | ||
| # All Rights Reserved. | ||
|
|
||
| import re | ||
|
|
||
| from coriolis import constants | ||
| from coriolis.osmorphing.osdetect import base | ||
| from coriolis.osmorphing.osdetect import redhat_common | ||
|
|
||
|
|
||
| ORACLE_DISTRO_IDENTIFIER = "Oracle Linux" | ||
| ORACLE_DISTRO_IDENTIFIER = redhat_common.ORACLE_DISTRO_IDENTIFIER | ||
|
|
||
|
|
||
| class OracleOSDetectTools(base.BaseLinuxOSDetectTools): | ||
|
|
||
| def detect_os(self): | ||
| info = {} | ||
| oracle_release_path = "etc/oracle-release" | ||
| if self._test_path(oracle_release_path): | ||
| release_info = self._read_file( | ||
| oracle_release_path).decode().splitlines() | ||
| if release_info: | ||
| m = re.match(r"^(.*) release ([0-9].*)$", | ||
| release_info[0].strip()) | ||
| if m: | ||
| distro, version = m.groups() | ||
| info = { | ||
| "os_type": constants.OS_TYPE_LINUX, | ||
| "distribution_name": ORACLE_DISTRO_IDENTIFIER, | ||
| "release_version": version, | ||
| "friendly_release_name": "%s Version %s" % ( | ||
| distro, version)} | ||
| return info | ||
| return redhat_common.detect_os_from_os_release( | ||
| self._get_os_release(), | ||
| match_ids={"ol"}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,40 +1,16 @@ | ||
| # Copyright 2020 Cloudbase Solutions Srl | ||
| # All Rights Reserved. | ||
|
|
||
| import re | ||
|
|
||
| from oslo_log import log as logging | ||
|
|
||
| from coriolis import constants | ||
| from coriolis.osmorphing.osdetect import base | ||
| from coriolis.osmorphing.osdetect import redhat_common | ||
|
|
||
|
|
||
| LOG = logging.getLogger(__name__) | ||
| RED_HAT_DISTRO_IDENTIFIER = "Red Hat Enterprise Linux" | ||
| RED_HAT_DISTRO_IDENTIFIER = redhat_common.RED_HAT_DISTRO_IDENTIFIER | ||
|
|
||
|
|
||
| class RedHatOSDetectTools(base.BaseLinuxOSDetectTools): | ||
|
|
||
| def detect_os(self): | ||
| info = {} | ||
| redhat_release_path = "etc/redhat-release" | ||
| if self._test_path(redhat_release_path): | ||
| release_info = self._read_file( | ||
| redhat_release_path).decode().splitlines() | ||
| if release_info: | ||
| m = re.match(r"^(.*) release ([0-9].*) \((.*)\).*$", | ||
| release_info[0].strip()) | ||
| if m: | ||
| distro, version, _ = m.groups() | ||
| if RED_HAT_DISTRO_IDENTIFIER not in distro: | ||
| LOG.debug( | ||
| "Distro does not appear to be a RHEL: %s", distro) | ||
| return {} | ||
|
|
||
| info = { | ||
| "os_type": constants.OS_TYPE_LINUX, | ||
| "distribution_name": RED_HAT_DISTRO_IDENTIFIER, | ||
| "release_version": version, | ||
| "friendly_release_name": "%s Version %s" % ( | ||
| RED_HAT_DISTRO_IDENTIFIER, version)} | ||
| return info | ||
| return redhat_common.detect_os_from_os_release( | ||
| self._get_os_release(), | ||
| match_ids={"rhel"}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # Copyright 2026 Cloudbase Solutions Srl | ||
| # All Rights Reserved. | ||
|
|
||
| """Shared /etc/os-release parsing for RHEL-family osdetect tools.""" | ||
|
|
||
| from typing import Dict | ||
| from typing import Optional | ||
| from typing import Set | ||
|
|
||
| from oslo_log import log as logging | ||
|
|
||
| from coriolis import constants | ||
|
|
||
| LOG = logging.getLogger(__name__) | ||
|
|
||
| ROCKY_LINUX_DISTRO_IDENTIFIER = "Rocky Linux" | ||
| CENTOS_DISTRO_IDENTIFIER = "CentOS" | ||
| CENTOS_STREAM_DISTRO_IDENTIFIER = "CentOS Stream" | ||
| RED_HAT_DISTRO_IDENTIFIER = "Red Hat Enterprise Linux" | ||
| ORACLE_DISTRO_IDENTIFIER = "Oracle Linux" | ||
|
|
||
|
|
||
| def detect_os_from_os_release( | ||
| os_release: Optional[Dict[str, str]], | ||
| *, | ||
| match_ids: Set[str]) -> 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()``. | ||
| :param match_ids: ``ID`` value(s) this osdetect module handles, e.g. | ||
| ``{"rocky"}`` or ``{"centos", "almalinux"}``. | ||
| """ | ||
| if not os_release: | ||
| LOG.warning( | ||
| "Could not detect OS from /etc/os-release: os_release dict " | ||
| "was not provided") | ||
| return {} | ||
|
|
||
| os_id = (os_release.get("ID") or "").lower() | ||
| if os_id not in match_ids: | ||
| return {} | ||
|
|
||
| distribution_name = os_release.get("NAME") | ||
| if not distribution_name: | ||
| LOG.warning( | ||
| "Could not detect OS from /etc/os-release: matched OS ID '%s' " | ||
| "but NAME is missing", os_id) | ||
| return {} | ||
|
|
||
| version = os_release.get("VERSION_ID") | ||
| if not version: | ||
| LOG.warning( | ||
| "Could not detect OS from /etc/os-release: matched OS ID '%s' " | ||
| "but VERSION_ID is missing", os_id) | ||
| return {} | ||
|
|
||
| return { | ||
| "os_type": constants.OS_TYPE_LINUX, | ||
| "distribution_name": distribution_name, | ||
| "release_version": version, | ||
| "friendly_release_name": "%s Version %s" % ( | ||
| distribution_name, version)} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,40 +1,16 @@ | ||
| # Copyright 2023 Cloudbase Solutions Srl | ||
| # All Rights Reserved. | ||
|
|
||
| import re | ||
|
|
||
| from coriolis import constants | ||
| from coriolis.osmorphing.osdetect import base | ||
| from oslo_log import log as logging | ||
| from coriolis.osmorphing.osdetect import redhat_common | ||
|
|
||
|
|
||
| LOG = logging.getLogger(__name__) | ||
| ROCKY_LINUX_DISTRO_IDENTIFIER = "Rocky Linux" | ||
| ROCKY_LINUX_DISTRO_IDENTIFIER = redhat_common.ROCKY_LINUX_DISTRO_IDENTIFIER | ||
|
|
||
|
|
||
| class RockyLinuxOSDetectTools(base.BaseLinuxOSDetectTools): | ||
|
|
||
| def detect_os(self): | ||
| info = {} | ||
| redhat_release_path = "etc/redhat-release" | ||
| if self._test_path(redhat_release_path): | ||
| release_info = self._read_file( | ||
| redhat_release_path).decode().splitlines() | ||
| if release_info: | ||
| m = re.match(r"^(.*) release ([0-9]+(\.[0-9]+)*)( \(.*\))?.*$", | ||
| release_info[0].strip()) | ||
| if m: | ||
| distro, version, _, _ = m.groups() | ||
| if ROCKY_LINUX_DISTRO_IDENTIFIER not in distro: | ||
| LOG.debug( | ||
| "Distro does not appear to be a Rocky Linux: %s", | ||
| distro) | ||
| return {} | ||
|
|
||
| info = { | ||
| "os_type": constants.OS_TYPE_LINUX, | ||
| "distribution_name": ROCKY_LINUX_DISTRO_IDENTIFIER, | ||
| "release_version": version, | ||
| "friendly_release_name": "%s Version %s" % ( | ||
| ROCKY_LINUX_DISTRO_IDENTIFIER, version)} | ||
| return info | ||
| return redhat_common.detect_os_from_os_release( | ||
| self._get_os_release(), | ||
| match_ids={"rocky"}) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RHEL 6 and derivate OS-es do not have the /etc/os-release file. Are we going to drop RHEL 6 support? If so, the PR description must clearly state it. We can also remove RHEL 6 specific os-morphing code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a NOTE in the PR description mentioning the
/etc/os-releasewas added starting Redhat version 7, anything before not having it and thus the logic not working for them.