Always check other OS release files if lsb_distrib_id grain not populated from /etc/lsb-release

Fixes #19953
This commit is contained in:
Johan van den Dorpe 2015-03-20 15:48:42 +00:00 committed by Justin Findlay
parent c27692cdab
commit 4fe795f66c

View File

@ -948,90 +948,91 @@ def os_data():
grains[ grains[
'lsb_{0}'.format(match.groups()[0].lower()) 'lsb_{0}'.format(match.groups()[0].lower())
] = match.groups()[1].rstrip() ] = match.groups()[1].rstrip()
elif os.path.isfile('/etc/os-release'): if 'lsb_distrib_id' not in grains:
# Arch ARM Linux if os.path.isfile('/etc/os-release'):
with salt.utils.fopen('/etc/os-release') as ifile: # Arch ARM Linux
# Imitate lsb-release with salt.utils.fopen('/etc/os-release') as ifile:
for line in ifile: # Imitate lsb-release
# NAME="Arch Linux ARM" for line in ifile:
# ID=archarm # NAME="Arch Linux ARM"
# ID_LIKE=arch # ID=archarm
# PRETTY_NAME="Arch Linux ARM" # ID_LIKE=arch
# ANSI_COLOR="0;36" # PRETTY_NAME="Arch Linux ARM"
# HOME_URL="http://archlinuxarm.org/" # ANSI_COLOR="0;36"
# SUPPORT_URL="https://archlinuxarm.org/forum" # HOME_URL="http://archlinuxarm.org/"
# BUG_REPORT_URL= # SUPPORT_URL="https://archlinuxarm.org/forum"
# "https://github.com/archlinuxarm/PKGBUILDs/issues" # BUG_REPORT_URL=
regex = re.compile( # "https://github.com/archlinuxarm/PKGBUILDs/issues"
'^([\\w]+)=(?:\'|")?([\\w\\s\\.-_]+)(?:\'|")?' regex = re.compile(
) '^([\\w]+)=(?:\'|")?([\\w\\s\\.-_]+)(?:\'|")?'
match = regex.match(line.rstrip('\n')) )
if match: match = regex.match(line.rstrip('\n'))
name, value = match.groups() if match:
if name.lower() == 'name': name, value = match.groups()
grains['lsb_distrib_id'] = value.strip() if name.lower() == 'name':
elif os.path.isfile('/etc/SuSE-release'): grains['lsb_distrib_id'] = value.strip()
grains['lsb_distrib_id'] = 'SUSE' elif os.path.isfile('/etc/SuSE-release'):
with salt.utils.fopen('/etc/SuSE-release') as fhr: grains['lsb_distrib_id'] = 'SUSE'
rel = re.sub("[^0-9]", "", fhr.read().split('\n')[1]) with salt.utils.fopen('/etc/SuSE-release') as fhr:
with salt.utils.fopen('/etc/SuSE-release') as fhr: rel = re.sub("[^0-9]", "", fhr.read().split('\n')[1])
patch = re.sub("[^0-9]", "", fhr.read().split('\n')[2]) with salt.utils.fopen('/etc/SuSE-release') as fhr:
release = rel + " SP" + patch patch = re.sub("[^0-9]", "", fhr.read().split('\n')[2])
grains['lsb_distrib_release'] = release release = rel + " SP" + patch
grains['lsb_distrib_codename'] = "n.a" grains['lsb_distrib_release'] = release
elif os.path.isfile('/etc/altlinux-release'): grains['lsb_distrib_codename'] = "n.a"
# ALT Linux elif os.path.isfile('/etc/altlinux-release'):
grains['lsb_distrib_id'] = 'altlinux' # ALT Linux
with salt.utils.fopen('/etc/altlinux-release') as ifile: grains['lsb_distrib_id'] = 'altlinux'
# This file is symlinked to from: with salt.utils.fopen('/etc/altlinux-release') as ifile:
# /etc/fedora-release # This file is symlinked to from:
# /etc/redhat-release # /etc/fedora-release
# /etc/system-release # /etc/redhat-release
for line in ifile: # /etc/system-release
# ALT Linux Sisyphus (unstable) for line in ifile:
comps = line.split() # ALT Linux Sisyphus (unstable)
if comps[0] == 'ALT': comps = line.split()
grains['lsb_distrib_release'] = comps[2] if comps[0] == 'ALT':
grains['lsb_distrib_codename'] = \ grains['lsb_distrib_release'] = comps[2]
comps[3].replace('(', '').replace(')', '') grains['lsb_distrib_codename'] = \
elif os.path.isfile('/etc/centos-release'): comps[3].replace('(', '').replace(')', '')
# CentOS Linux elif os.path.isfile('/etc/centos-release'):
grains['lsb_distrib_id'] = 'CentOS' # CentOS Linux
with salt.utils.fopen('/etc/centos-release') as ifile: grains['lsb_distrib_id'] = 'CentOS'
for line in ifile: with salt.utils.fopen('/etc/centos-release') as ifile:
# Need to pull out the version and codename for line in ifile:
# in the case of custom content in /etc/centos-release # Need to pull out the version and codename
find_release = re.compile(r'\d+\.\d+') # in the case of custom content in /etc/centos-release
find_codename = re.compile(r'(?<=\()(.*?)(?=\))') find_release = re.compile(r'\d+\.\d+')
release = find_release.search(line) find_codename = re.compile(r'(?<=\()(.*?)(?=\))')
codename = find_codename.search(line) release = find_release.search(line)
if release is not None: codename = find_codename.search(line)
grains['lsb_distrib_release'] = release.group() if release is not None:
if codename is not None: grains['lsb_distrib_release'] = release.group()
grains['lsb_distrib_codename'] = codename.group() if codename is not None:
elif os.path.isfile('/etc.defaults/VERSION') \ grains['lsb_distrib_codename'] = codename.group()
and os.path.isfile('/etc.defaults/synoinfo.conf'): elif os.path.isfile('/etc.defaults/VERSION') \
grains['osfullname'] = 'Synology' and os.path.isfile('/etc.defaults/synoinfo.conf'):
with salt.utils.fopen('/etc.defaults/VERSION', 'r') as fp_: grains['osfullname'] = 'Synology'
synoinfo = {} with salt.utils.fopen('/etc.defaults/VERSION', 'r') as fp_:
for line in fp_: synoinfo = {}
try: for line in fp_:
key, val = line.rstrip('\n').split('=') try:
except ValueError: key, val = line.rstrip('\n').split('=')
continue except ValueError:
if key in ('majorversion', 'minorversion', continue
'buildnumber'): if key in ('majorversion', 'minorversion',
synoinfo[key] = val.strip('"') 'buildnumber'):
if len(synoinfo) != 3: synoinfo[key] = val.strip('"')
log.warning( if len(synoinfo) != 3:
'Unable to determine Synology version info. ' log.warning(
'Please report this, as it is likely a bug.' 'Unable to determine Synology version info. '
) 'Please report this, as it is likely a bug.'
else: )
grains['osrelease'] = ( else:
'{majorversion}.{minorversion}-{buildnumber}' grains['osrelease'] = (
.format(**synoinfo) '{majorversion}.{minorversion}-{buildnumber}'
) .format(**synoinfo)
)
# Use the already intelligent platform module to get distro info # Use the already intelligent platform module to get distro info
# (though apparently it's not intelligent enough to strip quotes) # (though apparently it's not intelligent enough to strip quotes)