summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@chef.io>2015-06-19 14:59:35 -0700
committerdanielsdeleo <dan@chef.io>2015-06-19 14:59:35 -0700
commitcf6e9700516ab874ed714ea58d8068ac87516e54 (patch)
tree925ebe8458ebc8a0977395fe1dfc9839d9d1f974
parent25023850182bf188da1197e407e99e5e5b87c98a (diff)
downloadohai-cf6e9700516ab874ed714ea58d8068ac87516e54.tar.gz
File.exists? is deprecated, emits warnings w/ ruby -w
-rw-r--r--lib/ohai/plugins/linux/platform.rb30
-rw-r--r--spec/unit/plugins/linux/platform_spec.rb26
2 files changed, 28 insertions, 28 deletions
diff --git a/lib/ohai/plugins/linux/platform.rb b/lib/ohai/plugins/linux/platform.rb
index e84eacb4..a383c222 100644
--- a/lib/ohai/plugins/linux/platform.rb
+++ b/lib/ohai/plugins/linux/platform.rb
@@ -29,13 +29,13 @@ Ohai.plugin(:Platform) do
end
def os_release_file_is_cisco?
- return false unless File.exists?('/etc/os-release')
+ return false unless File.exist?('/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'])
+ if os_release_info['CISCO_RELEASE_INFO'] && File.exist?(os_release_info['CISCO_RELEASE_INFO'])
os_release_info
else
false
@@ -44,15 +44,15 @@ Ohai.plugin(:Platform) do
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")
+ if File.exist?("/etc/oracle-release")
contents = File.read("/etc/oracle-release").chomp
platform "oracle"
platform_version get_redhatish_version(contents)
- elsif File.exists?("/etc/enterprise-release")
+ elsif File.exist?("/etc/enterprise-release")
contents = File.read("/etc/enterprise-release").chomp
platform "oracle"
platform_version get_redhatish_version(contents)
- elsif File.exists?("/etc/debian_version")
+ elsif File.exist?("/etc/debian_version")
# Ubuntu and Debian both have /etc/debian_version
# Ubuntu should always have a working lsb, debian does not by default
if lsb[:id] =~ /Ubuntu/i
@@ -62,19 +62,19 @@ Ohai.plugin(:Platform) do
platform "linuxmint"
platform_version lsb[:release]
else
- if File.exists?("/usr/bin/raspi-config")
+ if File.exist?("/usr/bin/raspi-config")
platform "raspbian"
else
platform "debian"
end
platform_version File.read("/etc/debian_version").chomp
end
- elsif File.exists?("/etc/parallels-release")
+ elsif File.exist?("/etc/parallels-release")
contents = File.read("/etc/parallels-release").chomp
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') && (os_release_info = os_release_file_is_cisco? ) # check if Cisco
+ elsif File.exist?("/etc/redhat-release")
+ if File.exist?('/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'] || ""
@@ -83,14 +83,14 @@ Ohai.plugin(:Platform) do
platform get_redhatish_platform(contents)
platform_version get_redhatish_version(contents)
end
- elsif File.exists?("/etc/system-release")
+ elsif File.exist?("/etc/system-release")
contents = File.read("/etc/system-release").chomp
platform get_redhatish_platform(contents)
platform_version get_redhatish_version(contents)
- elsif File.exists?('/etc/gentoo-release')
+ elsif File.exist?('/etc/gentoo-release')
platform "gentoo"
platform_version File.read('/etc/gentoo-release').scan(/(\d+|\.+)/).join
- elsif File.exists?('/etc/SuSE-release')
+ elsif File.exist?('/etc/SuSE-release')
suse_release = File.read("/etc/SuSE-release")
suse_version = suse_release.scan(/VERSION = (\d+)\nPATCHLEVEL = (\d+)/).flatten.join(".")
suse_version = suse_release[/VERSION = ([\d\.]{2,})/, 1] if suse_version == ""
@@ -100,15 +100,15 @@ Ohai.plugin(:Platform) do
else
platform "suse"
end
- elsif File.exists?('/etc/slackware-version')
+ elsif File.exist?('/etc/slackware-version')
platform "slackware"
platform_version File.read("/etc/slackware-version").scan(/(\d+|\.+)/).join
- elsif File.exists?('/etc/arch-release')
+ elsif File.exist?('/etc/arch-release')
platform "arch"
# no way to determine platform_version in a rolling release distribution
# kernel release will be used - ex. 2.6.32-ARCH
platform_version `uname -r`.strip
- elsif File.exists?('/etc/exherbo-release')
+ elsif File.exist?('/etc/exherbo-release')
platform "exherbo"
# no way to determine platform_version in a rolling release distribution
# kernel release will be used - ex. 3.13
diff --git a/spec/unit/plugins/linux/platform_spec.rb b/spec/unit/plugins/linux/platform_spec.rb
index a15278ad..80f4bc4e 100644
--- a/spec/unit/plugins/linux/platform_spec.rb
+++ b/spec/unit/plugins/linux/platform_spec.rb
@@ -40,19 +40,19 @@ describe Ohai::System, "Linux plugin platform" do
@plugin = get_plugin("linux/platform")
allow(@plugin).to receive(:collect_os).and_return(:linux)
@plugin[:lsb] = Mash.new
- allow(File).to receive(:exists?).with("/etc/debian_version").and_return(have_debian_version)
- allow(File).to receive(:exists?).with("/etc/redhat-release").and_return(have_redhat_release)
- allow(File).to receive(:exists?).with("/etc/gentoo-release").and_return(have_gentoo_release)
- allow(File).to receive(:exists?).with("/etc/exherbo-release").and_return(have_exherbo_release)
- allow(File).to receive(:exists?).with("/etc/SuSE-release").and_return(have_suse_release)
- allow(File).to receive(:exists?).with("/etc/arch-release").and_return(have_arch_release)
- allow(File).to receive(:exists?).with("/etc/system-release").and_return(have_system_release)
- allow(File).to receive(:exists?).with("/etc/slackware-version").and_return(have_slackware_version)
- allow(File).to receive(:exists?).with("/etc/enterprise-release").and_return(have_enterprise_release)
- allow(File).to receive(:exists?).with("/etc/oracle-release").and_return(have_oracle_release)
- allow(File).to receive(:exists?).with("/etc/parallels-release").and_return(have_parallels_release)
- allow(File).to receive(:exists?).with("/usr/bin/raspi-config").and_return(have_raspi_config)
- allow(File).to receive(:exists?).with("/etc/os-release").and_return(have_os_release)
+ allow(File).to receive(:exist?).with("/etc/debian_version").and_return(have_debian_version)
+ allow(File).to receive(:exist?).with("/etc/redhat-release").and_return(have_redhat_release)
+ allow(File).to receive(:exist?).with("/etc/gentoo-release").and_return(have_gentoo_release)
+ allow(File).to receive(:exist?).with("/etc/exherbo-release").and_return(have_exherbo_release)
+ allow(File).to receive(:exist?).with("/etc/SuSE-release").and_return(have_suse_release)
+ allow(File).to receive(:exist?).with("/etc/arch-release").and_return(have_arch_release)
+ allow(File).to receive(:exist?).with("/etc/system-release").and_return(have_system_release)
+ allow(File).to receive(:exist?).with("/etc/slackware-version").and_return(have_slackware_version)
+ allow(File).to receive(:exist?).with("/etc/enterprise-release").and_return(have_enterprise_release)
+ allow(File).to receive(:exist?).with("/etc/oracle-release").and_return(have_oracle_release)
+ allow(File).to receive(:exist?).with("/etc/parallels-release").and_return(have_parallels_release)
+ allow(File).to receive(:exist?).with("/usr/bin/raspi-config").and_return(have_raspi_config)
+ allow(File).to receive(:exist?).with("/etc/os-release").and_return(have_os_release)
allow(File).to receive(:read).with("PLEASE STUB ALL File.read CALLS")
end