Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenSUSE Leap platform detection #377

Closed
clintoncwolfe opened this issue Nov 3, 2018 · 10 comments · Fixed by #505
Closed

OpenSUSE Leap platform detection #377

clintoncwolfe opened this issue Nov 3, 2018 · 10 comments · Fixed by #505

Comments

@clintoncwolfe
Copy link
Contributor

Description

A user reported an issue in which OpenSUSE Leap is not being detected.

Train and Platform Version

InSpec 3.0.12
Train 1.5.??
Target: OpenSUSE Leap 15 (Docker)

Replication Case

Extensive notes and repro instructions on the original issue, inspec/inspec#3574

Possible Solutions

Implement or refine SUSE detection

@megamorf
Copy link

megamorf commented Nov 3, 2018

I can see that Train's entire SUSE related detection is based around the existence of /etc/SuSE-release:

# suse family
plat.family('suse').in_family('linux')
.detect {
if !(suse = unix_file_contents('/etc/SuSE-release')).nil?
version = suse.scan(/VERSION = (\d+)\nPATCHLEVEL = (\d+)/).flatten.join('.')
version = suse[/VERSION = ([\d\.]{2,})/, 1] if version == ''
@platform[:release] = version
true
end
}
plat.name('opensuse').title('OpenSUSE Linux').in_family('suse')
.detect {
true if unix_file_contents('/etc/SuSE-release') =~ /^opensuse/i
}
plat.name('suse').title('Suse Linux').in_family('suse')
.detect {
true if unix_file_contents('/etc/SuSE-release') =~ /suse/i
}

/etc/os-release should be checked as a fallback (see the related issue for its contents) since the official openSUSE Leap Docker image has no /etc/SuSE-release file.

@tas50
Copy link
Contributor

tas50 commented Nov 3, 2018

This also means SLES 15 won’t detect correctly. I’m fixing this on the Ohai side and I can fix it here if no one minds.

@megamorf
Copy link

megamorf commented Nov 3, 2018

@tas50 I've created a corresponding ohai issue yesterday: chef/ohai#1289
My ruby skills are too bad to fix it myself in a reasonable time so your assistance would be appreciated :-)

@mcgege
Copy link

mcgege commented Jan 18, 2019

@tas50 Could you please fix this here? I also need this one :-)

@n-rodriguez
Copy link
Contributor

n-rodriguez commented May 15, 2019

I think the regex is wrong.

The file /etc/SuSE-release exists on openSUSE Leap 15 and its content is :

kitchen@b59935020e63:~> cat /etc/SuSE-release 
NAME="openSUSE Leap"
VERSION="15.0"
ID="opensuse-leap"
ID_LIKE="suse opensuse"
VERSION_ID="15.0"
PRETTY_NAME="openSUSE Leap 15.0"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:opensuse:leap:15.0"
BUG_REPORT_URL="https://bugs.opensuse.org"
HOME_URL="https://www.opensuse.org/"

Here the regex :

version = suse.scan(/VERSION = (\d+)\nPATCHLEVEL = (\d+)/).flatten.join('.') 
version = suse[/VERSION = ([\d\.]{2,})/, 1] if version == '' 

it waits for a white space before and after =, which is not the case in this Bash importable file.

@tas50
Copy link
Contributor

tas50 commented May 15, 2019

I'd suggest in the long run that train moves away from using files like /etc/SuSe-release and instead use /etc/os-release, which exists on every systemd based Linux distro and many distros prior to systemd. It has a standard format and can easily be combined with some case statements to make platform detection much more reliable. I made the switch in Ohai for Chef 15: chef/ohai#1299

@n-rodriguez
Copy link
Contributor

@tas50 actually both file has same content :

kitchen@b59935020e63:~> cat /etc/os-release 
NAME="openSUSE Leap"
VERSION="15.0"
ID="opensuse-leap"
ID_LIKE="suse opensuse"
VERSION_ID="15.0"
PRETTY_NAME="openSUSE Leap 15.0"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:opensuse:leap:15.0"
BUG_REPORT_URL="https://bugs.opensuse.org"
HOME_URL="https://www.opensuse.org/"
kitchen@b59935020e63:~> 
kitchen@b59935020e63:~> 
kitchen@b59935020e63:~> cat /etc/SuSE-release 
NAME="openSUSE Leap"
VERSION="15.0"
ID="opensuse-leap"
ID_LIKE="suse opensuse"
VERSION_ID="15.0"
PRETTY_NAME="openSUSE Leap 15.0"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:opensuse:leap:15.0"
BUG_REPORT_URL="https://bugs.opensuse.org"
HOME_URL="https://www.opensuse.org/"

@tas50
Copy link
Contributor

tas50 commented May 15, 2019

In this case they are the same, but moving to /etc/os-release as the main detection method allows us to skip a lot of the regex work and just perform some conversions on the ID field instead. That's what we do in ohai so we can remap opensuse-leap to opensuseleap for example. It eliminates dozens of brittle regexes across the different distro specific files. Prior to the os-release detecting platforms was pretty awful.

@n-rodriguez
Copy link
Contributor

Thanks for the enlightenment 👍

@mcgege
Copy link

mcgege commented May 16, 2019

The file /etc/SuSE-release exists on openSUSE Leap 15 and its content is :

On a fresh installation this file should not exist - beginning with Leap 15 this file is missing on my systems.

+1 on using /etc/os-release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants