diff options
author | danielsdeleo <dan@chef.io> | 2015-06-19 12:46:06 -0700 |
---|---|---|
committer | danielsdeleo <dan@chef.io> | 2015-06-19 13:29:42 -0700 |
commit | eccaff433d062a9d2ece196480032b7b96bf942a (patch) | |
tree | 67f0e6baa8b7ce5ac52b35ccf17ae1983f234a5c | |
parent | 8ee124b6574c0d6edf0a3a265cebac8ac9d27e51 (diff) | |
download | ohai-eccaff433d062a9d2ece196480032b7b96bf942a.tar.gz |
Fix EL7 not being detected b/c of etc/os-release
-rw-r--r-- | lib/ohai/plugins/linux/platform.rb | 27 | ||||
-rw-r--r-- | spec/unit/plugins/linux/platform_spec.rb | 20 |
2 files changed, 38 insertions, 9 deletions
diff --git a/lib/ohai/plugins/linux/platform.rb b/lib/ohai/plugins/linux/platform.rb index c194afa8..e84eacb4 100644 --- a/lib/ohai/plugins/linux/platform.rb +++ b/lib/ohai/plugins/linux/platform.rb @@ -28,6 +28,20 @@ Ohai.plugin(:Platform) do contents[/Rawhide/i] ? contents[/((\d+) \(Rawhide\))/i, 1].downcase : contents[/release ([\d\.]+)/, 1] end + def os_release_file_is_cisco? + return false unless File.exists?('/etc/os-release') + os_release_info = File.read('/etc/os-release').split.inject({}) do |map, key_value_line| + key, _separator, value = key_value_line.partition('=') + map[key] = value + map + end + if os_release_info['CISCO_RELEASE_INFO'] && File.exists?(os_release_info['CISCO_RELEASE_INFO']) + os_release_info + else + false + end + end + collect_data(:linux) do # platform [ and platform_version ? ] should be lower case to avoid dealing with RedHat/Redhat/redhat matching if File.exists?("/etc/oracle-release") @@ -60,15 +74,10 @@ Ohai.plugin(:Platform) do platform get_redhatish_platform(contents) platform_version contents.match(/(\d\.\d\.\d)/)[0] elsif File.exists?("/etc/redhat-release") - if File.exists?('/etc/os-release') # check if Cisco - # don't clobber existing os-release properties, point to a different cisco file - contents = {} - File.read('/etc/os-release').split.collect {|x| x.split('=')}.each {|x| contents[x[0]] = x[1]} - if contents['CISCO_RELEASE_INFO'] && File.exists?(contents['CISCO_RELEASE_INFO']) - platform contents['ID'] - platform_family contents['ID_LIKE'] - platform_version contents['VERSION'] || "" - end + if File.exists?('/etc/os-release') && (os_release_info = os_release_file_is_cisco? ) # check if Cisco + platform os_release_info['ID'] + platform_family os_release_info['ID_LIKE'] + platform_version os_release_info['VERSION'] || "" else contents = File.read("/etc/redhat-release").chomp platform get_redhatish_platform(contents) diff --git a/spec/unit/plugins/linux/platform_spec.rb b/spec/unit/plugins/linux/platform_spec.rb index 69dbc04e..ce21f2f7 100644 --- a/spec/unit/plugins/linux/platform_spec.rb +++ b/spec/unit/plugins/linux/platform_spec.rb @@ -311,6 +311,26 @@ describe Ohai::System, "Linux plugin platform" do end end + + #### + # TODO: This regression test won't work because we stub too much up front. + # need to refactor the tests first. + ## # https://github.com/chef/ohai/issues/560 + ## # Issue is seen on EL7, so that's what we're testing. + ## context "on versions that have /etc/os-release" do + + ## before do + ## allow(File).to receive(:exists?).with("/etc/os-release").and_return(true) + ## end + + ## it "correctly detects EL7" do + ## expect(File).to receive(:read).with("/etc/redhat-release").and_return("CentOS release 7.1") + ## @plugin.run + ## expect(@plugin[:platform]).to eq("centos") + ## expect(@plugin[:platform_version]).to eq("7.1") + ## end + + ## end end describe "on pcs linux" do |