Merge pull request #15420 from robinro/distribution_version_tests

Distribution version tests
This commit is contained in:
Toshio Kuratomi
2016-04-18 10:05:55 -07:00
3 changed files with 468 additions and 5 deletions

View File

@@ -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'),
@@ -282,6 +282,11 @@ class Facts(object):
# platform.dist() is deprecated in 2.6
# in 2.6 and newer, you should use platform.linux_distribution()
def get_distribution_facts(self):
"""
Fills facts about the distribution name and version.
This is unit tested. Please extend the tests to cover all distributions if you have them available.
"""
# A list with OS Family members
OS_FAMILY = dict(
@@ -459,7 +464,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 +526,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")