Skip to content

Commit

Permalink
Merge pull request #1300 from chef/new_ruby
Browse files Browse the repository at this point in the history
Require Ruby 2.5 or later
  • Loading branch information
tas50 authored Dec 5, 2018
2 parents 291c62b + c5e79b2 commit bfd436e
Show file tree
Hide file tree
Showing 25 changed files with 297 additions and 412 deletions.
6 changes: 4 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
AllCops:
TargetRubyVersion: 2.5
Exclude:
- "spec/data/**/*"
- "vendor/**/*"
Expand All @@ -10,5 +11,6 @@ Layout/Tab:
- "lib/ohai/plugins/mono.rb"
- "lib/ohai/plugins/darwin/hardware.rb"

Performance/UnneededSort:
Enabled: true
# this can cause failures that we need to look at one by one
Performance/RegexpMatch:
Enabled: false
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ before_install:
- bundle --version
- rm -f .bundle/config
rvm:
- 2.4.4
- 2.5.1
- 2.6
- ruby-head

matrix:
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ platform:

environment:
matrix:
- ruby_version: "24"
- ruby_version: "25"

clone_folder: c:\projects\ohai
clone_depth: 1
Expand Down
26 changes: 13 additions & 13 deletions lib/ohai/plugins/elixir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
depends "languages"

collect_data do
begin
so = shell_out("elixir -v")
# Sample output:
# Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
#
# Elixir 1.2.4
if so.exitstatus == 0 && so.stdout =~ /^Elixir (\S*)/
elixir = Mash.new
elixir[:version] = $1
languages[:elixir] = elixir
end
rescue Ohai::Exceptions::Exec
logger.trace('Plugin Elixir: Could not shell_out "elixir -v". Skipping plugin')

so = shell_out("elixir -v")
# Sample output:
# Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
#
# Elixir 1.2.4
if so.exitstatus == 0 && so.stdout =~ /^Elixir (\S*)/
elixir = Mash.new
elixir[:version] = $1
languages[:elixir] = elixir
end
rescue Ohai::Exceptions::Exec
logger.trace('Plugin Elixir: Could not shell_out "elixir -v". Skipping plugin')

end
end
20 changes: 10 additions & 10 deletions lib/ohai/plugins/filesystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,16 @@ def run_with_check(bin, &block)
# we have to non-block read dev files. Ew.
f = File.open("/proc/mounts")
loop do
begin
data = f.read_nonblock(4096)
mounts << data
# We should just catch EOFError, but the kernel had a period of
# bugginess with reading virtual files, so we're being extra
# cautious here, catching all exceptions, and then we'll read
# whatever data we might have
rescue Exception
break
end

data = f.read_nonblock(4096)
mounts << data
# We should just catch EOFError, but the kernel had a period of
# bugginess with reading virtual files, so we're being extra
# cautious here, catching all exceptions, and then we'll read
# whatever data we might have
rescue Exception
break

end
f.close
mounts.each_line do |line|
Expand Down
22 changes: 11 additions & 11 deletions lib/ohai/plugins/go.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
depends "languages"

collect_data do
begin
so = shell_out("go version")
# Sample output:
# go version go1.6.1 darwin/amd64
if so.exitstatus == 0 && so.stdout =~ /go(\S+)/
go = Mash.new
go[:version] = $1
languages[:go] = go
end
rescue Ohai::Exceptions::Exec
logger.trace('Plugin Go: Could not shell_out "go version". Skipping plugin')

so = shell_out("go version")
# Sample output:
# go version go1.6.1 darwin/amd64
if so.exitstatus == 0 && so.stdout =~ /go(\S+)/
go = Mash.new
go[:version] = $1
languages[:go] = go
end
rescue Ohai::Exceptions::Exec
logger.trace('Plugin Go: Could not shell_out "go version". Skipping plugin')

end
end
24 changes: 12 additions & 12 deletions lib/ohai/plugins/groovy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@
depends "languages"

collect_data do
begin
so = shell_out("groovy -v")
# Sample output:
# Groovy Version: 2.4.6 JVM: 1.8.0_60 Vendor: Oracle Corporation OS: Mac OS X
if so.exitstatus == 0 && so.stdout =~ /Groovy Version: (\S+).*JVM: (\S+)/
groovy = Mash.new
groovy[:version] = $1
groovy[:jvm] = $2
languages[:groovy] = groovy
end
rescue Ohai::Exceptions::Exec
logger.trace('Plugin Groovy: Could not shell_out "groovy -v". Skipping plugin')

