summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-11-24 13:56:48 -0800
committerTim Smith <tsmith@chef.io>2018-11-24 13:56:48 -0800
commit35f32a12f756c50a9cfd17ab9224853c2161fc0e (patch)
tree4e5cfe43b8cf6cf8476c6682b43383522c41a7b7
parenta946ff969ae335b163a1766901ccd960ad6dc4eb (diff)
downloadohai-35f32a12f756c50a9cfd17ab9224853c2161fc0e.tar.gz
Require Ruby 2.5 or later
As we do every year Ohai 15 will drop support for the N-2 support of Ruby. In the ~5 weeks Ruby 2.6 comes out so by the time we release this new version of Ohai N-2 will be Ruby 2.4. Also while we're at it get rid of the begins in rescue blocks. Ruby 2.5 doesn't require this and it's on the path to ruby throwing errors eventually. It's a Ruby < 2.4-ism. Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--.travis.yml2
-rw-r--r--appveyor.yml2
-rw-r--r--lib/ohai/plugins/elixir.rb26
-rw-r--r--lib/ohai/plugins/filesystem.rb20
-rw-r--r--lib/ohai/plugins/go.rb22
-rw-r--r--lib/ohai/plugins/groovy.rb24
-rw-r--r--lib/ohai/plugins/lua.rb26
-rw-r--r--lib/ohai/plugins/mono.rb46
-rw-r--r--lib/ohai/plugins/nodejs.rb26
-rw-r--r--lib/ohai/plugins/perl.rb34
-rw-r--r--lib/ohai/plugins/php.rb44
-rw-r--r--lib/ohai/plugins/powershell.rb60
-rw-r--r--lib/ohai/plugins/python.rb30
-rw-r--r--lib/ohai/plugins/rust.rb22
-rw-r--r--lib/ohai/plugins/virtualbox.rb42
-rw-r--r--ohai.gemspec2
-rw-r--r--spec/unit/plugins/abort_spec.rb16
-rw-r--r--spec/unit/plugins/fail_spec.rb48
-rw-r--r--spec/unit/plugins/linux/cpu_spec.rb10
-rw-r--r--spec/unit/plugins/linux/fips_spec.rb12
-rw-r--r--spec/unit/plugins/network_spec.rb20
-rw-r--r--spec/unit/plugins/windows/fips_spec.rb12
22 files changed, 273 insertions, 273 deletions
diff --git a/.travis.yml b/.travis.yml
index bb8a682d..d878aac5 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -18,8 +18,8 @@ before_install:
- bundle --version
- rm -f .bundle/config
rvm:
- - 2.4.4
- 2.5.1
+ - 2.6
- ruby-head
matrix:
diff --git a/appveyor.yml b/appveyor.yml
index bc3a43f5..650aab63 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -6,7 +6,7 @@ platform:
environment:
matrix:
- - ruby_version: "24"
+ - ruby_version: "25"
clone_folder: c:\projects\ohai
clone_depth: 1
diff --git a/lib/ohai/plugins/elixir.rb b/lib/ohai/plugins/elixir.rb
index 73bd60a9..233a9b9d 100644
--- a/lib/ohai/plugins/elixir.rb
+++ b/lib/ohai/plugins/elixir.rb
@@ -18,19 +18,19 @@ Ohai.plugin(:Elixir) do
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
diff --git a/lib/ohai/plugins/filesystem.rb b/lib/ohai/plugins/filesystem.rb
index 1a823f8b..76ab8ed9 100644
--- a/lib/ohai/plugins/filesystem.rb
+++ b/lib/ohai/plugins/filesystem.rb
@@ -250,16 +250,16 @@ Ohai.plugin(:Filesystem) do
# 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|
diff --git a/lib/ohai/plugins/go.rb b/lib/ohai/plugins/go.rb
index 7cfa132d..65eb23c8 100644
--- a/lib/ohai/plugins/go.rb
+++ b/lib/ohai/plugins/go.rb
@@ -18,17 +18,17 @@ Ohai.plugin(:Go) do
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
diff --git a/lib/ohai/plugins/groovy.rb b/lib/ohai/plugins/groovy.rb
index db49be6d..7b4134ff 100644
--- a/lib/ohai/plugins/groovy.rb
+++ b/lib/ohai/plugins/groovy.rb
@@ -21,18 +21,18 @@ Ohai.plugin(:Groovy) do
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
diff --git a/lib/ohai/plugins/lua.rb b/lib/ohai/plugins/lua.rb
index 0e984f16..94379ba0 100644
--- a/lib/ohai/plugins/lua.rb
+++ b/lib/ohai/plugins/lua.rb
@@ -21,19 +21,19 @@ Ohai.plugin(:Lua) do
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
diff --git a/lib/ohai/plugins/mono.rb b/lib/ohai/plugins/mono.rb
index 48d64e93..e7b2483b 100644
--- a/lib/ohai/plugins/mono.rb
+++ b/lib/ohai/plugins/mono.rb
@@ -21,30 +21,30 @@ Ohai.plugin(:Mono) do
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
diff --git a/lib/ohai/plugins/nodejs.rb b/lib/ohai/plugins/nodejs.rb
index 684e6b47..a24a0454 100644
--- a/lib/ohai/plugins/nodejs.rb
+++ b/lib/ohai/plugins/nodejs.rb
@@ -21,20 +21,20 @@ Ohai.plugin(:Nodejs) do
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
diff --git a/lib/ohai/plugins/perl.rb b/lib/ohai/plugins/perl.rb
index f86dc026..b3594148 100644
--- a/lib/ohai/plugins/perl.rb
+++ b/lib/ohai/plugins/perl.rb
@@ -21,25 +21,25 @@ Ohai.plugin(:Perl) do
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
diff --git a/lib/ohai/plugins/php.rb b/lib/ohai/plugins/php.rb
index d9efacd6..f9ecf917 100644
--- a/lib/ohai/plugins/php.rb
+++ b/lib/ohai/plugins/php.rb
@@ -23,30 +23,30 @@ Ohai.plugin(:PHP) do
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
diff --git a/lib/ohai/plugins/powershell.rb b/lib/ohai/plugins/powershell.rb
index 52dc8f6f..728e5b11 100644
--- a/lib/ohai/plugins/powershell.rb
+++ b/lib/ohai/plugins/powershell.rb
@@ -20,39 +20,39 @@ Ohai.plugin(:Powershell) do
depends "languages"
collect_data(:windows) do
- begin
- so = shell_out("powershell.exe -NoLogo -NonInteractive -NoProfile -command $PSVersionTable")
- # Sample output:
- #
- # Name Value
- # ---- -----
- # PSVersion 4.0
- # WSManStackVersion 3.0
- # SerializationVersion 1.1.0.1
- # CLRVersion 4.0.30319.34014
- # BuildVersion 6.3.9600.16394
- # PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
- # PSRemotingProtocolVersion 2.2
- if so.exitstatus == 0
- powershell = Mash.new
- version_info = {}
- so.stdout.strip.each_line do |line|
- kv = line.strip.split(/\s+/, 2)
- version_info[kv[0]] = kv[1] if kv.length == 2
- end
- powershell[:version] = version_info["PSVersion"]
- powershell[:ws_man_stack_version] = version_info["WSManStackVersion"]
- powershell[:serialization_version] = version_info["SerializationVersion"]
- powershell[:clr_version] = version_info["CLRVersion"]
- powershell[:build_version] = version_info["BuildVersion"]
- powershell[:compatible_versions] = parse_compatible_versions
- powershell[:remoting_protocol_version] = version_info["PSRemotingProtocolVersion"]
- languages[:powershell] = powershell unless powershell.empty?
+ so = shell_out("powershell.exe -NoLogo -NonInteractive -NoProfile -command $PSVersionTable")
+ # Sample output:
+ #
+ # Name Value
+ # ---- -----
+ # PSVersion 4.0
+ # WSManStackVersion 3.0
+ # SerializationVersion 1.1.0.1
+ # CLRVersion 4.0.30319.34014
+ # BuildVersion 6.3.9600.16394
+ # PSCompatibleVersions {1.0, 2.0, 3.0, 4.0}
+ # PSRemotingProtocolVersion 2.2
+
+ if so.exitstatus == 0
+ powershell = Mash.new
+ version_info = {}
+ so.stdout.strip.each_line do |line|
+ kv = line.strip.split(/\s+/, 2)
+ version_info[kv[0]] = kv[1] if kv.length == 2
end
- rescue Ohai::Exceptions::Exec
- logger.trace('Plugin Powershell: Could not shell_out "powershell.exe -NoLogo -NonInteractive -NoProfile -command $PSVersionTable". Skipping plugin')
+ powershell[:version] = version_info["PSVersion"]
+ powershell[:ws_man_stack_version] = version_info["WSManStackVersion"]
+ powershell[:serialization_version] = version_info["SerializationVersion"]
+ powershell[:clr_version] = version_info["CLRVersion"]
+ powershell[:build_version] = version_info["BuildVersion"]
+ powershell[:compatible_versions] = parse_compatible_versions
+ powershell[:remoting_protocol_version] = version_info["PSRemotingProtocolVersion"]
+ languages[:powershell] = powershell unless powershell.empty?
end
+ rescue Ohai::Exceptions::Exec
+ logger.trace('Plugin Powershell: Could not shell_out "powershell.exe -NoLogo -NonInteractive -NoProfile -command $PSVersionTable". Skipping plugin')
+
end
def version_command
diff --git a/lib/ohai/plugins/python.rb b/lib/ohai/plugins/python.rb
index 9aea8430..55601f79 100644
--- a/lib/ohai/plugins/python.rb
+++ b/lib/ohai/plugins/python.rb
@@ -22,22 +22,22 @@ Ohai.plugin(:Python) do
depends "languages"
collect_data do
- begin
- so = shell_out("python -c \"import sys; print (sys.version)\"")
- # Sample output:
- # 2.7.11 (default, Dec 26 2015, 17:47:53)
- # [GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]
- if so.exitstatus == 0
- python = Mash.new
- output = so.stdout.split
- python[:version] = output[0]
- if output.length >= 6
- python[:builddate] = "%s %s %s %s" % [output[2], output[3], output[4], output[5].delete!(")")]
- end
- languages[:python] = python unless python.empty?
+
+ so = shell_out("python -c \"import sys; print (sys.version)\"")
+ # Sample output:
+ # 2.7.11 (default, Dec 26 2015, 17:47:53)
+ # [GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]
+ if so.exitstatus == 0
+ python = Mash.new
+ output = so.stdout.split
+ python[:version] = output[0]
+ if output.length >= 6
+ python[:builddate] = "%s %s %s %s" % [output[2], output[3], output[4], output[5].delete!(")")]
end
- rescue Ohai::Exceptions::Exec
- logger.trace('Plugin Python: Could not shell_out "python -c "import sys; print (sys.version)"". Skipping plugin')
+ languages[:python] = python unless python.empty?
end
+ rescue Ohai::Exceptions::Exec
+ logger.trace('Plugin Python: Could not shell_out "python -c "import sys; print (sys.version)"". Skipping plugin')
+
end
end
diff --git a/lib/ohai/plugins/rust.rb b/lib/ohai/plugins/rust.rb
index ee62af17..6cd70d78 100644
--- a/lib/ohai/plugins/rust.rb
+++ b/lib/ohai/plugins/rust.rb
@@ -18,17 +18,17 @@ Ohai.plugin(:Rust) do
depends "languages"
collect_data do
- begin
- so = shell_out("rustc --version")
- # Sample output:
- # rustc 1.7.0
- if so.exitstatus == 0
- rust = Mash.new
- rust[:version] = so.stdout.split[1]
- languages[:rust] = rust if rust[:version]
- end
- rescue Ohai::Exceptions::Exec
- logger.trace('Plugin Rust: Could not shell_out "rustc --version". Skipping plugin')
+
+ so = shell_out("rustc --version")
+ # Sample output:
+ # rustc 1.7.0
+ if so.exitstatus == 0
+ rust = Mash.new
+ rust[:version] = so.stdout.split[1]
+ languages[:rust] = rust if rust[:version]
end
+ rescue Ohai::Exceptions::Exec
+ logger.trace('Plugin Rust: Could not shell_out "rustc --version". Skipping plugin')
+
end
end
diff --git a/lib/ohai/plugins/virtualbox.rb b/lib/ohai/plugins/virtualbox.rb
index b93d3e2a..80e73c86 100644
--- a/lib/ohai/plugins/virtualbox.rb
+++ b/lib/ohai/plugins/virtualbox.rb
@@ -20,30 +20,30 @@ Ohai.plugin(:Virtualbox) do
provides "virtualbox"
collect_data do
- begin
- so = shell_out("VBoxControl guestproperty enumerate")
- if so.exitstatus == 0
- virtualbox Mash.new
- virtualbox[:host] = Mash.new
- virtualbox[:guest] = Mash.new
- so.stdout.lines.each do |line|
- case line
- when /LanguageID, value: (\S*),/
- virtualbox[:host][:language] = Regexp.last_match(1)
- when /VBoxVer, value: (\S*),/
- virtualbox[:host][:version] = Regexp.last_match(1)
- when /VBoxRev, value: (\S*),/
- virtualbox[:host][:revision] = Regexp.last_match(1)
- when /GuestAdd\/VersionExt, value: (\S*),/
- virtualbox[:guest][:guest_additions_version] = Regexp.last_match(1)
- when /GuestAdd\/Revision, value: (\S*),/
- virtualbox[:guest][:guest_additions_revision] = Regexp.last_match(1)
- end
+ so = shell_out("VBoxControl guestproperty enumerate")
+
+ if so.exitstatus == 0
+ virtualbox Mash.new
+ virtualbox[:host] = Mash.new
+ virtualbox[:guest] = Mash.new
+ so.stdout.lines.each do |line|
+ case line
+ when /LanguageID, value: (\S*),/
+ virtualbox[:host][:language] = Regexp.last_match(1)
+ when /VBoxVer, value: (\S*),/
+ virtualbox[:host][:version] = Regexp.last_match(1)
+ when /VBoxRev, value: (\S*),/
+ virtualbox[:host][:revision] = Regexp.last_match(1)
+ when /GuestAdd\/VersionExt, value: (\S*),/
+ virtualbox[:guest][:guest_additions_version] = Regexp.last_match(1)
+ when /GuestAdd\/Revision, value: (\S*),/
+ virtualbox[:guest][:guest_additions_revision] = Regexp.last_match(1)
end
end
- rescue Ohai::Exceptions::Exec
- logger.trace('Plugin Virtualbox: Could not execute "VBoxControl guestproperty enumerate". Skipping data')
end
+ rescue Ohai::Exceptions::Exec
+ logger.trace('Plugin Virtualbox: Could not execute "VBoxControl guestproperty enumerate". Skipping data')
+
end
end
diff --git a/ohai.gemspec b/ohai.gemspec
index 34680611..9ddb3774 100644
--- a/ohai.gemspec
+++ b/ohai.gemspec
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
s.email = "adam@chef.io"
s.homepage = "https://docs.chef.io/ohai.html"
- s.required_ruby_version = ">= 2.4"
+ s.required_ruby_version = ">= 2.5"
s.add_dependency "systemu", "~> 2.6.4"
s.add_dependency "ffi-yajl", "~> 2.2"
diff --git a/spec/unit/plugins/abort_spec.rb b/spec/unit/plugins/abort_spec.rb
index 3227cecb..57eb0973 100644
--- a/spec/unit/plugins/abort_spec.rb
+++ b/spec/unit/plugins/abort_spec.rb
@@ -31,11 +31,11 @@ EOF
describe "a plug-in that aborts execution" do
before(:all) do
- begin
- Dir.mkdir("#{tmp}/plugins")
- rescue Errno::EEXIST
+
+ Dir.mkdir("#{tmp}/plugins")
+ rescue Errno::EEXIST
# ignore
- end
+
end
before(:each) do
@@ -49,11 +49,11 @@ describe "a plug-in that aborts execution" do
end
after(:all) do
- begin
- Dir.delete("#{tmp}/plugins")
- rescue
+
+ Dir.delete("#{tmp}/plugins")
+ rescue
# ignore
- end
+
end
before(:each) do
diff --git a/spec/unit/plugins/fail_spec.rb b/spec/unit/plugins/fail_spec.rb
index 75330cb4..6a8ac8d7 100644
--- a/spec/unit/plugins/fail_spec.rb
+++ b/spec/unit/plugins/fail_spec.rb
@@ -23,11 +23,11 @@ tmp = ENV["TMPDIR"] || ENV["TMP"] || ENV["TEMP"] || "/tmp"
shared_examples "a v7 loading failure" do
before(:all) do
- begin
- Dir.mkdir("#{tmp}/plugins")
- rescue Errno::EEXIST
+
+ Dir.mkdir("#{tmp}/plugins")
+ rescue Errno::EEXIST
# ignore
- end
+
end
before(:each) do
@@ -41,11 +41,11 @@ shared_examples "a v7 loading failure" do
end
after(:all) do
- begin
- Dir.delete("#{tmp}/plugins")
- rescue
+
+ Dir.delete("#{tmp}/plugins")
+ rescue
# ignore
- end
+
end
before(:each) do
@@ -67,11 +67,11 @@ end
shared_examples "a v7 loading success" do
before(:all) do
- begin
- Dir.mkdir("#{tmp}/plugins")
- rescue Errno::EEXIST
+
+ Dir.mkdir("#{tmp}/plugins")
+ rescue Errno::EEXIST
# ignore
- end
+
end
before(:each) do
@@ -85,11 +85,11 @@ shared_examples "a v7 loading success" do
end
after(:all) do
- begin
- Dir.delete("#{tmp}/plugins")
- rescue
+
+ Dir.delete("#{tmp}/plugins")
+ rescue
# ignore
- end
+
end
before(:each) do
@@ -110,11 +110,11 @@ end
shared_examples "a v7 run failure" do
before(:all) do
- begin
- Dir.mkdir("#{tmp}/plugins")
- rescue Errno::EEXIST
+
+ Dir.mkdir("#{tmp}/plugins")
+ rescue Errno::EEXIST
# ignore
- end
+
end
before(:each) do
@@ -128,11 +128,11 @@ shared_examples "a v7 run failure" do
end
after(:all) do
- begin
- Dir.delete("#{tmp}/plugins")
- rescue
+
+ Dir.delete("#{tmp}/plugins")
+ rescue
# ignore
- end
+
end
before(:each) do
diff --git a/spec/unit/plugins/linux/cpu_spec.rb b/spec/unit/plugins/linux/cpu_spec.rb
index a23cfd74..badd3271 100644
--- a/spec/unit/plugins/linux/cpu_spec.rb
+++ b/spec/unit/plugins/linux/cpu_spec.rb
@@ -92,12 +92,12 @@ describe Ohai::System, "General Linux cpu plugin" do
end
after(:each) do
- begin
- tempfile.close
- tempfile.unlink
- rescue
+
+ tempfile.close
+ tempfile.unlink
+ rescue
# really do not care
- end
+
end
context "with old kernel that doesn't include cores in /proc/cpuinfo" do
diff --git a/spec/unit/plugins/linux/fips_spec.rb b/spec/unit/plugins/linux/fips_spec.rb
index 570a5e04..43179b1c 100644
--- a/spec/unit/plugins/linux/fips_spec.rb
+++ b/spec/unit/plugins/linux/fips_spec.rb
@@ -36,12 +36,12 @@ describe Ohai::System, "plugin fips" do
end
around do |ex|
- begin
- $FIPS_TEST_MODE = openssl_test_mode
- ex.run
- ensure
- $FIPS_TEST_MODE = false
- end
+
+ $FIPS_TEST_MODE = openssl_test_mode
+ ex.run
+ ensure
+ $FIPS_TEST_MODE = false
+
end
context "fips file is present and contains 1" do
diff --git a/spec/unit/plugins/network_spec.rb b/spec/unit/plugins/network_spec.rb
index 6748b9aa..45c002d5 100644
--- a/spec/unit/plugins/network_spec.rb
+++ b/spec/unit/plugins/network_spec.rb
@@ -31,17 +31,17 @@ def it_populates_ipaddress_attributes
source = caller[0]
it "populates ipaddress, macaddress and ip6address" do
- begin
- allow(@plugin.logger).to receive(:warn)
- expect(@plugin.logger).not_to receive(:trace).with(/^Plugin network threw exception/)
- @plugin.run
- %w{ ipaddress macaddress ip6address }.each do |attribute|
- expect(@plugin).to have_key(attribute)
- end
- rescue Exception
- puts "RSpec context: #{source}"
- raise
+
+ allow(@plugin.logger).to receive(:warn)
+ expect(@plugin.logger).not_to receive(:trace).with(/^Plugin network threw exception/)
+ @plugin.run
+ %w{ ipaddress macaddress ip6address }.each do |attribute|
+ expect(@plugin).to have_key(attribute)
end
+ rescue Exception
+ puts "RSpec context: #{source}"
+ raise
+
end
end
diff --git a/spec/unit/plugins/windows/fips_spec.rb b/spec/unit/plugins/windows/fips_spec.rb
index b36e4265..88983cc8 100644
--- a/spec/unit/plugins/windows/fips_spec.rb
+++ b/spec/unit/plugins/windows/fips_spec.rb
@@ -37,12 +37,12 @@ describe Ohai::System, "plugin fips", :windows_only do
end
around do |ex|
- begin
- $FIPS_TEST_MODE = openssl_test_mode
- ex.run
- ensure
- $FIPS_TEST_MODE = false
- end
+
+ $FIPS_TEST_MODE = openssl_test_mode
+ ex.run
+ ensure
+ $FIPS_TEST_MODE = false
+
end
shared_examples "fips_plugin" do