diff options
author | Tim Smith <tsmith@chef.io> | 2016-10-18 14:27:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-18 14:27:07 +0200 |
commit | 954d9a3bdf9067575951b012be5dbf791c12f421 (patch) | |
tree | f60ce06e07e99eea440ece9dc5ecc88e5b2cf62c | |
parent | 7d440bc8e71db3cbdf91369e6f434185a9605375 (diff) | |
parent | 52c95309ff65374ac1ff0aa634ba73569cd7175a (diff) | |
download | ohai-954d9a3bdf9067575951b012be5dbf791c12f421.tar.gz |
Merge pull request #873 from kylev/kv_lsb_order
Prefer the LSB standard configurator.
-rw-r--r-- | lib/ohai/plugins/linux/lsb.rb | 31 | ||||
-rw-r--r-- | spec/unit/plugins/linux/lsb_spec.rb | 2 |
2 files changed, 17 insertions, 16 deletions
diff --git a/lib/ohai/plugins/linux/lsb.rb b/lib/ohai/plugins/linux/lsb.rb index 75baec83..f5ba064f 100644 --- a/lib/ohai/plugins/linux/lsb.rb +++ b/lib/ohai/plugins/linux/lsb.rb @@ -22,21 +22,8 @@ Ohai.plugin(:LSB) do collect_data(:linux) do lsb Mash.new - if File.exists?("/etc/lsb-release") - File.open("/etc/lsb-release").each do |line| - case line - when /^DISTRIB_ID=["']?(.+?)["']?$/ - lsb[:id] = $1 - when /^DISTRIB_RELEASE=["']?(.+?)["']?$/ - lsb[:release] = $1 - when /^DISTRIB_CODENAME=["']?(.+?)["']?$/ - lsb[:codename] = $1 - when /^DISTRIB_DESCRIPTION=["']?(.+?)["']?$/ - lsb[:description] = $1 - end - end - elsif File.exists?("/usr/bin/lsb_release") - # Fedora/Redhat, requires redhat-lsb package + if File.exists?("/usr/bin/lsb_release") + # From package redhat-lsb on Fedora/Redhat, lsb-release on Debian/Ubuntu so = shell_out("lsb_release -a") so.stdout.lines do |line| case line @@ -52,6 +39,20 @@ Ohai.plugin(:LSB) do lsb[:id] = line end end + elsif File.exists?("/etc/lsb-release") + # Old, non-standard Debian support + File.open("/etc/lsb-release").each do |line| + case line + when /^DISTRIB_ID=["']?(.+?)["']?$/ + lsb[:id] = $1 + when /^DISTRIB_RELEASE=["']?(.+?)["']?$/ + lsb[:release] = $1 + when /^DISTRIB_CODENAME=["']?(.+?)["']?$/ + lsb[:codename] = $1 + when /^DISTRIB_DESCRIPTION=["']?(.+?)["']?$/ + lsb[:description] = $1 + end + end else Ohai::Log.debug("Skipping LSB, cannot find /etc/lsb-release or /usr/bin/lsb_release") end diff --git a/spec/unit/plugins/linux/lsb_spec.rb b/spec/unit/plugins/linux/lsb_spec.rb index eac26412..309133d3 100644 --- a/spec/unit/plugins/linux/lsb_spec.rb +++ b/spec/unit/plugins/linux/lsb_spec.rb @@ -35,6 +35,7 @@ describe Ohai::System, "Linux lsb plugin" do and_yield("DISTRIB_CODENAME=hardy"). and_yield('DISTRIB_DESCRIPTION="Ubuntu 8.04"') allow(File).to receive(:open).with("/etc/lsb-release").and_return(@double_file) + allow(File).to receive(:exists?).with("/usr/bin/lsb_release").and_return(false) allow(File).to receive(:exists?).with("/etc/lsb-release").and_return(true) end @@ -61,7 +62,6 @@ describe Ohai::System, "Linux lsb plugin" do describe "on systems with /usr/bin/lsb_release" do before(:each) do - allow(File).to receive(:exists?).with("/etc/lsb-release").and_return(false) allow(File).to receive(:exists?).with("/usr/bin/lsb_release").and_return(true) @stdin = double("STDIN", { :close => true }) |