so = shell_out("groovy -v")
# Sample output:
# Groovy Version: 2.4.6 JVM: 1.8.0_60 Vendor: Oracle Corporation OS: Mac OS X
if so.exitstatus == 0 && so.stdout =~ /Groovy Version: (\S+).*JVM: (\S+)/
groovy = Mash.new
groovy[:version] = $1
groovy[:jvm] = $2
languages[:groovy] = groovy
end
rescue Ohai::Exceptions::Exec
logger.trace('Plugin Groovy: Could not shell_out "groovy -v". Skipping plugin')

end
end
11 changes: 2 additions & 9 deletions lib/ohai/plugins/linux/fips.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Author:: Matt Wrock (<[email protected]>)
# Copyright:: Copyright (c) 2016 Chef Software, Inc.
# Copyright:: Copyright (c) 2016-2018 Chef Software, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -28,18 +28,11 @@
collect_data(:linux) do
fips Mash.new

# Check for new fips_mode method added in Ruby 2.5. After we drop support
# for Ruby 2.4, clean up everything after this and collapse the FIPS plugins.
require "openssl"
if defined?(OpenSSL.fips_mode) && OpenSSL.fips_mode && !$FIPS_TEST_MODE
fips["kernel"] = { "enabled" => true }
else
begin
enabled = File.read("/proc/sys/crypto/fips_enabled").chomp
fips["kernel"] = { "enabled" => enabled == "0" ? false : true }
rescue Errno::ENOENT
fips["kernel"] = { "enabled" => false }
end
fips["kernel"] = { "enabled" => false }
end
end
end
26 changes: 13 additions & 13 deletions lib/ohai/plugins/lua.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@
depends "languages"

collect_data do
begin
so = shell_out("lua -v")
# Sample output:
# Lua 5.2.4 Copyright (C) 1994-2015 Lua.org, PUC-Rio
if so.exitstatus == 0
lua = Mash.new
# at some point in lua's history they went from outputting the version
# on stderr to doing it on stdout. This handles old / new versions
lua[:version] = so.stdout.empty? ? so.stderr.split[1] : so.stdout.split[1]
languages[:lua] = lua if lua[:version]
end
rescue Ohai::Exceptions::Exec
logger.trace('Plugin Lua: Could not shell_out "lua -v". Skipping plugin')

so = shell_out("lua -v")
# Sample output:
# Lua 5.2.4 Copyright (C) 1994-2015 Lua.org, PUC-Rio
if so.exitstatus == 0
lua = Mash.new
# at some point in lua's history they went from outputting the version
# on stderr to doing it on stdout. This handles old / new versions
lua[:version] = so.stdout.empty? ? so.stderr.split[1] : so.stdout.split[1]
languages[:lua] = lua if lua[:version]
end
rescue Ohai::Exceptions::Exec
logger.trace('Plugin Lua: Could not shell_out "lua -v". Skipping plugin')

end
end
46 changes: 23 additions & 23 deletions lib/ohai/plugins/mono.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,30 @@
depends "languages"

collect_data do
begin
so = shell_out("mono -V")
# Sample output:
# Mono JIT compiler version 4.2.3 (Stable 4.2.3.4/832de4b Wed Mar 30 13:57:48 PDT 2016)
# Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
# TLS: normal
# SIGSEGV: altstack
# Notification: kqueue
# Architecture: amd64
# Disabled: none
# Misc: softtrace
# LLVM: supported, not enabled.
# GC: sgen
if so.exitstatus == 0
mono = Mash.new
output = so.stdout.split
mono[:version] = output[4] unless output[4].nil?
if output.length >= 12
mono[:builddate] = "%s %s %s %s %s %s" % [output[7], output[8], output[9], output[10], output[11], output[12].delete!(")")]
end
languages[:mono] = mono unless mono.empty?

so = shell_out("mono -V")
# Sample output:
# Mono JIT compiler version 4.2.3 (Stable 4.2.3.4/832de4b Wed Mar 30 13:57:48 PDT 2016)
# Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
# TLS: normal
# SIGSEGV: altstack
# Notification: kqueue
# Architecture: amd64
# Disabled: none
# Misc: softtrace
# LLVM: supported, not enabled.
# GC: sgen
if so.exitstatus == 0
mono = Mash.new
output = so.stdout.split
mono[:version] = output[4] unless output[4].nil?
if output.length >= 12
mono[:builddate] = "%s %s %s %s %s %s" % [output[7], output[8], output[9], output[10], output[11], output[12].delete!(")")]
end
rescue Ohai::Exceptions::Exec
logger.trace('Plugin Mono: Could not shell_out "mono -V". Skipping plugin')
languages[:mono] = mono unless mono.empty?
end
rescue Ohai::Exceptions::Exec
logger.trace('Plugin Mono: Could not shell_out "mono -V". Skipping plugin')

