From 2b104fe6ad3b41d92d627f85b017602a0f4fef5a Mon Sep 17 00:00:00 2001 From: Robin Roth Date: Thu, 14 Apr 2016 19:01:24 +0200 Subject: [PATCH] fix tests for SLES and CoreOS * include #15230 --- lib/ansible/module_utils/facts.py | 12 +++++---- .../module_utils/test_distribution_version.py | 26 +++++++++---------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index 4e3c72d2f0..8d37a10b41 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -126,8 +126,8 @@ class Facts(object): ('/etc/alpine-release', 'Alpine'), ('/etc/release', 'Solaris'), ('/etc/arch-release', 'Archlinux'), - ('/etc/SuSE-release', 'SuSE'), ('/etc/os-release', 'SuSE'), + ('/etc/SuSE-release', 'SuSE'), ('/etc/gentoo-release', 'Gentoo'), ('/etc/os-release', 'Debian'), ('/etc/lsb-release', 'Mandriva'), @@ -459,7 +459,7 @@ class Facts(object): self.facts['distribution_release'] = release.groups()[0] elif 'enterprise' in data.lower() and 'VERSION_ID' in line: release = re.search('^VERSION_ID="?[0-9]+\.?([0-9]*)"?', line) # SLES doesn't got funny release names - if release.group(1): + if release and release.group(1): release = release.group(1) else: release = "0" # no minor number, so it is the first release @@ -521,9 +521,11 @@ class Facts(object): if self.facts['distribution'].lower() == 'coreos': data = get_file_content('/etc/coreos/update.conf') - release = re.search("^GROUP=(.*)", data) - if release: - self.facts['distribution_release'] = release.group(1).strip('"') + if data: + release = re.search("^GROUP=(.*)", data) + if release: + self.facts['distribution_release'] = release.group(1).strip('"') + else: self.facts['distribution'] = name machine_id = get_file_content("/var/lib/dbus/machine-id") or get_file_content("/etc/machine-id") diff --git a/test/units/module_utils/test_distribution_version.py b/test/units/module_utils/test_distribution_version.py index 403419ba89..1e283b2b58 100644 --- a/test/units/module_utils/test_distribution_version.py +++ b/test/units/module_utils/test_distribution_version.py @@ -113,9 +113,9 @@ class TestModuleUtilsFactsDistribution(unittest.TestCase): "name": "SLES 11.3", "input": { "/etc/SuSE-release":""" - SUSE Linux Enterprise Server 11 (x86_64) - VERSION = 11 - PATCHLEVEL = 3 +SUSE Linux Enterprise Server 11 (x86_64) +VERSION = 11 +PATCHLEVEL = 3 """ }, "platform.dist": ['SuSE', '11', 'x86_64'], @@ -130,18 +130,18 @@ class TestModuleUtilsFactsDistribution(unittest.TestCase): "name": "SLES 11.4", "input": { "/etc/SuSE-release":""" - SUSE Linux Enterprise Server 11 (x86_64) - VERSION = 11 - PATCHLEVEL = 4 +SUSE Linux Enterprise Server 11 (x86_64) +VERSION = 11 +PATCHLEVEL = 4 """, "/etc/os-release":""" - NAME="SLES" - VERSION="11.4" - VERSION_ID="11.4" - PRETTY_NAME="SUSE Linux Enterprise Server 11 SP4" - ID="sles" - ANSI_COLOR="0;32" - CPE_NAME="cpe:/o:suse:sles:11:4" +NAME="SLES" +VERSION="11.4" +VERSION_ID="11.4" +PRETTY_NAME="SUSE Linux Enterprise Server 11 SP4" +ID="sles" +ANSI_COLOR="0;32" +CPE_NAME="cpe:/o:suse:sles:11:4" """, }, "platform.dist": ['SuSE', '11', 'x86_64'],