Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion coriolis/osmorphing/centos.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ class BaseCentOSMorphingTools(redhat.BaseRedHatMorphingTools):
@classmethod
def check_os_supported(cls, detected_os_info):
supported_oses = [
CENTOS_STREAM_DISTRO_IDENTIFIER, CENTOS_DISTRO_IDENTIFIER]
CENTOS_STREAM_DISTRO_IDENTIFIER,
CENTOS_DISTRO_IDENTIFIER,
"CentOS Linux",
"AlmaLinux",
]
if detected_os_info['distribution_name'] not in supported_oses:
return False
return cls._version_supported_util(
Expand Down
4 changes: 2 additions & 2 deletions coriolis/osmorphing/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class BaseOracleMorphingTools(redhat.BaseRedHatMorphingTools):

@classmethod
def check_os_supported(cls, detected_os_info):
if detected_os_info['distribution_name'] != (
ORACLE_DISTRO_IDENTIFIER):
if detected_os_info['distribution_name'] not in (
ORACLE_DISTRO_IDENTIFIER, "Oracle Linux Server"):
return False
return cls._version_supported_util(
detected_os_info['release_version'], minimum=6)
Expand Down
41 changes: 6 additions & 35 deletions coriolis/osmorphing/osdetect/centos.py
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(),

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.

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.

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.

Left a NOTE in the PR description mentioning the /etc/os-release was added starting Redhat version 7, anything before not having it and thus the logic not working for them.

match_ids={"centos", "almalinux"})
26 changes: 5 additions & 21 deletions coriolis/osmorphing/osdetect/oracle.py
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"})
34 changes: 5 additions & 29 deletions coriolis/osmorphing/osdetect/redhat.py
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"})
63 changes: 63 additions & 0 deletions coriolis/osmorphing/osdetect/redhat_common.py
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)}
34 changes: 5 additions & 29 deletions coriolis/osmorphing/osdetect/rocky.py
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"})
Loading
Loading