end
end
26 changes: 13 additions & 13 deletions lib/ohai/plugins/nodejs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@
depends "languages"

collect_data do
begin
so = shell_out("node -v")
# Sample output:
# v5.10.1
if so.exitstatus == 0
nodejs = Mash.new
output = so.stdout.split
if output.length >= 1
nodejs[:version] = output[0][1..output[0].length]
end
languages[:nodejs] = nodejs if nodejs[:version]

so = shell_out("node -v")
# Sample output:
# v5.10.1
if so.exitstatus == 0
nodejs = Mash.new
output = so.stdout.split
if output.length >= 1
nodejs[:version] = output[0][1..output[0].length]
end
rescue Ohai::Exceptions::Exec
logger.trace('Plugin Nodejs: Could not shell_out "node -v". Skipping plugin')
languages[:nodejs] = nodejs if nodejs[:version]
end
rescue Ohai::Exceptions::Exec
logger.trace('Plugin Nodejs: Could not shell_out "node -v". Skipping plugin')

end
end
34 changes: 17 additions & 17 deletions lib/ohai/plugins/perl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@
depends "languages"

collect_data do
begin
so = shell_out("perl -V:version -V:archname")
# Sample output:
# version='5.18.2';
# archname='darwin-thread-multi-2level';
if so.exitstatus == 0
perl = Mash.new
so.stdout.split(/\r?\n/).each do |line|
case line
when /^version=\'(.+)\';$/
perl[:version] = $1
when /^archname=\'(.+)\';$/
perl[:archname] = $1
end

so = shell_out("perl -V:version -V:archname")
# Sample output:
# version='5.18.2';
# archname='darwin-thread-multi-2level';
if so.exitstatus == 0
perl = Mash.new
so.stdout.split(/\r?\n/).each do |line|
case line
when /^version=\'(.+)\';$/
perl[:version] = $1
when /^archname=\'(.+)\';$/
perl[:archname] = $1
end
languages[:perl] = perl unless perl.empty?
end
rescue Ohai::Exceptions::Exec
logger.trace('Plugin Perl: Could not shell_out "perl -V:version -V:archname". Skipping plugin')
languages[:perl] = perl unless perl.empty?
end
rescue Ohai::Exceptions::Exec
logger.trace('Plugin Perl: Could not shell_out "perl -V:version -V:archname". Skipping plugin')

end
end
44 changes: 22 additions & 22 deletions lib/ohai/plugins/php.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,30 +23,30 @@
depends "languages"

collect_data do
begin
so = shell_out("php -v")
# Sample output:
# PHP 5.5.31 (cli) (built: Feb 20 2016 20:33:10)
# Copyright (c) 1997-2015 The PHP Group
# Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
if so.exitstatus == 0
php = Mash.new
so.stdout.each_line do |line|
case line
when /^PHP (\S+)(?:.*built: ([^)]+))?/
php[:version] = $1
php[:builddate] = $2
when /Zend Engine v([^\s]+),/
php[:zend_engine_version] = $1
when /Zend OPcache v([^\s]+),/
php[:zend_opcache_version] = $1
end
end

languages[:php] = php unless php.empty?
so = shell_out("php -v")
# Sample output:
# PHP 5.5.31 (cli) (built: Feb 20 2016 20:33:10)
# Copyright (c) 1997-2015 The PHP Group
# Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
if so.exitstatus == 0
php = Mash.new
so.stdout.each_line do |line|
case line
when /^PHP (\S+)(?:.*built: ([^)]+))?/
php[:version] = $1
php[:builddate] = $2
when /Zend Engine v([^\s]+),/
php[:zend_engine_version] = $1
when /Zend OPcache v([^\s]+),/
php[:zend_opcache_version] = $1
end
end
rescue Ohai::Exceptions::Exec
logger.trace('Plugin Php: Could not shell_out "php -v". Skipping plugin')

languages[:php] = php unless php.empty?
end
rescue Ohai::Exceptions::Exec
logger.trace('Plugin Php: Could not shell_out "php -v". Skipping plugin')

end
end
Loading

0 comments on commit bfd436e

Please sign in to comment.