diff --git a/hotsos/core/plugins/kernel/common.py b/hotsos/core/plugins/kernel/common.py index b80f8514b..9034e03d6 100644 --- a/hotsos/core/plugins/kernel/common.py +++ b/hotsos/core/plugins/kernel/common.py @@ -1,17 +1,52 @@ import os import re +from datetime import datetime from hotsos.core.utils import cached_property +from hotsos.core.host_helpers.cli import CLIHelper from hotsos.core import host_helpers, plugintools from hotsos.core.config import HotSOSConfig +from hotsos.core.log import log from hotsos.core.plugins.kernel.config import KernelConfig +from hotsos.core.plugins.system import SystemBase + + +# NOTE(dosaboy): when updating this, refer to the kernel supported versions +# page: https://ubuntu.com/about/release-cycle#ubuntu-kernel-release-cycle +KERNEL_EOL_INFO = { + '5.19': + {'22.04.5': datetime(2027, 4, 30), + '20.04.0': datetime(2025, 4, 30)}, + '5.13': + {'21.10': datetime(2022, 6, 30), + '20.04.4': datetime(2022, 6, 30)}, + '5.11': + {'21.04': datetime(2022, 1, 30), + '20.04.3': datetime(2022, 1, 30)}, + '5.8': + {'20.10': datetime(2021, 6, 30), + '20.04.2': datetime(2021, 6, 30), + '18.04.5': datetime(2028, 4, 30), + '20.04.1': datetime(2030, 4, 30), + '20.04.0': datetime(2030, 4, 30)}, + '4.15': + {'16.04.5': datetime(2021, 4, 30), + '18.04.1': datetime(2023, 4, 30), + '18.04.0': datetime(2023, 4, 30)}, + '4.4': + {'16.04.1': datetime(2021, 4, 30), + '16.04.0': datetime(2021, 4, 30), + '14.04.5': datetime(2019, 4, 30)}, + '3.13': + {'14.04.1': datetime(2019, 4, 30), + '14.04.1': datetime(2019, 4, 30)}, +} class KernelBase(object): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self._kernel_version = "" self._boot_parameters = [] @cached_property @@ -21,9 +56,40 @@ def version(self): if uname: ret = re.compile(r"^Linux\s+\S+\s+(\S+)\s+.+").match(uname) if ret: - self._kernel_version = ret[1] + return ret[1] + + return '' + + @cached_property + def days_to_eol(self): + if self.version == '': + log.warning("kernel version could not be determined.") + return + + ret = re.match('(\d{1,2}.\d{1,2}).\d{1,2}\S+', self.version) + if not ret: + log.warning("unable to determine eol info for kernel " + "version '%s' - could not extract version", + self.version) + return + + eol = KERNEL_EOL_INFO.get(ret.group(1)) + if eol is None: + log.warning("unable to determine eol info for kernel " + "version '%s' (%s)", self.version, ret.group(1)) + return + + os_version = SystemBase().os_version + eol = eol.get(os_version) + if eol is None: + log.warning("unable to determine eol info for kernel " + "version '%s' and os version '%s'", self.version, + os_version) + return - return self._kernel_version + today = datetime.utcfromtimestamp(int(CLIHelper().date())) + delta = (eol - today).days + return delta @cached_property def isolcpus_enabled(self): diff --git a/hotsos/core/plugins/system/system.py b/hotsos/core/plugins/system/system.py index e44bb025e..18d526e3d 100644 --- a/hotsos/core/plugins/system/system.py +++ b/hotsos/core/plugins/system/system.py @@ -90,6 +90,15 @@ def os_release_name(self): if ret: return "ubuntu {}".format(ret[1]) + @cached_property + def os_version(self): + data_source = os.path.join(HotSOSConfig.data_root, "etc/lsb-release") + if os.path.exists(data_source): + for line in open(data_source).read().split(): + ret = re.compile(r"^DISTRIB_RELEASE=(.+)").match(line) + if ret: + return ret[1] + @cached_property def virtualisation_type(self): """ diff --git a/hotsos/defs/scenarios/kernel/eol.yaml b/hotsos/defs/scenarios/kernel/eol.yaml new file mode 100644 index 000000000..ddf42665c --- /dev/null +++ b/hotsos/defs/scenarios/kernel/eol.yaml @@ -0,0 +1,16 @@ +checks: + is_eol: + property: + path: hotsos.core.plugins.kernel.KernelBase.days_to_eol + ops: [[le, 0]] +conclusions: + is-eol: + decision: is_eol + raises: + type: KernelWarning + message: >- + This node is running a kernel version that is End of Life (release={version}) + which means it has limited support and is likely not receiving updates + anymore. Please consider upgrading to a newer release. + format-dict: + version: hotsos.core.plugins.kernel.KernelBase.version diff --git a/hotsos/defs/tests/scenarios/kernel/eol.yaml b/hotsos/defs/tests/scenarios/kernel/eol.yaml new file mode 100644 index 000000000..3d07c8500 --- /dev/null +++ b/hotsos/defs/tests/scenarios/kernel/eol.yaml @@ -0,0 +1,12 @@ +data-root: + files: + sos_commands/kernel/uname_-a: | + Linux compute4 4.15.0-97-generic #110-Ubuntu SMP Thu Jan 13 18:22:13 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux + copy-from-original: + - etc/lsb-release +raised-issues: + KernelWarning: >- + This node is running a kernel version that is End of Life + (version=3.4.0) which means it has limited support and is + likely not receiving updates anymore. Please consider upgrading + to a newer release.