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

/etc/os-release based OS detection #1299

Merged
merged 25 commits into from
Nov 27, 2018
Merged

/etc/os-release based OS detection #1299

merged 25 commits into from
Nov 27, 2018

Conversation

tas50
Copy link
Contributor

@tas50 tas50 commented Nov 24, 2018

/etc/os-release is the modern way of identifying Linux platforms and versions. It's far more reliable than the brittle regex mess that we have built up over the last decade. It also allows us to easily detect unknown / obscure distros since they have platform IDs in the os-release file.

Changes to call out:

  • Platform detection will now default to /etc/os-release if that file is present
  • The majority of the legacy logic is retained within a legacy method
  • Unless we override the value we just use the platform value from os-release. Going forward for new platforms we'll just use this value. The overrides are just to retain legacy compatibility
  • Unless it's missing we just use the version found in the os-release file. If it's not found we grab the kernel version with uname as we did before (gentoo/arch/etc)
  • Some platforms where we know users stay more up to date have been switched over to the os-release logic entirely: arch, alpine, and cumulus, mint, raspbian, and clearlinux. This also speeds up the remaining legacy platforms.
  • Testing has been simplified and expanded since we're mostly testing the platform remapping method, and the platform to platform_family methods. There's no need to run the plugin for each possible platform when the logic is entirely identical sans the value in the os-release file now.
  • The new logic should be faster as we don't have to check for the existence of a large number of files. We just read out a single file and then lookup a few things in a hash table.
  • Adds manjaro to the arch platform_family and kali to the debian platform_family.

Things that change:

  • Nexus switch versions are now properly identified with the shorter version string such as 7.0(3)I2(2b) instead of 7.0(3)I2(0.475E.6) which includes the build number.

We need to correctly read in the data in /etc/os-release and do the right thing. We already did this for SLES 15.

Signed-off-by: Tim Smith <tsmith@chef.io>
@tas50 tas50 requested a review from a team November 24, 2018 19:59
@tas50 tas50 force-pushed the os_release_detection branch from 50339fb to 648a0f8 Compare November 24, 2018 20:16
This is the modern way of identifying Linux platforms and versions. It's
far more reliable than the brittle regex mess that we have built up over
the last decade. It also allows us to easily detect unknown / obscure
distros.

Signed-off-by: Tim Smith <tsmith@chef.io>
@tas50 tas50 force-pushed the os_release_detection branch from 648a0f8 to 0d842f7 Compare November 24, 2018 21:42
tas50 added 23 commits November 24, 2018 23:25
Get ready to refactor these

Signed-off-by: Tim Smith <tsmith@chef.io>
Signed-off-by: Tim Smith <tsmith@chef.io>
Signed-off-by: Tim Smith <tsmith@chef.io>
This avoids the need to test the full plugin run on each of these platforms and it keeps us from accidentally breaking something here later on.

Signed-off-by: Tim Smith <tsmith@chef.io>
We test this better now

Signed-off-by: Tim Smith <tsmith@chef.io>
These are modern operating systems that will always use the new os-release logic:

Fedora, Arch, Linux Mint, raspbian, amazon 2, clearos

Signed-off-by: Tim Smith <tsmith@chef.io>
Signed-off-by: Tim Smith <tsmith@chef.io>
Break out more logic into simpler methods that can be tested

Signed-off-by: Tim Smith <tsmith@chef.io>
Avoid having to search path when it's always in the same path

Signed-off-by: Tim Smith <tsmith@chef.io>
I've confirmed this works on a cumulus system. Not sure where the previous logic came from.

Signed-off-by: Tim Smith <tsmith@chef.io>
This is wrong, but it's what we've been doing for a while

Signed-off-by: Tim Smith <tsmith@chef.io>
This is faster and also easier to read

Signed-off-by: Tim Smith <tsmith@chef.io>
These systems always have an os-release file. No need for the legacy method.

Signed-off-by: Tim Smith <tsmith@chef.io>
Nothing supported here lacks os-release files

Signed-off-by: Tim Smith <tsmith@chef.io>
Bumps things for the last 10 years

Signed-off-by: Tim Smith <tsmith@chef.io>
CentOS doesn't do the right thing with the os-release file. They treat it differently than redhat and every other distro I've seen. We need to work around that.

Signed-off-by: Tim Smith <tsmith@chef.io>
Signed-off-by: Tim Smith <tsmith@chef.io>
Signed-off-by: Tim Smith <tsmith@chef.io>
Signed-off-by: Tim Smith <tsmith@chef.io>
Signed-off-by: Tim Smith <tsmith@chef.io>
Signed-off-by: Tim Smith <tsmith@chef.io>
We'll never get to this code since it requires a os-release file

Signed-off-by: Tim Smith <tsmith@chef.io>
It's os-release file is not in a standard location

Signed-off-by: Tim Smith <tsmith@chef.io>
expect(@plugin[:platform]).to eq("amazon")
expect(@plugin[:platform_family]).to eq("amazon")
describe "#read_os_release_info" do
let(:file_contents) { "COW=MOO\nDOG=\"BARK\"" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but what does the fox say?

@tas50 tas50 changed the title WIP: /etc/os-release based OS detection /etc/os-release based OS detection Nov 27, 2018
@tas50 tas50 merged commit c41b15e into master Nov 27, 2018
@chef-ci chef-ci deleted the os_release_detection branch November 27, 2018 21:53
@lock
Copy link

lock bot commented Jan 26, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants