From b6b238ae4330dd84d5a7f18efb7bf18fd8ee20af Mon Sep 17 00:00:00 2001 From: Lars Date: Tue, 6 Nov 2018 14:12:38 +0100 Subject: [PATCH] facts: suse: fix SLES4SAP12 detection (#44388) --- .../module_utils/facts/system/distribution.py | 4 ++ .../module_utils/test_distribution_version.py | 59 ++++++++++++++++++- 2 files changed, 62 insertions(+), 1 deletion(-) diff --git a/lib/ansible/module_utils/facts/system/distribution.py b/lib/ansible/module_utils/facts/system/distribution.py index cf59fdc8b93..03c7acc3a16 100644 --- a/lib/ansible/module_utils/facts/system/distribution.py +++ b/lib/ansible/module_utils/facts/system/distribution.py @@ -269,6 +269,10 @@ class DistributionFiles: else: release = "0" # no minor number, so it is the first release suse_facts['distribution_release'] = release + # Starting with SLES4SAP12 SP3 NAME reports 'SLES' instead of 'SLES_SAP' + # According to SuSe Support (SR101182877871) we should use the CPE_NAME to detect SLES4SAP + if re.search("^CPE_NAME=.*sles_sap.*$", line): + suse_facts['distribution'] = 'SLES_SAP' elif path == '/etc/SuSE-release': if 'open' in data.lower(): data = data.splitlines() diff --git a/test/units/module_utils/test_distribution_version.py b/test/units/module_utils/test_distribution_version.py index 25f9169593a..3698cae892f 100644 --- a/test/units/module_utils/test_distribution_version.py +++ b/test/units/module_utils/test_distribution_version.py @@ -351,7 +351,64 @@ CPE_NAME="cpe:/o:suse:sles:12:sp1" "distribution_version": "12.1", } }, - + { + "name": "SLES4SAP 12 SP2", + "input": { + "/etc/SuSE-release": """ +SUSE Linux Enterprise Server 12 (x86_64) +VERSION = 12 +PATCHLEVEL = 2 +# This file is deprecated and will be removed in a future service pack or release. +# Please check /etc/os-release for details about this release. +""", + "/etc/os-release": """ +NAME="SLES_SAP" +VERSION="12-SP2" +VERSION_ID="12.2" +PRETTY_NAME="SUSE Linux Enterprise Server for SAP Applications 12 SP2" +ID="sles_sap" +ANSI_COLOR="0;32" +CPE_NAME="cpe:/o:suse:sles_sap:12:sp2" + """, + }, + "platform.dist": ['SuSE', '12', 'x86_64'], + "result":{ + "distribution": "SLES_SAP", + "distribution_major_version": "12", + "distribution_release": "2", + "os_family": "Suse", + "distribution_version": "12.2", + } + }, + { + "name": "SLES4SAP 12 SP3", + "input": { + "/etc/SuSE-release": """ +SUSE Linux Enterprise Server 12 (x86_64) +VERSION = 12 +PATCHLEVEL = 3 +# This file is deprecated and will be removed in a future service pack or release. +# Please check /etc/os-release for details about this release. +""", + "/etc/os-release": """ +NAME="SLES" +VERSION="12-SP3" +VERSION_ID="12.3" +PRETTY_NAME="SUSE Linux Enterprise Server 12 SP3" +ID="sles" +ANSI_COLOR="0;32" +CPE_NAME="cpe:/o:suse:sles_sap:12:sp3" + """, + }, + "platform.dist": ['SuSE', '12', 'x86_64'], + "result":{ + "distribution": "SLES_SAP", + "distribution_major_version": "12", + "distribution_release": "3", + "os_family": "Suse", + "distribution_version": "12.3", + } + }, { "name": "Debian stretch/sid", "input": {