diff -Nru ohai-8.21.0/bin/ohai ohai-13.8.0/bin/ohai --- ohai-8.21.0/bin/ohai 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/bin/ohai 2018-03-16 11:24:35.000000000 +0000 @@ -19,23 +19,8 @@ # limitations under the License. # -begin - require "rubygems" -rescue LoadError - # must be debian! ;) - missing_rubygems = true -end -begin - # if we're in a source code checkout, we want to run the code from that. - # have to do this *after* rubygems is loaded. - $:.unshift File.expand_path("../../lib", __FILE__) - require "ohai/application" -rescue LoadError - if missing_rubygems - STDERR.puts "rubygems previously failed to load - is it installed?" - end - - raise -end +# if we're in a source code checkout, we want to run the code from that. +$:.unshift File.expand_path("../../lib", __FILE__) +require "ohai/application" Ohai::Application.new.run diff -Nru ohai-8.21.0/debian/changelog ohai-13.8.0/debian/changelog --- ohai-8.21.0/debian/changelog 2016-10-31 12:44:19.000000000 +0000 +++ ohai-13.8.0/debian/changelog 2018-05-17 14:41:05.000000000 +0000 @@ -1,3 +1,19 @@ +ohai (13.8.0-1) unstable; urgency=medium + + * New upstream release. + - Supports ruby 2.5 (Closes: #892196) + * Refresh patches. + * Update copyright (and merge blocks with the same license, for sanity). + * Bump Standards-Version to 4.1.4, no changes needed. + * Patch: Ignore missing ipaddr_extensions. + * Declare Rules-Requires-Root: no. + * Bump debhelper compat to 10. + * Migrate watch file to version 4, https://gitwatch.debian.net/ + * Migrate package hosting to salsa.debian.org. + * Remove trailing whitespace from changelog. + + -- Stefano Rivera Thu, 17 May 2018 16:41:05 +0200 + ohai (8.21.0-1) unstable; urgency=medium * New upstream version 8.21.0 @@ -118,7 +134,7 @@ ohai (0.5.4-3) unstable; urgency=low - * Fix remove_rubygems patch for new version of bin/ohai. + * Fix remove_rubygems patch for new version of bin/ohai. [ Deepak Tripathi ] * Bumped Standard Version to 3.8.4 (no changes) @@ -157,7 +173,7 @@ ohai (0.5.0-2) unstable; urgency=low - * Remove rubygems patch missed bin/ohai. + * Remove rubygems patch missed bin/ohai. * ohai needs to depend on 'ruby' or it fails to process plugins. -- Joshua Timberman Tue, 09 Mar 2010 19:21:06 -0700 @@ -219,7 +235,7 @@ [Joshua Timberman] * Add DRE team to uploaders. - * Bump standards version to 3.8.3 + * Bump standards version to 3.8.3 [Bryan McLellan] * New upstream release diff -Nru ohai-8.21.0/debian/compat ohai-13.8.0/debian/compat --- ohai-8.21.0/debian/compat 2016-10-31 12:44:19.000000000 +0000 +++ ohai-13.8.0/debian/compat 2018-05-17 14:41:05.000000000 +0000 @@ -1 +1 @@ -9 +10 diff -Nru ohai-8.21.0/debian/control ohai-13.8.0/debian/control --- ohai-8.21.0/debian/control 2016-10-31 12:44:19.000000000 +0000 +++ ohai-13.8.0/debian/control 2018-05-17 14:41:05.000000000 +0000 @@ -2,10 +2,8 @@ Section: admin Priority: optional Maintainer: Debian Ruby Extras Maintainers -Uploaders: Joshua Timberman , - Praveen Arimbrathodiyil , - Antonio Terceiro -Build-Depends: debhelper (>= 9~), +Uploaders: Praveen Arimbrathodiyil +Build-Depends: debhelper (>= 10), gem2deb, rake, ruby-chef-config (>= 12.5.0.alpha.1), @@ -20,15 +18,15 @@ ruby-rspec, ruby-rspec-collection-matchers, ruby-systemu (>= 2.6.4), -Standards-Version: 3.9.8 -Vcs-Git: https://anonscm.debian.org/git/pkg-ruby-extras/ohai.git -Vcs-Browser: https://anonscm.debian.org/cgit/pkg-ruby-extras/ohai.git +Standards-Version: 4.1.4 +Vcs-Git: https://salsa.debian.org/ruby-team/ohai.git +Vcs-Browser: https://salsa.debian.org/ruby-team/ohai Homepage: https://docs.chef.io/ohai.html Testsuite: autopkgtest-pkg-ruby XS-Ruby-Versions: all +Rules-Requires-Root: no Package: ohai -Section: admin Architecture: all XB-Ruby-Versions: ${ruby:Versions} Depends: ruby | ruby-interpreter, diff -Nru ohai-8.21.0/debian/copyright ohai-13.8.0/debian/copyright --- ohai-8.21.0/debian/copyright 2016-10-31 12:44:19.000000000 +0000 +++ ohai-13.8.0/debian/copyright 2018-05-17 14:41:05.000000000 +0000 @@ -1,72 +1,33 @@ -Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: ohai Source: https://github.com/opscode/ohai Files: * -Copyright: 2008-2011 Opscode, Inc +Copyright: 2008-2018 Chef Software Inc. + 2008-2009 Bryan McLellan + 2016 Chris Dituri + 2009 Daniel DeLeo + 2015-2017 Facebook, Inc. + 2011 GLOBAL 2000/Friends of the Earth Austria + 2010 Kurt Yoder + 2013-2014 Limelight Networks, Inc. + 2009 Mathieu Sauve-Frankel + 2009 Matthew Kent + 2010 Sociable Limited + 2010 Tollef Fog Heen + 2009-2010 VMware, Inc License: Apache-2.0 Files: lib/ohai/mash.rb -Copyright: 2009 Dan Kubb +Copyright: 2009 Dan Kubb 2005-2008 David Heinemeier Hansson License: Expat -Files: lib/ohai/application.rb -Copyright: 2009 Mathieu Sauve-Frankel -License: Apache-2.0 - -Files: lib/ohai/plugins/netbsd/* - lib/ohai/plugins/openbsd/* - lib/ohai/plugins/freebsd/* -Copyright: 2008-2009 Bryan McLellan -License: Apache-2.0 - -Files: lib/ohai/plugins/netbsd/cpu.rb -Copyright:2009 Mathieu Sauve-Frankel -License: Apache-2.0 - -Files: lib/ohai/plugins/chef.rb - lib/ohai/plugins/ohai.rb -Copyright: 2010 Tollef Fog Heen -License: Apache-2.0 - -Files: lib/ohai/plugins/network_listeners.rb - lib/ohai/plugins/groovy.rb - lib/ohai/plugins/mono.rb - lib/ohai/plugins/lua.rb - lib/ohai/plugins/c.rb - lib/ohai/plugins/php.rb -Copyright: 2009 VMware, Inc -License: Apache-2.0 - -Files: lib/ohai/plugins/windows/cpu.rb - lib/ohai/plugins/sigar/* - lib/ohai/plugins/aix/* -Copyright: 2010 VMware, Inc -License: Apache-2.0 - -Files: lib/ohai/plugins/ip_scopes.rb -Copyright: 2010 Sociable Limited -License: Apache-2.0 - -Files: lib/ohai/plugins/solaris2/dmi.rb - lib/ohai/plugins/dmi.rb -Copyright: 2010 Kurt Yoder -License: Apache-2.0 - -Files: lib/ohai/plugins/solaris2/* -Copyright: 2008 Opscode, Inc - 2009 Daniel DeLeo -License: Apache-2.0 - -Files: lib/ohai/plugins/sigar/network.rb -Copyright: 2009 Matthew Kent -License: Apache-2.0 - Files: debian/* -Copyright: 2009 Bryan McLellan - 2011-2012 Praveen Arimbrathodiyil - 2016 Lucas Kanashiro +Copyright: 2009 Bryan McLellan + 2011-2012 Praveen Arimbrathodiyil + 2016 Lucas Kanashiro + 2018 Stefano Rivera License: Apache-2.0 License: Apache-2.0 diff -Nru ohai-8.21.0/debian/patches/0001-Drop-dependency-on-wmi-lite.patch ohai-13.8.0/debian/patches/0001-Drop-dependency-on-wmi-lite.patch --- ohai-8.21.0/debian/patches/0001-Drop-dependency-on-wmi-lite.patch 2016-10-31 12:44:19.000000000 +0000 +++ ohai-13.8.0/debian/patches/0001-Drop-dependency-on-wmi-lite.patch 2018-05-17 14:41:05.000000000 +0000 @@ -9,7 +9,7 @@ 2 files changed, 2 deletions(-) diff --git a/ohai.gemspec b/ohai.gemspec -index 7177f8c..616cd61 100644 +index 108b9fb..bce7aa5 100644 --- a/ohai.gemspec +++ b/ohai.gemspec @@ -23,7 +23,6 @@ Gem::Specification.new do |s| @@ -18,10 +18,10 @@ s.add_dependency "ipaddress" - s.add_dependency "wmi-lite", "~> 1.0" s.add_dependency "ffi", "~> 1.9" + s.add_dependency "chef-config", ">= 12.5.0.alpha.1", "< 14" # Note for ohai developers: If chef-config causes you grief, try: - # bundle install --with development diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb -index 8932cdc..c95ba2e 100644 +index 48c09f7..853eeda 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -8,7 +8,6 @@ $:.unshift(File.dirname(__FILE__) + "/../lib") diff -Nru ohai-8.21.0/debian/patches/0002-Remove-relative-references-for-source-code-in-tests.patch ohai-13.8.0/debian/patches/0002-Remove-relative-references-for-source-code-in-tests.patch --- ohai-8.21.0/debian/patches/0002-Remove-relative-references-for-source-code-in-tests.patch 2016-10-31 12:44:19.000000000 +0000 +++ ohai-13.8.0/debian/patches/0002-Remove-relative-references-for-source-code-in-tests.patch 2018-05-17 14:41:05.000000000 +0000 @@ -3,12 +3,11 @@ Subject: Remove relative references for source code in tests --- - spec/spec_helper.rb | 6 +++++- - spec/unit/plugins/root_group_spec.rb | 2 +- - 2 files changed, 6 insertions(+), 2 deletions(-) + spec/spec_helper.rb | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb -index c95ba2e..807f0da 100644 +index 853eeda..d7cee6b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -11,7 +11,11 @@ require "spec/support/integration_helper" @@ -24,16 +23,3 @@ SPEC_PLUGIN_PATH = File.expand_path("../data/plugins", __FILE__) RSpec.configure do |config| -diff --git a/spec/unit/plugins/root_group_spec.rb b/spec/unit/plugins/root_group_spec.rb -index 67ee4c1..2e8b035 100644 ---- a/spec/unit/plugins/root_group_spec.rb -+++ b/spec/unit/plugins/root_group_spec.rb -@@ -17,7 +17,7 @@ - # - - require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") --require File.expand_path(File.dirname(__FILE__) + "/../../../lib/ohai/util/win32/group_helper.rb") -+require 'ohai/util/win32/group_helper.rb' - - describe Ohai::System, "root_group" do - before(:each) do diff -Nru ohai-8.21.0/debian/patches/0003-Mark-Windows-only-tests-as-such.patch ohai-13.8.0/debian/patches/0003-Mark-Windows-only-tests-as-such.patch --- ohai-8.21.0/debian/patches/0003-Mark-Windows-only-tests-as-such.patch 2016-10-31 12:44:19.000000000 +0000 +++ ohai-13.8.0/debian/patches/0003-Mark-Windows-only-tests-as-such.patch 2018-05-17 14:41:05.000000000 +0000 @@ -10,12 +10,12 @@ 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/functional/plugins/windows/uptime_spec.rb b/spec/functional/plugins/windows/uptime_spec.rb -index d1abd68..1062aff 100644 +index b4effc6..c04e505 100644 --- a/spec/functional/plugins/windows/uptime_spec.rb +++ b/spec/functional/plugins/windows/uptime_spec.rb @@ -18,7 +18,7 @@ - require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") + require_relative "../../../spec_helper.rb" -describe Ohai::System, "Windows plugin uptime" do +describe Ohai::System, "Windows plugin uptime", :windows_only do @@ -23,10 +23,10 @@ context "for newer version of Windows" do let(:uptime_plugin) do diff --git a/spec/unit/plugins/windows/cpu_spec.rb b/spec/unit/plugins/windows/cpu_spec.rb -index 313104b..fdb65c3 100644 +index 0f18a1b..1f970fc 100644 --- a/spec/unit/plugins/windows/cpu_spec.rb +++ b/spec/unit/plugins/windows/cpu_spec.rb -@@ -55,7 +55,7 @@ shared_examples "a cpu" do |cpu_no| +@@ -60,7 +60,7 @@ shared_examples "a cpu" do |cpu_no| end end @@ -36,12 +36,12 @@ @plugin = get_plugin("windows/cpu") allow(@plugin).to receive(:collect_os).and_return(:windows) diff --git a/spec/unit/plugins/windows/uptime_spec.rb b/spec/unit/plugins/windows/uptime_spec.rb -index 05d2fd2..6b2a57b 100644 +index 2cede79..ce43b2e 100644 --- a/spec/unit/plugins/windows/uptime_spec.rb +++ b/spec/unit/plugins/windows/uptime_spec.rb @@ -18,7 +18,7 @@ - require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") + require_relative "../../../spec_helper.rb" -describe Ohai::System, "Windows plugin uptime" do +describe Ohai::System, "Windows plugin uptime", :windows_only do @@ -49,12 +49,12 @@ let(:wmi) { double("wmi", { :first_of => "" }) } diff --git a/spec/unit/plugins/windows/virtualization_spec.rb b/spec/unit/plugins/windows/virtualization_spec.rb -index 124e92f..4f25691 100644 +index 49d4446..08cca82 100644 --- a/spec/unit/plugins/windows/virtualization_spec.rb +++ b/spec/unit/plugins/windows/virtualization_spec.rb @@ -20,7 +20,7 @@ - require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") + require_relative "../../../spec_helper.rb" -describe Ohai::System, "Windows virtualization platform" do +describe Ohai::System, "Windows virtualization platform", :windows_only do diff -Nru ohai-8.21.0/debian/patches/0004-Ignore-missing-ipaddr_extensions.patch ohai-13.8.0/debian/patches/0004-Ignore-missing-ipaddr_extensions.patch --- ohai-8.21.0/debian/patches/0004-Ignore-missing-ipaddr_extensions.patch 1970-01-01 00:00:00.000000000 +0000 +++ ohai-13.8.0/debian/patches/0004-Ignore-missing-ipaddr_extensions.patch 2018-05-17 14:41:05.000000000 +0000 @@ -0,0 +1,26 @@ +From: Stefano Rivera +Date: Thu, 17 Aug 2017 01:01:17 -0700 +Subject: Ignore missing ipaddr_extensions + +We aren't going to package it, and the ipscopes plugin is being +removed in Chef 14. +--- + spec/unit/plugins/ip_scopes_spec.rb | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/spec/unit/plugins/ip_scopes_spec.rb b/spec/unit/plugins/ip_scopes_spec.rb +index 9e75465..7bc4c1e 100644 +--- a/spec/unit/plugins/ip_scopes_spec.rb ++++ b/spec/unit/plugins/ip_scopes_spec.rb +@@ -15,7 +15,10 @@ + # + + require_relative "../../spec_helper.rb" +-require "ipaddr_extensions" ++begin ++ require "ipaddr_extensions" ++rescue LoadError ++end + + describe Ohai::System, "plugin ip_scopes" do + let(:plugin) { get_plugin("ip_scopes") } diff -Nru ohai-8.21.0/debian/patches/series ohai-13.8.0/debian/patches/series --- ohai-8.21.0/debian/patches/series 2016-10-31 12:44:19.000000000 +0000 +++ ohai-13.8.0/debian/patches/series 2018-05-17 14:41:05.000000000 +0000 @@ -1,3 +1,4 @@ 0001-Drop-dependency-on-wmi-lite.patch 0002-Remove-relative-references-for-source-code-in-tests.patch 0003-Mark-Windows-only-tests-as-such.patch +0004-Ignore-missing-ipaddr_extensions.patch diff -Nru ohai-8.21.0/debian/watch ohai-13.8.0/debian/watch --- ohai-8.21.0/debian/watch 2016-10-31 12:44:19.000000000 +0000 +++ ohai-13.8.0/debian/watch 2018-05-17 14:41:05.000000000 +0000 @@ -1,2 +1,2 @@ -version=3 -http://pkg-ruby-extras.alioth.debian.org/cgi-bin/gemwatch/ohai .*/ohai-(.*).tar.gz +version=4 +https://gemwatch.debian.net/ohai .*/ohai-(.*).tar.gz diff -Nru ohai-8.21.0/Gemfile ohai-13.8.0/Gemfile --- ohai-8.21.0/Gemfile 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/Gemfile 2018-03-16 11:24:35.000000000 +0000 @@ -2,12 +2,27 @@ gemspec +# NOTE: do not submit PRs to add pry as a dep, add to your Gemfile.local group :development do - gem "sigar", :platform => "ruby" + gem "chefstyle" + gem "rake", ">= 10.1.0" + gem "rspec-core", "~> 3.0" + gem "rspec-expectations", "~> 3.0" + gem "rspec-mocks", "~> 3.0" + gem "rspec-collection_matchers", "~> 1.0" + gem "ipaddr_extensions" +end + +group :ci do + gem "rspec_junit_formatter" +end - gem "chefstyle", "= 0.4.0" - gem "overcommit", ">= 0.34.1" - gem "pry-byebug" - gem "pry-stack_explorer" - gem "rb-readline" +group :changelog do + gem "github_changelog_generator", git: "https://github.com/chef/github-changelog-generator" end + +instance_eval(ENV["GEMFILE_MOD"]) if ENV["GEMFILE_MOD"] + +# If you want to load debugging tools into the bundle exec sandbox, +# add these additional dependencies into Gemfile.local +eval_gemfile(__FILE__ + ".local") if File.exist?(__FILE__ + ".local") diff -Nru ohai-8.21.0/lib/ohai/application.rb ohai-13.8.0/lib/ohai/application.rb --- ohai-8.21.0/lib/ohai/application.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/application.rb 2018-03-16 11:24:35.000000000 +0000 @@ -20,6 +20,7 @@ require "ohai" require "ohai/log" require "mixlib/cli" +require "benchmark" class Ohai::Application include Mixlib::CLI @@ -74,8 +75,11 @@ end def run - configure_ohai - run_application + elapsed = Benchmark.measure do + configure_ohai + run_application + end + Ohai::Log.debug("Ohai took #{elapsed.total} total seconds to run.") end def configure_ohai @@ -83,9 +87,12 @@ @attributes = nil if @attributes.empty? load_workstation_config + + Ohai::Log.init(Ohai.config[:log_location]) end def run_application + config[:invoked_from_cli] = true ohai = Ohai::System.new(config) ohai.all_plugins(@attributes) diff -Nru ohai-8.21.0/lib/ohai/common/dmi.rb ohai-13.8.0/lib/ohai/common/dmi.rb --- ohai-8.21.0/lib/ohai/common/dmi.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/common/dmi.rb 2018-03-16 11:24:35.000000000 +0000 @@ -65,6 +65,9 @@ 37 => "memory_channel", 38 => "ipmi_device", 39 => "power_supply", + 40 => "additional_information", + 41 => "onboard_devices_extended_information", + 42 => "management_controller_host_interfaces", 126 => "disabled_entries", 127 => "end_of_table_marker", } @@ -75,20 +78,18 @@ # look up DMI ID def id_lookup(id) - begin - id = id.to_i - if (id >= 128) && (id <= 255) - id = "oem_data_#{id}" - elsif DMI::ID_TO_DESCRIPTION.has_key?(id) - id = DMI::ID_TO_DESCRIPTION[id] - else - Ohai::Log.debug("unrecognized header id; falling back to 'unknown'") - id = "unknown" - end - rescue - Ohai::Log.debug("failed to look up id #{id}, returning unchanged") - id + id = id.to_i + if (id >= 128) && (id <= 255) + id = "oem_data_#{id}" + elsif DMI::ID_TO_DESCRIPTION.has_key?(id) + id = DMI::ID_TO_DESCRIPTION[id] + else + Ohai::Log.debug("unrecognized header id; falling back to 'unknown'") + id = "unknown" end + rescue + Ohai::Log.debug("failed to look up id #{id}, returning unchanged") + id end # create simplified convenience access keys for each record type @@ -115,7 +116,7 @@ end end in_common.each do |field, value| - next if value == nil + next if value.nil? dmi[type][field] = value.strip end end diff -Nru ohai-8.21.0/lib/ohai/config.rb ohai-13.8.0/lib/ohai/config.rb --- ohai-8.21.0/lib/ohai/config.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/config.rb 2018-03-16 11:24:35.000000000 +0000 @@ -19,7 +19,6 @@ require "chef-config/config" require "ohai/exception" -require "ohai/log" require "ohai/plugin_config" module Ohai @@ -28,98 +27,15 @@ # Reopens ChefConfig::Config to add Ohai configuration settings. # see: https://github.com/chef/chef/blob/master/lib/chef/config.rb class Config - # These methods need to be defined before they are used as config defaults, - # otherwise they will get method_missing'd to nil. - - class << self - def merge_deprecated_config - [ :hints_path, :plugin_path ].each do |option| - if has_key?(option) && send(option) != send("default_#{option}".to_sym) - Ohai::Log.warn(option_deprecated(option)) - end - end - - ohai.merge!(configuration) - end - - def default_hints_path - [ ChefConfig::Config.platform_specific_path("/etc/chef/ohai/hints") ] - end - - def default_plugin_path - [ File.expand_path(File.join(File.dirname(__FILE__), "plugins")) ] - end - end - - # Copy deprecated configuration options into the ohai config context. - - # Keep "old" config defaults around so anyone calling Ohai::Config[:key] - # won't be broken. Also allows users to append to configuration options - # (e.g., Ohai::Config[:plugin_path] << some_path) in their config files. - default :disabled_plugins, [] - default :hints_path, default_hints_path - default :log_level, :auto - default :log_location, STDERR - default :plugin_path, default_plugin_path - - # Log deprecation warning when a top-level configuration option is set. - # TODO: Should we implement a config_attr_reader so that deprecation - # warnings will be generatd on read? - [ - :directory, - :disabled_plugins, - :log_level, - :log_location, - :version, - ].each do |option| - # https://docs.chef.io/config_rb_client.html#ohai-settings - # hints_path and plugin_path are intentionally excluded here; warnings for - # setting these attributes are generated in merge_deprecated_config since - # append (<<) operations bypass the config writer. - config_attr_writer option do |value| - # log_level and log_location are common configuration options for chef - # and other chef applications. When configuration files are read there - # is no distinction between log_level and Ohai::Config[:log_level] and - # we may emit a false deprecation warning. The deprecation warnings for - # these settings reflect that possibility. - # Furthermore, when the top-level config settings are removed we will - # need to ensure that Ohai.config[:log_level] can be set by writing - # log_level in a configuration file for consistent behavior with chef. - deprecation_warning = if [ :log_level, :log_location ].include?(value) - option_might_be_deprecated(option) - else - option_deprecated(option) - end - Ohai::Log.warn(deprecation_warning) - value - end - end config_context :ohai do default :disabled_plugins, [] - default :hints_path, Ohai::Config.default_hints_path + default :hints_path, [ ChefConfig::Config.platform_specific_path("/etc/chef/ohai/hints") ] default :log_level, :auto default :log_location, STDERR default :plugin, Ohai::PluginConfig.new { |h, k| h[k] = Ohai::PluginConfig.new } - default :plugin_path, Ohai::Config.default_plugin_path - end - - class << self - def option_deprecated(option) - <<-EOM.chomp!.tr("\n", " ") -Ohai::Config[:#{option}] is set. Ohai::Config[:#{option}] is deprecated and will -be removed in future releases of ohai. Use ohai.#{option} in your configuration -file to configure :#{option} for ohai. - EOM - end - - def option_might_be_deprecated(option) - option_deprecated(option) + <<-EOM.chomp!.tr("\n", " ") - If your configuration file is used with other applications which configure -:#{option}, and you have not configured Ohai::Config[:#{option}], you may -disregard this warning. - EOM - end + default :plugin_path, [ File.expand_path(File.join(File.dirname(__FILE__), "plugins")), ChefConfig::Config.platform_specific_path("/etc/chef/ohai/plugins") ] + default :critical_plugins, [] end end diff -Nru ohai-8.21.0/lib/ohai/dsl/plugin/versionvii.rb ohai-13.8.0/lib/ohai/dsl/plugin/versionvii.rb --- ohai-8.21.0/lib/ohai/dsl/plugin/versionvii.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/dsl/plugin/versionvii.rb 2018-03-16 11:24:35.000000000 +0000 @@ -85,11 +85,11 @@ platform = collect_os if collector.has_key?(platform) - self.instance_eval(&collector[platform]) + instance_eval(&collector[platform]) elsif collector.has_key?(:default) - self.instance_eval(&collector[:default]) + instance_eval(&collector[:default]) else - Ohai::Log.debug("Plugin #{self.name}: No data to collect. Skipping...") + Ohai::Log.debug("Plugin #{name}: No data to collect. Skipping...") end end @@ -122,7 +122,7 @@ # Memory => ["", "Memory"] # NetworkListeners => ["", "Network", "", "Listeners"] # SSHHostKey => ["SSH", "Host", "", "Key"] - parts = self.name.to_s.split(/([A-Z][a-z]+)/) + parts = name.to_s.split(/([A-Z][a-z]+)/) # ["DMI"] => ["DMI"] # ["", "Memory"] => ["Memory"] # ["", "Network", "", "Listeners"] => ["Network", "Listeners"] diff -Nru ohai-8.21.0/lib/ohai/dsl/plugin/versionvi.rb ohai-13.8.0/lib/ohai/dsl/plugin/versionvi.rb --- ohai-8.21.0/lib/ohai/dsl/plugin/versionvi.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/dsl/plugin/versionvi.rb 2018-03-16 11:24:35.000000000 +0000 @@ -44,7 +44,7 @@ end def self.collect_contents(contents) - define_method(:run_plugin) { self.instance_eval(contents) } + define_method(:run_plugin) { instance_eval(contents) } end def provides(*paths) diff -Nru ohai-8.21.0/lib/ohai/dsl/plugin.rb ohai-13.8.0/lib/ohai/dsl/plugin.rb --- ohai-8.21.0/lib/ohai/dsl/plugin.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/dsl/plugin.rb 2018-03-16 11:24:35.000000000 +0000 @@ -85,10 +85,12 @@ include Ohai::Util::FileHelper attr_reader :data + attr_reader :failed def initialize(data) @data = data @has_run = false + @failed = false end def run @@ -154,8 +156,19 @@ end end - def set_attribute(name, *values) - @data[name] = Array18(*values) + def set_attribute(name, *attrs, value) + # Initialize the path in the @data Mash with new Mashes, if needed. + # Will raise a TypeError if we hit a subattribute that is not a + # Hash, Mash, or Array. + keys = [name] + attrs + attribute = keys[0..-2].inject(@data) do |attrs, key| + attrs[key] ||= Mash.new + attrs[key] + end + + # Set the subattribute to the value. + attr_name = attrs.empty? ? name : attrs[-1] + attribute[attr_name] = value @data[name] end @@ -169,14 +182,14 @@ # emulates the old plugin loading behavior def safe_run - begin - self.run - rescue Ohai::Exceptions::Error => e - raise e - rescue => e - Ohai::Log.debug("Plugin #{self.name} threw #{e.inspect}") - e.backtrace.each { |line| Ohai::Log.debug( line ) } - end + run + rescue Ohai::Exceptions::Error => e + @failed = true + raise e + rescue => e + @failed = true + Ohai::Log.debug("Plugin #{name} threw #{e.inspect}") + e.backtrace.each { |line| Ohai::Log.debug( line ) } end def method_missing(name, *args) @@ -198,12 +211,6 @@ # NoMethodError occurs when trying to access a key on nil nil end - - def Array18(*args) - return nil if args.empty? - return args.first if args.length == 1 - return *args - end end end end diff -Nru ohai-8.21.0/lib/ohai/exception.rb ohai-13.8.0/lib/ohai/exception.rb --- ohai-8.21.0/lib/ohai/exception.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/exception.rb 2018-03-16 11:24:35.000000000 +0000 @@ -29,5 +29,6 @@ class DependencyNotFound < Error; end class AttributeSyntaxError < Error; end class PluginConfigError < Error; end + class CriticalPluginFailure < Error; end end end diff -Nru ohai-8.21.0/lib/ohai/loader.rb ohai-13.8.0/lib/ohai/loader.rb --- ohai-8.21.0/lib/ohai/loader.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/loader.rb 2018-03-16 11:24:35.000000000 +0000 @@ -40,7 +40,7 @@ # Finds all the *.rb files under the configured paths in :plugin_path def self.find_all_in(plugin_dir) unless Dir.exist?(plugin_dir) - Ohai::Log.warn("The plugin path #{plugin_dir} does not exist. Skipping...") + Ohai::Log.info("The plugin path #{plugin_dir} does not exist. Skipping...") return [] end @@ -70,8 +70,8 @@ # Searches all plugin paths and returns an Array of PluginFile objects # representing each plugin file. - def plugin_files_by_dir - Array(Ohai.config[:plugin_path]).inject([]) do |plugin_files, plugin_path| + def plugin_files_by_dir(dir = Ohai.config[:plugin_path]) + Array(dir).inject([]) do |plugin_files, plugin_path| plugin_files + PluginFile.find_all_in(plugin_path) end end @@ -85,6 +85,15 @@ collect_v7_plugins end + def load_additional(from) + from = [ Ohai.config[:plugin_path], from].flatten + plugin_files_by_dir(from).collect do |plugin_file| + Ohai::Log.debug "Loading additional plugin: #{plugin_file}" + plugin = load_plugin_class(plugin_file.path, plugin_file.plugin_root) + load_v7_plugin(plugin) + end + end + # Load a specified file as an ohai plugin and creates an instance of it. # Not used by ohai itself, but can be used to load a plugin for testing # purposes. @@ -124,8 +133,8 @@ load_v7_plugin_class(contents, plugin_path) else Ohai::Log.warn("[DEPRECATION] Plugin at #{plugin_path} is a version 6 plugin. \ -Version 6 plugins will not be supported in future releases of Ohai. \ -Please upgrade your plugin to version 7 plugin syntax. \ +Version 6 plugins will not be supported in Chef/Ohai 14. \ +Please upgrade your plugin to version 7 plugin format. \ For more information visit here: docs.chef.io/ohai_custom.html") load_v6_plugin_class(contents, plugin_path, plugin_dir_path) diff -Nru ohai-8.21.0/lib/ohai/log.rb ohai-13.8.0/lib/ohai/log.rb --- ohai-8.21.0/lib/ohai/log.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/log.rb 2018-03-16 11:24:35.000000000 +0000 @@ -1,6 +1,6 @@ # # Author:: Adam Jacob () -# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. +# Copyright:: Copyright (c) 2008-2017, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,6 +22,8 @@ class Log extend Mixlib::Log + # this class loading initalization is so that we don't lose early logger + # messages when run from the CLI? init(STDERR) level = :info diff -Nru ohai-8.21.0/lib/ohai/mash.rb ohai-13.8.0/lib/ohai/mash.rb --- ohai-8.21.0/lib/ohai/mash.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/mash.rb 2018-03-16 11:24:35.000000000 +0000 @@ -135,7 +135,7 @@ # # @return [Mash] A new mash with the hash values merged in. def merge(hash) - self.dup.update(hash) + dup.update(hash) end # @param key diff -Nru ohai-8.21.0/lib/ohai/mixin/azure_metadata.rb ohai-13.8.0/lib/ohai/mixin/azure_metadata.rb --- ohai-8.21.0/lib/ohai/mixin/azure_metadata.rb 1970-01-01 00:00:00.000000000 +0000 +++ ohai-13.8.0/lib/ohai/mixin/azure_metadata.rb 2018-03-16 11:24:35.000000000 +0000 @@ -0,0 +1,53 @@ +# +# Author:: Tim Smith () +# Copyright:: Copyright 2017 Chef Software, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require "net/http" + +module Ohai + module Mixin + module AzureMetadata + + AZURE_METADATA_ADDR = "169.254.169.254" unless defined?(AZURE_METADATA_ADDR) + AZURE_METADATA_URL = "/metadata/instance?api-version=2017-04-02" unless defined?(AZURE_METADATA_URL) + + # fetch the meta content with a timeout and the required header + def http_get(uri) + conn = Net::HTTP.start(AZURE_METADATA_ADDR) + conn.read_timeout = 6 + conn.get(uri, initheader = { "Metadata" => "true" }) + end + + def fetch_metadata + Ohai::Log.debug("Mixin AzureMetadata: Fetching metadata from host #{AZURE_METADATA_ADDR} at #{AZURE_METADATA_URL}") + response = http_get(AZURE_METADATA_URL) + if response.code == "200" + begin + data = StringIO.new(response.body) + parser = FFI_Yajl::Parser.new + parser.parse(data) + rescue FFI_Yajl::ParseError + Ohai::Log.warn("Mixin AzureMetadata: Metadata response is NOT valid JSON") + nil + end + else + Ohai::Log.warn("Mixin AzureMetadata: Received response code #{response.code} requesting metadata") + nil + end + end + end + end +end diff -Nru ohai-8.21.0/lib/ohai/mixin/command.rb ohai-13.8.0/lib/ohai/mixin/command.rb --- ohai-8.21.0/lib/ohai/mixin/command.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/mixin/command.rb 2018-03-16 11:24:35.000000000 +0000 @@ -1,5 +1,6 @@ # # Author:: Adam Jacob () +# Author:: Tim Smith () # Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. # License:: Apache License, Version 2.0 # @@ -17,12 +18,7 @@ # require "ohai/exception" -require "ohai/config" require "ohai/log" -require "stringio" -require "tmpdir" -require "fcntl" -require "etc" require "mixlib/shellout" module Ohai @@ -31,336 +27,28 @@ # DISCLAIMER: Logging only works in the context of a plugin!! # accept a command and any of the mixlib-shellout options def shell_out(cmd, **options) + options = options.dup # unless specified by the caller timeout after 30 seconds options[:timeout] ||= 30 + unless RUBY_PLATFORM =~ /mswin|mingw32|windows/ + options[:env] = options.key?(:env) ? options[:env].dup : {} + options[:env]["PATH"] ||= ((ENV["PATH"] || "").split(":") + %w{/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin}).join(":") + end so = Mixlib::ShellOut.new(cmd, options) begin so.run_command - Ohai::Log.debug("Plugin #{self.name}: ran '#{cmd}' and returned #{so.exitstatus}") + Ohai::Log.debug("Plugin #{name}: ran '#{cmd}' and returned #{so.exitstatus}") so rescue Errno::ENOENT => e - Ohai::Log.debug("Plugin #{self.name}: ran '#{cmd}' and failed #{e.inspect}") + Ohai::Log.debug("Plugin #{name}: ran '#{cmd}' and failed #{e.inspect}") raise Ohai::Exceptions::Exec, e rescue Mixlib::ShellOut::CommandTimeout => e - Ohai::Log.debug("Plugin #{self.name}: ran '#{cmd}' and timed out after #{options[:timeout]} seconds") + Ohai::Log.debug("Plugin #{name}: ran '#{cmd}' and timed out after #{options[:timeout]} seconds") raise Ohai::Exceptions::Exec, e end end module_function :shell_out - - def run_command(args = {}) - Ohai::Log.warn("Ohai::Mixin::Command run_command is deprecated and will be removed in Ohai 9.0.0") - if args.has_key?(:creates) - if File.exists?(args[:creates]) - Ohai::Log.debug("Skipping #{args[:command]} - creates #{args[:creates]} exists.") - return false - end - end - - stdout_string = nil - stderr_string = nil - - args[:cwd] ||= Dir.tmpdir - unless File.directory?(args[:cwd]) - raise Ohai::Exceptions::Exec, "#{args[:cwd]} does not exist or is not a directory" - end - - status = nil - Dir.chdir(args[:cwd]) do - status, stdout_string, stderr_string = run_command_backend(args[:command], args[:timeout]) - - if stdout_string - Ohai::Log.debug("---- Begin #{args[:command]} STDOUT ----") - Ohai::Log.debug(stdout_string.strip) - Ohai::Log.debug("---- End #{args[:command]} STDOUT ----") - end - if stderr_string - Ohai::Log.debug("---- Begin #{args[:command]} STDERR ----") - Ohai::Log.debug(stderr_string.strip) - Ohai::Log.debug("---- End #{args[:command]} STDERR ----") - end - - args[:returns] ||= 0 - args[:no_status_check] ||= false - if status.exitstatus != args[:returns] && (not args[:no_status_check]) - raise Ohai::Exceptions::Exec, "#{args[:command_string]} returned #{status.exitstatus}, expected #{args[:returns]}" - else - Ohai::Log.debug("Ran #{args[:command_string]} (#{args[:command]}) returned #{status.exitstatus}") - end - end - return status, stdout_string, stderr_string - end - - module_function :run_command - - def run_command_unix(command, timeout) - stderr_string, stdout_string, status = "", "", nil - - exec_processing_block = lambda do |pid, stdin, stdout, stderr| - stdout_string, stderr_string = stdout.string.chomp, stderr.string.chomp - end - - if timeout - begin - Timeout.timeout(timeout) do - status = popen4(command, {}, &exec_processing_block) - end - rescue Timeout::Error => e - Chef::Log.error("#{command} exceeded timeout #{timeout}") - raise(e) - end - else - status = popen4(command, {}, &exec_processing_block) - end - return status, stdout_string, stderr_string - end - - def run_command_windows(command, timeout) - shellout_opts = {} - shellout_opts[:timeout] = timeout if timeout - - m = Mixlib::ShellOut.new(command, shellout_opts) - m.run_command - [m.status, m.stdout, m.stderr] - end - - if RUBY_PLATFORM =~ /mswin|mingw32|windows/ - alias :run_command_backend :run_command_windows - else - alias :run_command_backend :run_command_unix - end - # This is taken directly from Ara T Howard's Open4 library, and then - # modified to suit the needs of Ohai. Any bugs here are most likely - # my own, and not Ara's. - # - # The original appears in external/open4.rb in its unmodified form. - # - # Thanks Ara! - def popen4(cmd, args = {}, &b) - Ohai::Log.warn("Ohai::Mixin::Command popen4 is deprecated and will be removed in Ohai 9.0.0") - - # Disable garbage collection to work around possible bug in MRI - # Ruby 1.8 suffers from intermittent segfaults believed to be due to GC while IO.select - # See OHAI-330 / CHEF-2916 / CHEF-1305 - GC.disable - - # Waitlast - this is magic. - # - # Do we wait for the child process to die before we yield - # to the block, or after? That is the magic of waitlast. - # - # By default, we are waiting before we yield the block. - args[:waitlast] ||= false - - args[:user] ||= nil - unless args[:user].kind_of?(Integer) - args[:user] = Etc.getpwnam(args[:user]).uid if args[:user] - end - args[:group] ||= nil - unless args[:group].kind_of?(Integer) - args[:group] = Etc.getgrnam(args[:group]).gid if args[:group] - end - args[:environment] ||= {} - - # Default on C locale so parsing commands output can be done - # independently of the node's default locale. - # "LC_ALL" could be set to nil, in which case we also must ignore it. - unless args[:environment].has_key?("LC_ALL") - args[:environment]["LC_ALL"] = "C" - end - - pw, pr, pe, ps = IO.pipe, IO.pipe, IO.pipe, IO.pipe - - verbose = $VERBOSE - begin - $VERBOSE = nil - ps.last.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) - - cid = fork do - Process.setsid - - pw.last.close - STDIN.reopen pw.first - pw.first.close - - pr.first.close - STDOUT.reopen pr.last - pr.last.close - - pe.first.close - STDERR.reopen pe.last - pe.last.close - - STDOUT.sync = STDERR.sync = true - - if args[:group] - Process.egid = args[:group] - Process.gid = args[:group] - end - - if args[:user] - Process.euid = args[:user] - Process.uid = args[:user] - end - - args[:environment].each do |key, value| - ENV[key] = value - end - - if args[:umask] - umask = ((args[:umask].respond_to?(:oct) ? args[:umask].oct : args[:umask].to_i) & 007777) - File.umask(umask) - end - - begin - if cmd.kind_of?(Array) - exec(*cmd) - else - exec(cmd) - end - raise "forty-two" - rescue Exception => e - Marshal.dump(e, ps.last) - ps.last.flush - end - ps.last.close unless ps.last.closed? - exit! - end - ensure - $VERBOSE = verbose - end - - [pw.first, pr.last, pe.last, ps.last].each { |fd| fd.close } - - begin - e = Marshal.load ps.first - pw.last.close - pr.first.close - pe.first.close - Process.wait(cid) - raise(Exception === e ? e : "unknown failure!") - rescue EOFError # If we get an EOF error, then the exec was successful - 42 - ensure - ps.first.close - end - - pw.last.sync = true - - pi = [pw.last, pr.first, pe.first] - - if b - begin - if args[:waitlast] - b[cid, *pi] - # send EOF so that if the child process is reading from STDIN - # it will actually finish up and exit - pi[0].close_write - Process.waitpid2(cid).last - else - # This took some doing. - # The trick here is to close STDIN - # Then set our end of the childs pipes to be O_NONBLOCK - # Then wait for the child to die, which means any IO it - # wants to do must be done - it's dead. If it isn't, - # it's because something totally skanky is happening, - # and we don't care. - o = StringIO.new - e = StringIO.new - - #pi[0].close - - stdout = pi[1] - stderr = pi[2] - - stdout.sync = true - stderr.sync = true - - stdout.fcntl(Fcntl::F_SETFL, pi[1].fcntl(Fcntl::F_GETFL) | Fcntl::O_NONBLOCK) - stderr.fcntl(Fcntl::F_SETFL, pi[2].fcntl(Fcntl::F_GETFL) | Fcntl::O_NONBLOCK) - - stdout_finished = false - stderr_finished = false - - results = nil - - while !stdout_finished || !stderr_finished - begin - channels_to_watch = [] - channels_to_watch << stdout if !stdout_finished - channels_to_watch << stderr if !stderr_finished - ready = IO.select(channels_to_watch, nil, nil, 1.0) - rescue Errno::EAGAIN - ensure - results = Process.waitpid2(cid, Process::WNOHANG) - if results - stdout_finished = true - stderr_finished = true - end - end - - if ready && ready.first.include?(stdout) - line = results ? stdout.gets(nil) : stdout.gets - if line - o.write(line) - else - stdout_finished = true - end - end - if ready && ready.first.include?(stderr) - line = results ? stderr.gets(nil) : stderr.gets - if line - e.write(line) - else - stderr_finished = true - end - end - end - results = Process.waitpid2(cid) unless results - o.rewind - e.rewind - - # **OHAI-275** - # The way we read from the pipes causes ruby to mark the strings - # as ASCII-8BIT (i.e., binary), but the content should be encoded - # as the default external encoding. For example, a command may - # return data encoded as UTF-8, but the strings will be marked as - # ASCII-8BIT. Later, when you attempt to print the values as - # UTF-8, Ruby will try to convert them and fail, raising an - # error. - # - # Ruby always marks strings as binary when read from IO in - # incomplete chunks, since you may have split the data within a - # multibyte char. In our case, we concat the chunks back - # together, so any multibyte chars will be reassembled. - # - # Note that all of this applies only to Ruby 1.9, which we check - # for by making sure that the Encoding class exists and strings - # have encoding methods. - if "".respond_to?(:force_encoding) && defined?(Encoding) - o.string.force_encoding(Encoding.default_external) - o.string.encode!("UTF-8", :invalid => :replace, :undef => :replace, :replace => "?") - e.string.force_encoding(Encoding.default_external) - e.string.encode!("UTF-8", :invalid => :replace, :undef => :replace, :replace => "?") - end - b[cid, pi[0], o, e] - results.last - end - ensure - pi.each { |fd| fd.close unless fd.closed? } - end - else - [cid, pw.last, pr.first, pe.first] - end - rescue Errno::ENOENT - raise Ohai::Exceptions::Exec, "command #{cmd} doesn't exist or is not in the PATH" - ensure - # we disabled GC entering - GC.enable - end - - module_function :popen4 end end end diff -Nru ohai-8.21.0/lib/ohai/mixin/dmi_decode.rb ohai-13.8.0/lib/ohai/mixin/dmi_decode.rb --- ohai-8.21.0/lib/ohai/mixin/dmi_decode.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/mixin/dmi_decode.rb 2018-03-16 11:24:35.000000000 +0000 @@ -42,8 +42,10 @@ return "kvm" when /Product.*: BHYVE/ return "bhyve" + when /Manufacturer: Veertu/ + return "veertu" end end - return nil + nil end end diff -Nru ohai-8.21.0/lib/ohai/mixin/do_metadata.rb ohai-13.8.0/lib/ohai/mixin/do_metadata.rb --- ohai-8.21.0/lib/ohai/mixin/do_metadata.rb 1970-01-01 00:00:00.000000000 +0000 +++ ohai-13.8.0/lib/ohai/mixin/do_metadata.rb 2018-03-16 11:24:35.000000000 +0000 @@ -0,0 +1,47 @@ + +# Author:: Dylan Page () +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require "net/http" + +module Ohai + module Mixin + module DOMetadata + + DO_METADATA_ADDR = "169.254.169.254" unless defined?(DO_METADATA_ADDR) + DO_METADATA_URL = "/metadata/v1.json" unless defined?(DO_METADATA_URL) + + def http_client + Net::HTTP.start(DO_METADATA_ADDR).tap { |h| h.read_timeout = 6 } + end + + def fetch_metadata + uri = "#{DO_METADATA_URL}" + response = http_client.get(uri) + case response.code + when "200" + parser = FFI_Yajl::Parser.new + parser.parse(response.body) + when "404" + Ohai::Log.debug("Mixin DOMetadata: Encountered 404 response retrieving Digital Ocean metadata: #{uri} ; continuing.") + {} + else + raise "Mixin DOMetadata: Encountered error retrieving Digital Ocean metadata (#{uri} returned #{response.code} response)" + end + end + + end + end +end diff -Nru ohai-8.21.0/lib/ohai/mixin/ec2_metadata.rb ohai-13.8.0/lib/ohai/mixin/ec2_metadata.rb --- ohai-8.21.0/lib/ohai/mixin/ec2_metadata.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/mixin/ec2_metadata.rb 2018-03-16 11:24:35.000000000 +0000 @@ -2,7 +2,7 @@ # Author:: Tim Dysinger () # Author:: Benjamin Black () # Author:: Christopher Brown () -# Copyright:: Copyright (c) 2009-2016 Chef Software, Inc. +# Copyright:: 2009-2017 Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,6 @@ # limitations under the License. require "net/http" -require "socket" module Ohai module Mixin @@ -43,63 +42,41 @@ EC2_METADATA_ADDR = "169.254.169.254" unless defined?(EC2_METADATA_ADDR) EC2_SUPPORTED_VERSIONS = %w{ 1.0 2007-01-19 2007-03-01 2007-08-29 2007-10-10 2007-12-15 2008-02-01 2008-09-01 2009-04-04 2011-01-01 2011-05-01 2012-01-12 - 2014-11-05 2014-02-25 } - + 2014-02-25 2014-11-05 2015-10-20 2016-04-19 2016-06-30 2016-09-02 } EC2_ARRAY_VALUES = %w{security-groups} EC2_ARRAY_DIR = %w{network/interfaces/macs} EC2_JSON_DIR = %w{iam} - def can_metadata_connect?(addr, port, timeout = 2) - t = Socket.new(Socket::Constants::AF_INET, Socket::Constants::SOCK_STREAM, 0) - saddr = Socket.pack_sockaddr_in(port, addr) - connected = false - - begin - t.connect_nonblock(saddr) - rescue Errno::EINPROGRESS - r, w, e = IO.select(nil, [t], nil, timeout) - if !w.nil? - connected = true - else - begin - t.connect_nonblock(saddr) - rescue Errno::EISCONN - t.close - connected = true - rescue SystemCallError - end - end - rescue SystemCallError - end - Ohai::Log.debug("ec2 metadata mixin: can_metadata_connect? == #{connected}") - connected - end - def best_api_version - response = http_client.get("/") - if response.code == "404" - Ohai::Log.debug("ec2 metadata mixin: Received HTTP 404 from metadata server while determining API version, assuming 'latest'") - return "latest" - elsif response.code != "200" - raise "Unable to determine EC2 metadata version (returned #{response.code} response)" - end - # Note: Sorting the list of versions may have unintended consequences in - # non-EC2 environments. It appears to be safe in EC2 as of 2013-04-12. - versions = response.body.split("\n") - versions = response.body.split("\n").sort - until versions.empty? || EC2_SUPPORTED_VERSIONS.include?(versions.last) - pv = versions.pop - Ohai::Log.debug("ec2 metadata mixin: EC2 shows unsupported metadata version: #{pv}") unless pv == "latest" - end - Ohai::Log.debug("ec2 metadata mixin: EC2 metadata version: #{versions.last}") - if versions.empty? - raise "Unable to determine EC2 metadata version (no supported entries found)" + @api_version ||= begin + Ohai::Log.debug("Mixin EC2: Fetching http://#{EC2_METADATA_ADDR}/ to determine the latest supported metadata release") + response = http_client.get("/") + if response.code == "404" + Ohai::Log.debug("Mixin EC2: Received HTTP 404 from metadata server while determining API version, assuming 'latest'") + return "latest" + elsif response.code != "200" + raise "Mixin EC2: Unable to determine EC2 metadata version (returned #{response.code} response)" + end + # Note: Sorting the list of versions may have unintended consequences in + # non-EC2 environments. It appears to be safe in EC2 as of 2013-04-12. + versions = response.body.split("\n").sort + until versions.empty? || EC2_SUPPORTED_VERSIONS.include?(versions.last) + pv = versions.pop + Ohai::Log.debug("Mixin EC2: EC2 lists metadata version: #{pv} not yet supported by Ohai") unless pv == "latest" + end + Ohai::Log.debug("Mixin EC2: Latest supported EC2 metadata version: #{versions.last}") + if versions.empty? + raise "Mixin EC2: Unable to determine EC2 metadata version (no supported entries found)" + end + versions.last end - versions.last end def http_client - Net::HTTP.start(EC2_METADATA_ADDR).tap { |h| h.read_timeout = 30 } + @conn ||= Net::HTTP.start(EC2_METADATA_ADDR).tap do |h| + h.read_timeout = 10 + h.keep_alive_timeout = 10 + end end # Get metadata for a given path and API version @@ -111,44 +88,42 @@ # `nil` and continue the run instead of failing it. def metadata_get(id, api_version) path = "/#{api_version}/meta-data/#{id}" + Ohai::Log.debug("Mixin EC2: Fetching http://#{EC2_METADATA_ADDR}#{path}") response = http_client.get(path) case response.code when "200" response.body when "404" - Ohai::Log.debug("ec2 metadata mixin: Encountered 404 response retreiving EC2 metadata path: #{path} ; continuing.") + Ohai::Log.debug("Mixin EC2: Encountered 404 response retrieving EC2 metadata path: #{path} ; continuing.") nil else - raise "Encountered error retrieving EC2 metadata (#{path} returned #{response.code} response)" + raise "Mixin EC2: Encountered error retrieving EC2 metadata (#{path} returned #{response.code} response)" end end def fetch_metadata(id = "", api_version = nil) - api_version ||= best_api_version - return {} if api_version.nil? - metadata = {} - retrieved_metadata = metadata_get(id, api_version) + retrieved_metadata = metadata_get(id, best_api_version) if retrieved_metadata retrieved_metadata.split("\n").each do |o| key = expand_path("#{id}#{o}") if key[-1..-1] != "/" metadata[metadata_key(key)] = if EC2_ARRAY_VALUES.include? key - retr_meta = metadata_get(key, api_version) + retr_meta = metadata_get(key, best_api_version) retr_meta ? retr_meta.split("\n") : retr_meta else - metadata_get(key, api_version) + metadata_get(key, best_api_version) end elsif (not key.eql?(id)) && (not key.eql?("/")) name = key[0..-2] sym = metadata_key(name) if EC2_ARRAY_DIR.include?(name) - metadata[sym] = fetch_dir_metadata(key, api_version) + metadata[sym] = fetch_dir_metadata(key, best_api_version) elsif EC2_JSON_DIR.include?(name) - metadata[sym] = fetch_json_dir_metadata(key, api_version) + metadata[sym] = fetch_json_dir_metadata(key, best_api_version) else - fetch_metadata(key, api_version).each { |k, v| metadata[k] = v } + fetch_metadata(key, best_api_version).each { |k, v| metadata[k] = v } end end end @@ -194,12 +169,23 @@ end def fetch_userdata - api_version = best_api_version - return nil if api_version.nil? - response = http_client.get("/#{api_version}/user-data/") + Ohai::Log.debug("Mixin EC2: Fetching http://#{EC2_METADATA_ADDR}/#{best_api_version}/user-data/") + response = http_client.get("/#{best_api_version}/user-data/") response.code == "200" ? response.body : nil end + def fetch_dynamic_data + @fetch_dynamic_data ||= begin + response = http_client.get("/#{best_api_version}/dynamic/instance-identity/document/") + + if json?(response.body) && response.code == "200" + FFI_Yajl::Parser.parse(response.body) + else + {} + end + end + end + private def expand_path(file_name) diff -Nru ohai-8.21.0/lib/ohai/mixin/gce_metadata.rb ohai-13.8.0/lib/ohai/mixin/gce_metadata.rb --- ohai-8.21.0/lib/ohai/mixin/gce_metadata.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/mixin/gce_metadata.rb 2018-03-16 11:24:35.000000000 +0000 @@ -15,7 +15,6 @@ # limitations under the License. require "net/http" -require "socket" module Ohai module Mixin @@ -25,38 +24,6 @@ GCE_METADATA_ADDR = "metadata.google.internal." unless defined?(GCE_METADATA_ADDR) GCE_METADATA_URL = "/computeMetadata/v1/?recursive=true" unless defined?(GCE_METADATA_URL) - def can_metadata_connect?(addr, port, timeout = 2) - t = Socket.new(Socket::Constants::AF_INET, Socket::Constants::SOCK_STREAM, 0) - begin - saddr = Socket.pack_sockaddr_in(port, addr) - rescue SocketError => e # occurs when non-GCE systems try to resolve metadata.google.internal - Ohai::Log.debug("Mixin GCE: can_metadata_connect? failed setting up socket: #{e}") - return false - end - - connected = false - - begin - t.connect_nonblock(saddr) - rescue Errno::EINPROGRESS - r, w, e = IO.select(nil, [t], nil, timeout) - if !w.nil? - connected = true - else - begin - t.connect_nonblock(saddr) - rescue Errno::EISCONN - t.close - connected = true - rescue SystemCallError - end - end - rescue SystemCallError - end - Ohai::Log.debug("Mixin GCE: can_metadata_connect? == #{connected}") - connected - end - # fetch the meta content with a timeout and the required header def http_get(uri) conn = Net::HTTP.start(GCE_METADATA_ADDR) @@ -94,10 +61,6 @@ end end - def multiline?(data) - data.lines.to_a.size > 1 - end - def has_trailing_slash?(data) !! ( data =~ %r{/$} ) end diff -Nru ohai-8.21.0/lib/ohai/mixin/http_helper.rb ohai-13.8.0/lib/ohai/mixin/http_helper.rb --- ohai-8.21.0/lib/ohai/mixin/http_helper.rb 1970-01-01 00:00:00.000000000 +0000 +++ ohai-13.8.0/lib/ohai/mixin/http_helper.rb 2018-03-16 11:24:35.000000000 +0000 @@ -0,0 +1,56 @@ +# +# Copyright:: 2017, Chef Software, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require "socket" + +module Ohai + module Mixin + module HttpHelper + + def can_socket_connect?(addr, port, timeout = 2) + t = Socket.new(Socket::Constants::AF_INET, Socket::Constants::SOCK_STREAM, 0) + begin + saddr = Socket.pack_sockaddr_in(port, addr) + rescue SocketError => e # generally means dns resolution error + Ohai::Log.debug("Mixin HttpHelper: can_socket_connect? failed setting up socket connection: #{e}") + return false + end + + connected = false + + begin + t.connect_nonblock(saddr) + rescue Errno::EINPROGRESS + r, w, e = IO.select(nil, [t], nil, timeout) + if !w.nil? + connected = true + else + begin + t.connect_nonblock(saddr) + rescue Errno::EISCONN + t.close + connected = true + rescue SystemCallError + end + end + rescue SystemCallError + end + Ohai::Log.debug("Mixin HttpHelper: can_socket_connect? == #{connected}") + connected + end + end + end +end diff -Nru ohai-8.21.0/lib/ohai/mixin/network_constants.rb ohai-13.8.0/lib/ohai/mixin/network_constants.rb --- ohai-8.21.0/lib/ohai/mixin/network_constants.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/mixin/network_constants.rb 2018-03-16 11:24:35.000000000 +0000 @@ -24,11 +24,6 @@ "inet" => "default", "inet6" => "default_inet6", } - - # From sigar: include/sigar.h sigar_net_route_t - SIGAR_ROUTE_METHODS = [:destination, :gateway, :mask, :flags, - :refcnt, :use, :metric, :mtu, :window, - :irtt, :ifname] end end end diff -Nru ohai-8.21.0/lib/ohai/mixin/os.rb ohai-13.8.0/lib/ohai/mixin/os.rb --- ohai-8.21.0/lib/ohai/mixin/os.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/mixin/os.rb 2018-03-16 11:24:35.000000000 +0000 @@ -26,32 +26,32 @@ def collect_os case ::RbConfig::CONFIG["host_os"] when /aix(.+)$/ - return "aix" + "aix" when /darwin(.+)$/ - return "darwin" + "darwin" when /hpux(.+)$/ - return "hpux" + "hpux" when /linux/ - return "linux" + "linux" when /freebsd(.+)$/ - return "freebsd" + "freebsd" when /openbsd(.+)$/ - return "openbsd" + "openbsd" when /netbsd(.*)$/ - return "netbsd" + "netbsd" when /dragonfly(.*)$/ - return "dragonflybsd" + "dragonflybsd" when /solaris2/ - return "solaris2" + "solaris2" when /mswin|mingw32|windows/ # After long discussion in IRC the "powers that be" have come to a consensus # that no Windows platform exists that was not based on the # Windows_NT kernel, so we herby decree that "windows" will refer to all # platforms built upon the Windows_NT kernel and have access to win32 or win64 # subsystems. - return "windows" + "windows" else - return ::RbConfig::CONFIG["host_os"] + ::RbConfig::CONFIG["host_os"] end end diff -Nru ohai-8.21.0/lib/ohai/mixin/softlayer_metadata.rb ohai-13.8.0/lib/ohai/mixin/softlayer_metadata.rb --- ohai-8.21.0/lib/ohai/mixin/softlayer_metadata.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/mixin/softlayer_metadata.rb 2018-03-16 11:24:35.000000000 +0000 @@ -47,18 +47,18 @@ full_url = "#{SOFTLAYER_API_QUERY_URL}/#{item}" u = URI(full_url) net = ::Net::HTTP.new(u.hostname, u.port) - net.ssl_version = "TLSv1" + net.ssl_version = :TLSv1_2 net.use_ssl = true net.ca_file = ca_file_location res = net.get(u.request_uri) if res.code.to_i.between?(200, 299) res.body else - ::Ohai::Log.error("Unable to fetch item #{full_url}: status (#{res.code}) body (#{res.body})") + ::Ohai::Log.error("Mixin Softlayer: Unable to fetch item #{full_url}: status (#{res.code}) body (#{res.body})") nil end rescue => e - ::Ohai::Log.error("Unable to fetch softlayer metadata from #{u}: #{e.class}: #{e.message}") + ::Ohai::Log.error("Mixin Softlayer: Unable to fetch softlayer metadata from #{u}: #{e.class}: #{e.message}") raise e end end diff -Nru ohai-8.21.0/lib/ohai/mixin/string.rb ohai-13.8.0/lib/ohai/mixin/string.rb --- ohai-8.21.0/lib/ohai/mixin/string.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/mixin/string.rb 2018-03-16 11:24:35.000000000 +0000 @@ -23,7 +23,7 @@ # This should implement the same functionality as underscore method in # ActiveSupport::CoreExtensions::String::Inflections def wmi_underscore - self.gsub(/::/, "/").gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2'). + gsub(/::/, "/").gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2'). gsub(/([a-z\d])([A-Z])/, '\1_\2').tr("-", "_").downcase end end diff -Nru ohai-8.21.0/lib/ohai/plugins/aix/uptime.rb ohai-13.8.0/lib/ohai/plugins/aix/uptime.rb --- ohai-8.21.0/lib/ohai/plugins/aix/uptime.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/aix/uptime.rb 2018-03-16 11:24:35.000000000 +0000 @@ -22,16 +22,32 @@ collect_data(:aix) do require "date" - # Example output: - # $ who -b - # . system boot Jul 9 17:51 - so = shell_out("who -b") - so.stdout.lines.each do |line| - if line =~ /.* boot (.+)/ - uptime_seconds Time.now.to_i - DateTime.parse($1 + " #{Time.now.zone}").strftime("%s").to_i - uptime seconds_to_human(uptime_seconds) - break - end + # below we're going to assume that PID 1 is init (this is true 99.99999% of the time) + # output will look like this + # 1148-20:54:50 + # This reads as 1148 days, 20 hours, 54 minutes, 50 seconds since the process was started (elapsed) + # who -b does not return the YEAR, so we need something more concrete + so = shell_out("LC_ALL=POSIX ps -o etime= -p 1").stdout + + # Here we'll check our shell_out for a dash, which indicates there is a # of days involved + # We'll chunk off the days, hours (where applicable), minutes, seconds into seperate vars + # We also need to do this because ps -o etime= will not display days if the machine has been up for less than 24 hours + # If the machine has been up for less than one hour, the shell_out will not output hours hence our else + # see here: https://www.ibm.com/support/knowledgecenter/en/ssw_aix_72/com.ibm.aix.cmds4/ps.htm#ps__row-d3e109655 + d = nil + h = nil + case so + when /^\d+-\d/ + (d, h, m, s) = so.split(/[-:]/) + when /^\d+:\d+:\d/ + (h, m, s) = so.split(/[:]/) + else + (m, s) = so.split(/[:]/) end + elapsed_seconds = ((d.to_i * 86400) + (h.to_i * 3600) + (m.to_i * 60) + s.to_i) + + # uptime seconds below will return the elapsed time since boot + uptime_seconds elapsed_seconds + uptime seconds_to_human(elapsed_seconds) end end diff -Nru ohai-8.21.0/lib/ohai/plugins/azure.rb ohai-13.8.0/lib/ohai/plugins/azure.rb --- ohai-8.21.0/lib/ohai/plugins/azure.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/azure.rb 2018-03-16 11:24:35.000000000 +0000 @@ -1,4 +1,4 @@ -# Copyright:: Copyright (c) 2013-2016 Chef Software, Inc. +# Copyright:: Copyright 2013-2017 Chef Software, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,23 +15,31 @@ # Ohai.plugin(:Azure) do + require "ohai/mixin/azure_metadata" + require "ohai/mixin/http_helper" + + include Ohai::Mixin::AzureMetadata + include Ohai::Mixin::HttpHelper + provides "azure" collect_data do - # The azure hints are populated by the knife plugin for Azure. - # The project is located at https://github.com/chef/knife-azure + # Before we had the metadata endpoint we relied exclusively on + # the knife-azure plugin populating data to the hint file. # Please see the lib/chef/knife/azure_server_create.rb file in that # project for details azure_metadata_from_hints = hint?("azure") if azure_metadata_from_hints - Ohai::Log.debug("azure plugin: azure_metadata_from_hints is present.") + Ohai::Log.debug("Plugin Azure: Azure hint is present. Parsing any hint data.") azure Mash.new azure_metadata_from_hints.each { |k, v| azure[k] = v } + azure["metadata"] = parse_metadata elsif has_waagent? || has_dhcp_option_245? - Ohai::Log.debug("azure plugin: No hints present, but system appears to be on azure.") + Ohai::Log.debug("Plugin Azure: No hints present, but system appears to be on Azure.") azure Mash.new + azure["metadata"] = parse_metadata else - Ohai::Log.debug("azure plugin: No hints present for azure and doesn't appear to be azure.") + Ohai::Log.debug("Plugin Azure: No hints present and doesn't appear to be on Azure.") false end end @@ -40,8 +48,8 @@ # http://blog.mszcool.com/index.php/2015/04/detecting-if-a-virtual-machine-runs-in-microsoft-azure-linux-windows-to-protect-your-software-when-distributed-via-the-azure-marketplace/ def has_waagent? if File.exist?("/usr/sbin/waagent") || Dir.exist?('C:\WindowsAzure') - Ohai::Log.debug("azure plugin: Found waagent used by MS Azure.") - return true + Ohai::Log.debug("Plugin Azure: Found waagent used by Azure.") + true end end @@ -50,13 +58,65 @@ if File.exist?("/var/lib/dhcp/dhclient.eth0.leases") File.open("/var/lib/dhcp/dhclient.eth0.leases").each do |line| if line =~ /unknown-245/ - Ohai::Log.debug("azure plugin: Found unknown-245 DHCP option used by MS Azure.") + Ohai::Log.debug("Plugin Azure: Found unknown-245 DHCP option used by Azure.") has_245 = true break end end end - return has_245 + has_245 + end + + # create the basic structure we'll store our data in + def initialize_metadata_mash + metadata = Mash.new + metadata["compute"] = Mash.new + metadata["network"] = Mash.new + metadata["network"]["interfaces"] = Mash.new + %w{public_ipv4 local_ipv4 public_ipv6 local_ipv6}.each do |type| + metadata["network"][type] = [] + end + metadata end + def fetch_ip_data(data, type, field) + ips = [] + + data[type]["ipAddress"].each do |val| + ips << val[field] unless val[field].empty? + end + ips + end + + def parse_metadata + return nil unless can_socket_connect?(Ohai::Mixin::AzureMetadata::AZURE_METADATA_ADDR, 80) + + endpoint_data = fetch_metadata + return nil if endpoint_data.nil? + metadata = initialize_metadata_mash + + # blindly add everything in compute to our data structure + endpoint_data["compute"].each do |k, v| + metadata["compute"][k] = v + end + + # parse out per interface interface IP data + endpoint_data["network"]["interface"].each do |int| + metadata["network"]["interfaces"][int["macAddress"]] = Mash.new + metadata["network"]["interfaces"][int["macAddress"]]["mac"] = int["macAddress"] + metadata["network"]["interfaces"][int["macAddress"]]["public_ipv6"] = fetch_ip_data(int, "ipv6", "publicIpAddress") + metadata["network"]["interfaces"][int["macAddress"]]["public_ipv4"] = fetch_ip_data(int, "ipv4", "publicIpAddress") + metadata["network"]["interfaces"][int["macAddress"]]["local_ipv6"] = fetch_ip_data(int, "ipv6", "privateIpAddress") + metadata["network"]["interfaces"][int["macAddress"]]["local_ipv4"] = fetch_ip_data(int, "ipv4", "privateIpAddress") + end + + # aggregate the total IP data + %w{public_ipv4 local_ipv4 public_ipv6 local_ipv6}.each do |type| + metadata["network"]["interfaces"].each_value do |val| + metadata["network"][type].concat val[type] unless val[type].empty? + end + end + + metadata + end end diff -Nru ohai-8.21.0/lib/ohai/plugins/cloud.rb ohai-13.8.0/lib/ohai/plugins/cloud.rb --- ohai-8.21.0/lib/ohai/plugins/cloud.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/cloud.rb 2018-03-16 11:24:35.000000000 +0000 @@ -15,6 +15,7 @@ # limitations under the License. Ohai.plugin(:Cloud) do + provides "cloud_v2" provides "cloud" depends "ec2" @@ -25,36 +26,106 @@ depends "openstack" depends "azure" depends "digital_ocean" - depends "softlayer" - # Make top-level cloud hashes + # Class to help enforce the interface exposed to node[:cloud] (OHAI-542) # - def create_objects - cloud Mash.new - cloud[:public_ips] = Array.new - cloud[:private_ips] = Array.new + # cloud[:provider] - (String) the cloud provider the VM is running on. + # + # cloud[:public_hostname] - (String) a fully qualified hostname + # cloud[:local_hostname] - (String) a hostname resolvable on the internal (private) network + # + # cloud[:public_ipv4_addrs] - (Array) a list of all publicly accessible IPv4 addresses + # cloud[:local_ipv4_addrs] - (Array) a list of all private IPv4 addresses + # cloud[:public_ipv4] - (String) the first public IPv4 address detected + # cloud[:local_ipv4] - (String) the first private IPv4 address detected + # + # cloud[:public_ipv6_addrs] - (Array) a list of all publicly accessible IPv6 addresses + # cloud[:local_ipv6_addrs] - (Array) a list of all private IPv6 addresses + # cloud[:public_ipv6] - (String) the first public IPv6 address detected + # cloud[:local_ipv6] - (String) the first private IPv6 address detected + # + class CloudAttrs + attr_writer :provider, :public_hostname, :local_hostname + + def initialize + @cloud = Mash.new + end + + def add_ipv4_addr(ip, accessibility) + return if ip.nil? # just skip if ip is nil + ipaddr = validate_ip_addr(ip, :ipv4) + + case accessibility + when :public + @cloud[:public_ipv4_addrs] ||= Array.new + @cloud[:public_ipv4_addrs] << ipaddr.to_s + when :private + @cloud[:local_ipv4_addrs] ||= Array.new + @cloud[:local_ipv4_addrs] << ipaddr.to_s + else + raise "ERROR: invalid accessibility param of '#{accessibility}'. must be :public or :private." + end + end + + def add_ipv6_addr(ip, accessibility) + return if ip.nil? # just skip if ip is nil + ipaddr = validate_ip_addr(ip, :ipv6) + + raise "ERROR: invalid ipv6 address of '#{ip}' detected. " unless ipaddr.ipv6? + case accessibility + when :public + @cloud[:public_ipv6_addrs] ||= Array.new + @cloud[:public_ipv6_addrs] << ipaddr.to_s + when :private + @cloud[:local_ipv6_addrs] ||= Array.new + @cloud[:local_ipv6_addrs] << ipaddr.to_s + else + raise "ERROR: invalid accessibility param of '#{accessibility}'. must be :public or :private." + end + end + + def cloud_mash + @cloud[:provider] = @provider if @provider + + @cloud[:public_hostname] = @public_hostname if @public_hostname + @cloud[:local_hostname] = @local_hostname if @local_hostname + + @cloud[:public_ipv4] = @cloud[:public_ipv4_addrs][0] if @cloud[:public_ipv4_addrs] + @cloud[:local_ipv4] = @cloud[:local_ipv4_addrs][0] if @cloud[:local_ipv4_addrs] + + @cloud[:public_ipv6] = @cloud[:public_ipv6_addrs][0] if @cloud[:public_ipv6_addrs] + @cloud[:local_ipv6] = @cloud[:local_ipv6_addrs][0] if @cloud[:local_ipv6_addrs] + + # if empty, return nil + (@cloud.empty?) ? nil : @cloud + end + + private + + def validate_ip_addr(ip, address_family = :ipv4) + ipaddr = "" + begin + ipaddr = IPAddr.new(ip) + raise ArgumentError, "not valid #{address_family} address" unless (address_family == :ipv4) ? ipaddr.ipv4? : ipaddr.ipv6? + rescue ArgumentError => e + raise "ERROR: the ohai 'cloud' plugin failed with an IP address of '#{ip}' : #{e.message}" + end + ipaddr + end end + #--------------------------------------- # Google Compute Engine (gce) #-------------------------------------- - # Is current cloud gce? - # - # === Return - # true:: If gce Hash is defined - # false:: Otherwise def on_gce? gce != nil end - # Fill cloud hash with gce values def get_gce_values - cloud[:public_ipv4] = [] - cloud[:local_ipv4] = [] - public_ips = gce["instance"]["networkInterfaces"].collect do |interface| if interface.has_key?("accessConfigs") - interface["accessConfigs"].collect { |ac| ac["externalIp"] } + interface["accessConfigs"].collect { |ac| ac["externalIp"] unless ac["externalIp"] == "" } end end.flatten.compact @@ -62,13 +133,10 @@ interface["ip"] end.compact - cloud[:public_ips] += public_ips - cloud[:private_ips] += private_ips - cloud[:public_ipv4] += public_ips - cloud[:public_hostname] = nil - cloud[:local_ipv4] += private_ips - cloud[:local_hostname] = gce["instance"]["hostname"] - cloud[:provider] = "gce" + public_ips.each { |ipaddr| @cloud_attr_obj.add_ipv4_addr(ipaddr, :public) } + private_ips.each { |ipaddr| @cloud_attr_obj.add_ipv4_addr(ipaddr, :private) } + @cloud_attr_obj.local_hostname = gce["instance"]["hostname"] + @cloud_attr_obj.provider = "gce" end # ---------------------------------------- @@ -86,13 +154,11 @@ # Fill cloud hash with ec2 values def get_ec2_values - cloud[:public_ips] << ec2["public_ipv4"] - cloud[:private_ips] << ec2["local_ipv4"] - cloud[:public_ipv4] = ec2["public_ipv4"] - cloud[:public_hostname] = ec2["public_hostname"] - cloud[:local_ipv4] = ec2["local_ipv4"] - cloud[:local_hostname] = ec2["local_hostname"] - cloud[:provider] = "ec2" + @cloud_attr_obj.add_ipv4_addr(ec2["public_ipv4"], :public) + @cloud_attr_obj.add_ipv4_addr(ec2["local_ipv4"], :private) + @cloud_attr_obj.public_hostname = ec2["public_hostname"] + @cloud_attr_obj.local_hostname = ec2["local_hostname"] + @cloud_attr_obj.provider = "ec2" end # ---------------------------------------- @@ -110,15 +176,13 @@ # Fill cloud hash with rackspace values def get_rackspace_values - cloud[:public_ips] << rackspace["public_ipv4"] if rackspace["public_ipv4"] - cloud[:private_ips] << rackspace["local_ipv4"] if rackspace["local_ipv4"] - cloud[:public_ipv4] = rackspace["public_ipv4"] - cloud[:public_ipv6] = rackspace["public_ipv6"] - cloud[:public_hostname] = rackspace["public_hostname"] - cloud[:local_ipv4] = rackspace["local_ipv4"] - cloud[:local_ipv6] = rackspace["local_ipv6"] - cloud[:local_hostname] = rackspace["local_hostname"] - cloud[:provider] = "rackspace" + @cloud_attr_obj.add_ipv4_addr(rackspace["public_ipv4"], :public) + @cloud_attr_obj.add_ipv4_addr(rackspace["local_ipv4"], :private) + @cloud_attr_obj.add_ipv6_addr(rackspace["public_ipv6"], :public) + @cloud_attr_obj.add_ipv6_addr(rackspace["local_ipv6"], :private) + @cloud_attr_obj.public_hostname = rackspace["public_hostname"] + @cloud_attr_obj.local_hostname = rackspace["local_hostname"] + @cloud_attr_obj.provider = "rackspace" end # ---------------------------------------- @@ -136,13 +200,11 @@ # Fill cloud hash with linode values def get_linode_values - cloud[:public_ips] << linode["public_ip"] - cloud[:private_ips] << linode["private_ip"] - cloud[:public_ipv4] = linode["public_ipv4"] - cloud[:public_hostname] = linode["public_hostname"] - cloud[:local_ipv4] = linode["local_ipv4"] - cloud[:local_hostname] = linode["local_hostname"] - cloud[:provider] = "linode" + @cloud_attr_obj.add_ipv4_addr(linode["public_ip"], :public) + @cloud_attr_obj.add_ipv4_addr(linode["private_ip"], :private) + @cloud_attr_obj.public_hostname = linode["public_hostname"] + @cloud_attr_obj.local_hostname = linode["local_hostname"] + @cloud_attr_obj.provider = "linode" end # ---------------------------------------- @@ -159,13 +221,11 @@ end def get_eucalyptus_values - cloud[:public_ips] << eucalyptus["public_ipv4"] - cloud[:private_ips] << eucalyptus["local_ipv4"] - cloud[:public_ipv4] = eucalyptus["public_ipv4"] - cloud[:public_hostname] = eucalyptus["public_hostname"] - cloud[:local_ipv4] = eucalyptus["local_ipv4"] - cloud[:local_hostname] = eucalyptus["local_hostname"] - cloud[:provider] = "eucalyptus" + @cloud_attr_obj.add_ipv4_addr(eucalyptus["public_ipv4"], :public) + @cloud_attr_obj.add_ipv4_addr(eucalyptus["local_ipv4"], :private) + @cloud_attr_obj.public_hostname = eucalyptus["public_hostname"] + @cloud_attr_obj.local_hostname = eucalyptus["local_hostname"] + @cloud_attr_obj.provider = "eucalyptus" end # ---------------------------------------- @@ -183,13 +243,11 @@ # Fill cloud hash with openstack values def get_openstack_values - cloud[:public_ips] << openstack["public_ipv4"] - cloud[:private_ips] << openstack["local_ipv4"] - cloud[:public_ipv4] = openstack["public_ipv4"] - cloud[:public_hostname] = openstack["public_hostname"] - cloud[:local_ipv4] = openstack["local_ipv4"] - cloud[:local_hostname] = openstack["local_hostname"] - cloud[:provider] = openstack["provider"] + @cloud_attr_obj.add_ipv4_addr(openstack["public_ipv4"], :public) + @cloud_attr_obj.add_ipv4_addr(openstack["local_ipv4"], :private) + @cloud_attr_obj.public_hostname = openstack["public_hostname"] + @cloud_attr_obj.local_hostname = openstack["local_hostname"] + @cloud_attr_obj.provider = openstack["provider"] end # ---------------------------------------- @@ -207,14 +265,12 @@ # Fill cloud hash with azure values def get_azure_values - cloud[:vm_name] = azure["vm_name"] - cloud[:public_ips] << azure["public_ip"] - cloud[:public_ipv4] = azure["public_ip"] - cloud[:public_fqdn] = azure["public_fqdn"] - cloud[:public_hostname] = azure["public_fqdn"] - cloud[:public_ssh_port] = azure["public_ssh_port"] if azure["public_ssh_port"] - cloud[:public_winrm_port] = azure["public_winrm_port"] if azure["public_winrm_port"] - cloud[:provider] = "azure" + azure["metadata"]["network"]["public_ipv4"].each { |ipaddr| @cloud_attr_obj.add_ipv4_addr(ipaddr, :public) } + azure["metadata"]["network"]["public_ipv6"].each { |ipaddr| @cloud_attr_obj.add_ipv6_addr(ipaddr, :public) } + azure["metadata"]["network"]["local_ipv4"].each { |ipaddr| @cloud_attr_obj.add_ipv4_addr(ipaddr, :private) } + azure["metadata"]["network"]["local_ipv6"].each { |ipaddr| @cloud_attr_obj.add_ipv6_addr(ipaddr, :private) } + @cloud_attr_obj.public_hostname = azure["public_fqdn"] + @cloud_attr_obj.provider = "azure" end # ---------------------------------------- @@ -230,97 +286,31 @@ digital_ocean != nil end - # Fill cloud hash with linode values + # Fill cloud hash with digital_ocean values def get_digital_ocean_values - public_ipv4 = digital_ocean["networks"]["v4"].select { |address| address["type"] == "public" } - private_ipv4 = digital_ocean["networks"]["v4"].select { |address| address["type"] == "private" } - public_ipv6 = digital_ocean["networks"]["v6"].select { |address| address["type"] == "public" } - private_ipv6 = digital_ocean["networks"]["v6"].select { |address| address["type"] == "private" } - cloud[:public_ips].concat public_ipv4 + public_ipv6 - cloud[:private_ips].concat private_ipv4 + private_ipv6 - cloud[:public_ipv4] = public_ipv4.first - cloud[:public_ipv6] = public_ipv6.first - cloud[:local_ipv4] = private_ipv4.first - cloud[:local_ipv6] = private_ipv6.first - cloud[:public_hostname] = digital_ocean["name"] - cloud[:provider] = "digital_ocean" - end - - # ---------------------------------------- - # softlayer - # ---------------------------------------- - - # Is current cloud softlayer? - # - # === Return - # true:: If softlayer Hash is defined - # false:: Otherwise - def on_softlayer? - softlayer != nil - end - - # Fill cloud hash with softlayer values - def get_softlayer_values - cloud[:public_ipv4] = softlayer["public_ipv4"] - cloud[:local_ipv4] = softlayer["local_ipv4"] - cloud[:public_ips] << softlayer["public_ipv4"] if softlayer["public_ipv4"] - cloud[:private_ips] << softlayer["local_ipv4"] if softlayer["local_ipv4"] - cloud[:public_hostname] = softlayer["public_fqdn"] - cloud[:provider] = "softlayer" + @cloud_attr_obj.add_ipv4_addr(digital_ocean["interfaces"]["public"][0]["ipv4"]["ip_address"], :public) rescue NoMethodError + @cloud_attr_obj.add_ipv4_addr(digital_ocean["interfaces"]["private"][0]["ipv4"]["ip_address"], :private) rescue NoMethodError + @cloud_attr_obj.add_ipv6_addr(digital_ocean["interfaces"]["public"][0]["ipv6"]["ip_address"], :public) rescue NoMethodError + @cloud_attr_obj.add_ipv6_addr(digital_ocean["interfaces"]["private"][0]["ipv6"]["ip_address"], :private) rescue NoMethodError + @cloud_attr_obj.provider = "digital_ocean" end collect_data do - # setup gce cloud - if on_gce? - create_objects - get_gce_values - end - - # setup ec2 cloud - if on_ec2? - create_objects - get_ec2_values - end - - # setup rackspace cloud - if on_rackspace? - create_objects - get_rackspace_values - end + require "ipaddr" - # setup linode cloud data - if on_linode? - create_objects - get_linode_values - end + @cloud_attr_obj = CloudAttrs.new - if on_eucalyptus? - create_objects - get_eucalyptus_values - end - - # setup openstack cloud - if on_openstack? - create_objects - get_openstack_values - end - - # setup azure cloud data - if on_azure? - create_objects - get_azure_values - end - - # setup digital_ocean cloud data - if on_digital_ocean? - create_objects - get_digital_ocean_values - end - - # setup softlayer cloud - if on_softlayer? - create_objects - get_softlayer_values - end + get_gce_values if on_gce? + get_ec2_values if on_ec2? + get_rackspace_values if on_rackspace? + get_linode_values if on_linode? + get_eucalyptus_values if on_eucalyptus? + get_openstack_values if on_openstack? + get_azure_values if on_azure? + get_digital_ocean_values if on_digital_ocean? + + # set node[:cloud] and node[:cloud_v2] hash here + cloud_v2 @cloud_attr_obj.cloud_mash + cloud @cloud_attr_obj.cloud_mash end end diff -Nru ohai-8.21.0/lib/ohai/plugins/cloud_v2.rb ohai-13.8.0/lib/ohai/plugins/cloud_v2.rb --- ohai-8.21.0/lib/ohai/plugins/cloud_v2.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/cloud_v2.rb 1970-01-01 00:00:00.000000000 +0000 @@ -1,315 +0,0 @@ -# -# Author:: Cary Penniman () -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -Ohai.plugin(:CloudV2) do - provides "cloud_v2" - - depends "ec2" - depends "gce" - depends "rackspace" - depends "eucalyptus" - depends "linode" - depends "openstack" - depends "azure" - depends "digital_ocean" - - # Class to help enforce the interface exposed to node[:cloud] (OHAI-542) - # - # cloud[:provider] - (String) the cloud provider the VM is running on. - # - # cloud[:public_hostname] - (String) a fully qualified hostname - # cloud[:local_hostname] - (String) a hostname resolvable on the internal (private) network - # - # cloud[:public_ipv4_addrs] - (Array) a list of all publicly accessible IPv4 addresses - # cloud[:local_ipv4_addrs] - (Array) a list of all private IPv4 addresses - # cloud[:public_ipv4] - (String) the first public IPv4 address detected - # cloud[:local_ipv4] - (String) the first private IPv4 address detected - # - # cloud[:public_ipv6_addrs] - (Array) a list of all publicly accessible IPv6 addresses - # cloud[:local_ipv6_addrs] - (Array) a list of all private IPv6 addresses - # cloud[:public_ipv6] - (String) the first public IPv6 address detected - # cloud[:local_ipv6] - (String) the first private IPv6 address detected - # - class CloudAttrs - attr_writer :provider, :public_hostname, :local_hostname - - def initialize - @cloud = Mash.new - end - - def add_ipv4_addr(ip, accessibility) - return if ip.nil? # just skip if ip is nil - ipaddr = validate_ip_addr(ip, :ipv4) - - case accessibility - when :public - @cloud[:public_ipv4_addrs] ||= Array.new - @cloud[:public_ipv4_addrs] << ipaddr.to_s - when :private - @cloud[:local_ipv4_addrs] ||= Array.new - @cloud[:local_ipv4_addrs] << ipaddr.to_s - else - raise "ERROR: invalid accessibility param of '#{accessibility}'. must be :public or :private." - end - end - - def add_ipv6_addr(ip, accessibility) - return if ip.nil? # just skip if ip is nil - ipaddr = validate_ip_addr(ip, :ipv6) - - raise "ERROR: invalid ipv6 address of '#{ip}' detected. " unless ipaddr.ipv6? - case accessibility - when :public - @cloud[:public_ipv6_addrs] ||= Array.new - @cloud[:public_ipv6_addrs] << ipaddr.to_s - when :private - @cloud[:local_ipv6_addrs] ||= Array.new - @cloud[:local_ipv6_addrs] << ipaddr.to_s - else - raise "ERROR: invalid accessibility param of '#{accessibility}'. must be :public or :private." - end - end - - def cloud_mash - @cloud[:provider] = @provider if @provider - - @cloud[:public_hostname] = @public_hostname if @public_hostname - @cloud[:local_hostname] = @local_hostname if @local_hostname - - @cloud[:public_ipv4] = @cloud[:public_ipv4_addrs][0] if @cloud[:public_ipv4_addrs] - @cloud[:local_ipv4] = @cloud[:local_ipv4_addrs][0] if @cloud[:local_ipv4_addrs] - - @cloud[:public_ipv6] = @cloud[:public_ipv6_addrs][0] if @cloud[:public_ipv6_addrs] - @cloud[:local_ipv6] = @cloud[:local_ipv6_addrs][0] if @cloud[:local_ipv6_addrs] - - # if empty, return nil - (@cloud.empty?) ? nil : @cloud - end - - private - - def validate_ip_addr(ip, address_family = :ipv4) - ipaddr = "" - begin - ipaddr = IPAddr.new(ip) - raise ArgumentError, "not valid #{address_family} address" unless (address_family == :ipv4) ? ipaddr.ipv4? : ipaddr.ipv6? - rescue ArgumentError => e - raise "ERROR: the ohai 'cloud' plugin failed with an IP address of '#{ip}' : #{e.message}" - end - ipaddr - end - end - - #--------------------------------------- - # Google Compute Engine (gce) - #-------------------------------------- - - def on_gce? - gce != nil - end - - def get_gce_values - public_ips = gce["instance"]["networkInterfaces"].collect do |interface| - if interface.has_key?("accessConfigs") - interface["accessConfigs"].collect { |ac| ac["externalIp"] unless ac["externalIp"] == "" } - end - end.flatten.compact - - private_ips = gce["instance"]["networkInterfaces"].collect do |interface| - interface["ip"] - end.compact - - public_ips.each { |ipaddr| @cloud_attr_obj.add_ipv4_addr(ipaddr, :public) } - private_ips.each { |ipaddr| @cloud_attr_obj.add_ipv4_addr(ipaddr, :private) } - @cloud_attr_obj.local_hostname = gce["instance"]["hostname"] - @cloud_attr_obj.provider = "gce" - end - - # ---------------------------------------- - # ec2 - # ---------------------------------------- - - # Is current cloud ec2? - # - # === Return - # true:: If ec2 Hash is defined - # false:: Otherwise - def on_ec2? - ec2 != nil - end - - # Fill cloud hash with ec2 values - def get_ec2_values - @cloud_attr_obj.add_ipv4_addr(ec2["public_ipv4"], :public) - @cloud_attr_obj.add_ipv4_addr(ec2["local_ipv4"], :private) - @cloud_attr_obj.public_hostname = ec2["public_hostname"] - @cloud_attr_obj.local_hostname = ec2["local_hostname"] - @cloud_attr_obj.provider = "ec2" - end - - # ---------------------------------------- - # rackspace - # ---------------------------------------- - - # Is current cloud rackspace? - # - # === Return - # true:: If rackspace Hash is defined - # false:: Otherwise - def on_rackspace? - rackspace != nil - end - - # Fill cloud hash with rackspace values - def get_rackspace_values - @cloud_attr_obj.add_ipv4_addr(rackspace["public_ipv4"], :public) - @cloud_attr_obj.add_ipv4_addr(rackspace["local_ipv4"], :private) - @cloud_attr_obj.add_ipv6_addr(rackspace["public_ipv6"], :public) - @cloud_attr_obj.add_ipv6_addr(rackspace["local_ipv6"], :private) - @cloud_attr_obj.public_hostname = rackspace["public_hostname"] - @cloud_attr_obj.local_hostname = rackspace["local_hostname"] - @cloud_attr_obj.provider = "rackspace" - end - - # ---------------------------------------- - # linode - # ---------------------------------------- - - # Is current cloud linode? - # - # === Return - # true:: If linode Hash is defined - # false:: Otherwise - def on_linode? - linode != nil - end - - # Fill cloud hash with linode values - def get_linode_values - @cloud_attr_obj.add_ipv4_addr(linode["public_ip"], :public) - @cloud_attr_obj.add_ipv4_addr(linode["private_ip"], :private) - @cloud_attr_obj.public_hostname = linode["public_hostname"] - @cloud_attr_obj.local_hostname = linode["local_hostname"] - @cloud_attr_obj.provider = "linode" - end - - # ---------------------------------------- - # eucalyptus - # ---------------------------------------- - - # Is current cloud eucalyptus? - # - # === Return - # true:: If eucalyptus Hash is defined - # false:: Otherwise - def on_eucalyptus? - eucalyptus != nil - end - - def get_eucalyptus_values - @cloud_attr_obj.add_ipv4_addr(eucalyptus["public_ipv4"], :public) - @cloud_attr_obj.add_ipv4_addr(eucalyptus["local_ipv4"], :private) - @cloud_attr_obj.public_hostname = eucalyptus["public_hostname"] - @cloud_attr_obj.local_hostname = eucalyptus["local_hostname"] - @cloud_attr_obj.provider = "eucalyptus" - end - - # ---------------------------------------- - # openstack - # ---------------------------------------- - - # Is current cloud openstack-based? - # - # === Return - # true:: If openstack Hash is defined - # false:: Otherwise - def on_openstack? - openstack != nil - end - - # Fill cloud hash with openstack values - def get_openstack_values - @cloud_attr_obj.add_ipv4_addr(openstack["public_ipv4"], :public) - @cloud_attr_obj.add_ipv4_addr(openstack["local_ipv4"], :private) - @cloud_attr_obj.public_hostname = openstack["public_hostname"] - @cloud_attr_obj.local_hostname = openstack["local_hostname"] - @cloud_attr_obj.provider = openstack["provider"] - end - - # ---------------------------------------- - # azure - # ---------------------------------------- - - # Is current cloud azure? - # - # === Return - # true:: If azure Hash is defined - # false:: Otherwise - def on_azure? - azure != nil - end - - # Fill cloud hash with azure values - def get_azure_values - @cloud_attr_obj.add_ipv4_addr(azure["public_ip"], :public) - @cloud_attr_obj.add_ipv4_addr(azure["private_ip"], :private) - @cloud_attr_obj.public_hostname = azure["public_fqdn"] - @cloud_attr_obj.provider = "azure" - end - - # ---------------------------------------- - # digital_ocean - # ---------------------------------------- - - # Is current cloud digital_ocean? - # - # === Return - # true:: If digital_ocean Mash is defined - # false:: Otherwise - def on_digital_ocean? - digital_ocean != nil - end - - # Fill cloud hash with digital_ocean values - def get_digital_ocean_values - digital_ocean["networks"].each do |network, addresses| - type = network == "v4" ? "ipv4" : "ipv6" - addresses.each do |address| - @cloud_attr_obj.send("add_#{type}_addr", address["ip_address"], address["type"].to_sym) - end - end - @cloud_attr_obj.public_hostname = digital_ocean["name"] - @cloud_attr_obj.provider = "digital_ocean" - end - - collect_data do - require "ipaddr" - - @cloud_attr_obj = CloudAttrs.new() - - get_gce_values if on_gce? - get_ec2_values if on_ec2? - get_rackspace_values if on_rackspace? - get_linode_values if on_linode? - get_eucalyptus_values if on_eucalyptus? - get_openstack_values if on_openstack? - get_azure_values if on_azure? - get_digital_ocean_values if on_digital_ocean? - - # set node[:cloud] hash here - cloud_v2 @cloud_attr_obj.cloud_mash - end -end diff -Nru ohai-8.21.0/lib/ohai/plugins/c.rb ohai-13.8.0/lib/ohai/plugins/c.rb --- ohai-8.21.0/lib/ohai/plugins/c.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/c.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,11 +16,8 @@ # limitations under the License. # -require "rbconfig" - Ohai.plugin(:C) do provides "languages/c" - depends "languages" def collect(cmd, &block) @@ -28,100 +25,175 @@ if so.exitstatus == 0 yield(so) else - Ohai::Log.debug("Plugin C '#{cmd}' failed. Skipping data.") + Ohai::Log.debug("Plugin C: '#{cmd}' failed. Skipping data.") end rescue Ohai::Exceptions::Exec - Ohai::Log.debug("Plugin C '#{cmd}' binary could not be found. Skipping data.") + Ohai::Log.debug("Plugin C: '#{cmd}' binary could not be found. Skipping data.") end - collect_data do - c = Mash.new + def xcode_installed? + Ohai::Log.debug("Plugin C: Checking for Xcode Command Line Tools.") + so = shell_out("/usr/bin/xcode-select -p") + if so.exitstatus == 0 + Ohai::Log.debug("Plugin C: Xcode Command Line Tools found.") + return true + else + Ohai::Log.debug("Plugin C: Xcode Command Line Tools not found.") + return false + end + rescue Ohai::Exceptions::Exec + Ohai::Log.debug("Plugin C: xcode-select binary could not be found. Skipping data.") + end - #gcc + def collect_gcc + # gcc + # Sample output on os x: + # Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 + # Apple LLVM version 7.3.0 (clang-703.0.29) + # Target: x86_64-apple-darwin15.4.0 + # Thread model: posix + # InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin + # + # + # Sample output on Linux: + # Using built-in specs. + # COLLECT_GCC=gcc + # COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/5/lto-wrapper + # Target: x86_64-linux-gnu + # Configured with: ../src/configure -v --with-pkgversion='Ubuntu 5.4.0-6ubuntu1~16.04.4' --with-bugurl=file:///usr/share/doc/gcc-5/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-5 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-5-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-5-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-5-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu + # Thread model: posix + # gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) + gcc = Mash.new collect("gcc -v") do |so| - # Sample output: - # Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 - # Apple LLVM version 7.3.0 (clang-703.0.29) - # Target: x86_64-apple-darwin15.4.0 - # Thread model: posix - # InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin - description = so.stderr.split($/).last - output = description.split - if output.length >= 3 - c[:gcc] = Mash.new - c[:gcc][:version] = output[2] - c[:gcc][:description] = description + so.stderr.each_line do |line| + case line + when /^(.*version\s(\S*).*)/ + gcc[:description] = $1 + gcc[:version] = $2 + when /^Target:\s(.*)/ + gcc[:target] = $1 + when /^Configured with:\s(.*)/ + gcc[:configured_with] = $1 + when /^Thread model:\s(.*)/ + gcc[:thread_model] = $1 + end end end + @c[:gcc] = gcc unless gcc.empty? + end - #glibc + def collect_glibc + # glibc ["/lib/libc.so.6", "/lib64/libc.so.6"].each do |glibc| collect( Ohai.abs_path( glibc )) do |so| description = so.stdout.split($/).first if description =~ /(\d+\.\d+\.?\d*)/ - c[:glibc] = Mash.new - c[:glibc][:version] = $1 - c[:glibc][:description] = description + @c[:glibc] = Mash.new + @c[:glibc][:version] = $1 + @c[:glibc][:description] = description end - end unless c[:glibc] || ::RbConfig::CONFIG["host_os"] =~ /mswin|mingw32|windows/ + end end + end - #ms cl + def check_for_cl + # ms cl collect("cl /?") do |so| description = so.stderr.lines.first.chomp if description =~ /Compiler Version ([\d\.]+)/ - c[:cl] = Mash.new - c[:cl][:version] = $1 - c[:cl][:description] = description + @c[:cl] = Mash.new + @c[:cl][:version] = $1 + @c[:cl][:description] = description end end + end - #ms vs + def check_for_devenv + # ms vs collect("devenv.com /?") do |so| lines = so.stdout.split($/) description = lines[0].length == 0 ? lines[1] : lines[0] if description =~ /Visual Studio Version ([\d\.]+)/ - c[:vs] = Mash.new - c[:vs][:version] = $1.chop - c[:vs][:description] = description + @c[:vs] = Mash.new + @c[:vs][:version] = $1.chop + @c[:vs][:description] = description end end + end - #ibm xlc - begin - so = shell_out("xlc -qversion") - if so.exitstatus == 0 || (so.exitstatus >> 8) == 249 - description = so.stdout.split($/).first - if description =~ /V(\d+\.\d+)/ - c[:xlc] = Mash.new - c[:xlc][:version] = $1 - c[:xlc][:description] = description.strip - end + def collect_xlc + # ibm xlc + + so = shell_out("xlc -qversion") + if so.exitstatus == 0 || (so.exitstatus >> 8) == 249 + description = so.stdout.split($/).first + if description =~ /V(\d+\.\d+)/ + @c[:xlc] = Mash.new + @c[:xlc][:version] = $1 + @c[:xlc][:description] = description.strip end - rescue Ohai::Exceptions::Exec end + rescue Ohai::Exceptions::Exec + Ohai::Log.debug("Plugin C: 'xlc' binary could not be found. Skipping data.") + end - #sun pro + def collect_sunpro + # sun pro collect("cc -V -flags") do |so| output = so.stderr.split if so.stderr =~ /^cc: Sun C/ && output.size >= 4 - c[:sunpro] = Mash.new - c[:sunpro][:version] = output[3] - c[:sunpro][:description] = so.stderr.chomp + @c[:sunpro] = Mash.new + @c[:sunpro][:version] = output[3] + @c[:sunpro][:description] = so.stderr.chomp end end + end - #hpux cc + def collect_hpux_cc + # hpux cc collect("what /opt/ansic/bin/cc") do |so| description = so.stdout.split($/).select { |line| line =~ /HP C Compiler/ }.first if description output = description.split - c[:hpcc] = Mash.new - c[:hpcc][:version] = output[1] if output.size >= 1 - c[:hpcc][:description] = description.strip + @c[:hpcc] = Mash.new + @c[:hpcc][:version] = output[1] if output.size >= 1 + @c[:hpcc][:description] = description.strip end end + end + + collect_data(:aix) do + @c = Mash.new + collect_xlc + collect_gcc + languages[:c] = @c unless @c.empty? + end + + collect_data(:darwin) do + @c = Mash.new + collect_gcc if xcode_installed? + languages[:c] = @c unless @c.empty? + end + + collect_data(:windows) do + @c = Mash.new + check_for_cl + check_for_devenv + languages[:c] = @c unless @c.empty? + end + + collect_data(:hpux) do + @c = Mash.new + collect_gcc + collect_hpux_cc + languages[:c] = @c unless @c.empty? + end - languages[:c] = c unless c.empty? + collect_data(:default) do + @c = Mash.new + collect_gcc + collect_glibc + collect_sunpro + languages[:c] = @c unless @c.empty? end end diff -Nru ohai-8.21.0/lib/ohai/plugins/darwin/cpu.rb ohai-13.8.0/lib/ohai/plugins/darwin/cpu.rb --- ohai-8.21.0/lib/ohai/plugins/darwin/cpu.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/darwin/cpu.rb 2018-03-16 11:24:35.000000000 +0000 @@ -22,25 +22,29 @@ collect_data(:darwin) do cpu Mash.new - so = shell_out("sysctl -n hw.packages") - cpu[:real] = so.stdout.to_i - so = shell_out("sysctl -n hw.physicalcpu") - cpu[:cores] = so.stdout.to_i - so = shell_out("sysctl -n hw.logicalcpu") - cpu[:total] = so.stdout.to_i - so = shell_out("sysctl -n hw.cpufrequency") - cpu[:mhz] = so.stdout.to_i / 1000000 - so = shell_out("sysctl -n machdep.cpu.vendor") - cpu[:vendor_id] = so.stdout.chomp - so = shell_out("sysctl -n machdep.cpu.brand_string") - cpu[:model_name] = so.stdout.chomp - so = shell_out("sysctl -n machdep.cpu.model") - cpu[:model] = so.stdout.to_i - so = shell_out("sysctl -n machdep.cpu.family") - cpu[:family] = so.stdout.to_i - so = shell_out("sysctl -n machdep.cpu.stepping") - cpu[:stepping] = so.stdout.to_i - so = shell_out("sysctl -n machdep.cpu.features") - cpu[:flags] = so.stdout.downcase.split(" ") + shell_out("sysctl -a").stdout.lines.each do |line| + case line + when /^hw.packages: (.*)$/ + cpu[:real] = Regexp.last_match[1].to_i + when /^hw.physicalcpu: (.*)$/ + cpu[:cores] = Regexp.last_match[1].to_i + when /^hw.logicalcpu: (.*)$/ + cpu[:total] = Regexp.last_match[1].to_i + when /^hw.cpufrequency: (.*)$/ + cpu[:mhz] = Regexp.last_match[1].to_i / 1000000 + when /^machdep.cpu.vendor: (.*)$/ + cpu[:vendor_id] = Regexp.last_match[1].chomp + when /^machdep.cpu.brand_string: (.*)$/ + cpu[:model_name] = Regexp.last_match[1].chomp + when /^machdep.cpu.model: (.*)$/ + cpu[:model] = Regexp.last_match[1].to_i + when /^machdep.cpu.family: (.*)$/ + cpu[:family] = Regexp.last_match[1].to_i + when /^machdep.cpu.stepping: (.*)$/ + cpu[:stepping] = Regexp.last_match[1].to_i + when /^machdep.cpu.features: (.*)$/ + cpu[:flags] = Regexp.last_match[1].downcase.split(" ") + end + end end end diff -Nru ohai-8.21.0/lib/ohai/plugins/darwin/filesystem2.rb ohai-13.8.0/lib/ohai/plugins/darwin/filesystem2.rb --- ohai-8.21.0/lib/ohai/plugins/darwin/filesystem2.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/darwin/filesystem2.rb 1970-01-01 00:00:00.000000000 +0000 @@ -1,107 +0,0 @@ -# -# Author:: Phil Dibowitz () -# Author:: Benjamin Black () -# Copyright:: Copyright (c) 2009-2016 Chef Software, Inc. -# Copyright:: Copyright (c) 2015 Facebook, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -Ohai.plugin(:Filesystem2) do - provides "filesystem2" - - def generate_device_view(fs) - view = {} - fs.each_value do |entry| - view[entry[:device]] = Mash.new unless view[entry[:device]] - entry.each do |key, val| - next if %w{device mount}.include?(key) - view[entry[:device]][key] = val - end - if entry[:mount] - view[entry[:device]][:mounts] = [] unless view[entry[:device]][:mounts] - view[entry[:device]][:mounts] << entry[:mount] - end - end - view - end - - def generate_mountpoint_view(fs) - view = {} - fs.each_value do |entry| - next unless entry[:mount] - view[entry[:mount]] = Mash.new unless view[entry[:mount]] - entry.each do |key, val| - next if %w{mount device}.include?(key) - view[entry[:mount]][key] = val - end - if entry[:device] - view[entry[:mount]][:devices] = [] unless view[entry[:mount]][:devices] - view[entry[:mount]][:devices] << entry[:device] - end - end - view - end - - collect_data(:darwin) do - fs = Mash.new - block_size = 0 - # on new versions of OSX, -i is default, on old versions it's not, so - # specifying it gets consistent output - so = shell_out("df -i") - so.stdout.each_line do |line| - case line - when /^Filesystem\s+(\d+)-/ - block_size = $1.to_i - next - when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(\d+)\s+(\d+)\s+(\d+%)\s+(.+)$/ - key = "#{$1},#{$9}" - fs[key] = Mash.new - fs[key][:block_size] = block_size - fs[key][:device] = $1 - fs[key][:kb_size] = ($2.to_i / (1024 / block_size)).to_s - fs[key][:kb_used] = ($3.to_i / (1024 / block_size)).to_s - fs[key][:kb_available] = ($4.to_i / (1024 / block_size)).to_s - fs[key][:percent_used] = $5 - fs[key][:inodes_used] = $6 - fs[key][:inodes_available] = $7 - fs[key][:total_inodes] = ($6.to_i + $7.to_i).to_s - fs[key][:inodes_percent_used] = $8 - fs[key][:mount] = $9 - end - end - - so = shell_out("mount") - so.stdout.lines do |line| - if line =~ /^(.+?) on (.+?) \((.+?), (.+?)\)$/ - key = "#{$1},#{$2}" - fs[key] = Mash.new unless fs.has_key?(key) - fs[key][:mount] = $2 - fs[key][:fs_type] = $3 - fs[key][:mount_options] = $4.split(/,\s*/) - end - end - - by_pair = fs - by_device = generate_device_view(fs) - by_mountpoint = generate_mountpoint_view(fs) - - fs2 = Mash.new - fs2["by_device"] = by_device - fs2["by_mountpoint"] = by_mountpoint - fs2["by_pair"] = by_pair - - filesystem2 fs2 - end -end diff -Nru ohai-8.21.0/lib/ohai/plugins/darwin/filesystem.rb ohai-13.8.0/lib/ohai/plugins/darwin/filesystem.rb --- ohai-8.21.0/lib/ohai/plugins/darwin/filesystem.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/darwin/filesystem.rb 2018-03-16 11:24:35.000000000 +0000 @@ -1,6 +1,8 @@ # +# Author:: Phil Dibowitz () # Author:: Benjamin Black () # Copyright:: Copyright (c) 2009-2016 Chef Software, Inc. +# Copyright:: Copyright (c) 2015 Facebook, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,46 +20,90 @@ Ohai.plugin(:Filesystem) do provides "filesystem" + provides "filesystem2" + + def generate_device_view(fs) + view = {} + fs.each_value do |entry| + view[entry[:device]] = Mash.new unless view[entry[:device]] + entry.each do |key, val| + next if %w{device mount}.include?(key) + view[entry[:device]][key] = val + end + if entry[:mount] + view[entry[:device]][:mounts] = [] unless view[entry[:device]][:mounts] + view[entry[:device]][:mounts] << entry[:mount] + end + end + view + end + + def generate_mountpoint_view(fs) + view = {} + fs.each_value do |entry| + next unless entry[:mount] + view[entry[:mount]] = Mash.new unless view[entry[:mount]] + entry.each do |key, val| + next if %w{mount device}.include?(key) + view[entry[:mount]][key] = val + end + if entry[:device] + view[entry[:mount]][:devices] = [] unless view[entry[:mount]][:devices] + view[entry[:mount]][:devices] << entry[:device] + end + end + view + end collect_data(:darwin) do fs = Mash.new - block_size = 0 + # on new versions of OSX, -i is default, on old versions it's not, so + # specifying it gets consistent output so = shell_out("df -i") - so.stdout.lines do |line| + so.stdout.each_line do |line| case line when /^Filesystem\s+(\d+)-/ block_size = $1.to_i next when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(\d+)\s+(\d+)\s+(\d+%)\s+(.+)$/ - filesystem = $1 - fs[filesystem] = Mash.new - fs[filesystem][:block_size] = block_size - # To match linux, these should be strings, but we don't want - # to break back compat so we'll leave them as they are. In filesystem2 - # we make them consistent. - fs[filesystem][:kb_size] = $2.to_i / (1024 / block_size) - fs[filesystem][:kb_used] = $3.to_i / (1024 / block_size) - fs[filesystem][:kb_available] = $4.to_i / (1024 / block_size) - fs[filesystem][:percent_used] = $5 - fs[filesystem][:inodes_used] = $6 - fs[filesystem][:inodes_available] = $7 - fs[filesystem][:total_inodes] = ($6.to_i + $7.to_i).to_s - fs[filesystem][:mount] = $9 + key = "#{$1},#{$9}" + fs[key] = Mash.new + fs[key][:block_size] = block_size + fs[key][:device] = $1 + fs[key][:kb_size] = ($2.to_i / (1024 / block_size)).to_s + fs[key][:kb_used] = ($3.to_i / (1024 / block_size)).to_s + fs[key][:kb_available] = ($4.to_i / (1024 / block_size)).to_s + fs[key][:percent_used] = $5 + fs[key][:inodes_used] = $6 + fs[key][:inodes_available] = $7 + fs[key][:total_inodes] = ($6.to_i + $7.to_i).to_s + fs[key][:inodes_percent_used] = $8 + fs[key][:mount] = $9 end end so = shell_out("mount") so.stdout.lines do |line| if line =~ /^(.+?) on (.+?) \((.+?), (.+?)\)$/ - filesystem = $1 - fs[filesystem] = Mash.new unless fs.has_key?(filesystem) - fs[filesystem][:mount] = $2 - fs[filesystem][:fs_type] = $3 - fs[filesystem][:mount_options] = $4.split(/,\s*/) + key = "#{$1},#{$2}" + fs[key] = Mash.new unless fs.has_key?(key) + fs[key][:mount] = $2 + fs[key][:fs_type] = $3 + fs[key][:mount_options] = $4.split(/,\s*/) end end - filesystem fs + by_pair = fs + by_device = generate_device_view(fs) + by_mountpoint = generate_mountpoint_view(fs) + + fs_data = Mash.new + fs_data["by_device"] = by_device + fs_data["by_mountpoint"] = by_mountpoint + fs_data["by_pair"] = by_pair + + filesystem fs_data + filesystem2 fs_data end end diff -Nru ohai-8.21.0/lib/ohai/plugins/darwin/hardware.rb ohai-13.8.0/lib/ohai/plugins/darwin/hardware.rb --- ohai-8.21.0/lib/ohai/plugins/darwin/hardware.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/darwin/hardware.rb 2018-03-16 11:24:35.000000000 +0000 @@ -30,7 +30,7 @@ unless hardware hardware Mash.new else - Ohai::Log.debug("Plugin Darwin Hardware: namespace already exists") + Ohai::Log.debug("Plugin Hardware: namespace already exists") next end @@ -46,16 +46,22 @@ hw_hash[0]["_items"][0].delete("_name") hardware.merge!(hw_hash[0]["_items"][0]) - { - "operating_system" => "sw_vers -productName", - "operating_system_version" => "sw_vers -productVersion", - "build_version" => "sw_vers -buildVersion", - "architecture" => "uname -m", - }.each do |var, cmd| - os_info = shell_out(cmd).stdout - hardware[var] = os_info.strip unless os_info.nil? + # ProductName: Mac OS X + # ProductVersion: 10.12.5 + # BuildVersion: 16F73 + shell_out("sw_vers").stdout.lines.each do |line| + case line + when /^ProductName:\s*(.*)$/ + hardware["operating_system"] = Regexp.last_match[1].strip + when /^ProductVersion:\s*(.*)$/ + hardware["operating_system_version"] = Regexp.last_match[1].strip + when /^BuildVersion:\s*(.*)$/ + hardware["build_version"] = Regexp.last_match[1].strip + end end + hardware["architecture"] = shell_out("uname -m").stdout.strip + # Storage queries storage = [] storage_hash = system_profiler("SPStorageDataType") diff -Nru ohai-8.21.0/lib/ohai/plugins/darwin/platform.rb ohai-13.8.0/lib/ohai/plugins/darwin/platform.rb --- ohai-8.21.0/lib/ohai/plugins/darwin/platform.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/darwin/platform.rb 2018-03-16 11:24:35.000000000 +0000 @@ -20,7 +20,7 @@ provides "platform", "platform_version", "platform_build", "platform_family" collect_data(:darwin) do - so = shell_out("#{ Ohai.abs_path( "/usr/bin/sw_vers" )}") + so = shell_out("#{Ohai.abs_path( "/usr/bin/sw_vers" )}") so.stdout.lines do |line| case line when /^ProductName:\s+(.+)$/ diff -Nru ohai-8.21.0/lib/ohai/plugins/digital_ocean.rb ohai-13.8.0/lib/ohai/plugins/digital_ocean.rb --- ohai-8.21.0/lib/ohai/plugins/digital_ocean.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/digital_ocean.rb 2018-03-16 11:24:35.000000000 +0000 @@ -1,4 +1,5 @@ # +# Author:: Dylan Page () # Author:: Stafford Brunk () # License:: Apache License, Version 2.0 # @@ -14,65 +15,46 @@ # See the License for the specific language governing permissions and # limitations under the License. -require "ohai/util/ip_helper" - Ohai.plugin(:DigitalOcean) do - include Ohai::Util::IpHelper + require "ohai/mixin/do_metadata" + require "ohai/mixin/http_helper" - DIGITALOCEAN_FILE = "/etc/digitalocean" unless defined?(DIGITALOCEAN_FILE) + include Ohai::Mixin::DOMetadata + include Ohai::Mixin::HttpHelper provides "digital_ocean" - depends "network/interfaces" - def extract_droplet_ip_addresses - addresses = Mash.new({ "v4" => [], "v6" => [] }) - network[:interfaces].each_value do |iface| - iface[:addresses].each do |address, details| - next if details[:family] == "lladdr" || loopback?(address) - - ip = IPAddress(address) - type = digital_ocean_address_type(ip) - address_hash = build_address_hash(ip, details) - addresses[type] << address_hash - end - end - addresses - end + depends "dmi" - def build_address_hash(ip, details) - address_hash = Mash.new({ - "ip_address" => ip.address, - "type" => private_address?(ip.address) ? "private" : "public", - }) - - if ip.ipv4? - address_hash["netmask"] = details[:netmask] - elsif ip.ipv6? - address_hash["cidr"] = ip.prefix + # look for digitalocean string in dmi bios data + def has_do_dmi? + begin + # detect a vendor of "DigitalOcean" + if dmi[:bios][:all_records][0][:Vendor] == "DigitalOcean" + Ohai::Log.debug("Plugin DigitalOcean: has_do_dmi? == true") + return true + end + rescue NoMethodError + # dmi[:bios][:all_records][0][:Vendor] may not exist end - address_hash - end - - def digital_ocean_address_type(ip) - ip.ipv4? ? "v4" : "v6" + Ohai::Log.debug("Plugin DigitalOcean: has_do_dmi? == false") + false end def looks_like_digital_ocean? - hint?("digital_ocean") || File.exist?(DIGITALOCEAN_FILE) + return true if hint?("digital_ocean") + return true if has_do_dmi? && can_socket_connect?(Ohai::Mixin::DOMetadata::DO_METADATA_ADDR, 80) + false end collect_data do if looks_like_digital_ocean? Ohai::Log.debug("Plugin Digitalocean: looks_like_digital_ocean? == true") digital_ocean Mash.new - hint = hint?("digital_ocean") || {} - hint.each { |k, v| digital_ocean[k] = v unless k == "ip_addresses" } - - # Extract actual ip addresses - # The networks sub-hash is structured similarly to how - # Digital Ocean's v2 API structures things: - # https://developers.digitalocean.com/#droplets - digital_ocean[:networks] = extract_droplet_ip_addresses + fetch_metadata.each do |k, v| + next if k == "vendor_data" # this may have sensitive data we shouldn't store + digital_ocean[k] = v + end else Ohai::Log.debug("Plugin Digitalocean: No hints present for and doesn't look like digitalocean") false diff -Nru ohai-8.21.0/lib/ohai/plugins/dmi.rb ohai-13.8.0/lib/ohai/plugins/dmi.rb --- ohai-8.21.0/lib/ohai/plugins/dmi.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/dmi.rb 2018-03-16 11:24:35.000000000 +0000 @@ -44,86 +44,90 @@ dmi_record = nil field = nil - so = shell_out("dmidecode") - # ==== EXAMPLE RECORD: ==== - #Handle 0x0000, DMI type 0, 24 bytes - #BIOS Information - # Vendor: American Megatrends Inc. - # Version: 080012 - # ... similar lines trimmed - # Characteristics: - # ISA is supported - # PCI is supported - # ... similar lines trimmed - so.stdout.lines do |line| - next if blank_line.match(line) - line = line.encode(line.encoding, :universal_newline => true) - - if dmidecode_version = dmidecode_version_line.match(line) - dmi[:dmidecode_version] = dmidecode_version[1] - - elsif smbios_version = smbios_version_line.match(line) - dmi[:smbios_version] = smbios_version[1] - - elsif structures = structures_line.match(line) - dmi[:structures] = Mash.new - dmi[:structures][:count] = structures[1] - dmi[:structures][:size] = structures[2] - - elsif table_location = table_location_line.match(line) - dmi[:table_location] = table_location[1] - - elsif handle = handle_line.match(line) - # Don't overcapture for now (OHAI-260) - unless Ohai::Common::DMI::ID_TO_CAPTURE.include?(handle[2].to_i) - dmi_record = nil - next - end - - dmi_record = { :type => Ohai::Common::DMI.id_lookup(handle[2]) } + begin + so = shell_out("dmidecode") + # ==== EXAMPLE RECORD: ==== + #Handle 0x0000, DMI type 0, 24 bytes + #BIOS Information + # Vendor: American Megatrends Inc. + # Version: 080012 + # ... similar lines trimmed + # Characteristics: + # ISA is supported + # PCI is supported + # ... similar lines trimmed + so.stdout.lines do |line| + next if blank_line.match(line) + line = line.encode(line.encoding, :universal_newline => true) + + if dmidecode_version = dmidecode_version_line.match(line) + dmi[:dmidecode_version] = dmidecode_version[1] + + elsif smbios_version = smbios_version_line.match(line) + dmi[:smbios_version] = smbios_version[1] + + elsif structures = structures_line.match(line) + dmi[:structures] = Mash.new + dmi[:structures][:count] = structures[1] + dmi[:structures][:size] = structures[2] + + elsif table_location = table_location_line.match(line) + dmi[:table_location] = table_location[1] + + elsif handle = handle_line.match(line) + # Don't overcapture for now (OHAI-260) + unless Ohai::Common::DMI::ID_TO_CAPTURE.include?(handle[2].to_i) + dmi_record = nil + next + end + + dmi_record = { :type => Ohai::Common::DMI.id_lookup(handle[2]) } + + dmi[dmi_record[:type]] = Mash.new unless dmi.has_key?(dmi_record[:type]) + dmi[dmi_record[:type]][:all_records] = [] unless dmi[dmi_record[:type]].has_key?(:all_records) + dmi_record[:position] = dmi[dmi_record[:type]][:all_records].length + dmi[dmi_record[:type]][:all_records].push(Mash.new) + dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:record_id] = handle[1] + dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:size] = handle[2] + field = nil + + elsif type = type_line.match(line) + if dmi_record .nil? + Ohai::Log.debug("Plugin DMI: unexpected data line found before header; discarding:\n#{line}") + next + end + dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:application_identifier] = type[1] + + elsif data = data_line.match(line) + if dmi_record .nil? + Ohai::Log.debug("Plugin DMI: unexpected data line found before header; discarding:\n#{line}") + next + end + dmi[dmi_record[:type]][:all_records][dmi_record[:position]][data[1]] = data[2] + field = data[1] + + elsif extended_data = extended_data_line.match(line) + if dmi_record .nil? + Ohai::Log.debug("Plugin DMI: unexpected extended data line found before header; discarding:\n#{line}") + next + end + if field .nil? + Ohai::Log.debug("Plugin DMI: unexpected extended data line found outside data section; discarding:\n#{line}") + next + end + # overwrite "raw" value with a new Mash + dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field] = Mash.new unless dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field].class.to_s == "Mash" + dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field][extended_data[1]] = nil - dmi[dmi_record[:type]] = Mash.new unless dmi.has_key?(dmi_record[:type]) - dmi[dmi_record[:type]][:all_records] = [] unless dmi[dmi_record[:type]].has_key?(:all_records) - dmi_record[:position] = dmi[dmi_record[:type]][:all_records].length - dmi[dmi_record[:type]][:all_records].push(Mash.new) - dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:record_id] = handle[1] - dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:size] = handle[2] - field = nil - - elsif type = type_line.match(line) - if dmi_record == nil - Ohai::Log.debug("unexpected data line found before header; discarding:\n#{line}") - next - end - dmi[dmi_record[:type]][:all_records][dmi_record[:position]][:application_identifier] = type[1] - - elsif data = data_line.match(line) - if dmi_record == nil - Ohai::Log.debug("unexpected data line found before header; discarding:\n#{line}") - next - end - dmi[dmi_record[:type]][:all_records][dmi_record[:position]][data[1]] = data[2] - field = data[1] + else + Ohai::Log.debug("Plugin DMI: unrecognized output line; discarding:\n#{line}") - elsif extended_data = extended_data_line.match(line) - if dmi_record == nil - Ohai::Log.debug("unexpected extended data line found before header; discarding:\n#{line}") - next end - if field == nil - Ohai::Log.debug("unexpected extended data line found outside data section; discarding:\n#{line}") - next - end - # overwrite "raw" value with a new Mash - dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field] = Mash.new unless dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field].class.to_s == "Mash" - dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field][extended_data[1]] = nil - - else - Ohai::Log.debug("unrecognized output line; discarding:\n#{line}") - end - end - Ohai::Common::DMI.convenience_keys(dmi) + Ohai::Common::DMI.convenience_keys(dmi) + rescue Ohai::Exceptions::Exec + Ohai::Log.debug('Plugin DMI: Could not shell_out "dmidecode". Skipping data') + end end end diff -Nru ohai-8.21.0/lib/ohai/plugins/dragonflybsd/network.rb ohai-13.8.0/lib/ohai/plugins/dragonflybsd/network.rb --- ohai-8.21.0/lib/ohai/plugins/dragonflybsd/network.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/dragonflybsd/network.rb 2018-03-16 11:24:35.000000000 +0000 @@ -39,7 +39,7 @@ end iface = Mash.new - so = shell_out("#{ Ohai.abs_path( "/sbin/ifconfig" )} -a") + so = shell_out("#{Ohai.abs_path( "/sbin/ifconfig" )} -a") cint = nil so.stdout.lines do |line| if line =~ /^([0-9a-zA-Z\.]+):\s+/ diff -Nru ohai-8.21.0/lib/ohai/plugins/dragonflybsd/os.rb ohai-13.8.0/lib/ohai/plugins/dragonflybsd/os.rb --- ohai-8.21.0/lib/ohai/plugins/dragonflybsd/os.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/dragonflybsd/os.rb 2018-03-16 11:24:35.000000000 +0000 @@ -18,9 +18,8 @@ # limitations under the License. # -require "ohai/mixin/os" - Ohai.plugin(:OS) do + require "ohai/mixin/os" provides "os", "os_version" collect_data(:dragonflybsd) do diff -Nru ohai-8.21.0/lib/ohai/plugins/ec2.rb ohai-13.8.0/lib/ohai/plugins/ec2.rb --- ohai-8.21.0/lib/ohai/plugins/ec2.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/ec2.rb 2018-03-16 11:24:35.000000000 +0000 @@ -21,65 +21,96 @@ # How we detect EC2 from easiest to hardest & least reliable # 1. Ohai ec2 hint exists. This always works # 2. Xen hypervisor UUID starts with 'ec2'. This catches Linux HVM & paravirt instances -# 3. DMI data mentions amazon. This catches HVM instances in a VPC +# 3. DMI bios version data mentions amazon. This catches HVM instances in a VPC on the Xen based hypervisor +# 3. DMI bios vendor data mentions amazon. This catches HVM instances in a VPC on the non-Xen based hypervisor # 4. Kernel data mentioned Amazon. This catches Windows HVM & paravirt instances -require "ohai/mixin/ec2_metadata" -require "base64" - Ohai.plugin(:EC2) do + require "ohai/mixin/ec2_metadata" + require "ohai/mixin/http_helper" + require "base64" + include Ohai::Mixin::Ec2Metadata + include Ohai::Mixin::HttpHelper provides "ec2" - depends "dmi" - depends "kernel" + # look for amazon string in dmi vendor bios data within the sys tree. + # this works even if the system lacks dmidecode use by the Dmi plugin + # this gets us detection of new Xen-less HVM instances that are within a VPC + # @return [Boolean] do we have Amazon DMI data? + def has_ec2_amazon_dmi? + # detect a version of '4.2.amazon' + if file_val_if_exists("/sys/class/dmi/id/bios_vendor") =~ /Amazon/ + Ohai::Log.debug("Plugin EC2: has_ec2_amazon_dmi? == true") + true + else + Ohai::Log.debug("Plugin EC2: has_ec2_amazon_dmi? == false") + false + end + end - # look for amazon string in dmi bios data + # look for amazon string in dmi bios version data within the sys tree. + # this works even if the system lacks dmidecode use by the Dmi plugin # this gets us detection of HVM instances that are within a VPC - def has_ec2_dmi? + # @return [Boolean] do we have Amazon DMI data? + def has_ec2_xen_dmi? # detect a version of '4.2.amazon' - if get_attribute(:dmi, :bios, :all_records, 0, :Version) =~ /amazon/ - Ohai::Log.debug("Plugin EC2: has_ec2_dmi? == true") - return true + if file_val_if_exists("/sys/class/dmi/id/bios_version") =~ /amazon/ + Ohai::Log.debug("Plugin EC2: has_ec2_xen_dmi? == true") + true else - Ohai::Log.debug("Plugin EC2: has_ec2_dmi? == false") - return false + Ohai::Log.debug("Plugin EC2: has_ec2_xen_dmi? == false") + false end end - # looks for a xen UUID that starts with ec2 - # this gets us detection of Linux HVM and Paravirt hosts + # looks for a xen UUID that starts with ec2 from within the Linux sys tree + # @return [Boolean] do we have a Xen UUID or not? def has_ec2_xen_uuid? - if ::File.exist?("/sys/hypervisor/uuid") - if ::File.read("/sys/hypervisor/uuid") =~ /^ec2/ - Ohai::Log.debug("Plugin EC2: has_ec2_xen_uuid? == true") - return true - end + if file_val_if_exists("/sys/hypervisor/uuid") =~ /^ec2/ + Ohai::Log.debug("Plugin EC2: has_ec2_xen_uuid? == true") + return true end Ohai::Log.debug("Plugin EC2: has_ec2_xen_uuid? == false") - return false + false end - # looks for the Amazon.com Organization in Windows Kernel data - # this gets us detection of Windows systems - def has_amazon_org? - # detect an Organization of 'Amazon.com' - if get_attribute(:kernel, :os_info, :organization) =~ /Amazon/ - Ohai::Log.debug("Plugin EC2: has_amazon_org? == true") - return true + # looks at the identifying number WMI value to see if it starts with ec2. + # this is actually the same value we're looking at in has_ec2_xen_uuid? on + # linux hosts + # @return [Boolean] do we have a Xen Identifying Number or not? + def has_ec2_identifying_number? + if RUBY_PLATFORM =~ /mswin|mingw32|windows/ + require "wmi-lite/wmi" + wmi = WmiLite::Wmi.new + if wmi.first_of("Win32_ComputerSystemProduct")["identifyingnumber"] =~ /^ec2/ + Ohai::Log.debug("Plugin EC2: has_ec2_identifying_number? == true") + return true + end else - Ohai::Log.debug("Plugin EC2: has_amazon_org? == false") - return false + Ohai::Log.debug("Plugin EC2: has_ec2_identifying_number? == false") + false + end + end + + # return the contents of a file if the file exists + # @param path[String] abs path to the file + # @return [String] contents of the file if it exists + def file_val_if_exists(path) + if ::File.exist?(path) + ::File.read(path) end end + # a single check that combines all the various detection methods for EC2 + # @return [Boolean] Does the system appear to be on EC2 def looks_like_ec2? return true if hint?("ec2") # Even if it looks like EC2 try to connect first - if has_ec2_xen_uuid? || has_ec2_dmi? || has_amazon_org? - return true if can_metadata_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80) + if has_ec2_xen_uuid? || has_ec2_amazon_dmi? || has_ec2_xen_dmi? || has_ec2_identifying_number? + return true if can_socket_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80) end end @@ -96,6 +127,9 @@ ec2[k] = v end ec2[:userdata] = fetch_userdata + ec2[:account_id] = fetch_dynamic_data["accountId"] + ec2[:availability_zone] = fetch_dynamic_data["availabilityZone"] + ec2[:region] = fetch_dynamic_data["region"] # ASCII-8BIT is equivalent to BINARY in this case if ec2[:userdata] && ec2[:userdata].encoding.to_s == "ASCII-8BIT" Ohai::Log.debug("Plugin EC2: Binary UserData Found. Storing in base64") diff -Nru ohai-8.21.0/lib/ohai/plugins/elixir.rb ohai-13.8.0/lib/ohai/plugins/elixir.rb --- ohai-8.21.0/lib/ohai/plugins/elixir.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/elixir.rb 2018-03-16 11:24:35.000000000 +0000 @@ -30,7 +30,7 @@ languages[:elixir] = elixir end rescue Ohai::Exceptions::Exec - Ohai::Log.debug('Elixir plugin: Could not shell_out "elixir -v". Skipping plugin') + Ohai::Log.debug('Plugin Elixir: Could not shell_out "elixir -v". Skipping plugin') end end end diff -Nru ohai-8.21.0/lib/ohai/plugins/erlang.rb ohai-13.8.0/lib/ohai/plugins/erlang.rb --- ohai-8.21.0/lib/ohai/plugins/erlang.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/erlang.rb 2018-03-16 11:24:35.000000000 +0000 @@ -24,19 +24,17 @@ erlang = Mash.new begin - so = shell_out("erl -eval 'erlang:display(erlang:system_info(otp_release)), erlang:display(erlang:system_info(version)), erlang:display(erlang:system_info(nif_version)), halt().' -noshell") + so = shell_out("erl -eval '{ok, Ver} = file:read_file(filename:join([code:root_dir(), \"releases\", erlang:system_info(otp_release), \"OTP_VERSION\"])), Vsn = binary:bin_to_list(Ver, {0, byte_size(Ver) - 1}), io:format(\"~s,~s,~s\", [Vsn, erlang:system_info(version), erlang:system_info(nif_version)]), halt().' -noshell") # Sample output: - # "18" - # "7.3" - # "2.10" + # 19.1,8.1,2.11 if so.exitstatus == 0 - output = so.stdout.split(/\r\n/).map! { |x| x.delete('\\"') } + output = so.stdout.split(",") erlang[:version] = output[0] erlang[:erts_version] = output[1] erlang[:nif_version] = output[2] end rescue Ohai::Exceptions::Exec - Ohai::Log.debug('Erlang plugin: Could not shell_out "erl -eval \'erlang:display(erlang:system_info(otp_release)), erlang:display(erlang:system_info(version)), erlang:display(erlang:system_info(nif_version)), halt().\' -noshell". Skipping data') + Ohai::Log.debug('Plugin Erlang: Could not shell_out "erl -eval \'erlang:display(erlang:system_info(otp_release)), erlang:display(erlang:system_info(version)), erlang:display(erlang:system_info(nif_version)), halt().\' -noshell". Skipping data') end begin @@ -53,7 +51,7 @@ end end rescue Ohai::Exceptions::Exec - Ohai::Log.debug('Erlang plugin: Could not shell_out "erl +V". Skipping data') + Ohai::Log.debug('Plugin Erlang: Could not shell_out "erl +V". Skipping data') end languages[:erlang] = erlang unless erlang.empty? diff -Nru ohai-8.21.0/lib/ohai/plugins/eucalyptus.rb ohai-13.8.0/lib/ohai/plugins/eucalyptus.rb --- ohai-8.21.0/lib/ohai/plugins/eucalyptus.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/eucalyptus.rb 2018-03-16 11:24:35.000000000 +0000 @@ -17,11 +17,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -# eucalyptus metadata service is compatible with the ec2 service calls -require "ohai/mixin/ec2_metadata" - Ohai.plugin(:Eucalyptus) do + # eucalyptus metadata service is compatible with the ec2 service calls + require "ohai/mixin/ec2_metadata" + require "ohai/mixin/http_helper" + include Ohai::Mixin::Ec2Metadata + include Ohai::Mixin::HttpHelper provides "eucalyptus" depends "network/interfaces" @@ -53,14 +55,14 @@ def looks_like_euca? # Try non-blocking connect so we don't "block" if # the metadata service doesn't respond - hint?("eucalyptus") || has_euca_mac? && can_metadata_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80) + hint?("eucalyptus") || has_euca_mac? && can_socket_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80) end collect_data do if looks_like_euca? Ohai::Log.debug("Plugin Eucalyptus: looks_like_euca? == true") eucalyptus Mash.new - self.fetch_metadata.each do |k, v| + fetch_metadata.each do |k, v| # Eucalyptus 3.4+ supports IAM roles and Instance Profiles much like AWS # https://www.eucalyptus.com/blog/2013/10/15/iam-roles-and-instance-profiles-eucalyptus-34 # @@ -71,7 +73,7 @@ next if k == "iam" && !hint?("iam") eucalyptus[k] = v end - eucalyptus[:userdata] = self.fetch_userdata + eucalyptus[:userdata] = fetch_userdata else Ohai::Log.debug("Plugin Eucalyptus: looks_like_euca? == false") false diff -Nru ohai-8.21.0/lib/ohai/plugins/freebsd/network.rb ohai-13.8.0/lib/ohai/plugins/freebsd/network.rb --- ohai-8.21.0/lib/ohai/plugins/freebsd/network.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/freebsd/network.rb 2018-03-16 11:24:35.000000000 +0000 @@ -39,7 +39,7 @@ end iface = Mash.new - so = shell_out("#{ Ohai.abs_path( "/sbin/ifconfig" )} -a") + so = shell_out("#{Ohai.abs_path( "/sbin/ifconfig" )} -a") cint = nil so.stdout.lines do |line| if line =~ /^([0-9a-zA-Z\.]+):\s+/ diff -Nru ohai-8.21.0/lib/ohai/plugins/freebsd/os.rb ohai-13.8.0/lib/ohai/plugins/freebsd/os.rb --- ohai-8.21.0/lib/ohai/plugins/freebsd/os.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/freebsd/os.rb 2018-03-16 11:24:35.000000000 +0000 @@ -18,10 +18,9 @@ # limitations under the License. # -require "ohai/mixin/os" - Ohai.plugin(:OS) do provides "os", "os_version" + require "ohai/mixin/os" collect_data(:freebsd) do os collect_os diff -Nru ohai-8.21.0/lib/ohai/plugins/gce.rb ohai-13.8.0/lib/ohai/plugins/gce.rb --- ohai-8.21.0/lib/ohai/plugins/gce.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/gce.rb 2018-03-16 11:24:35.000000000 +0000 @@ -14,10 +14,12 @@ # See the License for the specific language governing permissions and # limitations under the License. -require "ohai/mixin/gce_metadata" - Ohai.plugin(:GCE) do + require "ohai/mixin/gce_metadata" + require "ohai/mixin/http_helper" + include Ohai::Mixin::GCEMetadata + include Ohai::Mixin::HttpHelper provides "gce" @@ -27,7 +29,7 @@ # true:: If gce metadata server found # false:: Otherwise def has_gce_metadata? - can_metadata_connect?(Ohai::Mixin::GCEMetadata::GCE_METADATA_ADDR, 80) + can_socket_connect?(Ohai::Mixin::GCEMetadata::GCE_METADATA_ADDR, 80) end # Identifies gce diff -Nru ohai-8.21.0/lib/ohai/plugins/go.rb ohai-13.8.0/lib/ohai/plugins/go.rb --- ohai-8.21.0/lib/ohai/plugins/go.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/go.rb 2018-03-16 11:24:35.000000000 +0000 @@ -28,7 +28,7 @@ languages[:go] = go end rescue Ohai::Exceptions::Exec - Ohai::Log.debug('Go plugin: Could not shell_out "go version". Skipping plugin') + Ohai::Log.debug('Plugin Go: Could not shell_out "go version". Skipping plugin') end end end diff -Nru ohai-8.21.0/lib/ohai/plugins/groovy.rb ohai-13.8.0/lib/ohai/plugins/groovy.rb --- ohai-8.21.0/lib/ohai/plugins/groovy.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/groovy.rb 2018-03-16 11:24:35.000000000 +0000 @@ -32,7 +32,7 @@ languages[:groovy] = groovy end rescue Ohai::Exceptions::Exec - Ohai::Log.debug('Groovy plugin: Could not shell_out "groovy -v". Skipping plugin') + Ohai::Log.debug('Plugin Groovy: Could not shell_out "groovy -v". Skipping plugin') end end end diff -Nru ohai-8.21.0/lib/ohai/plugins/haskell.rb ohai-13.8.0/lib/ohai/plugins/haskell.rb --- ohai-8.21.0/lib/ohai/plugins/haskell.rb 1970-01-01 00:00:00.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/haskell.rb 2018-03-16 11:24:35.000000000 +0000 @@ -0,0 +1,95 @@ +# Author:: Chris Dituri () +# Copyright:: Copyright (c) 2016 Chris Dituri +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +Ohai.plugin(:Haskell) do + + provides "languages/haskell", + "languages/haskell/ghc", + "languages/haskell/ghci", + "languages/haskell/cabal", + "languages/haskell/stack" + + depends "languages" + + collect_data(:default) do + haskell = Mash.new + + # Check for ghc + begin + so = shell_out("ghc --version") + + # Sample output: + # The Glorious Glasgow Haskell Compilation System, version 7.6.3 + if so.exitstatus == 0 + haskell[:ghc] = Mash.new + haskell[:ghc][:version] = so.stdout.split[-1] + haskell[:ghc][:description] = so.stdout.chomp + end + rescue Ohai::Exceptions::Exec + Ohai::Log.debug('Plugin Haskell: Could not shell_out "ghc --version". Skipping data') + end + + # Check for ghci + begin + so = shell_out("ghci --version") + + # Sample output: + # The Glorious Glasgow Haskell Compilation System, version 7.6.3 + if so.exitstatus == 0 + haskell[:ghci] = Mash.new + haskell[:ghci][:version] = so.stdout.split[-1] + haskell[:ghci][:description] = so.stdout.chomp + end + rescue Ohai::Exceptions::Exec + Ohai::Log.debug('Plugin Haskell: Could not shell_out "ghci --version". Skipping data') + end + + # Check for cabal + begin + so = shell_out("cabal --version") + + # Sample output: + # cabal-install version 1.16.0.2 + # using version 1.16.0 of the Cabal library + if so.exitstatus == 0 + haskell[:cabal] = Mash.new + haskell[:cabal][:version] = so.stdout.split("\n")[0].split[-1] + haskell[:cabal][:description] = so.stdout.split("\n")[0].chomp + end + rescue Ohai::Exceptions::Exec + Ohai::Log.debug('Plugin Haskell: Could not shell_out "cabal --version". Skipping data') + end + + # Check for stack + begin + so = shell_out("stack --version") + + # Sample output: + # Version 1.1.0, Git revision 0e9430aad55841b5ff2c6c2851f0548c16bce7cf (3540 commits) x86_64 hpack-0.13.0 + # or + # Version 1.2.0 x86_64 hpack-0.14.0 + if so.exitstatus == 0 + haskell[:stack] = Mash.new + haskell[:stack][:version] = /Version ([^\s,]*)/.match(so.stdout)[1] rescue nil + haskell[:stack][:description] = so.stdout.chomp + end + rescue Ohai::Exceptions::Exec + Ohai::Log.debug('Plugin Haskell: Could not shell_out "stack --version". Skipping data') + end + + languages[:haskell] = haskell unless haskell.empty? + end +end diff -Nru ohai-8.21.0/lib/ohai/plugins/hostname.rb ohai-13.8.0/lib/ohai/plugins/hostname.rb --- ohai-8.21.0/lib/ohai/plugins/hostname.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/hostname.rb 2018-03-16 11:24:35.000000000 +0000 @@ -25,10 +25,10 @@ # limitations under the License. # -require "socket" -require "ipaddr" - Ohai.plugin(:Hostname) do + require "socket" + require "ipaddr" + provides "domain", "hostname", "fqdn", "machinename" # hostname : short hostname @@ -47,14 +47,12 @@ # forward and reverse lookup to canonicalize FQDN (hostname -f equivalent) # this is ipv6-safe, works on ruby 1.8.7+ def resolve_fqdn - begin - hostname = from_cmd("hostname") - addrinfo = Socket.getaddrinfo(hostname, nil).first - iaddr = IPAddr.new(addrinfo[3]) - Socket.gethostbyaddr(iaddr.hton)[0] - rescue - nil - end + hostname = from_cmd("hostname") + addrinfo = Socket.getaddrinfo(hostname, nil).first + iaddr = IPAddr.new(addrinfo[3]) + Socket.gethostbyaddr(iaddr.hton)[0] + rescue + nil end def collect_domain @@ -76,24 +74,9 @@ end end - def get_fqdn_from_sigar - require "sigar" - sigar = Sigar.new - sigar.fqdn - end - - def sigar_is_available? - begin - require "sigar" - true - rescue LoadError - false - end - end - collect_data(:hpux, :default) do machinename from_cmd("hostname") - fqdn sigar_is_available? ? get_fqdn_from_sigar : resolve_fqdn + fqdn resolve_fqdn collect_hostname collect_domain end @@ -105,13 +88,38 @@ collect_domain end - collect_data(:darwin, :netbsd, :openbsd, :dragonflybsd) do + collect_data(:netbsd, :openbsd, :dragonflybsd) do hostname from_cmd("hostname -s") fqdn resolve_fqdn machinename from_cmd("hostname") collect_domain end + collect_data(:darwin) do + hostname from_cmd("hostname -s") + machinename from_cmd("hostname") + begin + ourfqdn = resolve_fqdn + # Sometimes... very rarely, but sometimes, 'hostname --fqdn' falsely + # returns a blank string. WTF. + if ourfqdn.nil? || ourfqdn.empty? + Ohai::Log.debug("Plugin Hostname: hostname returned an empty string, retrying once.") + ourfqdn = resolve_fqdn + end + + if ourfqdn.nil? || ourfqdn.empty? + Ohai::Log.debug("Plugin Hostname: hostname returned an empty string twice and will" + + "not be set.") + else + fqdn ourfqdn + end + rescue + Ohai::Log.debug( + "Plugin Hostname: hostname returned an error, probably no domain set") + end + domain collect_domain + end + collect_data(:freebsd) do hostname from_cmd("hostname -s") machinename from_cmd("hostname") @@ -127,20 +135,19 @@ # Sometimes... very rarely, but sometimes, 'hostname --fqdn' falsely # returns a blank string. WTF. if ourfqdn.nil? || ourfqdn.empty? - Ohai::Log.debug("hostname --fqdn returned an empty string, retrying " + + Ohai::Log.debug("Plugin Hostname: hostname --fqdn returned an empty string, retrying " + "once.") ourfqdn = from_cmd("hostname --fqdn") end if ourfqdn.nil? || ourfqdn.empty? - Ohai::Log.debug("hostname --fqdn returned an empty string twice and " + + Ohai::Log.debug("Plugin Hostname: hostname --fqdn returned an empty string twice and " + "will not be set.") else fqdn ourfqdn end rescue - Ohai::Log.debug( - "hostname --fqdn returned an error, probably no domain set") + Ohai::Log.debug("Plugin Hostname: hostname --fqdn returned an error, probably no domain set") end domain collect_domain end diff -Nru ohai-8.21.0/lib/ohai/plugins/ip_scopes.rb ohai-13.8.0/lib/ohai/plugins/ip_scopes.rb --- ohai-8.21.0/lib/ohai/plugins/ip_scopes.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/ip_scopes.rb 2018-03-16 11:24:35.000000000 +0000 @@ -24,6 +24,8 @@ begin require "ipaddr_extensions" + Ohai::Log.warn("The IpScopes Ohai plugin has been deprecated and will be removed from Ohai 14 (April 2018).") + network["interfaces"].keys.sort.each do |if_name| next if network["interfaces"][if_name]["addresses"].nil? @@ -32,7 +34,7 @@ begin attrs["ip_scope"] = address.to_ip.scope - if private_addr?(address) && !tunnel_iface?(interface) + if private_addr?(address) && !tunnel_iface?(interface) && !ppp_iface?(interface) && !docker_iface?(interface) privateaddress(address) end rescue ArgumentError @@ -43,7 +45,7 @@ rescue LoadError => e # our favourite gem is not installed. Boohoo. - Ohai::Log.debug("Plugin ip_scopes: cannot load gem, plugin disabled: #{e}") + Ohai::Log.debug("Plugin IpScopes: cannot load gem, plugin disabled: #{e}") end end @@ -51,7 +53,15 @@ address.to_ip.scope =~ /PRIVATE/ end - def tunnel_iface?(interface) + def ppp_iface?(interface) interface["type"] == "ppp" end + + def tunnel_iface?(interface) + interface["type"] == "tunl" + end + + def docker_iface?(interface) + interface["type"] == "docker" + end end diff -Nru ohai-8.21.0/lib/ohai/plugins/java.rb ohai-13.8.0/lib/ohai/plugins/java.rb --- ohai-8.21.0/lib/ohai/plugins/java.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/java.rb 2018-03-16 11:24:35.000000000 +0000 @@ -21,30 +21,28 @@ depends "languages" def get_java_info - begin - so = shell_out("java -mx64m -version") - # Sample output: - # java version "1.8.0_60" - # Java(TM) SE Runtime Environment (build 1.8.0_60-b27) - # Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode) - if so.exitstatus == 0 - java = Mash.new - so.stderr.split(/\r?\n/).each do |line| - case line - when /(?:java|openjdk) version \"([0-9\.\_]+)\"/ - java[:version] = $1 - when /^(.+Runtime Environment.*) \((build)\s*(.+)\)$/ - java[:runtime] = { "name" => $1, "build" => $3 } - when /^(.+ (Client|Server) VM) \(build\s*(.+)\)$/ - java[:hotspot] = { "name" => $1, "build" => $3 } - end + so = shell_out("java -mx64m -version") + # Sample output: + # java version "1.8.0_60" + # Java(TM) SE Runtime Environment (build 1.8.0_60-b27) + # Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode) + if so.exitstatus == 0 + java = Mash.new + so.stderr.split(/\r?\n/).each do |line| + case line + when /(?:java|openjdk) version \"([0-9\.\_]+)\"/ + java[:version] = $1 + when /^(.+Runtime Environment.*) \((build)\s*(.+)\)$/ + java[:runtime] = { "name" => $1, "build" => $3 } + when /^(.+ (Client|Server) VM) \(build\s*(.+)\)$/ + java[:hotspot] = { "name" => $1, "build" => $3 } end - - languages[:java] = java unless java.empty? end - rescue Ohai::Exceptions::Exec - Ohai::Log.debug('Java plugin: Could not shell_out "java -mx64m -version". Skipping plugin') + + languages[:java] = java unless java.empty? end + rescue Ohai::Exceptions::Exec + Ohai::Log.debug('Plugin Java: Could not shell_out "java -mx64m -version". Skipping plugin') end # On Mac OS X, the development tools include "stubs" for JVM executables that diff -Nru ohai-8.21.0/lib/ohai/plugins/joyent.rb ohai-13.8.0/lib/ohai/plugins/joyent.rb --- ohai-8.21.0/lib/ohai/plugins/joyent.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/joyent.rb 2018-03-16 11:24:35.000000000 +0000 @@ -25,23 +25,18 @@ depends "os", "platform", "virtualization" def collect_product_file - lines = [] - if ::File.exists?("/etc/product") - ::File.open("/etc/product") do |file| - while line = file.gets - lines << line - end - end + data = ::File.read("/etc/product") rescue nil + if data + data.strip.split("\n") + else + [] end - lines end def collect_pkgsrc - if File.exist?("/opt/local/etc/pkg_install.conf") - sm_pkgsrc = ::File.read("/opt/local/etc/pkg_install.conf").split("=") - sm_pkgsrc[1].chomp - else - nil + data = ::File.read("/opt/local/etc/pkg_install.conf") rescue nil + if data + /PKG_PATH=(.*)/.match(data)[1] rescue nil end end @@ -76,7 +71,7 @@ end ## retrieve pkgsrc - joyent[:sm_pkgsrc] = collect_pkgsrc if collect_pkgsrc + joyent[:sm_pkgsrc] = collect_pkgsrc end end end diff -Nru ohai-8.21.0/lib/ohai/plugins/kernel.rb ohai-13.8.0/lib/ohai/plugins/kernel.rb --- ohai-8.21.0/lib/ohai/plugins/kernel.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/kernel.rb 2018-03-16 11:24:35.000000000 +0000 @@ -67,7 +67,7 @@ return "WIN98" if sys_type.to_s.eql?("17") return "WINNT" if sys_type.to_s.eql?("18") return "WINCE" if sys_type.to_s.eql?("19") - return nil + nil end collect_data(:default) do diff -Nru ohai-8.21.0/lib/ohai/plugins/linux/cpu.rb ohai-13.8.0/lib/ohai/plugins/linux/cpu.rb --- ohai-8.21.0/lib/ohai/plugins/linux/cpu.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/linux/cpu.rb 2018-03-16 11:24:35.000000000 +0000 @@ -59,6 +59,10 @@ cpuinfo[current_cpu]["cache_size"] = $1 when /flags\s+:\s(.+)/ cpuinfo[current_cpu]["flags"] = $1.split(" ") + when /BogoMIPS\s+:\s(.+)/ + cpuinfo[current_cpu]["bogomips"] = $1 + when /Features\s+:\s(.+)/ + cpuinfo[current_cpu]["features"] = $1.split(" ") when /bogomips per cpu:\s(.+)/ cpuinfo["bogomips_per_cpu"] = $1 when /features\s+:\s(.+)/ @@ -78,8 +82,39 @@ end cpu cpuinfo + cpu[:total] = cpu_number - cpu[:real] = real_cpu.keys.length - cpu[:cores] = real_cpu.keys.length * cpu["0"]["cores"].to_i + + # use data we collected unless cpuinfo is lacking core information + # which is the case on older linux distros + if !real_cpu.empty? && cpu["0"]["cores"] + cpu[:real] = real_cpu.keys.length + cpu[:cores] = real_cpu.keys.length * cpu["0"]["cores"].to_i + else + begin + Ohai::Log.debug("Plugin CPU: Falling back to aggregate data from lscpu as real cpu & core data is missing in /proc/cpuinfo") + so = shell_out("lscpu") + if so.exitstatus == 0 + lscpu_data = Mash.new + so.stdout.each_line do |line| + case line + when /^Thread\(s\) per core:\s(.+)/ # http://rubular.com/r/lOw2pRrw1q + lscpu_data[:threads] = $1.to_i + when /^Core\(s\) per socket:\s(.+)/ # http://rubular.com/r/lOw2pRrw1q + lscpu_data[:cores] = $1.to_i + when /^Socket\(s\):\s(.+)/ # http://rubular.com/r/DIzmPtJFvK + lscpu_data[:sockets] = $1.to_i + end + end + cpu[:total] = lscpu_data[:sockets] * lscpu_data[:cores] * lscpu_data[:threads] + cpu[:real] = lscpu_data[:sockets] + cpu[:cores] = lscpu_data[:sockets] * lscpu_data[:cores] + else + Ohai::Log.debug("Plugin CPU: Error executing lscpu. CPU data may not be available.") + end + rescue Ohai::Exceptions::Exec # util-linux isn't installed most likely + Ohai::Log.debug("Plugin CPU: Error executing lscpu. util-linux may not be installed.") + end + end end end diff -Nru ohai-8.21.0/lib/ohai/plugins/linux/filesystem2.rb ohai-13.8.0/lib/ohai/plugins/linux/filesystem2.rb --- ohai-8.21.0/lib/ohai/plugins/linux/filesystem2.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/linux/filesystem2.rb 1970-01-01 00:00:00.000000000 +0000 @@ -1,223 +0,0 @@ -# -# Author:: Phil Dibowitz -# Author:: Adam Jacob -# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. -# Copyright:: Copyright (c) 2015 Facebook, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -Ohai.plugin(:Filesystem2) do - provides "filesystem2" - - def find_device(name) - %w{/dev /dev/mapper}.each do |dir| - path = File.join(dir, name) - return path if File.exist?(path) - end - name - end - - def parse_line(line, have_lsblk) - if have_lsblk - regex = /NAME="(\S+).*?" UUID="(\S*)" LABEL="(\S*)" FSTYPE="(\S*)"/ - if line =~ regex - dev = $1 - dev = find_device(dev) unless dev.start_with?("/") - uuid = $2 - label = $3 - fs_type = $4 - return { :dev => dev, :uuid => uuid, :label => label, :fs_type => fs_type } - end - else - bits = line.split - dev = bits.shift.split(":")[0] - f = { :dev => dev } - bits.each do |keyval| - if keyval =~ /(\S+)="(\S+)"/ - key = $1.downcase.to_sym - key = :fs_type if key == :type - f[key] = $2 - end - end - return f - end - return nil - end - - def generate_device_view(fs) - view = {} - fs.each_value do |entry| - view[entry[:device]] = Mash.new unless view[entry[:device]] - entry.each do |key, val| - next if %w{device mount}.include?(key) - view[entry[:device]][key] = val - end - view[entry[:device]][:mounts] ||= [] - if entry[:mount] - view[entry[:device]][:mounts] << entry[:mount] - end - end - view - end - - def generate_mountpoint_view(fs) - view = {} - fs.each_value do |entry| - next unless entry[:mount] - view[entry[:mount]] = Mash.new unless view[entry[:mount]] - entry.each do |key, val| - next if %w{mount device}.include?(key) - view[entry[:mount]][key] = val - end - view[entry[:mount]][:devices] ||= [] - if entry[:device] - view[entry[:mount]][:devices] << entry[:device] - end - end - view - end - - collect_data(:linux) do - fs = Mash.new - - # Grab filesystem data from df - so = shell_out("df -P") - so.stdout.each_line do |line| - case line - when /^Filesystem\s+1024-blocks/ - next - when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/ - key = "#{$1},#{$6}" - fs[key] = Mash.new - fs[key][:device] = $1 - fs[key][:kb_size] = $2 - fs[key][:kb_used] = $3 - fs[key][:kb_available] = $4 - fs[key][:percent_used] = $5 - fs[key][:mount] = $6 - end - end - - # Grab filesystem inode data from df - so = shell_out("df -iP") - so.stdout.each_line do |line| - case line - when /^Filesystem\s+Inodes/ - next - when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/ - key = "#{$1},#{$6}" - fs[key] ||= Mash.new - fs[key][:device] = $1 - fs[key][:total_inodes] = $2 - fs[key][:inodes_used] = $3 - fs[key][:inodes_available] = $4 - fs[key][:inodes_percent_used] = $5 - fs[key][:mount] = $6 - end - end - - # Grab mount information from /bin/mount - so = shell_out("mount") - so.stdout.each_line do |line| - if line =~ /^(.+?) on (.+?) type (.+?) \((.+?)\)$/ - key = "#{$1},#{$2}" - fs[key] = Mash.new unless fs.has_key?(key) - fs[key][:device] = $1 - fs[key][:mount] = $2 - fs[key][:fs_type] = $3 - fs[key][:mount_options] = $4.split(",") - end - end - - have_lsblk = File.exist?("/bin/lsblk") - if have_lsblk - cmd = "lsblk -n -P -o NAME,UUID,LABEL,FSTYPE" - else - # CentOS5 and other platforms don't have lsblk - cmd = "blkid" - end - - so = shell_out(cmd) - so.stdout.each_line do |line| - parsed = parse_line(line, have_lsblk) - next if parsed.nil? - # lsblk lists each device once, so we need to update all entries - # in the hash that are related to this device - keys_to_update = [] - fs.each_key do |key| - keys_to_update << key if key.start_with?("#{parsed[:dev]},") - end - - if keys_to_update.empty? - key = "#{parsed[:dev]}," - fs[key] = Mash.new - fs[key][:device] = parsed[:dev] - keys_to_update << key - end - - keys_to_update.each do |key| - [:fs_type, :uuid, :label].each do |subkey| - if parsed[subkey] && !parsed[subkey].empty? - fs[key][subkey] = parsed[subkey] - end - end - end - end - - # Grab any missing mount information from /proc/mounts - if File.exist?("/proc/mounts") - mounts = "" - # Due to https://tickets.opscode.com/browse/OHAI-196 - # 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 - end - f.close - mounts.each_line do |line| - if line =~ /^(\S+) (\S+) (\S+) (\S+) \S+ \S+$/ - key = "#{$1},#{$2}" - next if fs.has_key?(key) - fs[key] = Mash.new - fs[key][:device] = $1 - fs[key][:mount] = $2 - fs[key][:fs_type] = $3 - fs[key][:mount_options] = $4.split(",") - end - end - end - - by_pair = fs - by_device = generate_device_view(fs) - by_mountpoint = generate_mountpoint_view(fs) - - fs2 = Mash.new - fs2["by_device"] = by_device - fs2["by_mountpoint"] = by_mountpoint - fs2["by_pair"] = by_pair - - # Set the filesystem data - filesystem2 fs2 - end -end diff -Nru ohai-8.21.0/lib/ohai/plugins/linux/filesystem.rb ohai-13.8.0/lib/ohai/plugins/linux/filesystem.rb --- ohai-8.21.0/lib/ohai/plugins/linux/filesystem.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/linux/filesystem.rb 2018-03-16 11:24:35.000000000 +0000 @@ -1,6 +1,8 @@ # -# Author:: Adam Jacob () -# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. +# Author:: Phil Dibowitz +# Author:: Adam Jacob +# Copyright:: Copyright (c) 2008-2017 Chef Software, Inc. +# Copyright:: Copyright (c) 2015 Facebook, Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,24 +20,7 @@ Ohai.plugin(:Filesystem) do provides "filesystem" - - def get_blk_cmd(attr, have_lsblk) - if have_lsblk - attr = "FSTYPE" if attr == "TYPE" - "lsblk -P -n -o NAME,#{attr}" - else - "blkid -s #{attr}" - end - end - - def get_blk_regex(attr, have_lsblk) - if have_lsblk - attr = "FSTYPE" if attr == "TYPE" - /^NAME="(\S+).*?" #{attr}="(\S+)"/ - else - /^(\S+): #{attr}="(\S+)"/ - end - end + provides "filesystem2" def find_device(name) %w{/dev /dev/mapper}.each do |dir| @@ -45,97 +30,180 @@ name end - collect_data(:linux) do - fs = Mash.new - have_lsblk = File.executable?("/bin/lsblk") - - # Grab filesystem data from df - so = shell_out("df -P") - so.stdout.lines do |line| - case line - when /^Filesystem\s+1024-blocks/ - next - when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/ - filesystem = $1 - fs[filesystem] = Mash.new - fs[filesystem][:kb_size] = $2 - fs[filesystem][:kb_used] = $3 - fs[filesystem][:kb_available] = $4 - fs[filesystem][:percent_used] = $5 - fs[filesystem][:mount] = $6 + def parse_line(line, cmdtype) + case cmdtype + when "lsblk" + regex = /NAME="(\S+).*?" UUID="(\S*)" LABEL="(\S*)" FSTYPE="(\S*)"/ + if line =~ regex + dev = $1 + dev = find_device(dev) unless dev.start_with?("/") + uuid = $2 + label = $3 + fs_type = $4 + return { :dev => dev, :uuid => uuid, :label => label, :fs_type => fs_type } + end + when "blkid" + bits = line.split + dev = bits.shift.split(":")[0] + f = { :dev => dev } + bits.each do |keyval| + if keyval =~ /(\S+)="(\S+)"/ + key = $1.downcase.to_sym + key = :fs_type if key == :type + f[key] = $2 + end end + return f end + nil + end - # Grab filesystem inode data from df - so = shell_out("df -iP") - so.stdout.lines do |line| - case line - when /^Filesystem\s+Inodes/ - next - when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/ - filesystem = $1 - fs[filesystem] ||= Mash.new - fs[filesystem][:total_inodes] = $2 - fs[filesystem][:inodes_used] = $3 - fs[filesystem][:inodes_available] = $4 - fs[filesystem][:inodes_percent_used] = $5 - fs[filesystem][:mount] = $6 + def generate_device_view(fs) + view = {} + fs.each_value do |entry| + view[entry[:device]] = Mash.new unless view[entry[:device]] + entry.each do |key, val| + next if %w{device mount}.include?(key) + view[entry[:device]][key] = val + end + view[entry[:device]][:mounts] ||= [] + if entry[:mount] + view[entry[:device]][:mounts] << entry[:mount] end end + view + end - # Grab mount information from /bin/mount - so = shell_out("mount") - so.stdout.lines do |line| - if line =~ /^(.+?) on (.+?) type (.+?) \((.+?)\)$/ - filesystem = $1 - fs[filesystem] = Mash.new unless fs.has_key?(filesystem) - fs[filesystem][:mount] = $2 - fs[filesystem][:fs_type] = $3 - fs[filesystem][:mount_options] = $4.split(",") + def generate_mountpoint_view(fs) + view = {} + fs.each_value do |entry| + next unless entry[:mount] + view[entry[:mount]] = Mash.new unless view[entry[:mount]] + entry.each do |key, val| + next if %w{mount device}.include?(key) + view[entry[:mount]][key] = val + end + view[entry[:mount]][:devices] ||= [] + if entry[:device] + view[entry[:mount]][:devices] << entry[:device] end end + view + end - have_lsblk = File.exist?("/bin/lsblk") - - # Gather more filesystem types via libuuid, even devices that's aren't mounted - cmd = get_blk_cmd("TYPE", have_lsblk) - regex = get_blk_regex("TYPE", have_lsblk) - so = shell_out(cmd) - so.stdout.lines do |line| - if line =~ regex - filesystem = $1 - type = $2 - filesystem = find_device(filesystem) unless filesystem.start_with?("/") - fs[filesystem] = Mash.new unless fs.has_key?(filesystem) - fs[filesystem][:fs_type] = type + collect_data(:linux) do + fs = Mash.new + + # Grab filesystem data from df + begin + so = shell_out("df -P") + so.stdout.each_line do |line| + case line + when /^Filesystem\s+1024-blocks/ + next + when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/ + key = "#{$1},#{$6}" + fs[key] = Mash.new + fs[key][:device] = $1 + fs[key][:kb_size] = $2 + fs[key][:kb_used] = $3 + fs[key][:kb_available] = $4 + fs[key][:percent_used] = $5 + fs[key][:mount] = $6 + end end - end - # Gather device UUIDs via libuuid - cmd = get_blk_cmd("UUID", have_lsblk) - regex = get_blk_regex("UUID", have_lsblk) - so = shell_out(cmd) - so.stdout.lines do |line| - if line =~ regex - filesystem = $1 - uuid = $2 - filesystem = find_device(filesystem) unless filesystem.start_with?("/") - fs[filesystem] = Mash.new unless fs.has_key?(filesystem) - fs[filesystem][:uuid] = uuid + # Grab filesystem inode data from df + so = shell_out("df -iP") + so.stdout.each_line do |line| + case line + when /^Filesystem\s+Inodes/ + next + when /^(.+?)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+\%)\s+(.+)$/ + key = "#{$1},#{$6}" + fs[key] ||= Mash.new + fs[key][:device] = $1 + fs[key][:total_inodes] = $2 + fs[key][:inodes_used] = $3 + fs[key][:inodes_available] = $4 + fs[key][:inodes_percent_used] = $5 + fs[key][:mount] = $6 + end end + rescue Ohai::Exceptions::Exec => e + unless Ohai.config[:plugin][:filesystem][:allow_partial_data] + raise e + end + Ohai::Log.warn("Plugin Filesystem: df binary is not available. Some data will not be available.") end - # Gather device labels via libuuid - cmd = get_blk_cmd("LABEL", have_lsblk) - regex = get_blk_regex("LABEL", have_lsblk) - so = shell_out(cmd) - so.stdout.lines do |line| - if line =~ regex - filesystem = $1 - label = $2 - filesystem = find_device(filesystem) unless filesystem.start_with?("/") - fs[filesystem] = Mash.new unless fs.has_key?(filesystem) - fs[filesystem][:label] = label + # Grab mount information from /bin/mount + begin + so = shell_out("mount") + so.stdout.each_line do |line| + if line =~ /^(.+?) on (.+?) type (.+?) \((.+?)\)$/ + key = "#{$1},#{$2}" + fs[key] = Mash.new unless fs.has_key?(key) + fs[key][:device] = $1 + fs[key][:mount] = $2 + fs[key][:fs_type] = $3 + fs[key][:mount_options] = $4.split(",") + end + end + rescue Ohai::Exceptions::Exec + unless Ohai.config[:plugin][:filesystem][:allow_partial_data] + raise e + end + Ohai::Log.warn("Plugin Filesystem: mount binary is not available. Some data will not be available.") + end + + # We used to try to decide if we wanted to run lsblk or blkid + # but they each have a variety of cases were they fail to report + # data. For example, there are a variety of cases where lsblk won't + # report unmounted filesystems, but blkid will. And vise-versa. Sweet. + # So for reliability, we'll run both, if we have them. + + lsblk = which("lsblk") + blkid = which("blkid") + cmds = [] + # These should be in order of preference... first writer wins. + if lsblk + cmds << "#{lsblk} -n -P -o NAME,UUID,LABEL,FSTYPE" + end + if blkid + cmds << blkid + end + + cmds.each do |cmd| + cmdtype = File.basename(cmd.split.first) + # setting the timeout here for `lsblk` and `blkid` commands to 60 + # this is to allow machines with large amounts of attached LUNs + # to respond back to the command successfully + so = shell_out(cmd, timeout: 60) + so.stdout.each_line do |line| + parsed = parse_line(line, cmdtype) + next if parsed.nil? + # lsblk lists each device once, so we need to update all entries + # in the hash that are related to this device + keys_to_update = [] + fs.each_key do |key| + keys_to_update << key if key.start_with?("#{parsed[:dev]},") + end + + if keys_to_update.empty? + key = "#{parsed[:dev]}," + fs[key] = Mash.new + fs[key][:device] = parsed[:dev] + keys_to_update << key + end + + keys_to_update.each do |key| + [:fs_type, :uuid, :label].each do |subkey| + if parsed[subkey] && !parsed[subkey].empty? + fs[key][subkey] = parsed[subkey] + end + end + end end end @@ -160,17 +228,28 @@ f.close mounts.each_line do |line| if line =~ /^(\S+) (\S+) (\S+) (\S+) \S+ \S+$/ - filesystem = $1 - next if fs.has_key?(filesystem) - fs[filesystem] = Mash.new - fs[filesystem][:mount] = $2 - fs[filesystem][:fs_type] = $3 - fs[filesystem][:mount_options] = $4.split(",") + key = "#{$1},#{$2}" + next if fs.has_key?(key) + fs[key] = Mash.new + fs[key][:device] = $1 + fs[key][:mount] = $2 + fs[key][:fs_type] = $3 + fs[key][:mount_options] = $4.split(",") end end end + by_pair = fs + by_device = generate_device_view(fs) + by_mountpoint = generate_mountpoint_view(fs) + + fs_data = Mash.new + fs_data["by_device"] = by_device + fs_data["by_mountpoint"] = by_mountpoint + fs_data["by_pair"] = by_pair + # Set the filesystem data - filesystem fs + filesystem fs_data + filesystem2 fs_data end end diff -Nru ohai-8.21.0/lib/ohai/plugins/linux/lsb.rb ohai-13.8.0/lib/ohai/plugins/linux/lsb.rb --- ohai-8.21.0/lib/ohai/plugins/linux/lsb.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/linux/lsb.rb 2018-03-16 11:24:35.000000000 +0000 @@ -22,21 +22,8 @@ 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,8 +39,22 @@ 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") + Ohai::Log.debug("Plugin LSB: Skipping LSB, cannot find /etc/lsb-release or /usr/bin/lsb_release") end end end diff -Nru ohai-8.21.0/lib/ohai/plugins/linux/lspci.rb ohai-13.8.0/lib/ohai/plugins/linux/lspci.rb --- ohai-8.21.0/lib/ohai/plugins/linux/lspci.rb 1970-01-01 00:00:00.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/linux/lspci.rb 2018-03-16 11:24:35.000000000 +0000 @@ -0,0 +1,76 @@ +# +# Author:: Joerg Herzinger +# Author:: Phil Dibowitz +# Copyright:: Copyright (c) 2011 GLOBAL 2000/Friends of the Earth Austria +# Copyright:: Copyright (c) 2017 Facebook, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +Ohai.plugin(:Lspci) do + depends "platform" + provides "pci" + + collect_data(:linux) do + devices = Mash.new + lspci = shell_out("lspci -vnnmk") + + h = /[0-9a-fA-F]/ #any hex digit + hh = /#{h}#{h}/ #any 2 hex digits + hhhh = /#{h}#{h}#{h}#{h}/ #any 4 hex digits + + d_id = String.new #This identifies our pci devices + + def standard_form(devices, d_id, hhhh, tag, line) + tmp = line.scan(/(.*)\s\[(#{hhhh})\]/)[0] + devices[d_id]["#{tag}_name"] = tmp[0] + devices[d_id]["#{tag}_id"] = tmp[1] + end + + def standard_array(devices, d_id, tag, line) + if !devices[d_id][tag].kind_of?(Array) + devices[d_id][tag] = [line] + else + devices[d_id][tag].push(line) + end + end + + lspci.stdout.split("\n").each do |line| + dev = line.scan(/^(.*):\s(.*)$/)[0] + next if dev.nil? + case dev[0] + when "Device" # There are two different Device tags + if tmp = dev[1].match(/(#{hh}:#{hh}.#{h})/) + # We have a device id + d_id = tmp[0] # From now on we will need this id + devices[d_id] = Mash.new + else + standard_form(devices, d_id, hhhh, "device", dev[1]) + end + when "Class" + standard_form(devices, d_id, hhhh, "class", dev[1]) + when "Vendor" + standard_form(devices, d_id, hhhh, "vendor", dev[1]) + when "Driver" + standard_array(devices, d_id, "driver", dev[1]) + when "Module" + standard_array(devices, d_id, "module", dev[1]) + when "SDevice" + standard_form(devices, d_id, hhhh, "sdevice", dev[1]) + else + end + end + + pci devices + end +end diff -Nru ohai-8.21.0/lib/ohai/plugins/linux/mdadm.rb ohai-13.8.0/lib/ohai/plugins/linux/mdadm.rb --- ohai-8.21.0/lib/ohai/plugins/linux/mdadm.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/linux/mdadm.rb 2018-03-16 11:24:35.000000000 +0000 @@ -1,6 +1,8 @@ # # Author:: Tim Smith +# Author:: Phil Dibowitz # Copyright:: Copyright (c) 2013-2014, Limelight Networks, Inc. +# Copyright:: Copyright (c) 2017 Facebook, Inc. # Plugin:: mdadm # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -52,15 +54,52 @@ collect_data(:linux) do # gather a list of all raid arrays if File.exist?("/proc/mdstat") - devices = [] + devices = {} File.open("/proc/mdstat").each do |line| - devices << Regexp.last_match[1] if line =~ /(md[0-9]+)/ + if line =~ /(md[0-9]+)/ + device = Regexp.last_match[1] + pieces = line.split(/\s+/) + # there are variable numbers of fields until you hit the raid level + # everything after that is members... + # unless the array is inactive, in which case you don't get a raid + # level. + members = pieces.drop_while { |x| !x.start_with?("raid", "inactive") } + # and drop that too + members.shift unless members.empty? + devices[device] = { + "active" => [], + "spare" => [], + "journal" => nil, + } + members.each do |member| + # We want to match the device, and optionally the type + # most entries will look like: + # sdc1[5] + # but some will look like: + # sdc1[5](J) + # where the format is: + # []() + # Type can be things like "J" for a journal device, or "S" for + # a spare device. + m = member.match(/(.+)\[\d+\](?:\((\w)\))?/) + member_device = m[1] + member_type = m[2] + case member_type + when "J" + devices[device]["journal"] = member_device + when "S" + devices[device]["spare"] << member_device + else + devices[device]["active"] << member_device + end + end + end end # create the mdadm mash and gather individual information if devices are present unless devices.empty? mdadm Mash.new - devices.sort.each do |device| + devices.keys.sort.each do |device| mdadm[device] = Mash.new # gather detailed information on the array @@ -68,6 +107,9 @@ # if the mdadm command was sucessful pass so.stdout to create_raid_device_mash to grab the tidbits we want mdadm[device] = create_raid_device_mash(so.stdout) if so.stdout + mdadm[device]["members"] = devices[device]["active"] + mdadm[device]["spares"] = devices[device]["spare"] + mdadm[device]["journal"] = devices[device]["journal"] end end end diff -Nru ohai-8.21.0/lib/ohai/plugins/linux/memory.rb ohai-13.8.0/lib/ohai/plugins/linux/memory.rb --- ohai-8.21.0/lib/ohai/plugins/linux/memory.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/linux/memory.rb 2018-03-16 11:24:35.000000000 +0000 @@ -30,6 +30,8 @@ memory[:total] = "#{$1}#{$2}" when /^MemFree:\s+(\d+) (.+)$/ memory[:free] = "#{$1}#{$2}" + when /^MemAvailable:\s+(\d+) (.+)$/ + memory[:available] = "#{$1}#{$2}" when /^Buffers:\s+(\d+) (.+)$/ memory[:buffers] = "#{$1}#{$2}" when /^Cached:\s+(\d+) (.+)$/ diff -Nru ohai-8.21.0/lib/ohai/plugins/linux/network.rb ohai-13.8.0/lib/ohai/plugins/linux/network.rb --- ohai-8.21.0/lib/ohai/plugins/linux/network.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/linux/network.rb 2018-03-16 11:24:35.000000000 +0000 @@ -1,7 +1,7 @@ # # Author:: Adam Jacob () # Author:: Chris Read -# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. +# Copyright:: Copyright (c) 2008-2017, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -37,16 +37,12 @@ File.exist? "/proc/net/if_inet6" end - def iproute2_binary_available? - ["/sbin/ip", "/usr/bin/ip", "/bin/ip"].any? { |path| File.exist?(path) } - end - - def find_ethtool_binary - ["/sbin/ethtool", "/usr/sbin/ethtool"].find { |path| File.exist?(path) } + def ethtool_binary_path + @ethtool ||= which("ethtool") end def is_openvz? - ::File.directory?("/proc/vz") + @openvz ||= ::File.directory?("/proc/vz") end def is_openvz_host? @@ -80,7 +76,7 @@ so = shell_out("ip -o -f #{family[:name]} route show table #{default_route_table}") so.stdout.lines do |line| line.strip! - Ohai::Log.debug("Parsing #{line}") + Ohai::Log.debug("Plugin Network: Parsing #{line}") if line =~ /\\/ parts = line.split('\\') route_dest = parts.shift.strip @@ -95,20 +91,21 @@ if route_ending =~ /\bdev\s+([^\s]+)\b/ route_int = $1 else - Ohai::Log.debug("Skipping route entry without a device: '#{line}'") + Ohai::Log.debug("Plugin Network: Skipping route entry without a device: '#{line}'") next end route_int = "venet0:0" if is_openvz? && !is_openvz_host? && route_int == "venet0" && iface["venet0:0"] unless iface[route_int] - Ohai::Log.debug("Skipping previously unseen interface from 'ip route show': #{route_int}") + Ohai::Log.debug("Plugin Network: Skipping previously unseen interface from 'ip route show': #{route_int}") next end route_entry = Mash.new(:destination => route_dest, :family => family[:name]) %w{via scope metric proto src}.each do |k| - route_entry[k] = $1 if route_ending =~ /\b#{k}\s+([^\s]+)\b/ + # http://rubular.com/r/pwTNp65VFf + route_entry[k] = $1 if route_ending =~ /\b#{k}\s+([^\s]+)/ end # a sanity check, especially for Linux-VServer, OpenVZ and LXC: @@ -118,7 +115,7 @@ addr = iface[route_int][:addresses] unless addr.nil? || addr.has_key?(route_entry[:src]) || addr.values.all? { |a| a["family"] != family[:name] } - Ohai::Log.debug("Skipping route entry whose src does not match the interface IP") + Ohai::Log.debug("Plugin Network: Skipping route entry whose src does not match the interface IP") next end end @@ -141,22 +138,24 @@ # using a temporary var to hold routes and their interface name def parse_routes(family, iface) iface.collect do |i, iv| - iv[:routes].collect do |r| - r.merge(:dev => i) if r[:family] == family[:name] - end.compact if iv[:routes] + if iv[:routes] + iv[:routes].collect do |r| + r.merge(:dev => i) if r[:family] == family[:name] + end.compact + end end.compact.flatten end # determine layer 1 details for the interface using ethtool def ethernet_layer_one(iface) - return iface unless ethtool_binary = find_ethtool_binary + return iface unless ethtool_binary_path keys = %w{ Speed Duplex Port Transceiver Auto-negotiation MDI-X } iface.each_key do |tmp_int| next unless iface[tmp_int][:encapsulation] == "Ethernet" - so = shell_out("#{ethtool_binary} #{tmp_int}") + so = shell_out("#{ethtool_binary_path} #{tmp_int}") so.stdout.lines do |line| line.chomp! - Ohai::Log.debug("Parsing ethtool output: #{line}") + Ohai::Log.debug("Plugin Network: Parsing ethtool output: #{line}") line.lstrip! k, v = line.split(": ") next unless keys.include? k @@ -173,11 +172,11 @@ # determine ring parameters for the interface using ethtool def ethernet_ring_parameters(iface) - return iface unless ethtool_binary = find_ethtool_binary + return iface unless ethtool_binary_path iface.each_key do |tmp_int| next unless iface[tmp_int][:encapsulation] == "Ethernet" - so = shell_out("#{ethtool_binary} -g #{tmp_int}") - Ohai::Log.debug("Parsing ethtool output: #{so.stdout}") + so = shell_out("#{ethtool_binary_path} -g #{tmp_int}") + Ohai::Log.debug("Plugin Network: Parsing ethtool output: #{so.stdout}") type = nil iface[tmp_int]["ring_params"] = {} so.stdout.lines.each do |line| @@ -213,6 +212,31 @@ net_counters[tmp_int] = Mash.new unless net_counters[tmp_int] end + if line =~ /^\s+(ip6tnl|ipip)/ + iface[tmp_int][:tunnel_info] = {} + words = line.split + words.each_with_index do |word, index| + case word + when "external" + iface[tmp_int][:tunnel_info][word] = true + when "any", "ipip6", "ip6ip6" + iface[tmp_int][:tunnel_info][:proto] = word + when "remote", + "local", + "encaplimit", + "hoplimit", + "tclass", + "flowlabel", + "addrgenmode", + "numtxqueues", + "numrxqueues", + "gso_max_size", + "gso_max_segs" + iface[tmp_int][:tunnel_info][word] = words[index + 1] + end + end + end + if line =~ /(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/ int = on_rx ? :rx : :tx net_counters[tmp_int][int] = Mash.new unless net_counters[tmp_int][int] @@ -380,7 +404,7 @@ end def interface_address_not_link_level?(iface, address) - !iface[:addresses][address][:scope].casecmp("link").zero? + !(iface[:addresses][address][:scope].casecmp("link") == 0) end def interface_valid_for_route?(iface, address, family) @@ -462,14 +486,14 @@ else default_route_table = configuration(:default_route_table) end - Ohai::Log.debug("default route table is '#{default_route_table}'") + Ohai::Log.debug("Plugin Network: default route table is '#{default_route_table}'") # Match the lead line for an interface from iproute2 # 3: eth0.11@eth0: mtu 1500 qdisc noqueue state UP # The '@eth0:' portion doesn't exist on primary interfaces and thus is optional in the regex IPROUTE_INT_REGEX = /^(\d+): ([0-9a-zA-Z@:\.\-_]*?)(@[0-9a-zA-Z]+|):\s/ unless defined? IPROUTE_INT_REGEX - if iproute2_binary_available? + if which("ip") # families to get default routes from families = [{ :name => "inet", @@ -478,12 +502,14 @@ :neighbour_attribute => :arp, }] - families << { - :name => "inet6", - :default_route => "::/0", - :default_prefix => :default_inet6, - :neighbour_attribute => :neighbour_inet6, - } if ipv6_enabled? + if ipv6_enabled? + families << { + :name => "inet6", + :default_route => "::/0", + :default_prefix => :default_inet6, + :neighbour_attribute => :neighbour_inet6, + } + end parse_ip_addr(iface) @@ -507,14 +533,14 @@ else "default_#{family[:name]}_interface" end - Ohai::Log.debug("Unable to determine '#{attribute_name}' as no default routes were found for that interface family") + Ohai::Log.debug("Plugin Network: Unable to determine '#{attribute_name}' as no default routes were found for that interface family") else network["#{default_prefix}_interface"] = default_route[:dev] - Ohai::Log.debug("#{default_prefix}_interface set to #{default_route[:dev]}") + Ohai::Log.debug("Plugin Network: #{default_prefix}_interface set to #{default_route[:dev]}") # setting gateway to 0.0.0.0 or :: if the default route is a link level one network["#{default_prefix}_gateway"] = default_route[:via] ? default_route[:via] : family[:default_route].chomp("/0") - Ohai::Log.debug("#{default_prefix}_gateway set to #{network["#{default_prefix}_gateway"]}") + Ohai::Log.debug("Plugin Network: #{default_prefix}_gateway set to #{network["#{default_prefix}_gateway"]}") # deduce the default route the user most likely cares about to pick {ip,mac,ip6}address below favored_route = favored_default_route(routes, iface, default_route, family) @@ -527,20 +553,20 @@ if family[:name] == "inet" ipaddress favored_route[:src] m = get_mac_for_interface(iface, favored_route[:dev]) - Ohai::Log.debug("Overwriting macaddress #{macaddress} with #{m} from interface #{favored_route[:dev]}") if macaddress + Ohai::Log.debug("Plugin Network: Overwriting macaddress #{macaddress} with #{m} from interface #{favored_route[:dev]}") if macaddress macaddress m elsif family[:name] == "inet6" # this rarely does anything since we rarely have src for ipv6, so this usually falls back on the network plugin ip6address favored_route[:src] if macaddress - Ohai::Log.debug("Not setting macaddress from ipv6 interface #{favored_route[:dev]} because macaddress is already set") + Ohai::Log.debug("Plugin Network: Not setting macaddress from ipv6 interface #{favored_route[:dev]} because macaddress is already set") else macaddress get_mac_for_interface(iface, favored_route[:dev]) end end else - Ohai::Log.debug("the linux/network plugin was unable to deduce the favored default route for family '#{family[:name]}' despite finding a default route, and is not setting ipaddress/ip6address/macaddress. the network plugin may provide fallbacks.") - Ohai::Log.debug("this potential default route was excluded: #{default_route}") + Ohai::Log.debug("Plugin Network: Unable to deduce the favored default route for family '#{family[:name]}' despite finding a default route, and is not setting ipaddress/ip6address/macaddress. the network plugin may provide fallbacks.") + Ohai::Log.debug("Plugin Network: This potential default route was excluded: #{default_route}") end end end # end families.each @@ -550,7 +576,7 @@ route_result = so.stdout.split($/).grep( /^0.0.0.0/ )[0].split( /[ \t]+/ ) network[:default_gateway], network[:default_interface] = route_result.values_at(1, 7) rescue Ohai::Exceptions::Exec - Ohai::Log.debug("Unable to determine default interface") + Ohai::Log.debug("Plugin Network: Unable to determine default interface") end so = shell_out("ifconfig -a") diff -Nru ohai-8.21.0/lib/ohai/plugins/linux/platform.rb ohai-13.8.0/lib/ohai/plugins/linux/platform.rb --- ohai-8.21.0/lib/ohai/plugins/linux/platform.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/linux/platform.rb 2018-03-16 11:24:35.000000000 +0000 @@ -1,6 +1,6 @@ # # Author:: Adam Jacob () -# Copyright:: Copyright (c) 2015-2016 Chef Software, Inc. +# Copyright:: Copyright (c) 2015-2017, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -72,6 +72,88 @@ File.exist?("/etc/os-release") && os_release_info["CISCO_RELEASE_INFO"] end + # + # Determines the platform version for Cumulus Linux systems + # + # @returns [String] cumulus Linux version from /etc/cumulus/etc.replace/os-release + # + def cumulus_version + release_contents = File.read("/etc/cumulus/etc.replace/os-release") + release_contents.match(/VERSION_ID=(.*)/)[1] + rescue NoMethodError, Errno::ENOENT, Errno::EACCES # rescue regex failure, file missing, or permission denied + Ohai::Log.warn("Detected Cumulus Linux, but /etc/cumulus/etc/replace/os-release could not be parsed to determine platform_version") + nil + end + + # + # Determines the platform version for F5 Big-IP systems + # + # @returns [String] bigip Linux version from /etc/f5-release + # + def bigip_version + release_contents = File.read("/etc/f5-release") + release_contents.match(/BIG-IP release (\S*)/)[1] # http://rubular.com/r/O8nlrBVqSb + rescue NoMethodError, Errno::ENOENT, Errno::EACCES # rescue regex failure, file missing, or permission denied + Ohai::Log.warn("Detected F5 Big-IP, but /etc/f5-release could not be parsed to determine platform_version") + nil + end + + # + # Determines the platform version for Debian based systems + # + # @returns [String] version of the platform + # + def debian_platform_version + if platform == "cumulus" + cumulus_version + else # not cumulus + File.read("/etc/debian_version").chomp + end + end + + # + # Determines the platform_family based on the platform + # + # @returns [String] platform_family value + # + def determine_platform_family + case platform + when /debian/, /ubuntu/, /linuxmint/, /raspbian/, /cumulus/ + # apt-get+dpkg almost certainly goes here + "debian" + when /oracle/, /centos/, /redhat/, /scientific/, /enterpriseenterprise/, /xenserver/, /cloudlinux/, /ibm_powerkvm/, /parallels/, /nexus_centos/, /clearos/, /bigip/ # Note that 'enterpriseenterprise' is oracle's LSB "distributor ID" + # NOTE: "rhel" should be reserved exclusively for recompiled rhel versions that are nearly perfectly compatible down to the platform_version. + # The operating systems that are "rhel" should all be as compatible as rhel7 = centos7 = oracle7 = scientific7 (98%-ish core RPM version compatibility + # and the version numbers MUST track the upstream). The appropriate EPEL version repo should work nearly perfectly. Some variation like the + # oracle kernel version differences and tuning and extra packages are clearly acceptable. Almost certainly some distros above (xenserver?) + # should not be in this list. Please use fedora, below, instead. Also note that this is the only platform_family with this strict of a rule, + # see the example of the debian platform family for how the rest of the platform_family designations should be used. + "rhel" + when /amazon/ + "amazon" + when /suse/ + "suse" + when /fedora/, /pidora/, /arista_eos/ + # In the broadest sense: RPM-based, fedora-derived distributions which are not strictly re-compiled RHEL (if it uses RPMs, and smells more like redhat and less like + # SuSE it probably goes here). + "fedora" + when /nexus/, /ios_xr/ + "wrlinux" + when /gentoo/ + "gentoo" + when /slackware/ + "slackware" + when /arch/ + "arch" + when /exherbo/ + "exherbo" + when /alpine/ + "alpine" + when /clearlinux/ + "clearlinux" + end + end + collect_data(:linux) do # platform [ and platform_version ? ] should be lower case to avoid dealing with RedHat/Redhat/redhat matching if File.exist?("/etc/oracle-release") @@ -82,6 +164,9 @@ contents = File.read("/etc/enterprise-release").chomp platform "oracle" platform_version get_redhatish_version(contents) + elsif File.exist?("/etc/f5-release") + platform "bigip" + platform_version bigip_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 @@ -94,10 +179,12 @@ else if File.exist?("/usr/bin/raspi-config") platform "raspbian" + elsif Dir.exist?("/etc/cumulus") + platform "cumulus" else platform "debian" end - platform_version File.read("/etc/debian_version").chomp + platform_version debian_platform_version end elsif File.exist?("/etc/parallels-release") contents = File.read("/etc/parallels-release").chomp @@ -116,12 +203,6 @@ contents = File.read("/etc/system-release").chomp platform get_redhatish_platform(contents) platform_version get_redhatish_version(contents) - elsif File.exist?("/etc/gentoo-release") - platform "gentoo" - # the gentoo release version is the base version used to bootstrap - # a node and doesn't have a lot of meaning in a rolling release distro - # kernel release will be used - ex. 3.18.7-gentoo - platform_version `uname -r`.strip elsif File.exist?("/etc/SuSE-release") suse_release = File.read("/etc/SuSE-release") suse_version = suse_release.scan(/VERSION = (\d+)\nPATCHLEVEL = (\d+)/).flatten.join(".") @@ -137,22 +218,6 @@ else platform "suse" end - elsif File.exist?("/etc/slackware-version") - platform "slackware" - platform_version File.read("/etc/slackware-version").scan(/(\d+|\.+)/).join - 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.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 - platform_version `uname -r`.strip - elsif File.exist?("/etc/alpine-release") - platform "alpine" - platform_version File.read("/etc/alpine-release").strip() elsif File.exist?("/etc/Eos-release") platform "arista_eos" platform_version File.read("/etc/Eos-release").strip.split[-1] @@ -172,6 +237,34 @@ platform_family "wrlinux" platform_version os_release_info["VERSION"] + elsif File.exist?("/etc/gentoo-release") + platform "gentoo" + # the gentoo release version is the base version used to bootstrap + # a node and doesn't have a lot of meaning in a rolling release distro + # kernel release will be used - ex. 3.18.7-gentoo + platform_version `uname -r`.strip + elsif File.exist?("/etc/slackware-version") + platform "slackware" + platform_version File.read("/etc/slackware-version").scan(/(\d+|\.+)/).join + 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.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 + platform_version `uname -r`.strip + elsif File.exist?("/etc/alpine-release") + platform "alpine" + platform_version File.read("/etc/alpine-release").strip + elsif File.exist?("/usr/lib/os-release") + contents = File.read("/usr/lib/os-release") + if /Clear Linux/ =~ contents + platform "clearlinux" + platform_version contents[/VERSION_ID=(\d+)/, 1] + end elsif lsb[:id] =~ /RedHat/i platform "redhat" platform_version lsb[:release] @@ -189,25 +282,6 @@ platform_version lsb[:release] end - case platform - when /debian/, /ubuntu/, /linuxmint/, /raspbian/ - platform_family "debian" - when /fedora/, /pidora/ - platform_family "fedora" - when /oracle/, /centos/, /redhat/, /scientific/, /enterpriseenterprise/, /amazon/, /xenserver/, /cloudlinux/, /ibm_powerkvm/, /parallels/, /nexus_centos/ # Note that 'enterpriseenterprise' is oracle's LSB "distributor ID" - platform_family "rhel" - when /suse/ - platform_family "suse" - when /gentoo/ - platform_family "gentoo" - when /slackware/ - platform_family "slackware" - when /arch/ - platform_family "arch" - when /exherbo/ - platform_family "exherbo" - when /alpine/ - platform_family "alpine" - end + platform_family determine_platform_family end end diff -Nru ohai-8.21.0/lib/ohai/plugins/linux/sessions.rb ohai-13.8.0/lib/ohai/plugins/linux/sessions.rb --- ohai-8.21.0/lib/ohai/plugins/linux/sessions.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/linux/sessions.rb 2018-03-16 11:24:35.000000000 +0000 @@ -45,6 +45,8 @@ sessions[:by_user][user] = [s] end end + else + Ohai::Log.debug("Plugin Sessions: Could not find loginctl. Skipping plugin.") end end end diff -Nru ohai-8.21.0/lib/ohai/plugins/linux/systemd_paths.rb ohai-13.8.0/lib/ohai/plugins/linux/systemd_paths.rb --- ohai-8.21.0/lib/ohai/plugins/linux/systemd_paths.rb 1970-01-01 00:00:00.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/linux/systemd_paths.rb 2018-03-16 11:24:35.000000000 +0000 @@ -0,0 +1,38 @@ +# +# Author:: Davide Cavalca +# Copyright:: Copyright (c) 2017 Facebook +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +Ohai.plugin(:SystemdPaths) do + provides "systemd_paths" + + require "ohai/util/file_helper" + include Ohai::Util::FileHelper + + collect_data(:linux) do + systemd_path_path = which("systemd-path") + if systemd_path_path + systemd_path = shell_out(systemd_path_path) + + systemd_paths Mash.new unless systemd_paths + + systemd_path.stdout.each_line do |line| + key, val = line.split(":") + systemd_paths[key] = val.strip + end + end + end +end diff -Nru ohai-8.21.0/lib/ohai/plugins/linux/virtualization.rb ohai-13.8.0/lib/ohai/plugins/linux/virtualization.rb --- ohai-8.21.0/lib/ohai/plugins/linux/virtualization.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/linux/virtualization.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,18 +16,13 @@ # limitations under the License. # -require "ohai/mixin/dmi_decode" - Ohai.plugin(:Virtualization) do + require "ohai/mixin/dmi_decode" include Ohai::Mixin::DmiDecode provides "virtualization" def lxc_version_exists? - which("lxc-version") - end - - def docker_exists? - which("docker") + which("lxc-version") || which("lxc-start") end def nova_exists? @@ -49,6 +44,7 @@ # This file should exist on most Xen systems, normally empty for guests if File.exist?("/proc/xen/capabilities") if File.read("/proc/xen/capabilities") =~ /control_d/i + Ohai::Log.debug("Plugin Virtualization: /proc/xen/capabilities contains control_d. Detecting as Xen host") virtualization[:role] = "host" virtualization[:systems][:xen] = "host" end @@ -65,10 +61,12 @@ if File.exist?("/proc/modules") modules = File.read("/proc/modules") if modules =~ /^vboxdrv/ + Ohai::Log.debug("Plugin Virtualization: /proc/modules contains vboxdrv. Detecting as vbox host") virtualization[:system] = "vbox" virtualization[:role] = "host" virtualization[:systems][:vbox] = "host" elsif modules =~ /^vboxguest/ + Ohai::Log.debug("Plugin Virtualization: /proc/modules contains vboxguest. Detecting as vbox guest") virtualization[:system] = "vbox" virtualization[:role] = "guest" virtualization[:systems][:vbox] = "guest" @@ -77,6 +75,7 @@ # if nova binary is present we're on an openstack host if nova_exists? + Ohai::Log.debug("Plugin Virtualization: nova command exists. Detecting as openstack host") virtualization[:system] = "openstack" virtualization[:role] = "host" virtualization[:systems][:openstack] = "host" @@ -85,6 +84,7 @@ # Detect paravirt KVM/QEMU from cpuinfo, report as KVM if File.exist?("/proc/cpuinfo") if File.read("/proc/cpuinfo") =~ /QEMU Virtual CPU|Common KVM processor|Common 32-bit KVM processor/ + Ohai::Log.debug("Plugin Virtualization: /proc/cpuinfo lists a KVM paravirt CPU string. Detecting as kvm guest") virtualization[:system] = "kvm" virtualization[:role] = "guest" virtualization[:systems][:kvm] = "guest" @@ -96,9 +96,11 @@ if File.exist?("/sys/devices/virtual/misc/kvm") virtualization[:system] = "kvm" if File.read("/proc/cpuinfo") =~ /hypervisor/ + Ohai::Log.debug("Plugin Virtualization: /sys/devices/virtual/misc/kvm present and /proc/cpuinfo lists the hypervisor feature. Detecting as kvm guest") virtualization[:role] = "guest" virtualization[:systems][:kvm] = "guest" else + Ohai::Log.debug("Plugin Virtualization: /sys/devices/virtual/misc/kvm present and /proc/cpuinfo does not list the hypervisor feature. Detecting as kvm host") virtualization[:role] = "host" virtualization[:systems][:kvm] = "host" end @@ -107,10 +109,12 @@ # Detect OpenVZ / Virtuozzo. # http://wiki.openvz.org/BC_proc_entries if File.exist?("/proc/bc/0") + Ohai::Log.debug("Plugin Virtualization: /proc/bc/0 exists. Detecting as openvz host") virtualization[:system] = "openvz" virtualization[:role] = "host" virtualization[:systems][:openvz] = "host" elsif File.exist?("/proc/vz") + Ohai::Log.debug("Plugin Virtualization: /proc/vz exists. Detecting as openvz guest") virtualization[:system] = "openvz" virtualization[:role] = "guest" virtualization[:systems][:openvz] = "guest" @@ -119,6 +123,7 @@ # Detect Parallels virtual machine from pci devices if File.exist?("/proc/bus/pci/devices") if File.read("/proc/bus/pci/devices") =~ /1ab84000/ + Ohai::Log.debug("Plugin Virtualization: /proc/bus/pci/devices contains '1ab84000' pci device. Detecting as parallels guest") virtualization[:system] = "parallels" virtualization[:role] = "guest" virtualization[:systems][:parallels] = "guest" @@ -129,6 +134,7 @@ if File.exist?("/usr/sbin/dmidecode") guest = guest_from_dmi(shell_out("dmidecode").stdout) if guest + Ohai::Log.debug("Plugin Virtualization: dmidecode contains string indicating #{guest} guest") virtualization[:system] = guest virtualization[:role] = "guest" virtualization[:systems][guest.to_sym] = "guest" @@ -142,16 +148,18 @@ if vxid && vxid[2] virtualization[:system] = "linux-vserver" if vxid[2] == "0" + Ohai::Log.debug("Plugin Virtualization: /proc/self/status contains 's_context' or 'VxID' with a value of 0. Detecting as linux-vserver host") virtualization[:role] = "host" virtualization[:systems]["linux-vserver"] = "host" else + Ohai::Log.debug("Plugin Virtualization: /proc/self/status contains 's_context' or 'VxID' with a non-0 value. Detecting as linux-vserver guest") virtualization[:role] = "guest" virtualization[:systems]["linux-vserver"] = "guest" end end end - # Detect LXC/Docker + # Detect LXC/Docker/Nspawn # # /proc/self/cgroup will look like this inside a docker container: # ::/lxc/ @@ -172,15 +180,27 @@ if File.exist?("/proc/self/cgroup") cgroup_content = File.read("/proc/self/cgroup") if cgroup_content =~ %r{^\d+:[^:]+:/(lxc|docker)/.+$} || - cgroup_content =~ %r{^\d+:[^:]+:/[^/]+/(lxc|docker)-.+$} + cgroup_content =~ %r{^\d+:[^:]+:/[^/]+/(lxc|docker)-?.+$} + Ohai::Log.debug("Plugin Virtualization: /proc/self/cgroup indicates #{$1} container. Detecting as #{$1} guest") virtualization[:system] = $1 virtualization[:role] = "guest" virtualization[:systems][$1.to_sym] = "guest" + elsif File.read("/proc/1/environ") =~ /container=lxc/ + Ohai::Log.debug("Plugin Virtualization: /proc/1/environ indicates lxc container. Detecting as lxc guest") + virtualization[:system] = "lxc" + virtualization[:role] = "guest" + virtualization[:systems][:lxc] = "guest" + elsif File.read("/proc/1/environ") =~ /container=systemd-nspawn/ + Ohai::Log.debug("Plugin Virtualization: /proc/1/environ indicates nspawn container. Detecting as nspawn guest") + virtualization[:system] = "nspawn" + virtualization[:role] = "guest" + virtualization[:systems][:nspawn] = "guest" elsif lxc_version_exists? && File.read("/proc/self/cgroup") =~ %r{\d:[^:]+:/$} # lxc-version shouldn't be installed by default # Even so, it is likely we are on an LXC capable host that is not being used as such # So we're cautious here to not overwrite other existing values (OHAI-573) unless virtualization[:system] && virtualization[:role] + Ohai::Log.debug("Plugin Virtualization: /proc/self/cgroup and lxc-version command exist. Detecting as lxc host") virtualization[:system] = "lxc" virtualization[:role] = "host" end @@ -190,6 +210,7 @@ virtualization[:systems][:lxc] = "host" end elsif File.exist?("/.dockerenv") || File.exist?("/.dockerinit") + Ohai::Log.debug("Plugin Virtualization: .dockerenv or .dockerinit exist. Detecting as docker guest") virtualization[:system] = "docker" virtualization[:role] = "guest" virtualization[:systems][:docker] = "guest" @@ -198,9 +219,11 @@ # Detect LXD # See https://github.com/lxc/lxd/blob/master/doc/dev-lxd.md if File.exist?("/dev/lxd/sock") + Ohai::Log.debug("Plugin Virtualization: /dev/lxd/sock exists. Detecting as lxd guest") virtualization[:system] = "lxd" virtualization[:role] = "guest" elsif File.exist?("/var/lib/lxd/devlxd") + Ohai::Log.debug("Plugin Virtualization: /var/lib/lxd/devlxd exists. Detecting as lxd host") virtualization[:system] = "lxd" virtualization[:role] = "host" end diff -Nru ohai-8.21.0/lib/ohai/plugins/lua.rb ohai-13.8.0/lib/ohai/plugins/lua.rb --- ohai-8.21.0/lib/ohai/plugins/lua.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/lua.rb 2018-03-16 11:24:35.000000000 +0000 @@ -27,11 +27,13 @@ # Lua 5.2.4 Copyright (C) 1994-2015 Lua.org, PUC-Rio if so.exitstatus == 0 lua = Mash.new - lua[:version] = so.stderr.split[1] + # 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 - Ohai::Log.debug('Lua plugin: Could not shell_out "lua -v". Skipping plugin') + Ohai::Log.debug('Plugin Lua: Could not shell_out "lua -v". Skipping plugin') end end end diff -Nru ohai-8.21.0/lib/ohai/plugins/mono.rb ohai-13.8.0/lib/ohai/plugins/mono.rb --- ohai-8.21.0/lib/ohai/plugins/mono.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/mono.rb 2018-03-16 11:24:35.000000000 +0000 @@ -44,7 +44,7 @@ languages[:mono] = mono unless mono.empty? end rescue Ohai::Exceptions::Exec - Ohai::Log.debug('Mono plugin: Could not shell_out "mono -V". Skipping plugin') + Ohai::Log.debug('Plugin Mono: Could not shell_out "mono -V". Skipping plugin') end end end diff -Nru ohai-8.21.0/lib/ohai/plugins/netbsd/network.rb ohai-13.8.0/lib/ohai/plugins/netbsd/network.rb --- ohai-8.21.0/lib/ohai/plugins/netbsd/network.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/netbsd/network.rb 2018-03-16 11:24:35.000000000 +0000 @@ -39,7 +39,7 @@ end iface = Mash.new - so = shell_out("#{ Ohai.abs_path( "/sbin/ifconfig" )} -a") + so = shell_out("#{Ohai.abs_path( "/sbin/ifconfig" )} -a") cint = nil so.stdout.lines do |line| if line =~ /^([0-9a-zA-Z\.]+):\s+/ diff -Nru ohai-8.21.0/lib/ohai/plugins/network_listeners.rb ohai-13.8.0/lib/ohai/plugins/network_listeners.rb --- ohai-8.21.0/lib/ohai/plugins/network_listeners.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/network_listeners.rb 1970-01-01 00:00:00.000000000 +0000 @@ -1,60 +0,0 @@ -# -# Author:: Doug MacEachern -# Copyright:: Copyright (c) 2009 VMware, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -Ohai.plugin(:NetworkListeners) do - provides "network/listeners" - - depends "network", "counters/network" - - collect_data do - begin - require "sigar" - flags = Sigar::NETCONN_TCP | Sigar::NETCONN_SERVER - - network Mash.new unless network - listeners = Mash.new - - sigar = Sigar.new - sigar.net_connection_list(flags).each do |conn| - port = conn.local_port - addr = conn.local_address.to_s - if addr == "0.0.0.0" || addr == "::" - addr = "*" - end - listeners[port] = Mash.new - listeners[port][:address] = addr - begin - pid = sigar.proc_port(conn.type, port) - # workaround for a failure of proc_state to throw - # after the first 0 has been supplied to it - # - # no longer required when hyperic/sigar#48 is fixed - throw ArgumentError.new("No such process") if pid == 0 - listeners[port][:pid] = pid - listeners[port][:name] = sigar.proc_state(pid).name - rescue - end - end - - network[:listeners] = Mash.new - network[:listeners][:tcp] = listeners - rescue LoadError - Ohai::Log.debug("Could not load sigar gem. Skipping NetworkListeners plugin") - end - end -end diff -Nru ohai-8.21.0/lib/ohai/plugins/network.rb ohai-13.8.0/lib/ohai/plugins/network.rb --- ohai-8.21.0/lib/ohai/plugins/network.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/network.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,10 +16,9 @@ # limitations under the License. # -require "ipaddress" -require "ohai/mixin/network_constants" - Ohai.plugin(:NetworkAddresses) do + require "ipaddress" + require "ohai/mixin/network_constants" include Ohai::Mixin::NetworkConstants provides "ipaddress", "ip6address", "macaddress" @@ -77,13 +76,13 @@ v[:iface] == network[int_attr] end if gw_if_ips.empty? - Ohai::Log.warn("[#{family}] no ip address on #{network[int_attr]}") + Ohai::Log.warn("Plugin Network: [#{family}] no ip address on #{network[int_attr]}") elsif network[gw_attr] && network["interfaces"][network[int_attr]] && network["interfaces"][network[int_attr]]["addresses"] if [ "0.0.0.0", "::", /^fe80:/ ].any? { |pat| pat === network[gw_attr] } # link level default route - Ohai::Log.debug("link level default #{family} route, picking ip from #{network[gw_attr]}") + Ohai::Log.debug("Plugin Network: link level default #{family} route, picking ip from #{network[gw_attr]}") r = gw_if_ips.first else # checking network masks @@ -92,9 +91,9 @@ end.first if r.nil? r = gw_if_ips.first - Ohai::Log.debug("[#{family}] no ipaddress/mask on #{network[int_attr]} matching the gateway #{network[gw_attr]}, picking #{r[:ipaddress]}") + Ohai::Log.debug("Plugin Network: [#{family}] no ipaddress/mask on #{network[int_attr]} matching the gateway #{network[gw_attr]}, picking #{r[:ipaddress]}") else - Ohai::Log.debug("[#{family}] Using default interface #{network[int_attr]} and default gateway #{network[gw_attr]} to set the default ip to #{r[:ipaddress]}") + Ohai::Log.debug("Plugin Network: [#{family}] Using default interface #{network[int_attr]} and default gateway #{network[gw_attr]} to set the default ip to #{r[:ipaddress]}") end end else @@ -103,7 +102,7 @@ end else r = ips.first - Ohai::Log.debug("[#{family}] no default interface, picking the first ipaddress") + Ohai::Log.debug("Plugin Network: [#{family}] no default interface, picking the first ipaddress") end return [ nil, nil ] if r.nil? || r.empty? @@ -149,13 +148,13 @@ # don't overwrite attributes if they've already been set by the "#{os}::network" plugin if (family == "inet") && ipaddress.nil? if r["ip"].nil? - Ohai::Log.warn("unable to detect ipaddress") + Ohai::Log.warn("Plugin Network: unable to detect ipaddress") else ipaddress r["ip"] end elsif (family == "inet6") && ip6address.nil? if r["ip"].nil? - Ohai::Log.debug("unable to detect ip6address") + Ohai::Log.debug("Plugin Network: unable to detect ip6address") else ip6address r["ip"] end @@ -165,10 +164,10 @@ # otherwise we set macaddress on a first-found basis (and we started with ipv4) if macaddress.nil? if r["mac"] - Ohai::Log.debug("setting macaddress to '#{r["mac"]}' from interface '#{r["iface"]}' for family '#{family}'") + Ohai::Log.debug("Plugin Network: setting macaddress to '#{r["mac"]}' from interface '#{r["iface"]}' for family '#{family}'") macaddress r["mac"] else - Ohai::Log.debug("unable to detect macaddress for family '#{family}'") + Ohai::Log.debug("Plugin Network: unable to detect macaddress for family '#{family}'") end end @@ -177,7 +176,7 @@ if results["inet"]["iface"] && results["inet6"]["iface"] && (results["inet"]["iface"] != results["inet6"]["iface"]) - Ohai::Log.debug("ipaddress and ip6address are set from different interfaces (#{results["inet"]["iface"]} & #{results["inet6"]["iface"]})") + Ohai::Log.debug("Plugin Network: ipaddress and ip6address are set from different interfaces (#{results["inet"]["iface"]} & #{results["inet6"]["iface"]})") end end end diff -Nru ohai-8.21.0/lib/ohai/plugins/nodejs.rb ohai-13.8.0/lib/ohai/plugins/nodejs.rb --- ohai-8.21.0/lib/ohai/plugins/nodejs.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/nodejs.rb 2018-03-16 11:24:35.000000000 +0000 @@ -34,7 +34,7 @@ languages[:nodejs] = nodejs if nodejs[:version] end rescue Ohai::Exceptions::Exec - Ohai::Log.debug('Nodejs plugin: Could not shell_out "node -v". Skipping plugin') + Ohai::Log.debug('Plugin Nodejs: Could not shell_out "node -v". Skipping plugin') end end end diff -Nru ohai-8.21.0/lib/ohai/plugins/openbsd/network.rb ohai-13.8.0/lib/ohai/plugins/openbsd/network.rb --- ohai-8.21.0/lib/ohai/plugins/openbsd/network.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/openbsd/network.rb 2018-03-16 11:24:35.000000000 +0000 @@ -39,7 +39,7 @@ end iface = Mash.new - so = shell_out( "#{ Ohai.abs_path( "/sbin/ifconfig" ) } -a" ) + so = shell_out( "#{Ohai.abs_path( "/sbin/ifconfig" )} -a" ) cint = nil so.stdout.lines do |line| if line =~ /^([0-9a-zA-Z\.]+):\s+/ diff -Nru ohai-8.21.0/lib/ohai/plugins/openstack.rb ohai-13.8.0/lib/ohai/plugins/openstack.rb --- ohai-8.21.0/lib/ohai/plugins/openstack.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/openstack.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,10 +16,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -require "ohai/mixin/ec2_metadata" - Ohai.plugin(:Openstack) do + require "ohai/mixin/ec2_metadata" + require "ohai/mixin/http_helper" include Ohai::Mixin::Ec2Metadata + include Ohai::Mixin::HttpHelper provides "openstack" depends "dmi" @@ -30,10 +31,10 @@ # detect a manufacturer of OpenStack Foundation if get_attribute(:dmi, :system, :all_records, 0, :Manufacturer) =~ /OpenStack/ Ohai::Log.debug("Plugin Openstack: has_openstack_dmi? == true") - return true + true else Ohai::Log.debug("Plugin Openstack: has_openstack_dmi? == false") - return false + false end end @@ -41,17 +42,17 @@ def openstack_hint? if hint?("openstack") Ohai::Log.debug("Plugin Openstack: openstack hint present") - return true + true else Ohai::Log.debug("Plugin Openstack: openstack hint not present") - return false + false end end # dreamhost systems have the dhc-user on them def openstack_provider return "dreamhost" if get_attribute("etc", "passwd", "dhc-user") - return "openstack" + "openstack" end collect_data do @@ -61,7 +62,7 @@ openstack[:provider] = openstack_provider # fetch the metadata if we can do a simple socket connect first - if can_metadata_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80) + if can_socket_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80) fetch_metadata.each do |k, v| openstack[k] = v end diff -Nru ohai-8.21.0/lib/ohai/plugins/os.rb ohai-13.8.0/lib/ohai/plugins/os.rb --- ohai-8.21.0/lib/ohai/plugins/os.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/os.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,9 +16,8 @@ # limitations under the License. # -require "ohai/mixin/os" - Ohai.plugin(:OS) do + require "ohai/mixin/os" provides "os", "os_version" depends "kernel" diff -Nru ohai-8.21.0/lib/ohai/plugins/packages.rb ohai-13.8.0/lib/ohai/plugins/packages.rb --- ohai-8.21.0/lib/ohai/plugins/packages.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/packages.rb 2018-03-16 11:24:35.000000000 +0000 @@ -22,15 +22,18 @@ provides "packages" depends "platform_family" - WINDOWS_ATTRIBUTE_ALIASES = { - "DisplayVersion" => "version", - "Publisher" => "publisher", - "InstallDate" => "installdate", - } unless defined?(WINDOWS_ATTRIBUTE_ALIASES) + unless defined?(WINDOWS_ATTRIBUTE_ALIASES) + WINDOWS_ATTRIBUTE_ALIASES = { + "DisplayVersion" => "version", + "Publisher" => "publisher", + "InstallDate" => "installdate", + } + end collect_data(:linux) do packages Mash.new - if %w{debian}.include? platform_family + case platform_family + when "debian" format = '${Package}\t${Version}\t${Architecture}\n' so = shell_out("dpkg-query -W -f='#{format}'") pkgs = so.stdout.lines @@ -40,7 +43,7 @@ packages[name] = { "version" => version, "arch" => arch } end - elsif %w{rhel fedora suse pld}.include? platform_family + when "rhel", "fedora", "suse", "pld", "amazon" format = '%{NAME}\t%|EPOCH?{%{EPOCH}}:{0}|\t%{VERSION}\t%{RELEASE}\t%{INSTALLTIME}\t%{ARCH}\n' so = shell_out("rpm -qa --qf '#{format}'") pkgs = so.stdout.lines @@ -49,6 +52,31 @@ name, epoch, version, release, installdate, arch = pkg.split packages[name] = { "epoch" => epoch, "version" => version, "release" => release, "installdate" => installdate, "arch" => arch } end + + when "arch" + require "date" + + # Set LANG=C to force an easy to parse date format + so = shell_out("LANG=C pacman -Qi") + + so.stdout.split("\n\n").each do |record| + pacman_info = {} + record.lines.each do |line| + if line =~ /\A(.*?)\s+:\s(.*)\z/m + key, value = Regexp.last_match[1..2] + key = key.strip.downcase.gsub(/\s+/, "") + pacman_info[key] = value.strip + end + end + + name = pacman_info["name"] + installdate = DateTime.strptime(pacman_info["installdate"], "%Ec").strftime("%s") + packages[name] = { + "version" => pacman_info["version"], + "installdate" => installdate, + "arch" => pacman_info["architecture"], + } + end end end @@ -92,8 +120,14 @@ # Package Name:Fileset:Level # On aix, filesets are packages and levels are versions pkgs.each do |pkg| - _, name, version = pkg.split(":") - packages[name] = { "version" => version } + name, fileset, version, _, _, _, pkg_type = pkg.split(":") + if pkg_type == "R" + # RPM + packages[name] = { "version" => version } + else + # LPP + packages[fileset] = { "version" => version } + end end end diff -Nru ohai-8.21.0/lib/ohai/plugins/passwd.rb ohai-13.8.0/lib/ohai/plugins/passwd.rb --- ohai-8.21.0/lib/ohai/plugins/passwd.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/passwd.rb 2018-03-16 11:24:35.000000000 +0000 @@ -1,7 +1,6 @@ -require "etc" - Ohai.plugin(:Passwd) do + require "etc" provides "etc", "current_user" def fix_encoding(str) diff -Nru ohai-8.21.0/lib/ohai/plugins/perl.rb ohai-13.8.0/lib/ohai/plugins/perl.rb --- ohai-8.21.0/lib/ohai/plugins/perl.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/perl.rb 2018-03-16 11:24:35.000000000 +0000 @@ -39,7 +39,7 @@ languages[:perl] = perl unless perl.empty? end rescue Ohai::Exceptions::Exec - Ohai::Log.debug('Perl plugin: Could not shell_out "perl -V:version -V:archname". Skipping plugin') + Ohai::Log.debug('Plugin Perl: Could not shell_out "perl -V:version -V:archname". Skipping plugin') end end end diff -Nru ohai-8.21.0/lib/ohai/plugins/php.rb ohai-13.8.0/lib/ohai/plugins/php.rb --- ohai-8.21.0/lib/ohai/plugins/php.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/php.rb 2018-03-16 11:24:35.000000000 +0000 @@ -46,7 +46,7 @@ languages[:php] = php unless php.empty? end rescue Ohai::Exceptions::Exec - Ohai::Log.debug('Php plugin: Could not shell_out "php -v". Skipping plugin') + Ohai::Log.debug('Plugin Php: Could not shell_out "php -v". Skipping plugin') end end end diff -Nru ohai-8.21.0/lib/ohai/plugins/powershell.rb ohai-13.8.0/lib/ohai/plugins/powershell.rb --- ohai-8.21.0/lib/ohai/plugins/powershell.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/powershell.rb 2018-03-16 11:24:35.000000000 +0000 @@ -51,7 +51,7 @@ languages[:powershell] = powershell unless powershell.empty? end rescue Ohai::Exceptions::Exec - Ohai::Log.debug('Powershell plugin: Could not shell_out "powershell.exe -NoLogo -NonInteractive -NoProfile -command $PSVersionTable". Skipping plugin') + Ohai::Log.debug('Plugin Powershell: Could not shell_out "powershell.exe -NoLogo -NonInteractive -NoProfile -command $PSVersionTable". Skipping plugin') end end diff -Nru ohai-8.21.0/lib/ohai/plugins/python.rb ohai-13.8.0/lib/ohai/plugins/python.rb --- ohai-8.21.0/lib/ohai/plugins/python.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/python.rb 2018-03-16 11:24:35.000000000 +0000 @@ -37,7 +37,7 @@ languages[:python] = python unless python.empty? end rescue Ohai::Exceptions::Exec - Ohai::Log.debug('Python plugin: Could not shell_out "python -c "import sys; print (sys.version)"". Skipping plugin') + Ohai::Log.debug('Plugin Python: Could not shell_out "python -c "import sys; print (sys.version)"". Skipping plugin') end end end diff -Nru ohai-8.21.0/lib/ohai/plugins/rackspace.rb ohai-13.8.0/lib/ohai/plugins/rackspace.rb --- ohai-8.21.0/lib/ohai/plugins/rackspace.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/rackspace.rb 2018-03-16 11:24:35.000000000 +0000 @@ -14,9 +14,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -require "resolv" - Ohai.plugin(:Rackspace) do + require "resolv" provides "rackspace" depends "kernel", "network/interfaces" @@ -38,19 +37,33 @@ def has_rackspace_metadata? so = shell_out("xenstore-read vm-data/provider_data/provider") if so.exitstatus == 0 - so.stdout.strip.casecmp("rackspace").zero? + so.stdout.strip.casecmp("rackspace") == 0 end rescue Ohai::Exceptions::Exec false end + # Checks for the rackspace manufacturer on Windows + # === Return + # true:: If the rackspace cloud can be identified + # false:: Otherwise + def has_rackspace_manufacturer? + return false unless RUBY_PLATFORM =~ /mswin|mingw32|windows/ + require "wmi-lite/wmi" + wmi = WmiLite::Wmi.new + if wmi.first_of("Win32_ComputerSystem")["PrimaryOwnerName"] == "Rackspace" + Ohai::Log.debug("Plugin Rackspace: has_rackspace_manufacturer? == true") + return true + end + end + # Identifies the rackspace cloud # # === Return # true:: If the rackspace cloud can be identified # false:: Otherwise def looks_like_rackspace? - hint?("rackspace") || has_rackspace_metadata? || has_rackspace_kernel? + hint?("rackspace") || has_rackspace_metadata? || has_rackspace_kernel? || has_rackspace_manufacturer? end # Names rackspace ip address @@ -84,7 +97,7 @@ # Get the rackspace region # - def get_region() + def get_region so = shell_out("xenstore-ls vm-data/provider_data") if so.exitstatus == 0 so.stdout.split("\n").each do |line| @@ -92,25 +105,25 @@ end end rescue Ohai::Exceptions::Exec - Ohai::Log.debug("rackspace plugin: Unable to find xenstore-ls, cannot capture region information for Rackspace cloud") + Ohai::Log.debug("Plugin Rackspace: Unable to find xenstore-ls, cannot capture region information for Rackspace cloud") nil end # Get the rackspace instance_id # - def get_instance_id() + def get_instance_id so = shell_out("xenstore-read name") if so.exitstatus == 0 rackspace[:instance_id] = so.stdout.gsub(/instance-/, "") end rescue Ohai::Exceptions::Exec - Ohai::Log.debug("rackspace plugin: Unable to find xenstore-read, cannot capture instance ID information for Rackspace cloud") + Ohai::Log.debug("Plugin Rackspace: Unable to find xenstore-read, cannot capture instance ID information for Rackspace cloud") nil end # Get the rackspace private networks # - def get_private_networks() + def get_private_networks so = shell_out("xenstore-ls vm-data/networking") if so.exitstatus == 0 networks = [] @@ -119,7 +132,7 @@ if so.exitstatus == 0 networks.push(FFI_Yajl::Parser.new.parse(so.stdout)) else - Ohai::Log.debug("rackspace plugin: Unable to capture custom private networking information for Rackspace cloud") + Ohai::Log.debug("Plugin Rackspace: Unable to capture custom private networking information for Rackspace cloud") return false end end @@ -128,7 +141,7 @@ networks.delete_if { |hash| hash["label"] == "public" } end rescue Ohai::Exceptions::Exec - Ohai::Log.debug("rackspace plugin: Unable to capture custom private networking information for Rackspace cloud") + Ohai::Log.debug("Plugin Rackspace: Unable to capture custom private networking information for Rackspace cloud") nil end @@ -138,8 +151,8 @@ rackspace Mash.new get_ip_address(:public_ip, :eth0) get_ip_address(:private_ip, :eth1) - get_region() - get_instance_id() + get_region + get_instance_id # public_ip + private_ip are deprecated in favor of public_ipv4 and local_ipv4 to standardize. rackspace[:public_ipv4] = rackspace[:public_ip] get_global_ipv6_address(:public_ipv6, :eth0) diff -Nru ohai-8.21.0/lib/ohai/plugins/rust.rb ohai-13.8.0/lib/ohai/plugins/rust.rb --- ohai-8.21.0/lib/ohai/plugins/rust.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/rust.rb 2018-03-16 11:24:35.000000000 +0000 @@ -28,7 +28,7 @@ languages[:rust] = rust if rust[:version] end rescue Ohai::Exceptions::Exec - Ohai::Log.debug('Rust plugin: Could not shell_out "rustc --version". Skipping plugin') + Ohai::Log.debug('Plugin Rust: Could not shell_out "rustc --version". Skipping plugin') end end end diff -Nru ohai-8.21.0/lib/ohai/plugins/scala.rb ohai-13.8.0/lib/ohai/plugins/scala.rb --- ohai-8.21.0/lib/ohai/plugins/scala.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/scala.rb 2018-03-16 11:24:35.000000000 +0000 @@ -15,7 +15,7 @@ # limitations under the License. Ohai.plugin(:Scala) do - provides "languages/scala", "languages/scala/sbt" + provides "languages/scala" depends "languages" collect_data(:default) do @@ -23,24 +23,13 @@ begin so = shell_out("scala -version") # Sample output: - # Scala code runner version 2.11.8 -- Copyright 2002-2016, LAMP/EPFL + # cat: /release: No such file or directory + # Scala code runner version 2.12.1 -- Copyright 2002-2016, LAMP/EPFL and Lightbend, Inc. if so.exitstatus == 0 - scala[:version] = so.stderr.split[4] + scala[:version] = so.stderr.match(/.*version (\S*)/)[1] end rescue Ohai::Exceptions::Exec - Ohai::Log.debug('Scala plugin: Could not shell_out "scala -version". Skipping data') - end - - # Check for sbt - begin - # sbt launcher version 0.13.7 - so = shell_out("sbt --version") - if so.exitstatus == 0 - scala[:sbt] = Mash.new - scala[:sbt][:version] = so.stdout.split[3] - end - rescue Ohai::Exceptions::Exec - Ohai::Log.debug('Scala plugin: Could not shell_out "sbt --version". Skipping data') + Ohai::Log.debug('Plugin Scala: Could not shell_out "scala -version". Skipping data') end languages[:scala] = scala unless scala.empty? diff -Nru ohai-8.21.0/lib/ohai/plugins/shard.rb ohai-13.8.0/lib/ohai/plugins/shard.rb --- ohai-8.21.0/lib/ohai/plugins/shard.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/shard.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,9 +16,8 @@ # limitations under the License. # -require "digest/md5" - Ohai.plugin(:ShardSeed) do + require "digest/md5" depends "hostname", "dmi", "machine_id", "machinename" provides "shard_seed" diff -Nru ohai-8.21.0/lib/ohai/plugins/sigar/cpu.rb ohai-13.8.0/lib/ohai/plugins/sigar/cpu.rb --- ohai-8.21.0/lib/ohai/plugins/sigar/cpu.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/sigar/cpu.rb 1970-01-01 00:00:00.000000000 +0000 @@ -1,44 +0,0 @@ -# -# Author:: Doug MacEachern -# Copyright:: Copyright (c) 2010 VMware, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -Ohai.plugin(:CPU) do - provides "cpu" - - collect_data(:hpux, :default) do - require "sigar" - - sigar = Sigar.new - - cpuinfo = Mash.new - ix = 0 - - sigar.cpu_info_list.each do |info| - current_cpu = ix.to_s - ix += 1 - cpuinfo[current_cpu] = Mash.new - cpuinfo[current_cpu]["vendor_id"] = info.vendor - cpuinfo[current_cpu]["model"] = info.model - cpuinfo[current_cpu]["mhz"] = info.mhz.to_s - cpuinfo[current_cpu]["cache_size"] = info.cache_size.to_s - cpuinfo[:total] = info.total_cores - cpuinfo[:real] = info.total_sockets - end - - cpu cpuinfo - end -end diff -Nru ohai-8.21.0/lib/ohai/plugins/sigar/filesystem.rb ohai-13.8.0/lib/ohai/plugins/sigar/filesystem.rb --- ohai-8.21.0/lib/ohai/plugins/sigar/filesystem.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/sigar/filesystem.rb 1970-01-01 00:00:00.000000000 +0000 @@ -1,50 +0,0 @@ -# -# Author:: Doug MacEachern -# Copyright:: Copyright (c) 2010 VMware, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -Ohai.plugin(:Filesystem) do - provides "filesystem" - - collect_data(:hpux, :default) do - require "sigar" - sigar = Sigar.new - - fs = Mash.new - - sigar.file_system_list.each do |fsys| - filesystem = fsys.dev_name - fs[filesystem] = Mash.new - fs[filesystem][:mount] = fsys.dir_name - fs[filesystem][:fs_type] = fsys.sys_type_name - fs[filesystem][:mount_options] = fsys.options - begin - usage = sigar.file_system_usage(fsys.dir_name) - fs[filesystem][:kb_size] = (usage.total / 1024).to_s - fs[filesystem][:kb_used] = ((usage.total - usage.free) / 1024).to_s - fs[filesystem][:kb_available] = (usage.free / 1024).to_s - fs[filesystem][:percent_used] = (usage.use_percent * 100).to_s + "%" - rescue SystemExit => e - raise - rescue Exception => e - #e.g. floppy or cdrom drive - end - end - - # Set the filesystem data - filesystem fs - end -end diff -Nru ohai-8.21.0/lib/ohai/plugins/sigar/memory.rb ohai-13.8.0/lib/ohai/plugins/sigar/memory.rb --- ohai-8.21.0/lib/ohai/plugins/sigar/memory.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/sigar/memory.rb 1970-01-01 00:00:00.000000000 +0000 @@ -1,39 +0,0 @@ -# -# Author:: Doug MacEachern -# Copyright:: Copyright (c) 2010 VMware, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -Ohai.plugin(:Memory) do - provides "memory" - - collect_data(:hpux, :default) do - require "sigar" - sigar = Sigar.new - - memory Mash.new - memory[:swap] = Mash.new - - mem = sigar.mem - swap = sigar.swap - - memory[:total] = (mem.total / 1024).to_s + "kB" - memory[:free] = (mem.free / 1024).to_s + "kB" - memory[:used] = (mem.used / 1024).to_s + "kB" - memory[:swap][:total] = (swap.total / 1024).to_s + "kB" - memory[:swap][:free] = (swap.free / 1024).to_s + "kB" - memory[:swap][:used] = (swap.used / 1024).to_s + "kB" - end -end diff -Nru ohai-8.21.0/lib/ohai/plugins/sigar/network.rb ohai-13.8.0/lib/ohai/plugins/sigar/network.rb --- ohai-8.21.0/lib/ohai/plugins/sigar/network.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/sigar/network.rb 1970-01-01 00:00:00.000000000 +0000 @@ -1,168 +0,0 @@ -# -# Author:: Matthew Kent () -# Copyright:: Copyright (c) 2009 Matthew Kent -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require "ohai/mixin/network_constants" - -Ohai.plugin(:Network) do - include Ohai::Mixin::NetworkConstants - - provides "network", "network/interfaces" - provides "counters/network", "counters/network/interfaces" - - def sigar_encaps_lookup(encap) - return "Loopback" if encap.eql?("Local Loopback") - return "PPP" if encap.eql?("Point-to-Point Protocol") - return "SLIP" if encap.eql?("Serial Line IP") - return "VJSLIP" if encap.eql?("VJ Serial Line IP") - return "IPIP" if encap.eql?("IPIP Tunnel") - return "6to4" if encap.eql?("IPv6-in-IPv4") - encap - end - - def fetch_interfaces(sigar) - iface = Mash.new - net_counters = Mash.new - - sigar.net_interface_list.each do |cint| - iface[cint] = Mash.new - - if cint =~ /^(\w+)(\d+.*)/ - iface[cint][:type] = $1 - iface[cint][:number] = $2 - end - - ifconfig = sigar.net_interface_config(cint) - iface[cint][:encapsulation] = sigar_encaps_lookup(ifconfig.type) - - iface[cint][:addresses] = Mash.new - # Backwards compat: loopback has no hwaddr - if (ifconfig.flags & Sigar::IFF_LOOPBACK) == 0 - iface[cint][:addresses][ifconfig.hwaddr] = { "family" => "lladdr" } - end - if ifconfig.address != "0.0.0.0" - iface[cint][:addresses][ifconfig.address] = { "family" => "inet" } - # Backwards compat: no broadcast on tunnel or loopback dev - if ((ifconfig.flags & Sigar::IFF_POINTOPOINT) == 0) && - ((ifconfig.flags & Sigar::IFF_LOOPBACK) == 0) - iface[cint][:addresses][ifconfig.address]["broadcast"] = ifconfig.broadcast - end - iface[cint][:addresses][ifconfig.address]["netmask"] = ifconfig.netmask - end - - if ifconfig.prefix6_length != 0 - iface[cint][:addresses][ifconfig.address6] = { "family" => "inet6" } - iface[cint][:addresses][ifconfig.address6]["prefixlen"] = ifconfig.prefix6_length.to_s - iface[cint][:addresses][ifconfig.address6]["scope"] = Sigar.net_scope_to_s(ifconfig.scope6) - end - - iface[cint][:flags] = Sigar.net_interface_flags_to_s(ifconfig.flags).split(" ") - iface[cint][:mtu] = ifconfig.mtu.to_s - iface[cint][:queuelen] = ifconfig.tx_queue_len.to_s - - net_counters[cint] = Mash.new unless net_counters[cint] - if !cint.include?(":") - ifstat = sigar.net_interface_stat(cint) - net_counters[cint][:rx] = { "packets" => ifstat.rx_packets.to_s, "errors" => ifstat.rx_errors.to_s, - "drop" => ifstat.rx_dropped.to_s, "overrun" => ifstat.rx_overruns.to_s, - "frame" => ifstat.rx_frame.to_s, "bytes" => ifstat.rx_bytes.to_s } - net_counters[cint][:tx] = { "packets" => ifstat.tx_packets.to_s, "errors" => ifstat.tx_errors.to_s, - "drop" => ifstat.tx_dropped.to_s, "overrun" => ifstat.tx_overruns.to_s, - "carrier" => ifstat.tx_carrier.to_s, "collisions" => ifstat.tx_collisions.to_s, - "bytes" => ifstat.tx_bytes.to_s } - end - end - - begin - sigar.arp_list.each do |arp| - next unless iface[arp.ifname] # this should never happen - iface[arp.ifname][:arp] = Mash.new unless iface[arp.ifname][:arp] - iface[arp.ifname][:arp][arp.address] = arp.hwaddr - end - rescue - #64-bit AIX for example requires 64-bit caller - end - - [iface, net_counters] - end - - # sigar-only, from network_route plugin - def flags(flags) - f = "" - if (flags & Sigar::RTF_UP) != 0 - f += "U" - end - if (flags & Sigar::RTF_GATEWAY) != 0 - f += "G" - end - if (flags & Sigar::RTF_HOST) != 0 - f += "H" - end - f - end - - collect_data(:hpux) do - require "sigar" - sigar = Sigar.new - - network Mash.new unless network - network[:interfaces] = Mash.new unless network[:interfaces] - counters Mash.new unless counters - counters[:network] = Mash.new unless counters[:network] - - ninfo = sigar.net_info - network[:default_interface] = ninfo.default_gateway_interface - network[:default_gateway] = ninfo.default_gateway - - iface, net_counters = fetch_interfaces(sigar) - counters[:network][:interfaces] = net_counters - network["interfaces"] = iface - end - - collect_data(:default) do - require "sigar" - sigar = Sigar.new - - network Mash.new unless network - network[:interfaces] = Mash.new unless network[:interfaces] - counters Mash.new unless counters - counters[:network] = Mash.new unless counters[:network] - - ninfo = sigar.net_info - network[:default_interface] = ninfo.default_gateway_interface - network[:default_gateway] = ninfo.default_gateway - - iface, net_counters = fetch_interfaces(sigar) - counters[:network][:interfaces] = net_counters - network[:interfaces] = iface - - sigar.net_route_list.each do |route| - next unless network[:interfaces][route.ifname] # this - # should never happen - network[:interfaces][route.ifname][:route] = Mash.new unless network[:interfaces][route.ifname][:route] - route_data = {} - Ohai::Mixin::NetworkConstants::SIGAR_ROUTE_METHODS.each do |m| - if m == :flags - route_data[m] = flags(route.send(m)) - else - route_data[m] = route.send(m) - end - end - network[:interfaces][route.ifname][:route][route.destination] = route_data - end - end -end diff -Nru ohai-8.21.0/lib/ohai/plugins/sigar/network_route.rb ohai-13.8.0/lib/ohai/plugins/sigar/network_route.rb --- ohai-8.21.0/lib/ohai/plugins/sigar/network_route.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/sigar/network_route.rb 1970-01-01 00:00:00.000000000 +0000 @@ -1,64 +0,0 @@ -# -# Author:: Toomas Pelberg () -# Copyright:: Copyright (c) 2011-2016 Chef Software, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require "ohai/mixin/network_constants" - -Ohai.plugin(:NetworkRoutes) do - begin - require "sigar" - - include Ohai::Mixin::NetworkConstants - - provides "network/interfaces/adapters/route" - depends "network/interfaces" - - def flags(flags) - f = "" - if (flags & Sigar::RTF_UP) != 0 - f += "U" - end - if (flags & Sigar::RTF_GATEWAY) != 0 - f += "G" - end - if (flags & Sigar::RTF_HOST) != 0 - f += "H" - end - f - end - - collect_data(:default) do - sigar = Sigar.new - - sigar.net_route_list.each do |route| - next unless network[:interfaces][route.ifname] # this should never happen - network[:interfaces][route.ifname][:route] = Mash.new unless network[:interfaces][route.ifname][:route] - route_data = {} - Ohai::Mixin::NetworkConstants::SIGAR_ROUTE_METHODS.each do |m| - if m == :flags - route_data[m] = flags(route.send(m)) - else - route_data[m] = route.send(m) - end - end - network[:interfaces][route.ifname][:route][route.destination] = route_data - end - end - rescue LoadError - Ohai::Log.debug("Could not load sigar gem. Skipping NetworkRoutes plugin") - end -end diff -Nru ohai-8.21.0/lib/ohai/plugins/sigar/platform.rb ohai-13.8.0/lib/ohai/plugins/sigar/platform.rb --- ohai-8.21.0/lib/ohai/plugins/sigar/platform.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/sigar/platform.rb 1970-01-01 00:00:00.000000000 +0000 @@ -1,30 +0,0 @@ -# -# Author:: Doug MacEachern -# Copyright:: Copyright (c) 2010 VMware, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -Ohai.plugin(:Platform) do - provides "platform", "platform_version", "platform_family" - - collect_data(:hpux) do - require "sigar" - sys = Sigar.new.sys_info - - platform sys.name.downcase - platform_version sys.version - platform_family platform - end -end diff -Nru ohai-8.21.0/lib/ohai/plugins/softlayer.rb ohai-13.8.0/lib/ohai/plugins/softlayer.rb --- ohai-8.21.0/lib/ohai/plugins/softlayer.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/softlayer.rb 2018-03-16 11:24:35.000000000 +0000 @@ -18,9 +18,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -require "ohai/mixin/softlayer_metadata" - Ohai.plugin(:Softlayer) do + require "ohai/mixin/softlayer_metadata" include ::Ohai::Mixin::SoftlayerMetadata provides "softlayer" diff -Nru ohai-8.21.0/lib/ohai/plugins/solaris2/dmi.rb ohai-13.8.0/lib/ohai/plugins/solaris2/dmi.rb --- ohai-8.21.0/lib/ohai/plugins/solaris2/dmi.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/solaris2/dmi.rb 2018-03-16 11:24:35.000000000 +0000 @@ -25,7 +25,7 @@ # if we already have a "dmi" with keys (presumably from dmidecode), don't try smbios # note that a single key just means dmidecode exited with its version if (dmi.class.to_s == "Mash") && (dmi.keys.length > 1) - Ohai::Log.debug("skipping smbios output, since DMI information has already been provided") + Ohai::Log.debug("Plugin DMI: skipping smbios output, since DMI information has already been provided") return end @@ -118,7 +118,7 @@ # remove/replace any characters that don't fall inside permissible ASCII range, or whitespace line = raw_line.gsub(/[^\x20-\x7E\n\t\r]/, ".") if line != raw_line - Ohai::Log.debug("converted characters from line:\n#{raw_line}") + Ohai::Log.debug("Plugin DMI: converted characters from line:\n#{raw_line}") end if header_information = header_information_line.match(line) @@ -137,7 +137,7 @@ dmi_record[:type] = Ohai::Common::DMI.id_lookup(id) else - Ohai::Log.debug("unrecognized header type; skipping") + Ohai::Log.debug("Plugin DMI: unrecognized header type; skipping") dmi_record = nil next end @@ -152,28 +152,28 @@ field = nil elsif data = data_key_value_line.match(line) - if dmi_record == nil - Ohai::Log.debug("unexpected data line found before header; discarding:\n#{line}") + if dmi_record.nil? + Ohai::Log.debug("Plugin DMI: unexpected data line found before header; discarding:\n#{line}") next end dmi[dmi_record[:type]][:all_records][dmi_record[:position]][data[1]] = data[2] field = data[1] elsif data = data_key_only_line.match(line) - if dmi_record == nil - Ohai::Log.debug("unexpected data line found before header; discarding:\n#{line}") + if dmi_record.nil? + Ohai::Log.debug("Plugin DMI: unexpected data line found before header; discarding:\n#{line}") next end dmi[dmi_record[:type]][:all_records][dmi_record[:position]][data[1]] = "" field = data[1] elsif extended_data = extended_data_line.match(line) - if dmi_record == nil - Ohai::Log.debug("unexpected extended data line found before header; discarding:\n#{line}") + if dmi_record.nil? + Ohai::Log.debug("Plugin DMI: unexpected extended data line found before header; discarding:\n#{line}") next end - if field == nil - Ohai::Log.debug("unexpected extended data line found outside data section; discarding:\n#{line}") + if field.nil? + Ohai::Log.debug("Plugin DMI: unexpected extended data line found outside data section; discarding:\n#{line}") next end # overwrite "raw" value with a new Mash @@ -181,7 +181,7 @@ dmi[dmi_record[:type]][:all_records][dmi_record[:position]][field][extended_data[1]] = extended_data[2] else - Ohai::Log.debug("unrecognized output line; discarding:\n#{line}") + Ohai::Log.debug("Plugin DMI: unrecognized output line; discarding:\n#{line}") end end diff -Nru ohai-8.21.0/lib/ohai/plugins/solaris2/network.rb ohai-13.8.0/lib/ohai/plugins/solaris2/network.rb --- ohai-8.21.0/lib/ohai/plugins/solaris2/network.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/solaris2/network.rb 2018-03-16 11:24:35.000000000 +0000 @@ -54,11 +54,13 @@ # inet6 fe80::203:baff:fe17:4444/128 # Extracted from http://illumos.org/hcl/ -ETHERNET_ENCAPS = %w{ afe amd8111s arn atge ath bfe bge bnx bnxe ce cxgbe - dmfe e1000g efe elxl emlxs eri hermon hme hxge igb - iprb ipw iwh iwi iwk iwp ixgb ixgbe mwl mxfe myri10ge - nge ntxn nxge pcn platform qfe qlc ral rge rtls rtw rwd - rwn sfe tavor vr wpi xge yge aggr} unless defined?(ETHERNET_ENCAPS) +unless defined?(ETHERNET_ENCAPS) + ETHERNET_ENCAPS = %w{ afe amd8111s arn atge ath bfe bge bnx bnxe ce cxgbe + dmfe e1000g efe elxl emlxs eri hermon hme hxge igb + iprb ipw iwh iwi iwk iwp ixgb ixgbe mwl mxfe myri10ge + nge ntxn nxge pcn platform qfe qlc ral rge rtls rtw rwd + rwn sfe tavor vr wpi xge yge aggr} +end Ohai.plugin(:Network) do provides "network", "network/interfaces" @@ -101,7 +103,8 @@ cint = nil so.stdout.lines do |line| - if line =~ /^([0-9a-zA-Z\.\:\-]+)\S/ + # regex: http://rubular.com/r/Iag7JLVTVe + if line =~ /^([0-9a-zA-Z\.\:\-]+): \S+ mtu (\d+) index (\d+)/ cint = $1 iface[cint] = Mash.new unless iface[cint] iface[cint][:mtu] = $2 @@ -178,11 +181,11 @@ else matches[:name] end - Ohai::Log.debug("found interface device: #{network[:default_interface]} #{matches[:name]}") + Ohai::Log.debug("Plugin Network: found interface device: #{network[:default_interface]} #{matches[:name]}") end matches = /gateway: (\S+)/.match(line) if matches - Ohai::Log.debug("found gateway: #{matches[1]}") + Ohai::Log.debug("Plugin Network: found gateway: #{matches[1]}") network[:default_gateway] = matches[1] end end diff -Nru ohai-8.21.0/lib/ohai/plugins/solaris2/virtualization.rb ohai-13.8.0/lib/ohai/plugins/solaris2/virtualization.rb --- ohai-8.21.0/lib/ohai/plugins/solaris2/virtualization.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/solaris2/virtualization.rb 2018-03-16 11:24:35.000000000 +0000 @@ -18,9 +18,8 @@ # limitations under the License. # -require "ohai/mixin/dmi_decode" - Ohai.plugin(:Virtualization) do + require "ohai/mixin/dmi_decode" include Ohai::Mixin::DmiDecode provides "virtualization" @@ -74,7 +73,11 @@ if zones.length == 1 first_zone = zones.keys[0] - unless first_zone == "global" + if first_zone == "global" + virtualization[:system] = "zone" + virtualization[:role] = "host" + virtualization[:systems][:zone] = "host" + else virtualization[:system] = "zone" virtualization[:role] = "guest" virtualization[:systems][:zone] = "guest" diff -Nru ohai-8.21.0/lib/ohai/plugins/solaris2/zpools.rb ohai-13.8.0/lib/ohai/plugins/solaris2/zpools.rb --- ohai-8.21.0/lib/ohai/plugins/solaris2/zpools.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/solaris2/zpools.rb 1970-01-01 00:00:00.000000000 +0000 @@ -1,64 +0,0 @@ -# -# Author:: Jason J. W. Williams (williamsjj@digitar.com) -# Copyright:: Copyright (c) 2011-2016 Chef Software, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -Ohai.plugin(:Zpools) do - provides "zpools" - - collect_data(:solaris2) do - pools = Mash.new - - # Grab ZFS zpools overall health and attributes - so = shell_out("zpool list -H -o name,size,alloc,free,cap,dedup,health,version") - so.stdout.lines do |line| - case line - when /^([-_0-9A-Za-z]*)\s+([.0-9]+[MGTPE])\s+([.0-9]+[MGTPE])\s+([.0-9]+[MGTPE])\s+(\d+%)\s+([.0-9]+x)\s+([-_0-9A-Za-z]+)\s+(\d+|-)$/ - pools[$1] = Mash.new - pools[$1][:pool_size] = $2 - pools[$1][:pool_allocated] = $3 - pools[$1][:pool_free] = $4 - pools[$1][:capacity_used] = $5 - pools[$1][:dedup_factor] = $6 - pools[$1][:health] = $7 - pools[$1][:zpool_version] = $8 - end - end - - # Grab individual health for devices in the zpools - pools.keys.each do |pool| - pools[pool][:devices] = Mash.new - # Run "zpool status" as non-root user (adm) so that - # the command won't try to open() each device which can - # hang the command if any of the disks are bad. - so = shell_out("su adm -c \"zpool status #{pool}\"") - so.stdout.lines do |line| - case line - when /^\s+(c[-_a-zA-Z0-9]+)\s+([-_a-zA-Z0-9]+)\s+(\d+)\s+(\d+)\s+(\d+)$/ - pools[pool][:devices][$1] = Mash.new - pools[pool][:devices][$1][:state] = $2 - pools[pool][:devices][$1][:errors] = Mash.new - pools[pool][:devices][$1][:errors][:read] = $3 - pools[pool][:devices][$1][:errors][:write] = $4 - pools[pool][:devices][$1][:errors][:checksum] = $5 - end - end - end - - # Set the zpools data - zpools pools - end -end diff -Nru ohai-8.21.0/lib/ohai/plugins/ssh_host_key.rb ohai-13.8.0/lib/ohai/plugins/ssh_host_key.rb --- ohai-8.21.0/lib/ohai/plugins/ssh_host_key.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/ssh_host_key.rb 2018-03-16 11:24:35.000000000 +0000 @@ -44,7 +44,7 @@ # Darwin "/etc/sshd_config" else - Ohai::Log.debug("Failed to find sshd configuration file") + Ohai::Log.debug("Plugin SSHHostKey: Failed to find sshd configuration file") nil end diff -Nru ohai-8.21.0/lib/ohai/plugins/sysconf.rb ohai-13.8.0/lib/ohai/plugins/sysconf.rb --- ohai-8.21.0/lib/ohai/plugins/sysconf.rb 1970-01-01 00:00:00.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/sysconf.rb 2018-03-16 11:24:35.000000000 +0000 @@ -0,0 +1,45 @@ +# +# Author:: Davide Cavalca +# Copyright:: Copyright (c) 2016 Facebook +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +Ohai.plugin(:Sysconf) do + provides "sysconf" + + collect_data(:aix, :linux, :solaris2) do + getconf_path = which("getconf") + if getconf_path + getconf = shell_out("#{getconf_path} -a") + + if getconf.exitstatus == 0 + sysconf Mash.new unless sysconf + + getconf.stdout.split("\n").each do |line| + key, val = /^(\S+)\s*(.*)?$/.match(line).captures + if val && !val.empty? + begin + sysconf[key] = Integer(val) + rescue + sysconf[key] = val + end + else + sysconf[key] = nil + end + end + end + end + end +end diff -Nru ohai-8.21.0/lib/ohai/plugins/uptime.rb ohai-13.8.0/lib/ohai/plugins/uptime.rb --- ohai-8.21.0/lib/ohai/plugins/uptime.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/uptime.rb 2018-03-16 11:24:35.000000000 +0000 @@ -24,9 +24,8 @@ # limitations under the License. # -require "ohai/mixin/seconds_to_human" - Ohai.plugin(:Uptime) do + require "ohai/mixin/seconds_to_human" provides "uptime", "uptime_seconds" provides "idletime", "idletime_seconds" # linux only depends "platform_version" @@ -40,16 +39,7 @@ return [usec, seconds_to_human(usec)] end end - return [nil, nil] - end - - collect_data(:hpux, :default) do - require "sigar" - - sigar = Sigar.new - uptime = sigar.uptime.uptime - uptime_seconds uptime.to_i * 1000 - uptime seconds_to_human(uptime.to_i) + [nil, nil] end collect_data(:darwin) do @@ -74,7 +64,7 @@ collect_data(:openbsd) do # kern.boottime=Tue Nov 1 14:45:52 2011 - so = shell_out("#{ Ohai.abs_path( "/sbin/sysctl" )} #kern.boottime") + so = shell_out("#{Ohai.abs_path( "/sbin/sysctl" )} #kern.boottime") so.stdout.lines do |line| if line =~ /kern.boottime=(.+)/ uptime_seconds Time.new.to_i - Time.parse($1).to_i diff -Nru ohai-8.21.0/lib/ohai/plugins/virtualbox.rb ohai-13.8.0/lib/ohai/plugins/virtualbox.rb --- ohai-8.21.0/lib/ohai/plugins/virtualbox.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/virtualbox.rb 2018-03-16 11:24:35.000000000 +0000 @@ -20,25 +20,30 @@ provides "virtualbox" collect_data do - 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) + 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 end end + rescue Ohai::Exceptions::Exec + Ohai::Log.debug('Plugin Virtualbox: Could not execute "VBoxControl guestproperty enumerate". Skipping data') end end end diff -Nru ohai-8.21.0/lib/ohai/plugins/vmware.rb ohai-13.8.0/lib/ohai/plugins/vmware.rb --- ohai-8.21.0/lib/ohai/plugins/vmware.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/vmware.rb 2018-03-16 11:24:35.000000000 +0000 @@ -42,7 +42,7 @@ def get_vm_attributes(vmtools_path) if !File.exist?(vmtools_path) - Ohai::Log.debug("#{vmtools_path} not found") + Ohai::Log.debug("Plugin VMware: #{vmtools_path} not found") else vmware Mash.new begin @@ -62,7 +62,7 @@ vmware[param] = from_cmd("#{vmtools_path} #{param} status") end rescue - Ohai::Log.debug("Error while collecting VMware guest attributes") + Ohai::Log.debug("Plugin VMware: Error while collecting VMware guest attributes") end end end diff -Nru ohai-8.21.0/lib/ohai/plugins/windows/cpu.rb ohai-13.8.0/lib/ohai/plugins/windows/cpu.rb --- ohai-8.21.0/lib/ohai/plugins/windows/cpu.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/windows/cpu.rb 2018-03-16 11:24:35.000000000 +0000 @@ -60,7 +60,8 @@ processor["stepping"] end cpu[current_cpu]["physical_id"] = processor["deviceid"] - cpu[current_cpu]["model_name"] = processor["description"] + cpu[current_cpu]["model_name"] = processor["name"] + cpu[current_cpu]["description"] = processor["description"] cpu[current_cpu]["mhz"] = processor["maxclockspeed"].to_s cpu[current_cpu]["cache_size"] = "#{processor['l2cachesize']} KB" end diff -Nru ohai-8.21.0/lib/ohai/plugins/windows/filesystem.rb ohai-13.8.0/lib/ohai/plugins/windows/filesystem.rb --- ohai-8.21.0/lib/ohai/plugins/windows/filesystem.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/windows/filesystem.rb 2018-03-16 11:24:35.000000000 +0000 @@ -44,7 +44,7 @@ fs[filesystem][:kb_used] = fs[filesystem][:kb_size].to_i - fs[filesystem][:kb_available].to_i fs[filesystem][:percent_used] = (fs[filesystem][:kb_size].to_i != 0 ? fs[filesystem][:kb_used].to_i * 100 / fs[filesystem][:kb_size].to_i : 0) fs[filesystem][:mount] = ld_info[filesystem][:name] - fs[filesystem][:fs_type] = ld_info[filesystem][:file_system].downcase unless ld_info[filesystem][:file_system] == nil + fs[filesystem][:fs_type] = ld_info[filesystem][:file_system].downcase unless ld_info[filesystem][:file_system].nil? fs[filesystem][:volume_name] = ld_info[filesystem][:volume_name] end diff -Nru ohai-8.21.0/lib/ohai/plugins/windows/network.rb ohai-13.8.0/lib/ohai/plugins/windows/network.rb --- ohai-8.21.0/lib/ohai/plugins/windows/network.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/windows/network.rb 2018-03-16 11:24:35.000000000 +0000 @@ -1,6 +1,6 @@ # # Author:: James Gartrell () -# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. +# Copyright:: Copyright (c) 2008-2017, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -39,7 +39,7 @@ # If we are running on windows nano or anothe roperating system from the future # that does not populate the deprecated win32_* WMI classes, then we should # grab data from the newer MSFT_* classes - return msft_adapter_data if data[:addresses].count.zero? + return msft_adapter_data if data[:addresses].count == 0 data[:adapters] = wmi.instances_of("Win32_NetworkAdapter") data end @@ -125,7 +125,7 @@ iface[cint][:type] = iface[cint][:instance][:adapter_type] if iface[cint][:instance][:adapter_type] iface[cint][:arp] = {} iface[cint][:encapsulation] = windows_encaps_lookup(iface[cint][:instance][:adapter_type]) if iface[cint][:instance][:adapter_type] - if iface[cint][:configuration][:default_ip_gateway] != nil && iface[cint][:configuration][:default_ip_gateway].size > 0 + if !iface[cint][:configuration][:default_ip_gateway].nil? && iface[cint][:configuration][:default_ip_gateway].size > 0 network[:default_gateway] = iface[cint][:configuration][:default_ip_gateway].first network[:default_interface] = cint end diff -Nru ohai-8.21.0/lib/ohai/plugins/windows/virtualization.rb ohai-13.8.0/lib/ohai/plugins/windows/virtualization.rb --- ohai-8.21.0/lib/ohai/plugins/windows/virtualization.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/windows/virtualization.rb 2018-03-16 11:24:35.000000000 +0000 @@ -44,6 +44,20 @@ virtualization[:system] = "kvm" virtualization[:role] = "guest" virtualization[:systems][:kvm] = "guest" + when "American Megatrends Inc." + if bios[0]["version"] =~ /VRTUAL -/ + virtualization[:system] = "hyper-v" + virtualization[:role] = "guest" + virtualization[:systems][:hyperv] = "guest" + end + when "Xen" + virtualization[:system] = "xen" + virtualization[:role] = "guest" + virtualization[:systems][:xen] = "guest" + when "Veertu" + virtualization[:system] = "veertu" + virtualization[:role] = "guest" + virtualization[:systems][:veertu] = "guest" end # vmware fusion detection diff -Nru ohai-8.21.0/lib/ohai/plugins/zpools.rb ohai-13.8.0/lib/ohai/plugins/zpools.rb --- ohai-8.21.0/lib/ohai/plugins/zpools.rb 1970-01-01 00:00:00.000000000 +0000 +++ ohai-13.8.0/lib/ohai/plugins/zpools.rb 2018-03-16 11:24:35.000000000 +0000 @@ -0,0 +1,87 @@ +# +# Author:: Jason J. W. Williams (williamsjj@digitar.com) +# Copyright:: Copyright (c) 2011-2017 Chef Software, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +Ohai.plugin(:Zpools) do + provides "zpools" + depends "platform_family" + + # If zpool status doesn't know about a field it returns '-'. + # We don't want to fill a field with that + def sanitize_value(value) + value == "-" ? nil : value + end + + def gather_pool_info + pools = Mash.new + # Grab ZFS zpools overall health and attributes + so = shell_out("zpool list -H -o name,size,alloc,free,cap,dedup,health,version") + so.stdout.lines do |line| + case line + when /^([-_0-9A-Za-z]*)\s+([.0-9]+[MGTPE])\s+([.0-9]+[MGTPE])\s+([.0-9]+[MGTPE])\s+(\d+%)\s+([.0-9]+x)\s+([-_0-9A-Za-z]+)\s+(\d+|-)$/ + Ohai::Log.debug("Plugin Zpools: Parsing zpool list line: #{line.chomp}") + pools[$1] = Mash.new + pools[$1][:pool_size] = sanitize_value($2) + pools[$1][:pool_allocated] = sanitize_value($3) + pools[$1][:pool_free] = sanitize_value($4) + pools[$1][:capacity_used] = sanitize_value($5) + pools[$1][:dedup_factor] = sanitize_value($6) + pools[$1][:health] = sanitize_value($7) + pools[$1][:zpool_version] = sanitize_value($8) + end + end + pools + end + + collect_data(:solaris2, :linux, :freebsd, :openbsd, :netbsd, :dragonflybsd) do + pools = gather_pool_info + + # Grab individual health for devices in the zpools + pools.keys.each do |pool| + pools[pool][:devices] = Mash.new + + # Run "zpool status" as non-root user (adm) so that + # the command won't try to open() each device which can + # hang the command if any of the disks are bad. + if platform_family == "solaris2" + command = "su adm -c \"zpool status #{pool}\"" + else + command = "zpool status #{pool}" + end + + so = shell_out(command) + so.stdout.lines do |line| + case line + # linux: http://rubular.com/r/J3wQC6E2lH + # solaris: http://rubular.com/r/FqOBzUQQ4p + # freebsd: http://rubular.com/r/RYkMNlytXl + when /^\s+((sd|c|ad|da)[-_a-zA-Z0-9]+)\s+([-_a-zA-Z0-9]+)\s+(\d+)\s+(\d+)\s+(\d+)$/ + Ohai::Log.debug("Plugin Zpools: Parsing zpool status line: #{line.chomp}") + pools[pool][:devices][$1] = Mash.new + pools[pool][:devices][$1][:state] = $3 + pools[pool][:devices][$1][:errors] = Mash.new + pools[pool][:devices][$1][:errors][:read] = $4 + pools[pool][:devices][$1][:errors][:write] = $5 + pools[pool][:devices][$1][:errors][:checksum] = $6 + end + end + end + + # Set the zpools data + zpools pools + end +end diff -Nru ohai-8.21.0/lib/ohai/runner.rb ohai-13.8.0/lib/ohai/runner.rb --- ohai-8.21.0/lib/ohai/runner.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/runner.rb 2018-03-16 11:24:35.000000000 +0000 @@ -18,41 +18,47 @@ # require "ohai/dsl" +require "benchmark" module Ohai class Runner + attr_reader :failed_plugins # safe_run: set to true if this runner will run plugins in # safe-mode. default false. def initialize(controller, safe_run = false) @provides_map = controller.provides_map @safe_run = safe_run + @failed_plugins = [] end # Runs plugins and any un-run dependencies. # If force is set to true, then this plugin and its dependencies # will be run even if they have been run before. def run_plugin(plugin) - unless plugin.kind_of?(Ohai::DSL::Plugin) - raise Ohai::Exceptions::InvalidPlugin, "Invalid plugin #{plugin} (must be an Ohai::DSL::Plugin or subclass)" - end + elapsed = Benchmark.measure do + unless plugin.kind_of?(Ohai::DSL::Plugin) + raise Ohai::Exceptions::InvalidPlugin, "Invalid plugin #{plugin} (must be an Ohai::DSL::Plugin or subclass)" + end - begin - case plugin.version - when :version7 - run_v7_plugin(plugin) - when :version6 - run_v6_plugin(plugin) - else - raise Ohai::Exceptions::InvalidPlugin, "Invalid plugin version #{plugin.version} for plugin #{plugin}" + begin + case plugin.version + when :version7 + run_v7_plugin(plugin) + when :version6 + run_v6_plugin(plugin) + else + raise Ohai::Exceptions::InvalidPlugin, "Invalid plugin version #{plugin.version} for plugin #{plugin}" + end + rescue Ohai::Exceptions::Error + raise + rescue SystemExit # abort or exit from plug-in should exit Ohai with failure code + raise + rescue Exception, Errno::ENOENT => e + Ohai::Log.debug("Plugin #{plugin.name} threw exception #{e.inspect} #{e.backtrace.join("\n")}") end - rescue Ohai::Exceptions::Error - raise - rescue SystemExit # abort or exit from plug-in should exit Ohai with failure code - raise - rescue Exception, Errno::ENOENT => e - Ohai::Log.debug("Plugin #{plugin.name} threw exception #{e.inspect} #{e.backtrace.join("\n")}") end + Ohai::Log.debug("Plugin #{plugin.name} took #{elapsed.total} seconds to run.") end def run_v6_plugin(plugin) @@ -69,7 +75,7 @@ next if next_plugin.has_run? if visited.include?(next_plugin) - raise Ohai::Exceptions::DependencyCycle, "Dependency cycle detected. Please refer to the following plugins: #{get_cycle(visited, plugin).join(", ") }" + raise Ohai::Exceptions::DependencyCycle, "Dependency cycle detected. Please refer to the following plugins: #{get_cycle(visited, plugin).join(", ")}" end dependency_providers = fetch_plugins(next_plugin.dependencies) @@ -82,6 +88,9 @@ if dependency_providers.empty? @safe_run ? next_plugin.safe_run : next_plugin.run + if next_plugin.failed + @failed_plugins << next_plugin.name + end else visited << next_plugin << dependency_providers.first end diff -Nru ohai-8.21.0/lib/ohai/system.rb ohai-13.8.0/lib/ohai/system.rb --- ohai-8.21.0/lib/ohai/system.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/system.rb 2018-03-16 11:24:35.000000000 +0000 @@ -1,6 +1,6 @@ # # Author:: Adam Jacob () -# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. +# Copyright:: Copyright (c) 2008-2017, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -28,6 +28,7 @@ require "ohai/provides_map" require "ohai/hints" require "mixlib/shellout" +require "ohai/config" module Ohai class System @@ -38,9 +39,15 @@ attr_reader :provides_map attr_reader :v6_dependency_solver + # the cli flag is used to determine if we're being constructed by + # something like chef-client (which doesn't not set this flag) and + # which sets up its own loggers, or if we're coming from Ohai::Application + # and therefore need to configure Ohai's own logger. def initialize(config = {}) + @cli = config[:invoked_from_cli] @plugin_path = "" @config = config + @failed_plugins = [] reset_system end @@ -50,12 +57,12 @@ @v6_dependency_solver = Hash.new configure_ohai - configure_logging + configure_logging if @cli @loader = Ohai::Loader.new(self) @runner = Ohai::Runner.new(self, true) - Ohai::Hints.refresh_hints() + Ohai::Hints.refresh_hints # Remove the previously defined plugins recursive_remove_constants(Ohai::NamedPlugin) @@ -101,6 +108,28 @@ Ohai::Log.error("Encountered error while running plugins: #{e.inspect}") raise end + critical_failed = Ohai::Config.ohai[:critical_plugins] & @runner.failed_plugins + unless critical_failed.empty? + msg = "The following Ohai plugins marked as critical failed: #{critical_failed}" + if @cli + Ohai::Log.error(msg) + exit(true) + else + raise Ohai::Exceptions::CriticalPluginFailure, "#{msg}. Failing Chef run." + end + end + + # Freeze all strings. + freeze_strings! + end + + def run_additional_plugins(plugin_path) + @loader.load_additional(plugin_path).each do |plugin| + Ohai::Log.debug "Running plugin #{plugin}" + @runner.run_plugin(plugin) + end + + freeze_strings! end def have_v6_plugin?(name) @@ -164,7 +193,7 @@ # This method takes a naive approach to v6 plugins: it simply re-runs all # of them whenever called. def refresh_plugins(attribute_filter = nil) - Ohai::Hints.refresh_hints() + Ohai::Hints.refresh_hints @provides_map.all_plugins(attribute_filter).each do |plugin| plugin.reset! end @@ -192,7 +221,7 @@ end raise ArgumentError, "I cannot find an attribute named #{a}!" if data.nil? case data - when Hash, Mash, Array, Fixnum + when Hash, Mash, Array, Integer json_pretty_print(data) when String if data.respond_to?(:lines) @@ -208,7 +237,6 @@ private def configure_ohai - Ohai::Config.merge_deprecated_config Ohai.config.merge!(@config) if Ohai.config[:directory] && @@ -220,15 +248,31 @@ end def configure_logging - return if Ohai::Log.configured? - - Ohai::Log.init(Ohai.config[:log_location]) - if Ohai.config[:log_level] == :auto Ohai::Log.level = :info else Ohai::Log.level = Ohai.config[:log_level] end end + + # Freeze all string values in @data. This makes them immutable and saves + # a bit of RAM. + # + # @api private + # @return [void] + def freeze_strings! + # Recursive visitor pattern helper. + visitor = lambda do |val| + case val + when Hash + val.each_value { |v| visitor.call(v) } + when Array + val.each { |v| visitor.call(v) } + when String + val.freeze + end + end + visitor.call(@data) + end end end diff -Nru ohai-8.21.0/lib/ohai/util/file_helper.rb ohai-13.8.0/lib/ohai/util/file_helper.rb --- ohai-8.21.0/lib/ohai/util/file_helper.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/util/file_helper.rb 2018-03-16 11:24:35.000000000 +0000 @@ -26,11 +26,11 @@ paths.each do |path| filename = File.join(path, cmd) if File.executable?(filename) - Ohai::Log.debug("#{self.name} plugin: found #{cmd} at #{filename}") + Ohai::Log.debug("Plugin #{name}: found #{cmd} at #{filename}") return filename end end - Ohai::Log.debug("#{self.name} plugin: did not find #{cmd}") + Ohai::Log.debug("Plugin #{name}: did not find #{cmd}") false end end diff -Nru ohai-8.21.0/lib/ohai/version.rb ohai-13.8.0/lib/ohai/version.rb --- ohai-8.21.0/lib/ohai/version.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/lib/ohai/version.rb 2018-03-16 11:24:35.000000000 +0000 @@ -1,6 +1,6 @@ # # Author:: Adam Jacob () -# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. +# Copyright:: Copyright (c) 2008-2017, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,5 +18,5 @@ module Ohai OHAI_ROOT = File.expand_path(File.dirname(__FILE__)) - VERSION = "8.21.0" + VERSION = "13.8.0" end diff -Nru ohai-8.21.0/ohai.gemspec ohai-13.8.0/ohai.gemspec --- ohai-8.21.0/ohai.gemspec 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/ohai.gemspec 2018-03-16 11:24:35.000000000 +0000 @@ -13,7 +13,7 @@ s.email = "adam@chef.io" s.homepage = "https://docs.chef.io/ohai.html" - s.required_ruby_version = ">= 2.1.0" + s.required_ruby_version = ">= 2.3" s.add_dependency "systemu", "~> 2.6.4" s.add_dependency "ffi-yajl", "~> 2.2" @@ -25,27 +25,11 @@ s.add_dependency "ipaddress" s.add_dependency "wmi-lite", "~> 1.0" s.add_dependency "ffi", "~> 1.9" + s.add_dependency "chef-config", ">= 12.5.0.alpha.1", "< 14" # Note for ohai developers: If chef-config causes you grief, try: # bundle install --with development # this should work as long as chef is a development dependency in Gemfile. # - # Chef depends on ohai and chef-config. Ohai depends on chef-config. The - # version of chef-config that chef depends on is whatver version chef - # happens to be on master. This will need to be updated again once work on - # Chef 13 starts, otherwise builds will break. - s.add_dependency "chef-config", ">= 12.5.0.alpha.1", "< 13" - - s.add_development_dependency "rake", ">= 10.1.0", "< 12.0.0" - s.add_development_dependency "rspec-core", "~> 3.0" - s.add_development_dependency "rspec-expectations", "~> 3.0" - s.add_development_dependency "rspec-mocks", "~> 3.0" - s.add_development_dependency "rspec-collection_matchers", "~> 1.0" - s.add_development_dependency "rspec_junit_formatter" - s.add_development_dependency "github_changelog_generator", "1.13.1" - - # github_changelog_generator -> github-api -> oauth2 -> rack - # rack being unconstrained breaks Ruby 2.1 installs - s.add_development_dependency "rack", "~> 1.0" s.bindir = "bin" s.executables = %w{ohai} diff -Nru ohai-8.21.0/Rakefile ohai-13.8.0/Rakefile --- ohai-8.21.0/Rakefile 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/Rakefile 2018-03-16 11:24:35.000000000 +0000 @@ -23,11 +23,13 @@ task.options += ["--display-cop-names", "--no-color"] end -require "github_changelog_generator/task" +begin + require "github_changelog_generator/task" -GitHubChangelogGenerator::RakeTask.new :changelog do |config| - config.future_release = Ohai::VERSION - config.enhancement_labels = "enhancement,Enhancement,New Feature,Feature".split(",") - config.bug_labels = "bug,Bug,Improvement,Upstream Bug".split(",") - config.exclude_labels = "duplicate,question,invalid,wontfix,no_changelog,Exclude From Changelog,Question,Discussion".split(",") + GitHubChangelogGenerator::RakeTask.new :changelog do |config| + config.future_release = Ohai::VERSION + config.max_issues = 0 + config.add_issues_wo_labels = false + end +rescue LoadError end diff -Nru ohai-8.21.0/spec/data/plugins/lslpp.output ohai-13.8.0/spec/data/plugins/lslpp.output --- ohai-8.21.0/spec/data/plugins/lslpp.output 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/data/plugins/lslpp.output 2018-03-16 11:24:35.000000000 +0000 @@ -47,3 +47,4 @@ devices.common.IBM.fc:devices.common.IBM.fc.hba-api:7.1.1.16: : :C:F:Common HBA API Library: : : : : : :0:0:/:1228 devices.common.IBM.fc:devices.common.IBM.fc.rte:7.1.1.16: : :C:F:Common IBM FC Software: : : : : : :0:0:/:1228 devices.common.IBM.fda:devices.common.IBM.fda.diag:7.1.0.0: : :C: :Common Diskette Adapter and Device Diagnostics: : : : : : :0:0:/:1036 +wget:wget-1.9.1-3:1.9.1-3: : :C:R:A utility for retrieving files using the HTTP or FTP protocols.: :/bin/rpm -e wget: : : : :0: :/opt/freeware:Wed Nov 5 01:37:09 MST 2014 diff -Nru ohai-8.21.0/spec/data/plugins/pacman.output ohai-13.8.0/spec/data/plugins/pacman.output --- ohai-8.21.0/spec/data/plugins/pacman.output 1970-01-01 00:00:00.000000000 +0000 +++ ohai-13.8.0/spec/data/plugins/pacman.output 2018-03-16 11:24:35.000000000 +0000 @@ -0,0 +1,51 @@ +Name : acl +Version : 2.2.52-3 +Description : Access control list utilities, libraries and headers +Architecture : x86_64 +URL : http://savannah.nongnu.org/projects/acl +Licenses : LGPL +Groups : None +Provides : xfsacl +Depends On : attr>=2.4.46 +Optional Deps : None +Required By : coreutils gettext libarchive logrotate sed shadow systemd tar +Optional For : None +Conflicts With : xfsacl +Replaces : xfsacl +Installed Size : 290.00 KiB +Packager : Bartlomiej Piotrowski +Build Date : Sun Nov 6 14:03:46 2016 +Install Date : Sun Jul 23 03:25:45 2017 +Install Reason : Installed as a dependency for another package +Install Script : No +Validated By : Signature + +Name : abcde +Version : 2.8.1-2 +Description : Frontend command-line utility that grabs tracks off a CD, encodes them to ogg or mp3 format, and tags them, all in one go +Architecture : any +URL : https://abcde.einval.com/ +Licenses : GPL +Groups : None +Provides : None +Depends On : bash cd-discid wget vorbis-tools python2-eyed3 +Optional Deps : cdparanoia: Paranoia ripping support [installed] + cdrkit: icedax ripping support [installed] + flac: FLAC encoding support [installed] + id3: ID3 v1 tag support + lame: MP3 encoding support [installed] + mp3gain: MP3 normalization support [installed] + perl-musicbrainz-discid: musicbrainz support (AUR) + perl-webservice-musicbrainz: musicbrainz support (AUR) + vorbisgain: Ogg Vorbis normalization support [installed] +Required By : None +Optional For : None +Conflicts With : None +Replaces : None +Installed Size : 334.00 KiB +Packager : Alexander Rødseth +Build Date : Wed Apr 26 02:04:21 2017 +Install Date : Fri May 5 15:36:23 2017 +Install Reason : Explicitly installed +Install Script : No +Validated By : Signature diff -Nru ohai-8.21.0/spec/functional/application_spec.rb ohai-13.8.0/spec/functional/application_spec.rb --- ohai-8.21.0/spec/functional/application_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/functional/application_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -17,7 +17,6 @@ # require_relative "../spec_helper" - require "ohai/application" RSpec.describe "Ohai::Application" do @@ -86,45 +85,6 @@ end end - context "when the configuration file contains deprecated config options" do - # For the purpose of these tests it doesn't matter if the configuration - # file was specified via command line or discovered on the local - # workstation. It's easier if we pass the configuration file as a cli - # argument (there's less to stub). - - let(:argv) { [ "-c", config_location ] } - - let(:config_content) do - <<-CONFIG -log_location "#{log_location}" -log_level :#{log_level} -Ohai::Config[:disabled_plugins] = #{disabled_plugins} -Ohai::Config[:plugin_path] << "#{plugin_path}" -CONFIG - end - - # config settings - let(:disabled_plugins) { [ :Foo, :Baz ] } - - let(:log_level) { :debug } - - let(:log_location) { "path/to/log" } - - let(:plugin_path) { "/path/to/plugins" } - - it "logs warnings for deprecated top-level options" do - # deprecation warnings for options need to be stubbed in the order - # they are received, in this case it's the order they appear in the - # configuration file. - options = [ :log_location, :log_level, :disabled_plugins ] - options.each do |option| - expect(Ohai::Log).to receive(:warn). - with(/Ohai::Config\[:#{option}\] is deprecated/) - end - app.configure_ohai - end - end - context "when the configuration file has a syntax error" do # For the purpose of these tests it doesn't matter if the configuration # file was specified via command line or discovered on the local diff -Nru ohai-8.21.0/spec/functional/plugins/powershell_spec.rb ohai-13.8.0/spec/functional/plugins/powershell_spec.rb --- ohai-8.21.0/spec/functional/plugins/powershell_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/functional/plugins/powershell_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" describe Ohai::System, "languages plugin" do VERSION_MATCHING_REGEX = /^(?:[\d]+\.)+[\d]+$/ diff -Nru ohai-8.21.0/spec/functional/plugins/root_group_spec.rb ohai-13.8.0/spec/functional/plugins/root_group_spec.rb --- ohai-8.21.0/spec/functional/plugins/root_group_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/functional/plugins/root_group_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -18,7 +18,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" describe Ohai::System, "root_group plugin" do let(:plugin) { get_plugin("root_group") } diff -Nru ohai-8.21.0/spec/functional/plugins/windows/uptime_spec.rb ohai-13.8.0/spec/functional/plugins/windows/uptime_spec.rb --- ohai-8.21.0/spec/functional/plugins/windows/uptime_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/functional/plugins/windows/uptime_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Windows plugin uptime" do diff -Nru ohai-8.21.0/spec/ohai_spec.rb ohai-13.8.0/spec/ohai_spec.rb --- ohai-8.21.0/spec/ohai_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/ohai_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/spec_helper.rb") +require_relative "spec_helper.rb" describe Ohai do diff -Nru ohai-8.21.0/spec/spec_helper.rb ohai-13.8.0/spec/spec_helper.rb --- ohai-8.21.0/spec/spec_helper.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/spec_helper.rb 2018-03-16 11:24:35.000000000 +0000 @@ -109,8 +109,6 @@ config.filter_run_excluding :windows_only => true unless windows? config.filter_run_excluding :unix_only => true unless unix? - config.filter_run_excluding :ruby_18_only => true unless ruby_18? - config.filter_run_excluding :ruby_19_only => true unless ruby_19? config.filter_run_excluding :requires_root => true unless ENV["USER"] == "root" config.filter_run_excluding :requires_unprivileged_user => true if ENV["USER"] == "root" diff -Nru ohai-8.21.0/spec/support/integration_helper.rb ohai-13.8.0/spec/support/integration_helper.rb --- ohai-8.21.0/spec/support/integration_helper.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/support/integration_helper.rb 2018-03-16 11:24:35.000000000 +0000 @@ -1,3 +1,20 @@ +# +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); you +# may not use this file except in compliance with the License. You may +# obtain a copy of the license at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expressed or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License +# + require "tmpdir" module IntegrationSupport diff -Nru ohai-8.21.0/spec/support/platform_helpers.rb ohai-13.8.0/spec/support/platform_helpers.rb --- ohai-8.21.0/spec/support/platform_helpers.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/support/platform_helpers.rb 2018-03-16 11:24:35.000000000 +0000 @@ -1,17 +1,24 @@ -def ruby_19? - !!(RUBY_VERSION =~ /^1.9/) -end - -def ruby_18? - !!(RUBY_VERSION =~ /^1.8/) -end +# +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); you +# may not use this file except in compliance with the License. You may +# obtain a copy of the license at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expressed or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License +# def windows? !!(RUBY_PLATFORM =~ /mswin|mingw|windows/) end -# def jruby? - def unix? !windows? end diff -Nru ohai-8.21.0/spec/unit/application_spec.rb ohai-13.8.0/spec/unit/application_spec.rb --- ohai-8.21.0/spec/unit/application_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/application_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -17,7 +17,6 @@ # require_relative "../spec_helper" - require "ohai/application" RSpec.describe "Ohai::Application" do diff -Nru ohai-8.21.0/spec/unit/config_spec.rb ohai-13.8.0/spec/unit/config_spec.rb --- ohai-8.21.0/spec/unit/config_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/config_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -17,79 +17,10 @@ # require_relative "../spec_helper" - require "ohai/config" RSpec.describe Ohai::Config do - describe "top-level configuration options" do - shared_examples_for "option" do - it "logs a deprecation warning and sets the value" do - expect(Ohai::Log).to receive(:warn). - with(/Ohai::Config\[:#{option}\] is deprecated/) - Ohai::Config[option] = value - expect(Ohai::Config[option]).to eq(value) - end - end - - shared_examples_for "appendable option" do - it "sets the value" do - expect(Ohai::Log).to_not receive(:warn) - Ohai::Config[option] << value - expect(Ohai::Config[option]).to include(value) - end - end - - describe ":directory" do - include_examples "option" do - let(:option) { :directory } - let(:value) { "/some/fantastic/plugins" } - end - end - - describe ":disabled_plugins" do - include_examples "option" do - let(:option) { :disabled_plugins } - let(:value) { [ :Foo, :Baz ] } - end - end - - describe ":hints_path" do - include_examples "appendable option" do - let(:option) { :hints_path } - let(:value) { "/some/helpful/hints" } - end - end - - describe ":log_level" do - include_examples "option" do - let(:option) { :log_level } - let(:value) { :cheese } - end - end - - describe ":log_location" do - include_examples "option" do - let(:option) { :log_location } - let(:value) { "/etc/chef/cache/loooogs" } - end - end - - describe ":plugin_path" do - include_examples "appendable option" do - let(:option) { :plugin_path } - let(:value) { "/some/fantastic/plugins" } - end - end - - describe ":version" do - include_examples "option" do - let(:option) { :version } - let(:value) { "8.2.0" } - end - end - end - describe "config_context :ohai" do describe "option :plugin" do it "gets configured with a value" do @@ -117,48 +48,6 @@ end end end - - describe "::merge_deprecated_config" do - before(:each) do - allow(Ohai::Log).to receive(:warn) - configure_ohai - end - - def configure_ohai - Ohai::Config[:directory] = "/some/fantastic/plugins" - Ohai::Config[:disabled_plugins] = [ :Foo, :Baz ] - Ohai::Config[:log_level] = :debug - end - - it "merges top-level config values into the ohai config context" do - Ohai::Config.merge_deprecated_config - expect(Ohai::Config.ohai.configuration).to eq (Ohai::Config.configuration) - end - - shared_examples_for "delayed warn" do - it "logs a deprecation warning and merges the value" do - expect(Ohai::Log).to receive(:warn). - with(/Ohai::Config\[:#{option}\] is deprecated/) - Ohai::Config[option] << value - Ohai::Config.merge_deprecated_config - expect(Ohai::Config.ohai[option]).to include(value) - end - end - - context "when :hints_path is set" do - include_examples "delayed warn" do - let(:option) { :hints_path } - let(:value) { "/some/helpful/hints" } - end - end - - context "when :plugin_path is set" do - include_examples "delayed warn" do - let(:option) { :plugin_path } - let(:value) { "/some/fantastic/plugins" } - end - end - end describe "Ohai.config" do it "returns the ohai config context" do diff -Nru ohai-8.21.0/spec/unit/dsl/plugin_spec.rb ohai-13.8.0/spec/unit/dsl/plugin_spec.rb --- ohai-8.21.0/spec/unit/dsl/plugin_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/dsl/plugin_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -17,7 +17,7 @@ # limitations under the License # -require File.expand_path("../../../spec_helper.rb", __FILE__) +require_relative "../../spec_helper.rb" shared_examples "Ohai::DSL::Plugin" do context "#initialize" do @@ -90,11 +90,68 @@ end end - context "when setting attributes" do + describe "set_attribute" do + it "raises an ArgumentError when given one argument" do + expect { plugin.set_attribute(:tea) }.to raise_error(ArgumentError) + end + it "lets you set an attribute" do plugin.set_attribute(:tea, "is soothing") expect(plugin.data["tea"]).to eql("is soothing") end + + it "lets you set an attribute to an empty array" do + plugin.set_attribute(:tea, []) + expect(plugin.data["tea"]).to eql([]) + end + + it "lets you set an attribute to an empty Mash" do + plugin.set_attribute(:tea, {}) + expect(plugin.data["tea"]).to eql({}) + end + + it "lets you modify an attribute" do + plugin.data["tea"] = "is soothing" + plugin.set_attribute(:tea, "tastes like plants") + expect(plugin.data["tea"]).to eql("tastes like plants") + end + + it "lets you set a subattribute" do + plugin.data["tea"] = Mash.new + plugin.set_attribute(:tea, :green, "tastes like green") + expect(plugin.data["tea"]["green"]).to eql("tastes like green") + end + + it "lets you set a subattribute to an empty array" do + plugin.set_attribute(:tea, :green, []) + expect(plugin.data["tea"]["green"]).to eql([]) + end + + it "lets you set a subattribute to an empty Mash" do + plugin.set_attribute(:tea, :green, {}) + expect(plugin.data["tea"]["green"]).to eql({}) + end + + it "lets you modify a subattribute" do + plugin.data["tea"] = Mash.new + plugin.data["tea"]["green"] = "tastes like green" + plugin.set_attribute(:tea, :green, "made from leaves") + expect(plugin.data["tea"]["green"]).to eql("made from leaves") + end + + it "raises a TypeError when modifying an attribute that is not a Mash" do + plugin.data["tea"] = Mash.new + plugin.data["tea"] = "is soothing" + expect { plugin.set_attribute(:tea, :green, "tastes like green") }.to raise_error(TypeError) + end + + it "lets you modify a subattribute with an array" do + green = { flavor: "tastes like green" } + black = { flavor: "tastes like black" } + plugin.data[:tea] = [green, black] + plugin.set_attribute(:tea, 0, :source, "made from leaves") + expect(plugin.data[:tea][0][:source]).to eq("made from leaves") + end end context "when getting attributes" do diff -Nru ohai-8.21.0/spec/unit/hints_spec.rb ohai-13.8.0/spec/unit/hints_spec.rb --- ohai-8.21.0/spec/unit/hints_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/hints_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -17,7 +17,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../spec_helper.rb") +require_relative "../spec_helper.rb" describe "Ohai::Hints" do # We are using the plugins directory infrastructure to test hints diff -Nru ohai-8.21.0/spec/unit/loader_spec.rb ohai-13.8.0/spec/unit/loader_spec.rb --- ohai-8.21.0/spec/unit/loader_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/loader_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -17,7 +17,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../spec_helper.rb") +require_relative "../spec_helper.rb" describe Ohai::Loader do extend IntegrationSupport @@ -95,6 +95,31 @@ end end + when_plugins_directory "is an additional plugin path" do + with_plugin("cookbook_a/alpha.rb", < +# Copyright:: 2017 Chef Software, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDIT"Net::HTTP Response"NS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require_relative "../../spec_helper.rb" +require "ohai/mixin/azure_metadata" + +describe Ohai::Mixin::AzureMetadata do + let(:mixin) do + mixin = Object.new.extend(::Ohai::Mixin::AzureMetadata) + mixin + end + + describe "#http_get" do + it "gets the passed URI" do + http_mock = double("http") + allow(http_mock).to receive(:read_timeout=) + allow(Net::HTTP).to receive(:start).with("169.254.169.254").and_return(http_mock) + + expect(http_mock).to receive(:get).with("http://www.chef.io", initheader = { "Metadata" => "true" }) + mixin.http_get("http://www.chef.io") + end + end + + describe "#fetch_metadata" do + it "returns an empty hash given a non-200 response" do + http_mock = double("http", { :code => "500" }) + allow(mixin).to receive(:http_get).and_return(http_mock) + + expect(Ohai::Log).to receive(:warn) + vals = mixin.fetch_metadata + expect(vals).to eq(nil) + end + + it "returns an empty hash given invalid JSON response" do + http_mock = double("http", { :code => "200", :body => '{ "foo" "bar"}' }) + allow(mixin).to receive(:http_get).and_return(http_mock) + + expect(Ohai::Log).to receive(:warn) + vals = mixin.fetch_metadata + expect(vals).to eq(nil) + end + + it "returns a populated hash given valid JSON response" do + http_mock = double("http", { :code => "200", :body => '{ "foo": "bar"}' }) + allow(mixin).to receive(:http_get).and_return(http_mock) + + expect(Ohai::Log).not_to receive(:warn) + vals = mixin.fetch_metadata + expect(vals).to eq({ "foo" => "bar" }) + end + end +end diff -Nru ohai-8.21.0/spec/unit/mixin/command_spec.rb ohai-13.8.0/spec/unit/mixin/command_spec.rb --- ohai-8.21.0/spec/unit/mixin/command_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/mixin/command_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -17,75 +17,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") - -describe Ohai::Mixin::Command, "popen4" do - break if RUBY_PLATFORM =~ /(win|w)32$/ - - it "should default all commands to be run in the POSIX standard C locale" do - Ohai::Mixin::Command.popen4("echo $LC_ALL") do |pid, stdin, stdout, stderr| - stdin.close - expect(stdout.read.strip).to eq("C") - end - end - - it "should respect locale when specified explicitly" do - Ohai::Mixin::Command.popen4("echo $LC_ALL", :environment => { "LC_ALL" => "es" }) do |pid, stdin, stdout, stderr| - stdin.close - expect(stdout.read.strip).to eq("es") - end - end - - if defined?(::Encoding) && "".respond_to?(:force_encoding) #i.e., ruby 1.9 - context "when external commands return UTF-8 strings and we are running under LANG=C encoding" do - before do - @saved_default_external = Encoding.default_external - @saved_default_internal = Encoding.default_internal - Encoding.default_external = Encoding::US_ASCII - Encoding.default_internal = Encoding::US_ASCII - end - - after do - Encoding.default_external = @saved_default_external - Encoding.default_internal = @saved_default_internal - end - - it "should force encode the string to UTF-8" do - extend Ohai::Mixin::Command - snowy = run_command(:command => ("echo '" + ("☃" * 8096) + "'"))[1] - expect(snowy.encoding).to eq(Encoding::UTF_8) - end - end - - it "should force encode the string to UTF-8" do - extend Ohai::Mixin::Command - snowy = run_command(:command => ("echo '" + ("☃" * 8096) + "'"))[1] - expect(snowy.encoding).to eq(Encoding::UTF_8) - end - end - - it "reaps zombie processes after exec fails [OHAI-455]" do - # NOTE: depending on ulimit settings, GC, etc., before the OHAI-455 patch, - # ohai could also exhaust the available file descriptors when creating this - # many zombie processes. A regression _could_ cause Errno::EMFILE but this - # probably won't be consistent on different environments. - created_procs = 0 - 100.times do - begin - Ohai::Mixin::Command.popen4("/bin/this-is-not-a-real-command") { |p, i, o, e| nil } - rescue Ohai::Exceptions::Exec - created_procs += 1 - end - end - expect(created_procs).to eq(100) - reaped_procs = 0 - begin - loop { Process.wait(-1); reaped_procs += 1 } - rescue Errno::ECHILD - end - expect(reaped_procs).to eq(0) - end -end +require_relative "../../spec_helper.rb" describe Ohai::Mixin::Command, "shell_out" do let(:cmd) { "sparkle-dream --version" } @@ -94,15 +26,24 @@ let(:plugin_name) { :OSSparkleDream } + let(:options) { windows? ? { timeout: 30 } : { timeout: 30, env: { "PATH" => "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" } } } + before(:each) do allow(Ohai::Mixin::Command).to receive(:name).and_return(plugin_name) + @original_env = ENV.to_hash + ENV.clear + end + + after(:each) do + ENV.clear + ENV.update(@original_env) end describe "when the command runs" do it "logs the command and exitstatus" do expect(Mixlib::ShellOut). to receive(:new). - with(cmd, { timeout: 30 }). + with(cmd, options). and_return(shell_out) expect(shell_out). @@ -123,7 +64,7 @@ it "logs the command and error message" do expect(Mixlib::ShellOut). to receive(:new). - with(cmd, { timeout: 30 }). + with(cmd, options). and_return(shell_out) expect(shell_out). @@ -144,7 +85,7 @@ it "logs the command an timeout error message" do expect(Mixlib::ShellOut). to receive(:new). - with(cmd, { timeout: 30 }). + with(cmd, options). and_return(shell_out) expect(shell_out). @@ -162,7 +103,7 @@ end describe "when a timeout option is provided" do - let(:options) { { timeout: 10 } } + let(:options) { windows? ? { timeout: 10 } : { timeout: 10, env: { "PATH" => "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" } } } it "runs the command with the provided timeout" do expect(Mixlib::ShellOut). diff -Nru ohai-8.21.0/spec/unit/mixin/ec2_metadata_spec.rb ohai-13.8.0/spec/unit/mixin/ec2_metadata_spec.rb --- ohai-8.21.0/spec/unit/mixin/ec2_metadata_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/mixin/ec2_metadata_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" require "ohai/mixin/ec2_metadata" describe Ohai::Mixin::Ec2Metadata do diff -Nru ohai-8.21.0/spec/unit/mixin/softlayer_metadata_spec.rb ohai-13.8.0/spec/unit/mixin/softlayer_metadata_spec.rb --- ohai-8.21.0/spec/unit/mixin/softlayer_metadata_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/mixin/softlayer_metadata_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -17,7 +17,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" require "ohai/mixin/softlayer_metadata" describe ::Ohai::Mixin::SoftlayerMetadata do @@ -36,7 +36,7 @@ end context "fetch_metadata" do - it "riases error if softlayer api query results with error" do + it "raises error if softlayer api query results with error" do http_mock = double("http", { :ssl_version= => true, :use_ssl= => true, :ca_file= => true }) allow(http_mock).to receive(:get).and_raise(StandardError.new("API return fake error")) allow(::Net::HTTP).to receive(:new).with("api.service.softlayer.com", 443).and_return(http_mock) diff -Nru ohai-8.21.0/spec/unit/plugin_config_spec.rb ohai-13.8.0/spec/unit/plugin_config_spec.rb --- ohai-8.21.0/spec/unit/plugin_config_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugin_config_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,6 @@ # require_relative "../spec_helper" - require "ohai/plugin_config" describe "Ohai::PluginConfig" do diff -Nru ohai-8.21.0/spec/unit/plugins/abort_spec.rb ohai-13.8.0/spec/unit/plugins/abort_spec.rb --- ohai-8.21.0/spec/unit/plugins/abort_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/abort_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb")) +require_relative "../../spec_helper.rb" tmp = ENV["TMPDIR"] || ENV["TMP"] || ENV["TEMP"] || "/tmp" diff -Nru ohai-8.21.0/spec/unit/plugins/aix/cpu_spec.rb ohai-13.8.0/spec/unit/plugins/aix/cpu_spec.rb --- ohai-8.21.0/spec/unit/plugins/aix/cpu_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/aix/cpu_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "AIX cpu plugin" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/aix/filesystem_spec.rb ohai-13.8.0/spec/unit/plugins/aix/filesystem_spec.rb --- ohai-8.21.0/spec/unit/plugins/aix/filesystem_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/aix/filesystem_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -15,7 +15,8 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") + +require_relative "../../../spec_helper.rb" describe Ohai::System, "AIX filesystem plugin" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/aix/hostname_spec.rb ohai-13.8.0/spec/unit/plugins/aix/hostname_spec.rb --- ohai-8.21.0/spec/unit/plugins/aix/hostname_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/aix/hostname_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "AIX hostname plugin" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/aix/kernel_spec.rb ohai-13.8.0/spec/unit/plugins/aix/kernel_spec.rb --- ohai-8.21.0/spec/unit/plugins/aix/kernel_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/aix/kernel_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "AIX kernel plugin" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/aix/memory_spec.rb ohai-13.8.0/spec/unit/plugins/aix/memory_spec.rb --- ohai-8.21.0/spec/unit/plugins/aix/memory_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/aix/memory_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "AIX memory plugin" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/aix/network_spec.rb ohai-13.8.0/spec/unit/plugins/aix/network_spec.rb --- ohai-8.21.0/spec/unit/plugins/aix/network_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/aix/network_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "AIX network plugin" do diff -Nru ohai-8.21.0/spec/unit/plugins/aix/os_spec.rb ohai-13.8.0/spec/unit/plugins/aix/os_spec.rb --- ohai-8.21.0/spec/unit/plugins/aix/os_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/aix/os_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -15,7 +15,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "AIX os plugin" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/aix/platform_spec.rb ohai-13.8.0/spec/unit/plugins/aix/platform_spec.rb --- ohai-8.21.0/spec/unit/plugins/aix/platform_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/aix/platform_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Aix plugin platform" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/aix/uptime_spec.rb ohai-13.8.0/spec/unit/plugins/aix/uptime_spec.rb --- ohai-8.21.0/spec/unit/plugins/aix/uptime_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/aix/uptime_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,26 +16,23 @@ # See the License for the specific language governing permissions and # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Aix plugin uptime" do before(:each) do @plugin = get_plugin("aix/uptime") allow(@plugin).to receive(:collect_os).and_return(:aix) - allow(Time).to receive_message_chain(:now, :to_i).and_return(1412072511) - allow(Time).to receive_message_chain(:now, :zone).and_return("IST") - allow(DateTime).to receive_message_chain(:parse, :strftime, :to_i).and_return(1411561320) - allow(@plugin).to receive(:shell_out).with("who -b").and_return(mock_shell_out(0, " . system boot Sep 24 17:52", nil)) - + allow(@plugin).to receive(:shell_out).and_call_original + allow(@plugin).to receive(:shell_out).with("LC_ALL=POSIX ps -o etime= -p 1").and_return(mock_shell_out(0, "1148-20:54:50", nil)) @plugin.run end - it "should set uptime_seconds to uptime" do - expect(@plugin[:uptime_seconds]).to eq(511191) + it "should set uptime_seconds to uptime with days" do + expect(@plugin[:uptime_seconds]).to eq(99262490) end - it "should set uptime to a human readable date" do - expect(@plugin[:uptime]).to eq("5 days 21 hours 59 minutes 51 seconds") + it "should set uptime to a human readable date with days" do + expect(@plugin[:uptime]).to eq("1148 days 20 hours 54 minutes 50 seconds") end end diff -Nru ohai-8.21.0/spec/unit/plugins/aix/virtualization_spec.rb ohai-13.8.0/spec/unit/plugins/aix/virtualization_spec.rb --- ohai-8.21.0/spec/unit/plugins/aix/virtualization_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/aix/virtualization_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require "spec_helper" +require_relative "../../../spec_helper.rb" describe Ohai::System, "AIX virtualization plugin" do diff -Nru ohai-8.21.0/spec/unit/plugins/azure_spec.rb ohai-13.8.0/spec/unit/plugins/azure_spec.rb --- ohai-8.21.0/spec/unit/plugins/azure_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/azure_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" require "open-uri" describe Ohai::System, "plugin azure" do @@ -31,6 +31,33 @@ } end + let(:response_data) do + { "compute" => { "location" => "westus", + "name" => "timtest", + "offer" => "UbuntuServer", + "osType" => "Linux", + "platformFaultDomain" => "0", + "platformUpdateDomain" => "0", + "publisher" => "Canonical", + "sku" => "16.04-LTS", + "version" => "16.04.201707270", + "vmId" => "f78151b3-da8b-4bd8-a592-d9ce8a57ea65", + "vmSize" => "Standard_DS2_v2" }, + "network" => { "interface" => [ { "ipv4" => + { "ipAddress" => [{ "privateIpAddress" => "10.0.1.6", "publicIpAddress" => "40.118.212.225" }], + "subnet" => [{ "address" => "10.0.1.0", "prefix" => "24" }] }, + "ipv6" => + { "ipAddress" => [] }, + "macAddress" => "000D3A37F080" }] } } + end + + before do + # skips all the metadata logic unless we want to test it + allow(plugin).to receive(:can_socket_connect?). + with(Ohai::Mixin::AzureMetadata::AZURE_METADATA_ADDR, 80). + and_return(false) + end + shared_examples_for "!azure" do it "does not set the azure attribute" do plugin.run @@ -42,6 +69,7 @@ it "sets the azure attribute" do plugin.run expect(plugin[:azure]).to be_truthy + expect(plugin[:azure]).to have_key(:metadata) end end @@ -159,4 +187,57 @@ it_behaves_like "azure" end + describe "with non-responsive metadata endpoint" do + before(:each) do + allow(plugin).to receive(:hint?).with("azure").and_return({}) + end + + it "does not return metadata information" do + allow(plugin).to receive(:can_socket_connect?). + with(Ohai::Mixin::AzureMetadata::AZURE_METADATA_ADDR, 80). + and_return(true) + allow(plugin).to receive(:fetch_metadata).and_return(nil) + + plugin.run + expect(plugin[:azure]).to have_key(:metadata) + expect(plugin[:azure][:metadata]).to be_nil + end + end + + describe "with responsive metadata endpoint" do + before(:each) do + allow(plugin).to receive(:hint?).with("azure").and_return({}) + allow(plugin).to receive(:can_socket_connect?). + with(Ohai::Mixin::AzureMetadata::AZURE_METADATA_ADDR, 80). + and_return(true) + allow(plugin).to receive(:fetch_metadata).and_return(response_data) + plugin.run + end + + it "returns metadata compute information" do + expect(plugin[:azure][:metadata][:compute][:location]).to eq("westus") + expect(plugin[:azure][:metadata][:compute][:name]).to eq("timtest") + expect(plugin[:azure][:metadata][:compute][:offer]).to eq("UbuntuServer") + expect(plugin[:azure][:metadata][:compute][:osType]).to eq("Linux") + expect(plugin[:azure][:metadata][:compute][:platformFaultDomain]).to eq("0") + expect(plugin[:azure][:metadata][:compute][:platformUpdateDomain]).to eq("0") + expect(plugin[:azure][:metadata][:compute][:publisher]).to eq("Canonical") + expect(plugin[:azure][:metadata][:compute][:sku]).to eq("16.04-LTS") + expect(plugin[:azure][:metadata][:compute][:version]).to eq("16.04.201707270") + expect(plugin[:azure][:metadata][:compute][:vmId]).to eq("f78151b3-da8b-4bd8-a592-d9ce8a57ea65") + expect(plugin[:azure][:metadata][:compute][:vmSize]).to eq("Standard_DS2_v2") + end + + it "returns metadata network information" do + expect(plugin[:azure][:metadata][:network][:interfaces]["000D3A37F080"][:mac]).to eq("000D3A37F080") + expect(plugin[:azure][:metadata][:network][:interfaces]["000D3A37F080"][:public_ipv6]).to eq([]) + expect(plugin[:azure][:metadata][:network][:interfaces]["000D3A37F080"][:public_ipv4]).to eq(["40.118.212.225"]) + expect(plugin[:azure][:metadata][:network][:interfaces]["000D3A37F080"][:local_ipv6]).to eq([]) + expect(plugin[:azure][:metadata][:network][:interfaces]["000D3A37F080"][:local_ipv4]).to eq(["10.0.1.6"]) + expect(plugin[:azure][:metadata][:network][:public_ipv6]).to eq([]) + expect(plugin[:azure][:metadata][:network][:public_ipv4]).to eq(["40.118.212.225"]) + expect(plugin[:azure][:metadata][:network][:local_ipv6]).to eq([]) + expect(plugin[:azure][:metadata][:network][:local_ipv4]).to eq(["10.0.1.6"]) + end + end end diff -Nru ohai-8.21.0/spec/unit/plugins/bsd/filesystem_spec.rb ohai-13.8.0/spec/unit/plugins/bsd/filesystem_spec.rb --- ohai-8.21.0/spec/unit/plugins/bsd/filesystem_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/bsd/filesystem_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -17,7 +17,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "BSD filesystem plugin" do let(:plugin) { get_plugin("bsd/filesystem") } diff -Nru ohai-8.21.0/spec/unit/plugins/bsd/virtualization_spec.rb ohai-13.8.0/spec/unit/plugins/bsd/virtualization_spec.rb --- ohai-8.21.0/spec/unit/plugins/bsd/virtualization_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/bsd/virtualization_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,14 +16,14 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "BSD virtualization plugin" do before(:each) do @plugin = get_plugin("bsd/virtualization") allow(@plugin).to receive(:collect_os).and_return(:freebsd) allow(@plugin).to receive(:shell_out).with("sysctl -n security.jail.jailed").and_return(mock_shell_out(0, "0", "")) - allow(@plugin).to receive(:shell_out).with("#{ Ohai.abs_path( "/sbin/kldstat" )}").and_return(mock_shell_out(0, "", "")) + allow(@plugin).to receive(:shell_out).with("#{Ohai.abs_path( "/sbin/kldstat" )}").and_return(mock_shell_out(0, "", "")) allow(@plugin).to receive(:shell_out).with("jls -nd").and_return(mock_shell_out(0, "", "")) allow(@plugin).to receive(:shell_out).with("sysctl -n hw.model").and_return(mock_shell_out(0, "", "")) allow(@plugin).to receive(:shell_out).with("sysctl -n kern.vm_guest").and_return(mock_shell_out(0, "", "")) @@ -77,7 +77,7 @@ 1 40 0xffffffff80100000 d20428 kernel 7 3 0xffffffff81055000 41e88 vboxguest.ko OUT - allow(@plugin).to receive(:shell_out).with("#{ Ohai.abs_path("/sbin/kldstat")}").and_return(mock_shell_out(0, @vbox_guest, "")) + allow(@plugin).to receive(:shell_out).with("#{Ohai.abs_path("/sbin/kldstat")}").and_return(mock_shell_out(0, @vbox_guest, "")) end it "detects we are a guest" do diff -Nru ohai-8.21.0/spec/unit/plugins/chef_spec.rb ohai-13.8.0/spec/unit/plugins/chef_spec.rb --- ohai-8.21.0/spec/unit/plugins/chef_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/chef_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -19,8 +19,7 @@ # begin - require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") - + require_relative "../../spec_helper.rb" require "chef/version" describe Ohai::System, "plugin chef" do diff -Nru ohai-8.21.0/spec/unit/plugins/cloud_spec.rb ohai-13.8.0/spec/unit/plugins/cloud_spec.rb --- ohai-8.21.0/spec/unit/plugins/cloud_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/cloud_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -15,7 +15,62 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" +require "ipaddr" + +describe "CloudAttrs object" do + before(:each) do + @plugin = get_plugin("cloud") + end + + let(:cloud_node) do + { "public_ipv4_addrs" => ["1.2.3.1"], + "local_ipv4_addrs" => ["1.2.4.1"], + "public_ipv6_addrs" => ["3ffe:505:2::1"], + "local_ipv6_addrs" => ["3ffe:506:2::1"], + "public_ipv4" => "1.2.3.1", + "local_ipv4" => "1.2.4.1", + "public_ipv6" => "3ffe:505:2::1", + "local_ipv6" => "3ffe:506:2::1", + "public_hostname" => "myhost.somewhere.com", + "local_hostname" => "my-localhost", + "provider" => "my_awesome_cloud", + } + end + + it "populates cloud mash" do + @cloud_attr_obj = ::CloudAttrs.new + @cloud_attr_obj.add_ipv4_addr("1.2.3.1", :public) + @cloud_attr_obj.add_ipv4_addr("1.2.4.1", :private) + @cloud_attr_obj.add_ipv6_addr("3ffe:505:2::1", :public) + @cloud_attr_obj.add_ipv6_addr("3ffe:506:2::1", :private) + @cloud_attr_obj.public_hostname = "myhost.somewhere.com" + @cloud_attr_obj.local_hostname = "my-localhost" + @cloud_attr_obj.provider = "my_awesome_cloud" + expect(@cloud_attr_obj.cloud_mash).to eq(cloud_node) + end + + it "throws exception with a bad ipv4 address" do + @cloud_attr_obj = ::CloudAttrs.new + expect { @cloud_attr_obj.add_ipv6_addr("somebogusstring", :public) }.to raise_error(RuntimeError) + end + + it "throws exception with a bad ipv6 address" do + @cloud_attr_obj = ::CloudAttrs.new + expect { @cloud_attr_obj.add_ipv6_addr("FEED:B0B:DEAD:BEEF", :public) }.to raise_error(RuntimeError) + end + + it "throws exception with ipv6 address passed to ipv4" do + @cloud_attr_obj = ::CloudAttrs.new + expect { @cloud_attr_obj.add_ipv4_addr("3ffe:506:2::1", :public) }.to raise_error(RuntimeError) + end + + it "throws exception with ipv4 address passed to ipv6" do + @cloud_attr_obj = ::CloudAttrs.new + expect { @cloud_attr_obj.add_ipv6_addr("1.2.3.4", :public) }.to raise_error(RuntimeError) + end + +end describe Ohai::System, "plugin cloud" do before(:each) do @@ -29,27 +84,40 @@ @plugin[:eucalyptus] = nil @plugin[:linode] = nil @plugin[:azure] = nil + @plugin[:gce] = nil @plugin[:digital_ocean] = nil @plugin.run expect(@plugin[:cloud]).to be_nil + expect(@plugin[:cloud_v2]).to be_nil + end + end + + describe "with a cloud mash" do + before do + @plugin[:ec2] = Mash.new + end + + it "populates cloud public ip" do + @plugin.run + expect(@plugin[:cloud]).to eq(@plugin[:cloud_v2]) end end describe "with EC2 mash" do before do - @plugin[:ec2] = Mash.new() + @plugin[:ec2] = Mash.new end it "populates cloud public ip" do @plugin[:ec2]["public_ipv4"] = "174.129.150.8" @plugin.run - expect(@plugin[:cloud][:public_ips][0]).to eq(@plugin[:ec2]["public_ipv4"]) + expect(@plugin[:cloud][:public_ipv4_addrs][0]).to eq(@plugin[:ec2]["public_ipv4"]) end it "populates cloud private ip" do @plugin[:ec2]["local_ipv4"] = "10.252.42.149" @plugin.run - expect(@plugin[:cloud][:private_ips][0]).to eq(@plugin[:ec2]["local_ipv4"]) + expect(@plugin[:cloud][:local_ipv4_addrs][0]).to eq(@plugin[:ec2]["local_ipv4"]) end it "populates cloud provider" do @@ -58,9 +126,69 @@ end end + describe "with GCE mash" do + describe "with a public IP" do + before do + @plugin[:gce] = Mash.new + @plugin[:gce]["instance"] = Mash.new + @plugin[:gce]["instance"]["networkInterfaces"] = [ + { + "accessConfigs" => [ { "externalIp" => "8.35.198.173", "type" => "ONE_TO_ONE_NAT" } ], + "ip" => "10.240.0.102", + "network" => "projects/foo/networks/default", + }, + ] + end + + it "populates cloud public ip" do + @plugin.run + expect(@plugin[:cloud][:public_ipv4_addrs][0]).to eq("8.35.198.173") + end + + it "populates cloud private ip" do + @plugin.run + expect(@plugin[:cloud][:local_ipv4_addrs][0]).to eq("10.240.0.102") + end + + it "populates cloud provider" do + @plugin.run + expect(@plugin[:cloud][:provider]).to eq("gce") + end + end + + describe "with no public IP" do + before do + @plugin[:gce] = Mash.new + @plugin[:gce]["instance"] = Mash.new + @plugin[:gce]["instance"]["networkInterfaces"] = [ + { + "accessConfigs" => [ { "externalIp" => "", "type" => "ONE_TO_ONE_NAT" } ], + "ip" => "10.240.0.102", + "network" => "projects/foo/networks/default", + }, + ] + end + + it "does not populate cloud public ip" do + @plugin.run + expect(@plugin[:cloud][:public_ipv4_addrs]).to be_nil + end + + it "populates cloud private ip" do + @plugin.run + expect(@plugin[:cloud][:local_ipv4_addrs][0]).to eq("10.240.0.102") + end + + it "populates cloud provider" do + @plugin.run + expect(@plugin[:cloud][:provider]).to eq("gce") + end + end + end + describe "with rackspace" do before do - @plugin[:rackspace] = Mash.new() + @plugin[:rackspace] = Mash.new end it "populates cloud public ip" do @@ -90,13 +218,13 @@ it "populates first cloud public ip" do @plugin[:rackspace][:public_ipv4] = "174.129.150.8" @plugin.run - expect(@plugin[:cloud][:public_ips].first).to eq(@plugin[:rackspace][:public_ipv4]) + expect(@plugin[:cloud][:public_ipv4_addrs].first).to eq(@plugin[:rackspace][:public_ipv4]) end it "populates first cloud public ip" do @plugin[:rackspace][:local_ipv4] = "174.129.150.8" @plugin.run - expect(@plugin[:cloud][:private_ips].first).to eq(@plugin[:rackspace][:local_ipv4]) + expect(@plugin[:cloud][:local_ipv4_addrs].first).to eq(@plugin[:rackspace][:local_ipv4]) end it "populates cloud provider" do @@ -107,25 +235,25 @@ describe "with linode mash" do before do - @plugin[:linode] = Mash.new() + @plugin[:linode] = Mash.new end it "populates cloud public ip" do @plugin[:linode]["public_ip"] = "174.129.150.8" @plugin.run - expect(@plugin[:cloud][:public_ips][0]).to eq(@plugin[:linode][:public_ip]) + expect(@plugin[:cloud][:public_ipv4_addrs][0]).to eq(@plugin[:linode][:public_ip]) end it "populates cloud private ip" do @plugin[:linode]["private_ip"] = "10.252.42.149" @plugin.run - expect(@plugin[:cloud][:private_ips][0]).to eq(@plugin[:linode][:private_ip]) + expect(@plugin[:cloud][:local_ipv4_addrs][0]).to eq(@plugin[:linode][:private_ip]) end it "populates first cloud public ip" do @plugin[:linode]["public_ip"] = "174.129.150.8" @plugin.run - expect(@plugin[:cloud][:public_ips].first).to eq(@plugin[:linode][:public_ip]) + expect(@plugin[:cloud][:public_ipv4_addrs].first).to eq(@plugin[:linode][:public_ip]) end it "populates cloud provider" do @@ -136,19 +264,19 @@ describe "with eucalyptus mash" do before do - @plugin[:eucalyptus] = Mash.new() + @plugin[:eucalyptus] = Mash.new end it "populates cloud public ip" do @plugin[:eucalyptus]["public_ipv4"] = "174.129.150.8" @plugin.run - expect(@plugin[:cloud][:public_ips][0]).to eq(@plugin[:eucalyptus]["public_ipv4"]) + expect(@plugin[:cloud][:public_ipv4_addrs][0]).to eq(@plugin[:eucalyptus]["public_ipv4"]) end it "populates cloud private ip" do @plugin[:eucalyptus]["local_ipv4"] = "10.252.42.149" @plugin.run - expect(@plugin[:cloud][:private_ips][0]).to eq(@plugin[:eucalyptus]["local_ipv4"]) + expect(@plugin[:cloud][:local_ipv4_addrs][0]).to eq(@plugin[:eucalyptus]["local_ipv4"]) end it "populates cloud provider" do @@ -159,33 +287,63 @@ describe "with Azure mash" do before do - @plugin[:azure] = Mash.new() + @plugin[:azure] = Mash.new + @plugin[:azure][:metadata] = { + "compute" => + { + "location" => "westus", + "name" => "timtest", + "offer" => "UbuntuServer", + "osType" => "Linux", + "platformFaultDomain" => "0", + "platformUpdateDomain" => "0", + "publisher" => "Canonical", + "sku" => "16.04-LTS", + "version" => "16.04.201707270", + "vmId" => "f78151b3-da8b-4bd8-a592-d9ce8357e365", + "vmSize" => "Standard_DS2_v2", + }, + "network" => + { + "interfaces" => + { + "000D3A37F080" => + { + "mac" => "000D3A37F080", + "public_ipv6" => [], + "public_ipv4" => ["40.118.212.225"], + "local_ipv6" => [], + "local_ipv4" => ["10.0.1.6"], + }, + }, + "public_ipv4" => ["40.118.212.225"], + "local_ipv4" => ["10.0.1.6"], + "public_ipv6" => [], + "local_ipv6" => [], + }, + } end it "populates cloud public ip" do - @plugin[:azure]["public_ip"] = "174.129.150.8" @plugin.run - expect(@plugin[:cloud][:public_ips][0]).to eq(@plugin[:azure]["public_ip"]) - expect(@plugin[:cloud][:public_ipv4]).to eq(@plugin[:azure]["public_ip"]) + expect(@plugin[:cloud][:public_ipv4_addrs][0]).to eq("40.118.212.225") end - it "populates cloud vm_name" do - @plugin[:azure]["vm_name"] = "linux-vm" + it "doesn't populates cloud vm_name" do @plugin.run - expect(@plugin[:cloud][:vm_name]).to eq(@plugin[:azure]["vm_name"]) + expect(@plugin[:cloud][:vm_name]).not_to eq("timtest") end - it "populates cloud public_fqdn" do + it "populates cloud public_hostname" do @plugin[:azure]["public_fqdn"] = "linux-vm-svc.cloudapp.net" @plugin.run - expect(@plugin[:cloud][:public_fqdn]).to eq(@plugin[:azure]["public_fqdn"]) - expect(@plugin[:cloud][:public_hostname]).to eq(@plugin[:azure]["public_fqdn"]) + expect(@plugin[:cloud][:public_hostname]).to eq("linux-vm-svc.cloudapp.net") end - it "populates cloud public_ssh_port" do + it "doesn't populate cloud public_ssh_port" do @plugin[:azure]["public_ssh_port"] = "22" @plugin.run - expect(@plugin[:cloud][:public_ssh_port]).to eq(@plugin[:azure]["public_ssh_port"]) + expect(@plugin[:cloud][:public_ssh_port]).to be_nil end it "should not populate cloud public_ssh_port when winrm is used" do @@ -197,7 +355,7 @@ it "populates cloud public_winrm_port" do @plugin[:azure]["public_winrm_port"] = "5985" @plugin.run - expect(@plugin[:cloud][:public_winrm_port]).to eq(@plugin[:azure]["public_winrm_port"]) + expect(@plugin[:cloud][:public_winrm_port]).to be_nil end it "populates cloud provider" do @@ -209,54 +367,94 @@ describe "with digital_ocean mash" do before do @plugin[:digital_ocean] = Mash.new - @plugin[:digital_ocean][:name] = "public.example.com" - @plugin[:digital_ocean][:networks] = Mash.new - @plugin[:digital_ocean][:networks][:v4] = [{ "ip_address" => "1.2.3.4", "type" => "public" }, - { "ip_address" => "5.6.7.8", "type" => "private" }] - @plugin[:digital_ocean][:networks][:v6] = [{ "ip_address" => "fe80::4240:95ff:fe47:6eee", "type" => "public" }, - { "ip_address" => "fdf8:f53b:82e4::53", "type" => "private" }] + @plugin[:digital_ocean][:interfaces] = Mash.new + @plugin[:digital_ocean][:interfaces] = { + "private" => + [ + { + "ipv4" => + { + "ip_address" => "10.135.32.4", + "netmask" => "255.255.0.0", + "gateway" => "10.135.0.1", + }, + "mac" => "36:9e:23:65:c1:fe", + "type" => "private", + }, + ], + "public" => + [ + { + "ipv4" => + { + "ip_address" => "207.154.221.42", + "netmask" => "255.255.240.0", + "gateway" => "207.154.208.1", + }, + "ipv6" => + { + "ip_address" => "2A03:B0C0:0003:00D0:0000:0000:3B15:B001", + "cidr" => 64, + "gateway" => "2A03:B0C0:0003:00D0:0000:0000:0000:0001", + }, + "anchor_ipv4" => + { + "ip_address" => "10.19.0.5", + "netmask" => "255.255.0.0", + "gateway" => "10.19.0.1", + }, + "mac" => "9a:80:15:02:7a:c1", + "type" => "public", + }, + ], + } end before(:each) do @plugin.run end - it "populates cloud public hostname" do - expect(@plugin[:cloud][:public_hostname]).to eq("public.example.com") - end - it "populates cloud local hostname" do expect(@plugin[:cloud][:local_hostname]).to be_nil end - it "populates cloud public ips" do - expect(@plugin[:cloud][:public_ips]).to eq(@plugin[:digital_ocean][:networks][:v4].select { |ip| ip["type"] == "public" } + - @plugin[:digital_ocean][:networks][:v6].select { |ip| ip["type"] == "public" }) + it "populates cloud public_ipv4_addrs" do + expect(@plugin[:cloud][:public_ipv4_addrs]).to eq(["207.154.221.42"]) + end - it "populates cloud private ips" do - expect(@plugin[:cloud][:private_ips]).to eq(@plugin[:digital_ocean][:networks][:v4].select { |ip| ip["type"] == "private" } + - @plugin[:digital_ocean][:networks][:v6].select { |ip| ip["type"] == "private" }) + it "populates cloud local_ipv4_addrs" do + expect(@plugin[:cloud][:local_ipv4_addrs]).to eq(["10.135.32.4"]) + end it "populates cloud public_ipv4" do - expect(@plugin[:cloud][:public_ipv4]).to eq(@plugin[:digital_ocean][:networks][:v4].find { |ip| ip["type"] == "public" }) + expect(@plugin[:cloud][:public_ipv4]).to eq("207.154.221.42") end it "populates cloud local_ipv4" do - expect(@plugin[:cloud][:local_ipv4]).to eq(@plugin[:digital_ocean][:networks][:v4].find { |ip| ip["type"] == "private" }) + expect(@plugin[:cloud][:local_ipv4]).to eq("10.135.32.4") + end + + it "populates cloud public_ipv6_addrs" do + expect(@plugin[:cloud][:public_ipv6_addrs]).to eq(["2a03:b0c0:3:d0::3b15:b001"]) + end + + it "populates cloud local_ipv6_addrs" do + expect(@plugin[:cloud][:local_ipv6_addrs]).to be_nil end it "populates cloud public_ipv6" do - expect(@plugin[:cloud][:public_ipv6]).to eq(@plugin[:digital_ocean][:networks][:v6].find { |ip| ip["type"] == "public" }) + expect(@plugin[:cloud][:public_ipv6]).to eq("2a03:b0c0:3:d0::3b15:b001") end it "populates cloud local_ipv6" do - expect(@plugin[:cloud][:local_ipv6]).to eq(@plugin[:digital_ocean][:networks][:v6].find { |ip| ip["type"] == "private" }) + expect(@plugin[:cloud][:local_ipv6]).to be_nil end it "populates cloud provider" do expect(@plugin[:cloud][:provider]).to eq("digital_ocean") end end + end diff -Nru ohai-8.21.0/spec/unit/plugins/cloud_v2_spec.rb ohai-13.8.0/spec/unit/plugins/cloud_v2_spec.rb --- ohai-8.21.0/spec/unit/plugins/cloud_v2_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/cloud_v2_spec.rb 1970-01-01 00:00:00.000000000 +0000 @@ -1,389 +0,0 @@ -# -# Author:: Cary Penniman () -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") -require "ipaddr" - -describe "CloudAttrs object" do - before(:each) do - @plugin = get_plugin("cloud_v2") - end - - let(:cloud_node) do - { "public_ipv4_addrs" => ["1.2.3.1"], - "local_ipv4_addrs" => ["1.2.4.1"], - "public_ipv6_addrs" => ["3ffe:505:2::1"], - "local_ipv6_addrs" => ["3ffe:506:2::1"], - "public_ipv4" => "1.2.3.1", - "local_ipv4" => "1.2.4.1", - "public_ipv6" => "3ffe:505:2::1", - "local_ipv6" => "3ffe:506:2::1", - "public_hostname" => "myhost.somewhere.com", - "local_hostname" => "my-localhost", - "provider" => "my_awesome_cloud", - } - end - - it "populates cloud mash" do - @cloud_attr_obj = ::CloudAttrs.new() - @cloud_attr_obj.add_ipv4_addr("1.2.3.1", :public) - @cloud_attr_obj.add_ipv4_addr("1.2.4.1", :private) - @cloud_attr_obj.add_ipv6_addr("3ffe:505:2::1", :public) - @cloud_attr_obj.add_ipv6_addr("3ffe:506:2::1", :private) - @cloud_attr_obj.public_hostname = "myhost.somewhere.com" - @cloud_attr_obj.local_hostname = "my-localhost" - @cloud_attr_obj.provider = "my_awesome_cloud" - expect(@cloud_attr_obj.cloud_mash).to eq(cloud_node) - end - - it "throws exception with a bad ipv4 address" do - @cloud_attr_obj = ::CloudAttrs.new() - expect { @cloud_attr_obj.add_ipv6_addr("somebogusstring", :public) }.to raise_error(RuntimeError) - end - - it "throws exception with a bad ipv6 address" do - @cloud_attr_obj = ::CloudAttrs.new() - expect { @cloud_attr_obj.add_ipv6_addr("FEED:B0B:DEAD:BEEF", :public) }.to raise_error(RuntimeError) - end - - it "throws exception with ipv6 address passed to ipv4" do - @cloud_attr_obj = ::CloudAttrs.new() - expect { @cloud_attr_obj.add_ipv4_addr("3ffe:506:2::1", :public) }.to raise_error(RuntimeError) - end - - it "throws exception with ipv4 address passed to ipv6" do - @cloud_attr_obj = ::CloudAttrs.new() - expect { @cloud_attr_obj.add_ipv6_addr("1.2.3.4", :public) }.to raise_error(RuntimeError) - end - -end - -describe Ohai::System, "plugin cloud" do - before(:each) do - @plugin = get_plugin("cloud_v2") - end - - describe "with no cloud mashes" do - it "doesn't populate the cloud data" do - @plugin[:ec2] = nil - @plugin[:rackspace] = nil - @plugin[:eucalyptus] = nil - @plugin[:linode] = nil - @plugin[:azure] = nil - @plugin[:gce] = nil - @plugin[:digital_ocean] = nil - @plugin.run - expect(@plugin[:cloud_v2]).to be_nil - end - end - - describe "with EC2 mash" do - before do - @plugin[:ec2] = Mash.new() - end - - it "populates cloud public ip" do - @plugin[:ec2]["public_ipv4"] = "174.129.150.8" - @plugin.run - expect(@plugin[:cloud_v2][:public_ipv4_addrs][0]).to eq(@plugin[:ec2]["public_ipv4"]) - end - - it "populates cloud private ip" do - @plugin[:ec2]["local_ipv4"] = "10.252.42.149" - @plugin.run - expect(@plugin[:cloud_v2][:local_ipv4_addrs][0]).to eq(@plugin[:ec2]["local_ipv4"]) - end - - it "populates cloud provider" do - @plugin.run - expect(@plugin[:cloud_v2][:provider]).to eq("ec2") - end - end - - describe "with GCE mash" do - describe "with a public IP" do - before do - @plugin[:gce] = Mash.new() - @plugin[:gce]["instance"] = Mash.new() - @plugin[:gce]["instance"]["networkInterfaces"] = [ - { - "accessConfigs" => [ { "externalIp" => "8.35.198.173", "type" => "ONE_TO_ONE_NAT" } ], - "ip" => "10.240.0.102", - "network" => "projects/foo/networks/default", - }, - ] - end - - it "populates cloud public ip" do - @plugin.run - expect(@plugin[:cloud_v2][:public_ipv4_addrs][0]).to eq("8.35.198.173") - end - - it "populates cloud private ip" do - @plugin.run - expect(@plugin[:cloud_v2][:local_ipv4_addrs][0]).to eq("10.240.0.102") - end - - it "populates cloud provider" do - @plugin.run - expect(@plugin[:cloud_v2][:provider]).to eq("gce") - end - end - - describe "with no public IP" do - before do - @plugin[:gce] = Mash.new() - @plugin[:gce]["instance"] = Mash.new() - @plugin[:gce]["instance"]["networkInterfaces"] = [ - { - "accessConfigs" => [ { "externalIp" => "", "type" => "ONE_TO_ONE_NAT" } ], - "ip" => "10.240.0.102", - "network" => "projects/foo/networks/default", - }, - ] - end - - it "does not populate cloud public ip" do - @plugin.run - expect(@plugin[:cloud_v2][:public_ipv4_addrs]).to be_nil - end - - it "populates cloud private ip" do - @plugin.run - expect(@plugin[:cloud_v2][:local_ipv4_addrs][0]).to eq("10.240.0.102") - end - - it "populates cloud provider" do - @plugin.run - expect(@plugin[:cloud_v2][:provider]).to eq("gce") - end - end - end - - describe "with rackspace" do - before do - @plugin[:rackspace] = Mash.new() - end - - it "populates cloud public ip" do - @plugin[:rackspace][:public_ipv4] = "174.129.150.8" - @plugin.run - expect(@plugin[:cloud_v2][:public_ipv4]).to eq(@plugin[:rackspace][:public_ipv4]) - end - - it "populates cloud public ipv6" do - @plugin[:rackspace][:public_ipv6] = "2a00:1a48:7805:111:e875:efaf:ff08:75" - @plugin.run - expect(@plugin[:cloud_v2][:public_ipv6]).to eq(@plugin[:rackspace][:public_ipv6]) - end - - it "populates cloud private ip" do - @plugin[:rackspace][:local_ipv4] = "10.252.42.149" - @plugin.run - expect(@plugin[:cloud_v2][:local_ipv4]).to eq(@plugin[:rackspace][:local_ipv4]) - end - - it "populates cloud private ipv6" do - @plugin[:rackspace][:local_ipv6] = "2a00:1a48:7805:111:e875:efaf:ff08:75" - @plugin.run - expect(@plugin[:cloud_v2][:local_ipv6]).to eq(@plugin[:rackspace][:local_ipv6]) - end - - it "populates first cloud public ip" do - @plugin[:rackspace][:public_ipv4] = "174.129.150.8" - @plugin.run - expect(@plugin[:cloud_v2][:public_ipv4_addrs].first).to eq(@plugin[:rackspace][:public_ipv4]) - end - - it "populates first cloud public ip" do - @plugin[:rackspace][:local_ipv4] = "174.129.150.8" - @plugin.run - expect(@plugin[:cloud_v2][:local_ipv4_addrs].first).to eq(@plugin[:rackspace][:local_ipv4]) - end - - it "populates cloud provider" do - @plugin.run - expect(@plugin[:cloud_v2][:provider]).to eq("rackspace") - end - end - - describe "with linode mash" do - before do - @plugin[:linode] = Mash.new() - end - - it "populates cloud public ip" do - @plugin[:linode]["public_ip"] = "174.129.150.8" - @plugin.run - expect(@plugin[:cloud_v2][:public_ipv4_addrs][0]).to eq(@plugin[:linode][:public_ip]) - end - - it "populates cloud private ip" do - @plugin[:linode]["private_ip"] = "10.252.42.149" - @plugin.run - expect(@plugin[:cloud_v2][:local_ipv4_addrs][0]).to eq(@plugin[:linode][:private_ip]) - end - - it "populates first cloud public ip" do - @plugin[:linode]["public_ip"] = "174.129.150.8" - @plugin.run - expect(@plugin[:cloud_v2][:public_ipv4_addrs].first).to eq(@plugin[:linode][:public_ip]) - end - - it "populates cloud provider" do - @plugin.run - expect(@plugin[:cloud_v2][:provider]).to eq("linode") - end - end - - describe "with eucalyptus mash" do - before do - @plugin[:eucalyptus] = Mash.new() - end - - it "populates cloud public ip" do - @plugin[:eucalyptus]["public_ipv4"] = "174.129.150.8" - @plugin.run - expect(@plugin[:cloud_v2][:public_ipv4_addrs][0]).to eq(@plugin[:eucalyptus]["public_ipv4"]) - end - - it "populates cloud private ip" do - @plugin[:eucalyptus]["local_ipv4"] = "10.252.42.149" - @plugin.run - expect(@plugin[:cloud_v2][:local_ipv4_addrs][0]).to eq(@plugin[:eucalyptus]["local_ipv4"]) - end - - it "populates cloud provider" do - @plugin.run - expect(@plugin[:cloud_v2][:provider]).to eq("eucalyptus") - end - end - - describe "with Azure mash" do - before do - @plugin[:azure] = Mash.new() - end - - it "populates cloud public ip" do - @plugin[:azure]["public_ip"] = "174.129.150.8" - @plugin.run - expect(@plugin[:cloud_v2][:public_ipv4_addrs][0]).to eq(@plugin[:azure]["public_ip"]) - end - - it "doesn't populates cloud vm_name" do - @plugin[:azure]["vm_name"] = "linux-vm" - @plugin.run - expect(@plugin[:cloud_v2][:vm_name]).not_to eq(@plugin[:azure]["vm_name"]) - end - - it "populates cloud public_hostname" do - @plugin[:azure]["public_fqdn"] = "linux-vm-svc.cloudapp.net" - @plugin.run - expect(@plugin[:cloud_v2][:public_hostname]).to eq(@plugin[:azure]["public_fqdn"]) - end - - it "doesn't populate cloud public_ssh_port" do - @plugin[:azure]["public_ssh_port"] = "22" - @plugin.run - expect(@plugin[:cloud_v2][:public_ssh_port]).to be_nil - end - - it "should not populate cloud public_ssh_port when winrm is used" do - @plugin[:azure]["public_winrm_port"] = "5985" - @plugin.run - expect(@plugin[:cloud_v2][:public_ssh_port]).to be_nil - end - - it "populates cloud public_winrm_port" do - @plugin[:azure]["public_winrm_port"] = "5985" - @plugin.run - expect(@plugin[:cloud_v2][:public_winrm_port]).to be_nil - end - - it "populates cloud provider" do - @plugin.run - expect(@plugin[:cloud_v2][:provider]).to eq("azure") - end - end - - describe "with digital_ocean mash" do - before do - @plugin[:digital_ocean] = Mash.new - @plugin[:digital_ocean][:name] = "public.example.com" - @plugin[:digital_ocean][:networks] = Mash.new - @plugin[:digital_ocean][:networks][:v4] = [{ "ip_address" => "1.2.3.4", "type" => "public" }, - { "ip_address" => "5.6.7.8", "type" => "private" }] - @plugin[:digital_ocean][:networks][:v6] = [{ "ip_address" => "fe80::4240:95ff:fe47:6eee", "type" => "public" }, - { "ip_address" => "fdf8:f53b:82e4::53", "type" => "private" }] - end - - before(:each) do - @plugin.run - end - - it "populates cloud public hostname" do - expect(@plugin[:cloud_v2][:public_hostname]).to eq("public.example.com") - end - - it "populates cloud local hostname" do - expect(@plugin[:cloud_v2][:local_hostname]).to be_nil - end - - it "populates cloud public_ipv4_addrs" do - expect(@plugin[:cloud_v2][:public_ipv4_addrs]).to eq(@plugin[:digital_ocean][:networks][:v4].select { |ip| ip["type"] == "public" } - .map { |ip| ip["ip_address"] }) - - end - - it "populates cloud local_ipv4_addrs" do - expect(@plugin[:cloud_v2][:local_ipv4_addrs]).to eq(@plugin[:digital_ocean][:networks][:v4].select { |ip| ip["type"] == "private" } - .map { |ip| ip["ip_address"] }) - - end - - it "populates cloud public_ipv4" do - expect(@plugin[:cloud_v2][:public_ipv4]).to eq(@plugin[:digital_ocean][:networks][:v4].find { |ip| ip["type"] == "public" }["ip_address"]) - end - - it "populates cloud local_ipv4" do - expect(@plugin[:cloud_v2][:local_ipv4]).to eq(@plugin[:digital_ocean][:networks][:v4].find { |ip| ip["type"] == "private" }["ip_address"]) - end - - it "populates cloud public_ipv6_addrs" do - expect(@plugin[:cloud_v2][:public_ipv6_addrs]).to eq(@plugin[:digital_ocean][:networks][:v6].select { |ip| ip["type"] == "public" } - .map { |ip| ip["ip_address"] }) - end - - it "populates cloud local_ipv6_addrs" do - expect(@plugin[:cloud_v2][:local_ipv6_addrs]).to eq(@plugin[:digital_ocean][:networks][:v6].select { |ip| ip["type"] == "private" } - .map { |ip| ip["ip_address"] }) - end - - it "populates cloud public_ipv6" do - expect(@plugin[:cloud_v2][:public_ipv6]).to eq(@plugin[:digital_ocean][:networks][:v6].find { |ip| ip["type"] == "public" }["ip_address"]) - end - - it "populates cloud local_ipv6" do - expect(@plugin[:cloud_v2][:local_ipv6]).to eq(@plugin[:digital_ocean][:networks][:v6].find { |ip| ip["type"] == "private" }["ip_address"]) - end - - it "populates cloud provider" do - expect(@plugin[:cloud_v2][:provider]).to eq("digital_ocean") - end - end - -end diff -Nru ohai-8.21.0/spec/unit/plugins/c_spec.rb ohai-13.8.0/spec/unit/plugins/c_spec.rb --- ohai-8.21.0/spec/unit/plugins/c_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/c_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,41 +16,19 @@ # limitations under the License. # -require "rbconfig" - -require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb")) +require_relative "../../spec_helper.rb" C_GCC = <. -EOF - -C_GLIBC_2_5 = <) -# Copyright:: Copyright (c) 2015 Facebook, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") - -describe Ohai::System, "darwin filesystem2 plugin" do - let (:plugin) { get_plugin("darwin/filesystem2") } - before(:each) do - allow(plugin).to receive(:collect_os).and_return(:darwin) - - allow(plugin).to receive(:shell_out).with("df -i").and_return(mock_shell_out(0, "", "")) - allow(plugin).to receive(:shell_out).with("mount").and_return(mock_shell_out(0, "", "")) - end - - describe "when gathering filesystem usage data from df" do - before(:each) do - @stdout = <<-DF -Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted on -/dev/disk0s2 488555536 313696448 174347088 65% 39276054 21793386 64% / -devfs 385 385 0 100% 666 0 100% /dev -map /etc/auto.direct 0 0 0 100% 0 0 100% /mnt/vol -map -hosts 0 0 0 100% 0 0 100% /net -map -static 0 0 0 100% 0 0 100% /mobile_symbol -deweyfs@osxfuse0 0 0 0 100% 0 0 100% /mnt/dewey -DF - allow(plugin).to receive(:shell_out).with("df -i").and_return(mock_shell_out(0, @stdout, "")) - end - - it "should run df -i" do - expect(plugin).to receive(:shell_out).ordered.with("df -i").and_return(mock_shell_out(0, @stdout, "")) - plugin.run - end - - it "should set size to value from df -i" do - plugin.run - expect(plugin[:filesystem2]["by_pair"]["/dev/disk0s2,/"][:kb_size]).to eq("244277768") - expect(plugin[:filesystem2]["by_pair"]["/dev/disk0s2,/"][:kb_used]).to eq("156848224") - expect(plugin[:filesystem2]["by_pair"]["/dev/disk0s2,/"][:kb_available]).to eq("87173544") - expect(plugin[:filesystem2]["by_pair"]["/dev/disk0s2,/"][:percent_used]).to eq("65%") - end - - it "should set device and mount to value from df -i" do - plugin.run - expect(plugin[:filesystem2]["by_pair"]["/dev/disk0s2,/"][:mount]).to eq("/") - expect(plugin[:filesystem2]["by_pair"]["/dev/disk0s2,/"][:device]).to eq("/dev/disk0s2") - end - - it "should set inode info to value from df -i" do - plugin.run - expect(plugin[:filesystem2]["by_pair"]["/dev/disk0s2,/"][:total_inodes]).to eq("61069440") - expect(plugin[:filesystem2]["by_pair"]["/dev/disk0s2,/"][:inodes_used]).to eq("39276054") - expect(plugin[:filesystem2]["by_pair"]["/dev/disk0s2,/"][:inodes_available]).to eq("21793386") - end - end - - describe "when gathering mounted filesystem data from mount" do - before(:each) do - @stdout = <<-MOUNT -/dev/disk0s2 on / (hfs, local, journaled) -devfs on /dev (devfs, local, nobrowse) -map /etc/auto.direct on /mnt/vol (autofs, automounted, nobrowse) -map -hosts on /net (autofs, nosuid, automounted, nobrowse) -map -static on /mobile_symbol (autofs, automounted, nobrowse) -deweyfs@osxfuse0 on /mnt/dewey (osxfusefs, synchronous, nobrowse) -MOUNT - allow(plugin).to receive(:shell_out).with("mount").and_return(mock_shell_out(0, @stdout, "")) - end - - it "should run mount" do - expect(plugin).to receive(:shell_out).with("mount").and_return(mock_shell_out(0, @stdout, "")) - plugin.run - end - - it "should set values from mount" do - plugin.run - expect(plugin[:filesystem2]["by_pair"]["/dev/disk0s2,/"][:mount]).to eq("/") - expect(plugin[:filesystem2]["by_pair"]["/dev/disk0s2,/"][:fs_type]).to eq("hfs") - expect(plugin[:filesystem2]["by_pair"]["/dev/disk0s2,/"][:mount_options]).to eq(%w{local journaled}) - end - end - - describe "when gathering filesystem data with devices mounted more than once" do - before(:each) do - @dfstdout = <<-DF -Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted on -/dev/disk0s2 488555536 313696448 174347088 65% 39276054 21793386 64% / -devfs 385 385 0 100% 666 0 100% /dev -map /etc/auto.direct 0 0 0 100% 0 0 100% /mnt/vol -map -hosts 0 0 0 100% 0 0 100% /net -map -static 0 0 0 100% 0 0 100% /mobile_symbol -deweyfs@osxfuse0 0 0 0 100% 0 0 100% /mnt/dewey -/dev/disk0s2 488555536 313696448 174347088 65% 39276054 21793386 64% /another/mountpoint -DF - allow(plugin).to receive(:shell_out).with("df -i").and_return(mock_shell_out(0, @dfstdout, "")) - end - - it "should provide a devices view with all mountpoints" do - plugin.run - expect(plugin[:filesystem2]["by_device"]["/dev/disk0s2"][:mounts]).to eq(["/", "/another/mountpoint"]) - end - end - - describe "when gathering filesystem data with double-mounts" do - before(:each) do - @dfstdout = <<-DF -Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted on -/dev/disk0s2 488555536 313696448 174347088 65% 39276054 21793386 64% / -devfs 385 385 0 100% 666 0 100% /dev -map /etc/auto.direct 0 0 0 100% 0 0 100% /mnt/vol -map -hosts 0 0 0 100% 0 0 100% /net -map -static 0 0 0 100% 0 0 100% /mobile_symbol -deweyfs@osxfuse0 0 0 0 100% 0 0 100% /mnt/dewey -/dev/disk0s3 488555536 313696448 174347088 65% 39276054 21793386 64% /mnt -/dev/disk0s4 488555536 313696448 174347088 65% 39276054 21793386 64% /mnt -DF - allow(plugin).to receive(:shell_out).with("df -i").and_return(mock_shell_out(0, @dfstdout, "")) - end - - it "should provide a mounts view with all devices" do - plugin.run - expect(plugin[:filesystem2]["by_mountpoint"]["/mnt"][:devices]).to eq(["/dev/disk0s3", "/dev/disk0s4"]) - end - end -end diff -Nru ohai-8.21.0/spec/unit/plugins/darwin/filesystem_spec.rb ohai-13.8.0/spec/unit/plugins/darwin/filesystem_spec.rb --- ohai-8.21.0/spec/unit/plugins/darwin/filesystem_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/darwin/filesystem_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "darwin filesystem plugin" do let (:plugin) { get_plugin("darwin/filesystem") } @@ -27,6 +27,11 @@ allow(plugin).to receive(:shell_out).with("mount").and_return(mock_shell_out(0, "", "")) end + it "sets both filesystem and filesystem2 attributes" do + plugin.run + expect(plugin[:filesystem]).to eq(plugin[:filesystem2]) + end + describe "when gathering filesystem usage data from df" do before(:each) do @stdout = <<-DF @@ -48,22 +53,23 @@ it "should set size to value from df -i" do plugin.run - expect(plugin[:filesystem]["/dev/disk0s2"][:kb_size]).to eq(244277768) - expect(plugin[:filesystem]["/dev/disk0s2"][:kb_used]).to eq(156848224) - expect(plugin[:filesystem]["/dev/disk0s2"][:kb_available]).to eq(87173544) - expect(plugin[:filesystem]["/dev/disk0s2"][:percent_used]).to eq("65%") + expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:kb_size]).to eq("244277768") + expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:kb_used]).to eq("156848224") + expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:kb_available]).to eq("87173544") + expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:percent_used]).to eq("65%") end - it "should set mount to value from df -i" do + it "should set device and mount to value from df -i" do plugin.run - expect(plugin[:filesystem]["/dev/disk0s2"][:mount]).to eq("/") + expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:mount]).to eq("/") + expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:device]).to eq("/dev/disk0s2") end it "should set inode info to value from df -i" do plugin.run - expect(plugin[:filesystem]["/dev/disk0s2"][:total_inodes]).to eq("61069440") - expect(plugin[:filesystem]["/dev/disk0s2"][:inodes_used]).to eq("39276054") - expect(plugin[:filesystem]["/dev/disk0s2"][:inodes_available]).to eq("21793386") + expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:total_inodes]).to eq("61069440") + expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:inodes_used]).to eq("39276054") + expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:inodes_available]).to eq("21793386") end end @@ -87,9 +93,52 @@ it "should set values from mount" do plugin.run - expect(plugin[:filesystem]["/dev/disk0s2"][:mount]).to eq("/") - expect(plugin[:filesystem]["/dev/disk0s2"][:fs_type]).to eq("hfs") - expect(plugin[:filesystem]["/dev/disk0s2"][:mount_options]).to eq(%w{local journaled}) + expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:mount]).to eq("/") + expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:fs_type]).to eq("hfs") + expect(plugin[:filesystem]["by_pair"]["/dev/disk0s2,/"][:mount_options]).to eq(%w{local journaled}) + end + end + + describe "when gathering filesystem data with devices mounted more than once" do + before(:each) do + @dfstdout = <<-DF +Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted on +/dev/disk0s2 488555536 313696448 174347088 65% 39276054 21793386 64% / +devfs 385 385 0 100% 666 0 100% /dev +map /etc/auto.direct 0 0 0 100% 0 0 100% /mnt/vol +map -hosts 0 0 0 100% 0 0 100% /net +map -static 0 0 0 100% 0 0 100% /mobile_symbol +deweyfs@osxfuse0 0 0 0 100% 0 0 100% /mnt/dewey +/dev/disk0s2 488555536 313696448 174347088 65% 39276054 21793386 64% /another/mountpoint +DF + allow(plugin).to receive(:shell_out).with("df -i").and_return(mock_shell_out(0, @dfstdout, "")) + end + + it "should provide a devices view with all mountpoints" do + plugin.run + expect(plugin[:filesystem]["by_device"]["/dev/disk0s2"][:mounts]).to eq(["/", "/another/mountpoint"]) + end + end + + describe "when gathering filesystem data with double-mounts" do + before(:each) do + @dfstdout = <<-DF +Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted on +/dev/disk0s2 488555536 313696448 174347088 65% 39276054 21793386 64% / +devfs 385 385 0 100% 666 0 100% /dev +map /etc/auto.direct 0 0 0 100% 0 0 100% /mnt/vol +map -hosts 0 0 0 100% 0 0 100% /net +map -static 0 0 0 100% 0 0 100% /mobile_symbol +deweyfs@osxfuse0 0 0 0 100% 0 0 100% /mnt/dewey +/dev/disk0s3 488555536 313696448 174347088 65% 39276054 21793386 64% /mnt +/dev/disk0s4 488555536 313696448 174347088 65% 39276054 21793386 64% /mnt +DF + allow(plugin).to receive(:shell_out).with("df -i").and_return(mock_shell_out(0, @dfstdout, "")) + end + + it "should provide a mounts view with all devices" do + plugin.run + expect(plugin[:filesystem]["by_mountpoint"]["/mnt"][:devices]).to eq(["/dev/disk0s3", "/dev/disk0s4"]) end end end diff -Nru ohai-8.21.0/spec/unit/plugins/darwin/hardware_spec.rb ohai-13.8.0/spec/unit/plugins/darwin/hardware_spec.rb --- ohai-8.21.0/spec/unit/plugins/darwin/hardware_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/darwin/hardware_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,8 +16,8 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") -require File.expand_path("#{File.dirname(__FILE__)}/hardware_system_profiler_output.rb") +require_relative "../../../spec_helper.rb" +require_relative "hardware_system_profiler_output.rb" describe Ohai::System, "Darwin hardware plugin", :unix_only do let (:plugin) { get_plugin("darwin/hardware") } @@ -31,21 +31,9 @@ ) allow(plugin).to receive(:shell_out).with( - "sw_vers -productName" + "sw_vers" ).and_return( - mock_shell_out(0, "Mac OS X", "") - ) - - allow(plugin).to receive(:shell_out).with( - "sw_vers -productVersion" - ).and_return( - mock_shell_out(0, "10.12", "") - ) - - allow(plugin).to receive(:shell_out).with( - "sw_vers -buildVersion" - ).and_return( - mock_shell_out(0, "16A239j", "") + mock_shell_out(0, "ProductName: Mac OS X\nProductVersion: 10.12\nBuildVersion: 16A239j", "") ) allow(plugin).to receive(:shell_out).with( diff -Nru ohai-8.21.0/spec/unit/plugins/darwin/hostname_spec.rb ohai-13.8.0/spec/unit/plugins/darwin/hostname_spec.rb --- ohai-8.21.0/spec/unit/plugins/darwin/hostname_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/darwin/hostname_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Darwin hostname plugin" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/darwin/kernel_spec.rb ohai-13.8.0/spec/unit/plugins/darwin/kernel_spec.rb --- ohai-8.21.0/spec/unit/plugins/darwin/kernel_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/darwin/kernel_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Darwin kernel plugin" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/darwin/memory_spec.rb ohai-13.8.0/spec/unit/plugins/darwin/memory_spec.rb --- ohai-8.21.0/spec/unit/plugins/darwin/memory_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/darwin/memory_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Darwin Memory Plugin" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/darwin/network_spec.rb ohai-13.8.0/spec/unit/plugins/darwin/network_spec.rb --- ohai-8.21.0/spec/unit/plugins/darwin/network_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/darwin/network_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Darwin Network Plugin" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/darwin/platform_spec.rb ohai-13.8.0/spec/unit/plugins/darwin/platform_spec.rb --- ohai-8.21.0/spec/unit/plugins/darwin/platform_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/darwin/platform_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Darwin plugin platform" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/darwin/system_profiler_spec.rb ohai-13.8.0/spec/unit/plugins/darwin/system_profiler_spec.rb --- ohai-8.21.0/spec/unit/plugins/darwin/system_profiler_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/darwin/system_profiler_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,15 +16,8 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") -require File.expand_path("#{File.dirname(__FILE__)}/system_profiler_output.rb") - -begin - require "plist" -rescue LoadError => e - puts "The darwin systemprofile plugin spec tests will fail without the 'plist' library/gem.\n\n" - raise e -end +require_relative "../../../spec_helper.rb" +require_relative "system_profiler_output.rb" describe Ohai::System, "Darwin system_profiler plugin", :unix_only do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/darwin/virtualization_spec.rb ohai-13.8.0/spec/unit/plugins/darwin/virtualization_spec.rb --- ohai-8.21.0/spec/unit/plugins/darwin/virtualization_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/darwin/virtualization_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -18,7 +18,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Darwin virtualization platform" do let(:plugin) { get_plugin("darwin/virtualization") } diff -Nru ohai-8.21.0/spec/unit/plugins/digital_ocean_spec.rb ohai-13.8.0/spec/unit/plugins/digital_ocean_spec.rb --- ohai-8.21.0/spec/unit/plugins/digital_ocean_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/digital_ocean_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -1,4 +1,5 @@ # +# Author:: Dylan Page () # Author:: Stafford Brunk () # License:: Apache License, Version 2.0 # @@ -15,12 +16,10 @@ # limitations under the License. # -require "ipaddress" require "spec_helper" describe Ohai::System, "plugin digital_ocean" do let(:plugin) { get_plugin("digital_ocean") } - let(:digitalocean_path) { "/etc/digitalocean" } let(:hint) do { "droplet_id" => 12345678, @@ -35,141 +34,71 @@ } end - before do - plugin[:network] = { - "interfaces" => { - "eth0" => { - "addresses" => { - "00:D3:AD:B3:3F:00" => { - "family" => "lladdr", - }, - "1.2.3.4" => { - "netmask" => "255.255.255.0", - }, - "2400:6180:0000:00d0:0000:0000:0009:7001" => {}, - }, - }, - }, - } - - allow(plugin).to receive(:hint?).with("digital_ocean").and_return(hint) + before(:each) do + allow(plugin).to receive(:hint?).with("digital_ocean").and_return(false) end shared_examples_for "!digital_ocean" do - before(:each) do - plugin.run - end - - it "does not create the digital_ocean mash" do + it "should NOT attempt to fetch the digital_ocean metadata" do + expect(plugin).not_to receive(:http_client) expect(plugin[:digital_ocean]).to be_nil - end - end - - shared_examples_for "digital_ocean_networking" do - it "creates the networks attribute" do - expect(plugin[:digital_ocean][:networks]).not_to be_nil - end - - it "pulls ip addresses from the network interfaces" do - expect(plugin[:digital_ocean][:networks][:v4]).to eq([{ "ip_address" => "1.2.3.4", - "type" => "public", - "netmask" => "255.255.255.0" }]) - expect(plugin[:digital_ocean][:networks][:v6]).to eq([{ "ip_address" => "2400:6180:0000:00d0:0000:0000:0009:7001", - "type" => "public", - "cidr" => 128 }]) + plugin.run end end shared_examples_for "digital_ocean" do before(:each) do + @http_client = double("Net::HTTP client") + allow(plugin).to receive(:http_client).and_return(@http_client) + allow(IO).to receive(:select).and_return([[], [1], []]) + t = double("connection") + allow(t).to receive(:connect_nonblock).and_raise(Errno::EINPROGRESS) + allow(Socket).to receive(:new).and_return(t) + allow(Socket).to receive(:pack_sockaddr_in).and_return(nil) + end + + let(:body) do + '{"droplet_id":2756924,"hostname":"sample-droplet","vendor_data":"#cloud-config\ndisable_root: false\nmanage_etc_hosts: true\n\n# The modules that run in the \'init\' stage\ncloud_init_modules:\n - migrator\n - ubuntu-init-switch\n - seed_random\n - bootcmd\n - write-files\n - growpart\n - resizefs\n - set_hostname\n - update_hostname\n - [ update_etc_hosts, once-per-instance ]\n - ca-certs\n - rsyslog\n - users-groups\n - ssh\n\n# The modules that run in the \'config\' stage\ncloud_config_modules:\n - disk_setup\n - mounts\n - ssh-import-id\n - locale\n - set-passwords\n - grub-dpkg\n - apt-pipelining\n - apt-configure\n - package-update-upgrade-install\n - landscape\n - timezone\n - puppet\n - chef\n - salt-minion\n - mcollective\n - disable-ec2-metadata\n - runcmd\n - byobu\n\n# The modules that run in the \'final\' stage\ncloud_final_modules:\n - rightscale_userdata\n - scripts-vendor\n - scripts-per-once\n - scripts-per-boot\n - scripts-per-instance\n - scripts-user\n - ssh-authkey-fingerprints\n - keys-to-console\n - phone-home\n - final-message\n - power-state-change\n","public_keys":["ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDAkMD3PYKHaH0KbDiXrRE6KCBo/OKcFqhM+fmnnb0+LUh4RalJWX4edeJmnT5bxLeqmLV/Yggjlpfq73R+Dy7JB4pbBLuM959mSM9ohBCSnByAGoT2iUPev4aZFZZ/ahUzTCylNxXrhZV/bopD399CvYREt7Q+FlauBv0O8MMuMGR8aC69Z3jNL+r+fGWNq98JVHGFO/UgoNL15wGCaidMhzfRqkt1u+m1nY77SFM5qWJz2R0CEC4fMlOiCg8mWBklnryV4yDEPgiXp2I8Rli1Eu2GHwuY1YX9elMeQS7n3Pzq7l6aIQmSgvcEWx6TgMD2V7nQUWpfcud/8dpp/t7z9UyfzLmNwnULHNmUeEp52sejcH5lYzISnkkWa1LzlKSeIrhF3y45m9AyxIfjEqyh/mlKQtUaW3NVXXLPwrNitxHtMIZPU5b16BODn0wb8bqPxpDNpUYrQd/BS7mWDxNpICP2ObLPhd9LW9KIYRNTzryE+uKwxm9NkMlhRku2fu415fH0G0+7aURsHviNN9SO4zct3Pj6QE5rnbVHqxt3biplUTOScdWxSk2Nv3V2dGdt/lBfu6iRPAV9IAS31s7Po3qK1t2jpEPCJwstaCBOM80kmoi3zAgotiAW50X8CelaWsHNrq5jBBgeHUZWgn/c8BkcI61pUE9l34Q6gsiEMQ== tsmith84@gmail.com"],"region":"nyc3","interfaces":{"public":[{"ipv4":{"ip_address":"159.203.92.161","netmask":"255.255.240.0","gateway":"159.203.80.1"},"ipv6":{"ip_address":"2604:A880:0800:00A1:0000:0000:0201:0001","cidr":64,"gateway":"2604:A880:0800:00A1:0000:0000:0000:0001"},"anchor_ipv4":{"ip_address":"10.17.0.5","netmask":"255.255.0.0","gateway":"10.17.0.1"},"mac":"04:01:e5:14:03:01","type":"public"}]},"floating_ip":{"ipv4":{"active":false}},"dns":{"nameservers":["2001:4860:4860::8844","2001:4860:4860::8888","8.8.8.8"]}}' + end + + it "should fetch and properly parse json metadata" do + expect(@http_client).to receive(:get). + with("/metadata/v1.json"). + and_return(double("Net::HTTP Response", :body => body, :code => "200")) plugin.run - end - it "creates a digital_ocean mash" do expect(plugin[:digital_ocean]).not_to be_nil + expect(plugin[:digital_ocean]["droplet_id"]).to eq(2756924) + expect(plugin[:digital_ocean]["hostname"]).to eq("sample-droplet") end - it "has all hint attributes" do - expect(plugin[:digital_ocean][:droplet_id]).not_to be_nil - expect(plugin[:digital_ocean][:name]).not_to be_nil - expect(plugin[:digital_ocean][:image_id]).not_to be_nil - expect(plugin[:digital_ocean][:size_id]).not_to be_nil - expect(plugin[:digital_ocean][:region_id]).not_to be_nil - end - - it "skips the ip_addresses hint attribute" do - expect(plugin[:digital_ocean][:ip_addresses]).to be_nil - end + it "should complete the run despite unavailable metadata" do + expect(@http_client).to receive(:get). + with("/metadata/v1.json"). + and_return(double("Net::HTTP Response", :body => "", :code => "404")) + plugin.run - it "has correct values for all hint attributes" do - expect(plugin[:digital_ocean][:droplet_id]).to eq(12345678) - expect(plugin[:digital_ocean][:name]).to eq("example.com") - expect(plugin[:digital_ocean][:image_id]).to eq(3240036) - expect(plugin[:digital_ocean][:size_id]).to eq(66) - expect(plugin[:digital_ocean][:region_id]).to eq(4) + expect(plugin[:digitalocean]).to be_nil end + end - include_examples "digital_ocean_networking" + describe "without hint or dmi data" do + it_should_behave_like "!digital_ocean" end describe "with digital_ocean hint file" do - before do - allow(plugin).to receive(:hint?).with("digital_ocean").and_return(hint) - end - - context "without private networking enabled" do - it_behaves_like "digital_ocean" - end + it_should_behave_like "digital_ocean" - context "with private networking enabled" do - before do - plugin[:network][:interfaces][:eth1] = { - "addresses" => { - "10.128.142.89" => { - "netmask" => "255.255.255.0", - }, - "fdf8:f53b:82e4:0000:0000:0000:0000:0053" => {}, - }, - } - - plugin.run - end - - it "extracts the private networking ips" do - expect(plugin[:digital_ocean][:networks][:v4]).to eq([{ "ip_address" => "1.2.3.4", - "type" => "public", - "netmask" => "255.255.255.0" }, - { "ip_address" => "10.128.142.89", - "type" => "private", - "netmask" => "255.255.255.0" }]) - expect(plugin[:digital_ocean][:networks][:v6]).to eq([{ "ip_address" => "2400:6180:0000:00d0:0000:0000:0009:7001", - "type" => "public", - "cidr" => 128 }, - { "ip_address" => "fdf8:f53b:82e4:0000:0000:0000:0000:0053", - "type" => "private", - "cidr" => 128 }]) - end + before(:each) do + allow(plugin).to receive(:hint?).with("digital_ocean").and_return(true) end end - describe "without digital_ocean hint file" do - before do - allow(plugin).to receive(:hint?).with("digital_ocean").and_return(false) - end - - describe "with the /etc/digitalocean file" do - before do - allow(File).to receive(:exist?).with(digitalocean_path).and_return(true) - plugin.run - end - it_behaves_like "digital_ocean_networking" - end - - describe "without the /etc/digitalocean file" do - before do - allow(File).to receive(:exist?).with(digitalocean_path).and_return(false) - end - it_behaves_like "!digital_ocean" + describe "with digital_ocean DMI data" do + it_should_behave_like "digital_ocean" + + before(:each) do + plugin[:dmi] = { :bios => { :all_records => [ { :Vendor => "DigitalOcean" } ] } } end end end diff -Nru ohai-8.21.0/spec/unit/plugins/dmi_spec.rb ohai-13.8.0/spec/unit/plugins/dmi_spec.rb --- ohai-8.21.0/spec/unit/plugins/dmi_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/dmi_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" # NOTE: These data lines must be prefixed with one or two tabs, not spaces. DMI_OUT = <<-EOS diff -Nru ohai-8.21.0/spec/unit/plugins/ec2_spec.rb ohai-13.8.0/spec/unit/plugins/ec2_spec.rb --- ohai-8.21.0/spec/unit/plugins/ec2_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/ec2_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -17,20 +17,22 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" require "open-uri" require "base64" describe Ohai::System, "plugin ec2" do + let(:plugin) { get_plugin("ec2") } + before(:each) do allow(plugin).to receive(:hint?).with("ec2").and_return(false) allow(File).to receive(:exist?).with("/sys/hypervisor/uuid").and_return(false) + allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_vendor").and_return(false) + allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_version").and_return(false) end shared_examples_for "!ec2" do - let(:plugin) { get_plugin("ec2") } - it "DOESN'T attempt to fetch the ec2 metadata or set ec2 attribute" do expect(plugin).not_to receive(:http_client) expect(plugin[:ec2]).to be_nil @@ -39,8 +41,6 @@ end shared_examples_for "ec2" do - let(:plugin) { get_plugin("ec2") } - before(:each) do @http_client = double("Net::HTTP client") allow(plugin).to receive(:http_client).and_return(@http_client) @@ -49,7 +49,7 @@ allow(t).to receive(:connect_nonblock).and_raise(Errno::EINPROGRESS) allow(Socket).to receive(:new).and_return(t) expect(@http_client).to receive(:get). - with("/").twice. + with("/"). and_return(double("Net::HTTP Response", :body => "2012-01-12", :code => "200")) end @@ -71,6 +71,9 @@ expect(@http_client).to receive(:get). with("/2012-01-12/user-data/"). and_return(double("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200")) + expect(@http_client).to receive(:get). + with("/2012-01-12/dynamic/instance-identity/document/"). + and_return(double("Net::HTTP Response", :body => "{\"accountId\":\"4815162342\"}", :code => "200")) plugin.run @@ -89,6 +92,9 @@ expect(@http_client).to receive(:get). with("/2012-01-12/user-data/"). and_return(double("Net::HTTP Response", :body => "^_<8B>^H^HU^@^Csomething^@KT,)IU(I-.II^B^@^Qz^R^@^@^@", :code => "200")) + expect(@http_client).to receive(:get). + with("/2012-01-12/dynamic/instance-identity/document/"). + and_return(double("Net::HTTP Response", :body => "{\"accountId\":\"4815162342\"}", :code => "200")) plugin.run @@ -98,6 +104,72 @@ expect(plugin[:ec2]["security_groups"]).to eql %w{group1 group2} expect(plugin[:ec2]["userdata"]).to eq(Base64.decode64("Xl88OEI+XkheSDxDNz5VXkBeQ3NvbWV0aGluZ15AS1Q8Qzg+PEM5PiwpPEM5\nPklVKEktLkk8Q0I+PENDPkk8RTU+XkJeQF5RejxCRj48QjA+XlJeQF5AXkA=")) end + + it "fetches AWS account id" do + paths.each do |name, body| + expect(@http_client).to receive(:get). + with("/2012-01-12/#{name}"). + and_return(double("Net::HTTP Response", :body => body, :code => "200")) + end + expect(@http_client).to receive(:get). + with("/2012-01-12/user-data/"). + and_return(double("Net::HTTP Response", :body => "^_<8B>^H^HU^@^Csomething^@KT,)IU(I-.II^B^@^Qz^R^@^@^@", :code => "200")) + expect(@http_client).to receive(:get). + with("/2012-01-12/dynamic/instance-identity/document/"). + and_return(double("Net::HTTP Response", :body => "{\"accountId\":\"4815162342\"}", :code => "200")) + + plugin.run + + expect(plugin[:ec2]).not_to be_nil + expect(plugin[:ec2]["instance_type"]).to eq("c1.medium") + expect(plugin[:ec2]["ami_id"]).to eq("ami-5d2dc934") + expect(plugin[:ec2]["security_groups"]).to eql %w{group1 group2} + expect(plugin[:ec2]["account_id"]).to eq("4815162342") + end + + it "fetches AWS region" do + paths.each do |name, body| + expect(@http_client).to receive(:get). + with("/2012-01-12/#{name}"). + and_return(double("Net::HTTP Response", :body => body, :code => "200")) + end + expect(@http_client).to receive(:get). + with("/2012-01-12/user-data/"). + and_return(double("Net::HTTP Response", :body => "^_<8B>^H^HU^@^Csomething^@KT,)IU(I-.II^B^@^Qz^R^@^@^@", :code => "200")) + expect(@http_client).to receive(:get). + with("/2012-01-12/dynamic/instance-identity/document/"). + and_return(double("Net::HTTP Response", :body => "{\"region\":\"us-east-1\"}", :code => "200")) + + plugin.run + + expect(plugin[:ec2]).not_to be_nil + expect(plugin[:ec2]["instance_type"]).to eq("c1.medium") + expect(plugin[:ec2]["ami_id"]).to eq("ami-5d2dc934") + expect(plugin[:ec2]["security_groups"]).to eql %w{group1 group2} + expect(plugin[:ec2]["region"]).to eq("us-east-1") + end + + it "fetches AWS availability zone" do + paths.each do |name, body| + expect(@http_client).to receive(:get). + with("/2012-01-12/#{name}"). + and_return(double("Net::HTTP Response", :body => body, :code => "200")) + end + expect(@http_client).to receive(:get). + with("/2012-01-12/user-data/"). + and_return(double("Net::HTTP Response", :body => "^_<8B>^H^HU^@^Csomething^@KT,)IU(I-.II^B^@^Qz^R^@^@^@", :code => "200")) + expect(@http_client).to receive(:get). + with("/2012-01-12/dynamic/instance-identity/document/"). + and_return(double("Net::HTTP Response", :body => "{\"availabilityZone\":\"us-east-1d\"}", :code => "200")) + + plugin.run + + expect(plugin[:ec2]).not_to be_nil + expect(plugin[:ec2]["instance_type"]).to eq("c1.medium") + expect(plugin[:ec2]["ami_id"]).to eq("ami-5d2dc934") + expect(plugin[:ec2]["security_groups"]).to eql %w{group1 group2} + expect(plugin[:ec2]["availability_zone"]).to eq("us-east-1d") + end end it "parses ec2 network/ directory as a multi-level hash" do @@ -122,6 +194,9 @@ expect(@http_client).to receive(:get). with("/2012-01-12/user-data/"). and_return(double("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200")) + expect(@http_client).to receive(:get). + with("/2012-01-12/dynamic/instance-identity/document/"). + and_return(double("Net::HTTP Response", :body => "{\"accountId\":\"4815162342\"}", :code => "200")) plugin.run @@ -150,6 +225,9 @@ expect(@http_client).to receive(:get). with("/2012-01-12/user-data/"). and_return(double("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200")) + expect(@http_client).to receive(:get). + with("/2012-01-12/dynamic/instance-identity/document/"). + and_return(double("Net::HTTP Response", :body => "{\"accountId\":\"4815162342\"}", :code => "200")) plugin.run @@ -180,6 +258,9 @@ expect(@http_client).to receive(:get). with("/2012-01-12/user-data/"). and_return(double("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200")) + expect(@http_client).to receive(:get). + with("/2012-01-12/dynamic/instance-identity/document/"). + and_return(double("Net::HTTP Response", :body => "{\"accountId\":\"4815162342\"}", :code => "200")) plugin.run @@ -219,6 +300,9 @@ expect(@http_client).to receive(:get). with("/2012-01-12/user-data/"). and_return(double("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200")) + expect(@http_client).to receive(:get). + with("/2012-01-12/dynamic/instance-identity/document/"). + and_return(double("Net::HTTP Response", :body => "{\"accountId\":\"4815162342\"}", :code => "200")) plugin.run @@ -238,6 +322,9 @@ expect(@http_client).to receive(:get). with("/2012-01-12/user-data/"). and_return(double("Net::HTTP Response", :body => "By the pricking of my thumb...", :code => "200")) + expect(@http_client).to receive(:get). + with("/2012-01-12/dynamic/instance-identity/document/"). + and_return(double("Net::HTTP Response", :body => "{\"accountId\":\"4815162342\"}", :code => "200")) plugin.run @@ -247,19 +334,39 @@ end end # shared examples for ec2 - describe "with ec2 dmi data" do + describe "with amazon dmi bios version data" do it_behaves_like "ec2" before(:each) do - plugin[:dmi] = { :bios => { :all_records => [ { :Version => "4.2.amazon" } ] } } + allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_version").and_return(true) + allow(File).to receive(:read).with("/sys/class/dmi/id/bios_version").and_return("4.2.amazon\n") end end - describe "with amazon kernel data" do + describe "with non-amazon dmi bios version data" do + it_behaves_like "!ec2" + + before(:each) do + allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_version").and_return(true) + allow(File).to receive(:read).with("/sys/class/dmi/id/bios_version").and_return("1.0\n") + end + end + + describe "with amazon dmi bios vendor data" do it_behaves_like "ec2" before(:each) do - plugin[:kernel] = { :os_info => { :organization => "Amazon.com" } } + allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_vendor").and_return(true) + allow(File).to receive(:read).with("/sys/class/dmi/id/bios_vendor").and_return("Amazon EC2\n") + end + end + + describe "with non-amazon dmi bios vendor data" do + it_behaves_like "!ec2" + + before(:each) do + allow(File).to receive(:exist?).with("/sys/class/dmi/id/bios_vendor").and_return(true) + allow(File).to receive(:read).with("/sys/class/dmi/id/bios_vendor").and_return("Xen\n") end end @@ -268,7 +375,7 @@ before(:each) do allow(File).to receive(:exist?).with("/sys/hypervisor/uuid").and_return(true) - allow(File).to receive(:read).with("/sys/hypervisor/uuid").and_return("ec2a0561-e4d6-8e15-d9c8-2e0e03adcde8") + allow(File).to receive(:read).with("/sys/hypervisor/uuid").and_return("ec2a0561-e4d6-8e15-d9c8-2e0e03adcde8\n") end end @@ -277,7 +384,39 @@ before(:each) do allow(File).to receive(:exist?).with("/sys/hypervisor/uuid").and_return(true) - allow(File).to receive(:read).with("/sys/hypervisor/uuid").and_return("123a0561-e4d6-8e15-d9c8-2e0e03adcde8") + allow(File).to receive(:read).with("/sys/hypervisor/uuid").and_return("123a0561-e4d6-8e15-d9c8-2e0e03adcde8\n") + end + end + + describe "with EC2 Identifying Number", :windows_only do + it_behaves_like "ec2" + + before do + allow_any_instance_of(WmiLite::Wmi).to receive(:first_of).and_return( + { "caption" => "Computer System Product", + "description" => "Computer System Product", + "identifyingnumber" => "ec2a355a-91cd-5fe8-bbfc-cc891d0bf9d6", + "name" => "HVM domU", + "skunumber" => nil, + "uuid" => "5A352AEC-CD91-E85F-BBFC-CC891D0BF9D6", + "vendor" => "Xen", + "version" => "4.2.amazon" }) + end + end + + describe "without EC2 Identifying Number", :windows_only do + it_behaves_like "!ec2" + + before do + allow_any_instance_of(WmiLite::Wmi).to receive(:first_of).and_return( + { "caption" => "Computer System Product", + "description" => "Computer System Product", + "identifyingnumber" => "1234", + "name" => "HVM domU", + "skunumber" => nil, + "uuid" => "5A352AEC-CD91-E85F-BBFC-CC891D0BF9D6", + "vendor" => "Xen", + "version" => "1.2.3" }) end end diff -Nru ohai-8.21.0/spec/unit/plugins/elixir_spec.rb ohai-13.8.0/spec/unit/plugins/elixir_spec.rb --- ohai-8.21.0/spec/unit/plugins/elixir_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/elixir_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -14,7 +14,7 @@ # limitations under the License. # -require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb")) +require_relative "../../spec_helper.rb" describe Ohai::System, "plugin elixir" do let(:plugin) { get_plugin("elixir") } diff -Nru ohai-8.21.0/spec/unit/plugins/erlang_spec.rb ohai-13.8.0/spec/unit/plugins/erlang_spec.rb --- ohai-8.21.0/spec/unit/plugins/erlang_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/erlang_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -17,7 +17,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" describe Ohai::System, "plugin erlang" do let(:plugin) { get_plugin("erlang") } @@ -25,10 +25,10 @@ before(:each) do plugin[:languages] = Mash.new erl_v_output = "Erlang (SMP,ASYNC_THREADS,HIPE) (BEAM) emulator version 7.3\n" - erl_systeminfo_output = "\"18\"\r\n\"7.3\"\r\n\"2.10\"\r\n" + erl_systeminfo_output = "19.1,8.1,2.11" allow(plugin).to receive(:shell_out).with("erl +V") .and_return(mock_shell_out(0, "", erl_v_output)) - allow(plugin).to receive(:shell_out).with("erl -eval 'erlang:display(erlang:system_info(otp_release)), erlang:display(erlang:system_info(version)), erlang:display(erlang:system_info(nif_version)), halt().' -noshell") + allow(plugin).to receive(:shell_out).with("erl -eval '{ok, Ver} = file:read_file(filename:join([code:root_dir(), \"releases\", erlang:system_info(otp_release), \"OTP_VERSION\"])), Vsn = binary:bin_to_list(Ver, {0, byte_size(Ver) - 1}), io:format(\"~s,~s,~s\", [Vsn, erlang:system_info(version), erlang:system_info(nif_version)]), halt().' -noshell") .and_return(mock_shell_out(0, erl_systeminfo_output, "")) end @@ -44,17 +44,17 @@ it "sets languages[:erlang][:version]" do plugin.run - expect(plugin.languages[:erlang][:version]).to eql("18") + expect(plugin.languages[:erlang][:version]).to eql("19.1") end it "sets languages[:erlang][:erts_version]" do plugin.run - expect(plugin.languages[:erlang][:erts_version]).to eql("7.3") + expect(plugin.languages[:erlang][:erts_version]).to eql("8.1") end it "sets languages[:erlang][:nif_version]" do plugin.run - expect(plugin.languages[:erlang][:nif_version]).to eql("2.10") + expect(plugin.languages[:erlang][:nif_version]).to eql("2.11") end it "does not set languages[:erlang] if the erl commands fails" do diff -Nru ohai-8.21.0/spec/unit/plugins/eucalyptus_spec.rb ohai-13.8.0/spec/unit/plugins/eucalyptus_spec.rb --- ohai-8.21.0/spec/unit/plugins/eucalyptus_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/eucalyptus_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -17,7 +17,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" require "open-uri" describe Ohai::System, "plugin eucalyptus" do @@ -36,7 +36,7 @@ allow(plugin).to receive(:http_client).and_return(@http_client) expect(@http_client).to receive(:get). - with("/").twice. + with("/"). and_return(double("Net::HTTP Response", :body => "2012-01-12", :code => "200")) expect(@http_client).to receive(:get). with("/2012-01-12/meta-data/"). diff -Nru ohai-8.21.0/spec/unit/plugins/fail_spec.rb ohai-13.8.0/spec/unit/plugins/fail_spec.rb --- ohai-8.21.0/spec/unit/plugins/fail_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/fail_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -17,7 +17,7 @@ # limitations under the License. # -require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb")) +require_relative "../../spec_helper.rb" tmp = ENV["TMPDIR"] || ENV["TMP"] || ENV["TEMP"] || "/tmp" diff -Nru ohai-8.21.0/spec/unit/plugins/freebsd/cpu_spec.rb ohai-13.8.0/spec/unit/plugins/freebsd/cpu_spec.rb --- ohai-8.21.0/spec/unit/plugins/freebsd/cpu_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/freebsd/cpu_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "FreeBSD cpu plugin on FreeBSD >=10.2" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/freebsd/hostname_spec.rb ohai-13.8.0/spec/unit/plugins/freebsd/hostname_spec.rb --- ohai-8.21.0/spec/unit/plugins/freebsd/hostname_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/freebsd/hostname_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "FreeBSD hostname plugin" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/freebsd/kernel_spec.rb ohai-13.8.0/spec/unit/plugins/freebsd/kernel_spec.rb --- ohai-8.21.0/spec/unit/plugins/freebsd/kernel_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/freebsd/kernel_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "FreeBSD kernel plugin" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/freebsd/os_spec.rb ohai-13.8.0/spec/unit/plugins/freebsd/os_spec.rb --- ohai-8.21.0/spec/unit/plugins/freebsd/os_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/freebsd/os_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "FreeBSD plugin os" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/freebsd/platform_spec.rb ohai-13.8.0/spec/unit/plugins/freebsd/platform_spec.rb --- ohai-8.21.0/spec/unit/plugins/freebsd/platform_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/freebsd/platform_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "FreeBSD plugin platform" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/gce_spec.rb ohai-13.8.0/spec/unit/plugins/gce_spec.rb --- ohai-8.21.0/spec/unit/plugins/gce_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/gce_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -15,7 +15,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" require "open-uri" describe Ohai::System, "plugin gce" do diff -Nru ohai-8.21.0/spec/unit/plugins/go_spec.rb ohai-13.8.0/spec/unit/plugins/go_spec.rb --- ohai-8.21.0/spec/unit/plugins/go_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/go_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb")) +require_relative "../../spec_helper.rb" describe Ohai::System, "plugin go" do let(:plugin) { get_plugin("go") } diff -Nru ohai-8.21.0/spec/unit/plugins/groovy_spec.rb ohai-13.8.0/spec/unit/plugins/groovy_spec.rb --- ohai-8.21.0/spec/unit/plugins/groovy_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/groovy_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb")) +require_relative "../../spec_helper.rb" describe Ohai::System, "plugin groovy" do let(:plugin) { get_plugin("groovy") } diff -Nru ohai-8.21.0/spec/unit/plugins/haskell_spec.rb ohai-13.8.0/spec/unit/plugins/haskell_spec.rb --- ohai-8.21.0/spec/unit/plugins/haskell_spec.rb 1970-01-01 00:00:00.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/haskell_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -0,0 +1,231 @@ +# Author:: Chris Dituri () +# Copyright:: Copyright (c) 2016 Chris Dituri +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +require_relative "../../spec_helper.rb" + +describe Ohai::System, "plugin haskell" do + + let(:plugin) do + plugin = get_plugin("haskell").tap do |plugin| + plugin[:languages] = Mash.new + end + end + + let(:ghc_out) { "The Glorious Glasgow Haskell Compilation System, version 7.6.3" } + let(:ghci_out) { "The Glorious Glasgow Haskell Compilation System, version 7.6.3" } + let(:cabal_out) { "cabal-install version 1.16.0.2\nusing version 1.16.0 of the Cabal library" } + let(:stack_out) { "Version 1.2.0 x86_64 hpack-0.14.0" } + let(:stack_out_git) { "Version 1.1.0, Git revision 0e9430aad55841b5ff2c6c2851f0548c16bce7cf (3540 commits) x86_64 hpack-0.13.0" } + + def setup_plugin + allow(plugin).to receive(:shell_out) + .with("ghc --version") + .and_return(mock_shell_out(0, ghc_out, "")) + allow(plugin).to receive(:shell_out) + .with("ghci --version") + .and_return(mock_shell_out(0, ghci_out, "")) + allow(plugin).to receive(:shell_out) + .with("cabal --version") + .and_return(mock_shell_out(0, cabal_out, "")) + allow(plugin).to receive(:shell_out) + .with("stack --version") + .and_return(mock_shell_out(0, stack_out, "")) + end + + context "if haskell/ghc is installed" do + + before(:each) do + setup_plugin + plugin.run + end + + it "set languages[:haskell][:ghc][:version]" do + expect(plugin[:languages][:haskell][:ghc][:version]).to eql("7.6.3") + end + + it "set languages[:haskell][:ghc][:description]" do + expect(plugin[:languages][:haskell][:ghc][:description]).to eql(ghc_out) + end + end + + context "if haskell/ghci is installed" do + + before(:each) do + setup_plugin + plugin.run + end + + it "set languages[:haskell][:ghci][:version]" do + expect(plugin[:languages][:haskell][:ghci][:version]).to eql("7.6.3") + end + + it "set languages[:haskell][:ghci][:description]" do + expect(plugin[:languages][:haskell][:ghci][:description]).to eql(ghci_out) + end + end + + context "if haskell/cabal is installed" do + + before(:each) do + setup_plugin + plugin.run + end + + it "set languages[:haskell][:cabal][:version]" do + expect(plugin[:languages][:haskell][:cabal][:version]).to eql("1.16.0.2") + end + + it "set languages[:haskell][:cabal][:description]" do + expect(plugin[:languages][:haskell][:cabal][:description]).to eql(cabal_out.split("\n")[0].chomp) + end + end + + context "if haskell/stack is installed" do + + before(:each) do + setup_plugin + plugin.run + end + + it "set languages[:haskell][:stack][:version]" do + expect(plugin[:languages][:haskell][:stack][:version]).to eql("1.2.0") + end + + it "set languages[:haskell][:stack][:description]" do + expect(plugin[:languages][:haskell][:stack][:description]).to eql(stack_out) + end + end + + context "if haskell/stack prerelease is installed" do + + before(:each) do + setup_plugin + allow(plugin).to receive(:shell_out) + .with("stack --version") + .and_return(mock_shell_out(0, stack_out_git, "")) + plugin.run + end + + it "set languages[:haskell][:stack][:version]" do + expect(plugin[:languages][:haskell][:stack][:version]).to eql("1.1.0") + end + + it "set languages[:haskell][:stack][:description]" do + expect(plugin[:languages][:haskell][:stack][:description]).to eql(stack_out_git) + end + end + + context "if haskell is NOT installed" do + + before(:each) do + allow(plugin).to receive(:shell_out) + .and_raise( Ohai::Exceptions::Exec ) + plugin.run + end + + it "do NOT set languages[:haskell]" do + expect(plugin[:languages]).not_to have_key(:haskell) + end + end + + context "if haskell/ghc is NOT installed" do + before(:each) do + allow(plugin).to receive(:shell_out) + .with("ghc --version") + .and_raise( Ohai::Exceptions::Exec ) + allow(plugin).to receive(:shell_out) + .with("ghci --version") + .and_return(mock_shell_out(0, ghci_out, "")) + allow(plugin).to receive(:shell_out) + .with("cabal --version") + .and_return(mock_shell_out(0, cabal_out, "")) + allow(plugin).to receive(:shell_out) + .with("stack --version") + .and_return(mock_shell_out(0, stack_out, "")) + plugin.run + end + + it "do NOT set languages[:haskell][:ghc]" do + expect(plugin[:languages][:haskell]).not_to have_key(:ghc) + end + end + + context "if haskell/ghci is NOT installed" do + before(:each) do + allow(plugin).to receive(:shell_out) + .with("ghc --version") + .and_return(mock_shell_out(0, ghc_out, "")) + allow(plugin).to receive(:shell_out) + .with("ghci --version") + .and_raise( Ohai::Exceptions::Exec ) + allow(plugin).to receive(:shell_out) + .with("cabal --version") + .and_return(mock_shell_out(0, cabal_out, "")) + allow(plugin).to receive(:shell_out) + .with("stack --version") + .and_return(mock_shell_out(0, stack_out, "")) + plugin.run + end + + it "do NOT set languages[:haskell][:ghci]" do + expect(plugin[:languages][:haskell]).not_to have_key(:ghci) + end + end + + context "if haskell/cabal is NOT installed" do + before(:each) do + allow(plugin).to receive(:shell_out) + .with("ghc --version") + .and_return(mock_shell_out(0, ghc_out, "")) + allow(plugin).to receive(:shell_out) + .with("ghci --version") + .and_return(mock_shell_out(0, ghci_out, "")) + allow(plugin).to receive(:shell_out) + .with("cabal --version") + .and_raise( Ohai::Exceptions::Exec ) + allow(plugin).to receive(:shell_out) + .with("stack --version") + .and_return(mock_shell_out(0, stack_out, "")) + plugin.run + end + + it "do NOT set languages[:haskell][:cabal]" do + expect(plugin[:languages][:haskell]).not_to have_key(:cabal) + end + end + + context "if haskell/stack is NOT installed" do + before(:each) do + allow(plugin).to receive(:shell_out) + .with("ghc --version") + .and_return(mock_shell_out(0, ghc_out, "")) + allow(plugin).to receive(:shell_out) + .with("ghci --version") + .and_return(mock_shell_out(0, ghci_out, "")) + allow(plugin).to receive(:shell_out) + .with("cabal --version") + .and_return(mock_shell_out(0, cabal_out, "")) + allow(plugin).to receive(:shell_out) + .with("stack --version") + .and_raise( Ohai::Exceptions::Exec ) + plugin.run + end + + it "do NOT set languages[:haskell][:stack]" do + expect(plugin[:languages][:haskell]).not_to have_key(:stack) + end + end +end diff -Nru ohai-8.21.0/spec/unit/plugins/hostname_spec.rb ohai-13.8.0/spec/unit/plugins/hostname_spec.rb --- ohai-8.21.0/spec/unit/plugins/hostname_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/hostname_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" describe Ohai::System, "hostname plugin" do before(:each) do @@ -25,50 +25,25 @@ allow(@plugin).to receive(:shell_out).with("hostname").and_return(mock_shell_out(0, "katie.local", "")) end - context "when sigar is not installed" do - before(:each) do - allow(@plugin).to receive(:sigar_is_available?).and_return(false) - expect(@plugin).not_to receive(:get_fqdn_from_sigar) - allow(@plugin).to receive(:resolve_fqdn).and_return("katie.bethell") - end - it_should_check_from("linux::hostname", "machinename", "hostname", "katie.local") - - it "should use #resolve_fqdn to find the fqdn" do - @plugin.run - expect(@plugin[:fqdn]).to eq("katie.bethell") - end - - it "should set the domain to everything after the first dot of the fqdn" do - @plugin.run - expect(@plugin[:domain]).to eq("bethell") - end - - it "should set the [short] hostname to everything before the first dot of the fqdn" do - @plugin.run - expect(@plugin[:hostname]).to eq("katie") - end + context "default behavior" + before(:each) do + allow(@plugin).to receive(:resolve_fqdn).and_return("katie.bethell") + end + it_should_check_from("linux::hostname", "machinename", "hostname", "katie.local") + + it "should use #resolve_fqdn to find the fqdn" do + @plugin.run + expect(@plugin[:fqdn]).to eq("katie.bethell") + end + + it "should set the domain to everything after the first dot of the fqdn" do + @plugin.run + expect(@plugin[:domain]).to eq("bethell") end - context "when sigar is installed" do - before(:each) do - allow(@plugin).to receive(:sigar_is_available?).and_return(true) - allow(@plugin).to receive(:get_fqdn_from_sigar).and_return("katie.bethell") - end - it_should_check_from("linux::hostname", "machinename", "hostname", "katie.local") - it "should set the fqdn to the returned value from sigar" do - @plugin.run - expect(@plugin[:fqdn]).to eq("katie.bethell") - end - - it "should set the domain to everything after the first dot of the fqdn" do - @plugin.run - expect(@plugin[:domain]).to eq("bethell") - end - - it "should set the [short] hostname to everything before the first dot of the fqdn" do - @plugin.run - expect(@plugin[:hostname]).to eq("katie") - end + it "should set the [short] hostname to everything before the first dot of the fqdn" do + @plugin.run + expect(@plugin[:hostname]).to eq("katie") end context "when a system has a bare hostname without a FQDN" do diff -Nru ohai-8.21.0/spec/unit/plugins/init_package_spec.rb ohai-13.8.0/spec/unit/plugins/init_package_spec.rb --- ohai-8.21.0/spec/unit/plugins/init_package_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/init_package_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb")) +require_relative "../../spec_helper.rb" describe Ohai::System, "Init package" do let(:plugin) do diff -Nru ohai-8.21.0/spec/unit/plugins/ip_scopes_spec.rb ohai-13.8.0/spec/unit/plugins/ip_scopes_spec.rb --- ohai-8.21.0/spec/unit/plugins/ip_scopes_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/ip_scopes_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -1,9 +1,21 @@ -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +# +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# -begin - require "ipaddr_extensions" -rescue LoadError -end +require_relative "../../spec_helper.rb" +require "ipaddr_extensions" describe Ohai::System, "plugin ip_scopes" do let(:plugin) { get_plugin("ip_scopes") } @@ -11,13 +23,17 @@ let(:interfaces) do Hash[ interface1, { :addresses => addresses1, :type => interface1_type }, - interface2, { :addresses => addresses2, :type => interface2_type }] end + interface2, { :addresses => addresses2, :type => interface2_type }, + interface3, { :addresses => addresses3, :type => interface3_type }] end let(:interface1) { :eth0 } let(:interface2) { :eth1 } + let(:interface3) { :eth2 } let(:addresses1) { {} } let(:addresses2) { {} } + let(:addresses3) { {} } let(:interface1_type) { "eth" } let(:interface2_type) { "eth" } + let(:interface3_type) { "eth" } before { plugin[:network] = network } @@ -62,11 +78,36 @@ end end + context "when host has tunl" do + let(:ip1) { "10.0.0.1" } + let(:ip2) { "192.168.1.1" } + let(:interface1_type) { "eth" } + let(:interface2_type) { "tunl" } + + it "picks the non-virtual address" do + expect(plugin[:privateaddress]).to eq("10.0.0.1") + end + end + + context "when host has docker" do + let(:ip1) { "10.0.0.1" } + let(:ip2) { "192.168.1.1" } + let(:interface1_type) { "eth" } + let(:interface2_type) { "docker" } + + it "picks the non-virtual address" do + expect(plugin[:privateaddress]).to eq("10.0.0.1") + end + end + context "when host only has virtual RFC1918 addresses" do let(:ip1) { "10.0.0.1" } let(:ip2) { "192.168.1.1" } + let(:ip3) { "172.16.1.1" } + let(:interface1_type) { "ppp" } - let(:interface2_type) { "ppp" } + let(:interface2_type) { "tunl" } + let(:interface3_type) { "docker" } it "ignores them" do expect(plugin[:privateaddress]).to be nil diff -Nru ohai-8.21.0/spec/unit/plugins/java_spec.rb ohai-13.8.0/spec/unit/plugins/java_spec.rb --- ohai-8.21.0/spec/unit/plugins/java_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/java_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -17,7 +17,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" describe Ohai::System, "plugin java (Java5 Client VM)" do let(:plugin) { get_plugin("java") } diff -Nru ohai-8.21.0/spec/unit/plugins/joyent_spec.rb ohai-13.8.0/spec/unit/plugins/joyent_spec.rb --- ohai-8.21.0/spec/unit/plugins/joyent_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/joyent_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -1,71 +1,99 @@ -require "spec_helper" +# +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require_relative "../../spec_helper.rb" describe Ohai::System, "plugin joyent" do - before(:each) do - @plugin = get_plugin("joyent") - end + let(:plugin) { get_plugin("joyent") } describe "without joyent" do before(:each) do - allow(@plugin).to receive(:is_smartos?).and_return(false) + allow(plugin).to receive(:is_smartos?).and_return(false) end - it "should NOT create joyent" do - @plugin.run - expect(@plugin[:joyent]).to be_nil + it "DOES NOT create joyent mash" do + plugin.run + expect(plugin[:joyent]).to be_nil end end describe "with joyent" do before(:each) do - allow(@plugin).to receive(:is_smartos?).and_return(true) - @plugin[:virtualization] = Mash.new - @plugin[:virtualization][:guest_uuid] = "global" + allow(plugin).to receive(:is_smartos?).and_return(true) + plugin[:virtualization] = Mash.new + plugin[:virtualization][:guest_uuid] = "global" end - it "should create joyent" do - @plugin.run - expect(@plugin[:joyent]).not_to be_nil + it "creates joyent mash" do + plugin.run + expect(plugin[:joyent]).not_to be_nil end describe "under global zone" do before(:each) do - @plugin.run + plugin.run end - it "should ditect global zone" do - expect(@plugin[:joyent][:sm_uuid]).to eql "global" + it "detects global zone" do + expect(plugin[:joyent][:sm_uuid]).to eql "global" end - it "should NOT create sm_id" do - expect(@plugin[:joyent][:sm_id]).to be_nil + it "DOES NOT create sm_id" do + expect(plugin[:joyent][:sm_id]).to be_nil end end describe "under smartmachine" do before(:each) do - @plugin[:virtualization][:guest_uuid] = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx" - @plugin[:virtualization][:guest_id] = "30" - allow(@plugin).to receive(:collect_product_file).and_return(["Name: Joyent Instance", "Image: base64 13.4.2", "Documentation: http://wiki.joyent.com/jpc2/SmartMachine+Base"]) - allow(@plugin).to receive(:collect_pkgsrc).and_return("http://pkgsrc.joyent.com/packages/SmartOS/2013Q4/x86_64/All") - @plugin.run + plugin[:virtualization][:guest_uuid] = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx" + plugin[:virtualization][:guest_id] = "30" + + etc_product = <<-EOS +Name: Joyent Instance +Image: pkgbuild 16.3.1 +Documentation: https://docs.joyent.com/images/smartos/pkgbuild + EOS + + pkg_install_conf = <<-EOS +GPG_KEYRING_VERIFY=/opt/local/etc/gnupg/pkgsrc.gpg +GPG_KEYRING_PKGVULN=/opt/local/share/gnupg/pkgsrc-security.gpg +PKG_PATH=https://pkgsrc.joyent.com/packages/SmartOS/2016Q3/x86_64/All +VERIFIED_INSTALLATION=trusted + EOS + + allow(::File).to receive(:read).with("/etc/product").and_return(etc_product) + allow(::File).to receive(:read).with("/opt/local/etc/pkg_install.conf").and_return(pkg_install_conf) + plugin.run end - it "should retrive zone uuid" do - expect(@plugin[:joyent][:sm_uuid]).to eql "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx" + it "retrieves zone uuid" do + expect(plugin[:joyent][:sm_uuid]).to eql "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx" end - it "should collect sm_id" do - expect(@plugin[:joyent][:sm_id]).to eql "30" + it "collects sm_id" do + expect(plugin[:joyent][:sm_id]).to eql "30" end - it "should collect images" do - expect(@plugin[:joyent][:sm_image_id]).not_to be_nil - expect(@plugin[:joyent][:sm_image_ver]).not_to be_nil + it "collects images" do + expect(plugin[:joyent][:sm_image_id]).to eql "pkgbuild" + expect(plugin[:joyent][:sm_image_ver]).to eql "16.3.1" end - it "should collect pkgsrc" do - expect(@plugin[:joyent][:sm_pkgsrc]).to eql "http://pkgsrc.joyent.com/packages/SmartOS/2013Q4/x86_64/All" + it "collects pkgsrc" do + expect(plugin[:joyent][:sm_pkgsrc]).to eql "https://pkgsrc.joyent.com/packages/SmartOS/2016Q3/x86_64/All" end end end diff -Nru ohai-8.21.0/spec/unit/plugins/kernel_spec.rb ohai-13.8.0/spec/unit/plugins/kernel_spec.rb --- ohai-8.21.0/spec/unit/plugins/kernel_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/kernel_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" describe Ohai::System, "plugin kernel" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/linode_spec.rb ohai-13.8.0/spec/unit/plugins/linode_spec.rb --- ohai-8.21.0/spec/unit/plugins/linode_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/linode_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -15,7 +15,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" describe Ohai::System, "plugin linode" do let(:plugin) { get_plugin("linode") } diff -Nru ohai-8.21.0/spec/unit/plugins/linux/block_device_spec.rb ohai-13.8.0/spec/unit/plugins/linux/block_device_spec.rb --- ohai-8.21.0/spec/unit/plugins/linux/block_device_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/linux/block_device_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -15,7 +15,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Linux Block Device Plugin" do DISKS = { diff -Nru ohai-8.21.0/spec/unit/plugins/linux/cpu_spec.rb ohai-13.8.0/spec/unit/plugins/linux/cpu_spec.rb --- ohai-8.21.0/spec/unit/plugins/linux/cpu_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/linux/cpu_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -17,8 +17,7 @@ # require "tempfile" - -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" shared_examples "Common cpu info" do |total_cpu, real_cpu| describe "cpu" do @@ -61,32 +60,24 @@ end end -describe Ohai::System, "General Linux cpu plugin" do - let(:plugin) { get_plugin("linux/cpu") } +shared_examples "arm64 processor info" do |cpu_no, bogomips, features| + describe "arm64 processor" do + it "has bogomips for cpu #{cpu_no}" do + plugin.run + expect(plugin[:cpu]["#{cpu_no}"]).to have_key("bogomips") + expect(plugin[:cpu]["#{cpu_no}"]["bogomips"]).to eql(bogomips) + end - let(:cpuinfo_contents) do - <<-EOF -processor : 0 -vendor_id : GenuineIntel -cpu family : 6 -model : 23 -model name : Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz -stepping : 6 -cpu MHz : 1968.770 -cache size : 64 KB -fdiv_bug : no -hlt_bug : no -f00f_bug : no -coma_bug : no -fpu : yes -fpu_exception : yes -cpuid level : 10 -wp : yes -flags : fpu pse tsc msr mce cx8 sep mtrr pge cmov -bogomips : 2575.86 -clflush size : 32 - EOF + it "has features for cpu #{cpu_no}" do + plugin.run + expect(plugin[:cpu]["#{cpu_no}"]).to have_key("features") + expect(plugin[:cpu]["#{cpu_no}"]["features"]).to eql(features) + end end +end + +describe Ohai::System, "General Linux cpu plugin" do + let(:plugin) { get_plugin("linux/cpu") } let(:tempfile_handle) do tempfile = Tempfile.new("ohai-rspec-proc-cpuinfo") @@ -109,81 +100,139 @@ end end - it_behaves_like "Common cpu info", 1, 0 + context "with old kernel that doesn't include cores in /proc/cpuinfo" do + let(:cpuinfo_contents) do + <<-EOF + processor : 0 + vendor_id : GenuineIntel + cpu family : 6 + model : 23 + model name : Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz + stepping : 6 + cpu MHz : 1968.770 + cache size : 64 KB + fdiv_bug : no + hlt_bug : no + f00f_bug : no + coma_bug : no + fpu : yes + fpu_exception : yes + cpuid level : 10 + wp : yes + flags : fpu pse tsc msr mce cx8 sep mtrr pge cmov + bogomips : 2575.86 + clflush size : 32 + EOF + end - it "gets total cores" do - plugin.run - expect(plugin[:cpu][:cores]).to eql(0) - end + let(:lscpu) do + <<-EOF +Architecture: x86_64 +CPU op-mode(s): 32-bit, 64-bit +Byte Order: Little Endian +CPU(s): 1 +On-line CPU(s) list: 0 +Thread(s) per core: 1 +Core(s) per socket: 1 +Socket(s): 1 +NUMA node(s): 1 +Vendor ID: GenuineIntel +CPU family: 6 +Model: 23 +Model name: Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz +Stepping: 2 +CPU MHz: 1968.770 +BogoMIPS: 2575.86 +Hypervisor vendor: Xen +Virtualization type: full +L1d cache: 32K +L1i cache: 32K +L2 cache: 256K +L3 cache: 30720K +NUMA node0 CPU(s): 0 +Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm fsgsbase bmi1 avx2 smep bmi2 erms invpcid xsaveopt + EOF + end - it "doesn't have a cpu 1" do - plugin.run - expect(plugin[:cpu]).not_to have_key("1") - end + it_behaves_like "Common cpu info", 1, 1 - it "has a vendor_id for cpu 0" do - plugin.run - expect(plugin[:cpu]["0"]).to have_key("vendor_id") - expect(plugin[:cpu]["0"]["vendor_id"]).to eql("GenuineIntel") - end + before(:each) do + allow(plugin).to receive(:shell_out).with("lscpu").and_return(mock_shell_out(0, lscpu, "")) + end - it "has a family for cpu 0" do - plugin.run - expect(plugin[:cpu]["0"]).to have_key("family") - expect(plugin[:cpu]["0"]["family"]).to eql("6") - end + it "gets total cores" do + plugin.run + expect(plugin[:cpu][:cores]).to eql(1) + end - it "has a model for cpu 0" do - plugin.run - expect(plugin[:cpu]["0"]).to have_key("model") - expect(plugin[:cpu]["0"]["model"]).to eql("23") - end + it "doesn't have a cpu 1" do + plugin.run + expect(plugin[:cpu]).not_to have_key("1") + end - it "has a stepping for cpu 0" do - plugin.run - expect(plugin[:cpu]["0"]).to have_key("stepping") - expect(plugin[:cpu]["0"]["stepping"]).to eql("6") - end + it "has a vendor_id for cpu 0" do + plugin.run + expect(plugin[:cpu]["0"]).to have_key("vendor_id") + expect(plugin[:cpu]["0"]["vendor_id"]).to eql("GenuineIntel") + end - it "doesn't have a phyiscal_id for cpu 0" do - plugin.run - expect(plugin[:cpu]["0"]).not_to have_key("physical_id") - end + it "has a family for cpu 0" do + plugin.run + expect(plugin[:cpu]["0"]).to have_key("family") + expect(plugin[:cpu]["0"]["family"]).to eql("6") + end - it "doesn't have a core_id for cpu 0" do - plugin.run - expect(plugin[:cpu]["0"]).not_to have_key("core_id") - end + it "has a model for cpu 0" do + plugin.run + expect(plugin[:cpu]["0"]).to have_key("model") + expect(plugin[:cpu]["0"]["model"]).to eql("23") + end - it "doesn't have a cores for cpu 0" do - plugin.run - expect(plugin[:cpu]["0"]).not_to have_key("cores") - end + it "has a stepping for cpu 0" do + plugin.run + expect(plugin[:cpu]["0"]).to have_key("stepping") + expect(plugin[:cpu]["0"]["stepping"]).to eql("6") + end - it "has a model name for cpu 0" do - plugin.run - expect(plugin[:cpu]["0"]).to have_key("model_name") - expect(plugin[:cpu]["0"]["model_name"]).to eql("Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz") - end + it "doesn't have a phyiscal_id for cpu 0" do + plugin.run + expect(plugin[:cpu]["0"]).not_to have_key("physical_id") + end - it "has a mhz for cpu 0" do - plugin.run - expect(plugin[:cpu]["0"]).to have_key("mhz") - expect(plugin[:cpu]["0"]["mhz"]).to eql("1968.770") - end + it "doesn't have a core_id for cpu 0" do + plugin.run + expect(plugin[:cpu]["0"]).not_to have_key("core_id") + end - it "has a cache_size for cpu 0" do - plugin.run - expect(plugin[:cpu]["0"]).to have_key("cache_size") - expect(plugin[:cpu]["0"]["cache_size"]).to eql("64 KB") - end + it "doesn't have a cores for cpu 0" do + plugin.run + expect(plugin[:cpu]["0"]).not_to have_key("cores") + end - it "has flags for cpu 0" do - plugin.run - expect(plugin[:cpu]["0"]).to have_key("flags") - expect(plugin[:cpu]["0"]["flags"]).to eq(%w{fpu pse tsc msr mce cx8 sep mtrr pge cmov}) - end + it "has a model name for cpu 0" do + plugin.run + expect(plugin[:cpu]["0"]).to have_key("model_name") + expect(plugin[:cpu]["0"]["model_name"]).to eql("Intel(R) Core(TM)2 Duo CPU T8300 @ 2.40GHz") + end + + it "has a mhz for cpu 0" do + plugin.run + expect(plugin[:cpu]["0"]).to have_key("mhz") + expect(plugin[:cpu]["0"]["mhz"]).to eql("1968.770") + end + + it "has a cache_size for cpu 0" do + plugin.run + expect(plugin[:cpu]["0"]).to have_key("cache_size") + expect(plugin[:cpu]["0"]["cache_size"]).to eql("64 KB") + end + it "has flags for cpu 0" do + plugin.run + expect(plugin[:cpu]["0"]).to have_key("flags") + expect(plugin[:cpu]["0"]["flags"]).to eq(%w{fpu pse tsc msr mce cx8 sep mtrr pge cmov}) + end + end context "with a dual-core hyperthreaded /proc/cpuinfo" do let(:cpuinfo_contents) do <<-EOF @@ -316,6 +365,7 @@ before(:each) do allow(plugin).to receive(:collect_os).and_return(:linux) + allow(plugin).to receive(:shell_out).with("lscpu").and_return(mock_shell_out(1, "", "")) @double_file = double("/proc/cpuinfo") allow(@double_file).to receive(:each). @@ -328,7 +378,7 @@ allow(File).to receive(:open).with("/proc/cpuinfo").and_return(@double_file) end - it_behaves_like "Common cpu info", 2, 0 + it_behaves_like "Common cpu info", 2, nil it "has a cpu 1" do plugin.run @@ -356,3 +406,35 @@ it_behaves_like "S390 processor info", 0, "EE", "06E276", "2717" it_behaves_like "S390 processor info", 1, "FF", "06E278", "2818" end + +describe Ohai::System, "arm64 linux cpu plugin" do + let(:plugin) { get_plugin("linux/cpu") } + + before(:each) do + allow(plugin).to receive(:collect_os).and_return(:linux) + allow(plugin).to receive(:shell_out).with("lscpu").and_return(mock_shell_out(1, "", "")) + + @double_file = double("/proc/cpuinfo") + allow(@double_file).to receive(:each). + and_yield("processor : 0"). + and_yield("BogoMIPS : 40.00"). + and_yield("Features : fp asimd evtstrm aes pmull sha1 sha2 crc32"). + and_yield(""). + and_yield("processor : 1"). + and_yield("BogoMIPS : 40.00"). + and_yield("Features : fp asimd evtstrm aes pmull sha1 sha2 crc32"). + and_yield("") + allow(File).to receive(:open).with("/proc/cpuinfo").and_return(@double_file) + end + + it_behaves_like "Common cpu info", 2, nil + + it "has a cpu 1" do + plugin.run + expect(plugin[:cpu]).to have_key("1") + end + + features = %w{fp asimd evtstrm aes pmull sha1 sha2 crc32} + it_behaves_like "arm64 processor info", 0, "40.00", features + it_behaves_like "arm64 processor info", 1, "40.00", features +end diff -Nru ohai-8.21.0/spec/unit/plugins/linux/filesystem2_spec.rb ohai-13.8.0/spec/unit/plugins/linux/filesystem2_spec.rb --- ohai-8.21.0/spec/unit/plugins/linux/filesystem2_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/linux/filesystem2_spec.rb 1970-01-01 00:00:00.000000000 +0000 @@ -1,437 +0,0 @@ -# -# Author:: Matthew Kent () -# Copyright:: Copyright (c) 2011-2016 Chef Software, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") - -describe Ohai::System, "Linux filesystem plugin" do - let (:plugin) { get_plugin("linux/filesystem2") } - before(:each) do - allow(plugin).to receive(:collect_os).and_return(:linux) - - allow(plugin).to receive(:shell_out).with("df -P").and_return(mock_shell_out(0, "", "")) - allow(plugin).to receive(:shell_out).with("df -iP").and_return(mock_shell_out(0, "", "")) - allow(plugin).to receive(:shell_out).with("mount").and_return(mock_shell_out(0, "", "")) - allow(File).to receive(:exist?).with("/bin/lsblk").and_return(false) - allow(plugin).to receive(:shell_out).with("blkid").and_return(mock_shell_out(0, "", "")) - - allow(plugin).to receive(:shell_out). - with("lsblk -n -P -o NAME,UUID,LABEL,FSTYPE"). - and_return(mock_shell_out(0, "", "")) - - allow(File).to receive(:exist?).with("/proc/mounts").and_return(false) - - %w{sdb1 sdb2 sda1 sda2 md0 md1 md2}.each do |name| - allow(File).to receive(:exist?).with("/dev/#{name}").and_return(true) - end - %w{ - sys.vg-root.lv - sys.vg-swap.lv - sys.vg-tmp.lv - sys.vg-usr.lv - sys.vg-var.lv - sys.vg-home.lv - debian--7-root - }.each do |name| - allow(File).to receive(:exist?).with("/dev/#{name}").and_return(false) - allow(File).to receive(:exist?).with("/dev/mapper/#{name}").and_return(true) - end - end - - describe "when gathering filesystem usage data from df" do - before(:each) do - @stdout = <<-DF -Filesystem 1024-blocks Used Available Capacity Mounted on -/dev/mapper/sys.vg-root.lv 4805760 378716 4182924 9% / -tmpfs 2030944 0 2030944 0% /lib/init/rw -udev 2025576 228 2025348 1% /dev -tmpfs 2030944 2960 2027984 1% /dev/shm -/dev/mapper/sys.vg-home.lv 97605056 53563252 44041804 55% /home -/dev/mapper/sys.vg-special.lv 97605057 53563253 44041805 56% /special -/dev/mapper/sys.vg-tmp.lv 1919048 46588 1774976 3% /tmp -/dev/mapper/sys.vg-usr.lv 19223252 5479072 12767696 31% /usr -/dev/mapper/sys.vg-var.lv 19223252 3436556 14810212 19% /var -/dev/md0 960492 36388 875312 4% /boot -DF - allow(plugin).to receive(:shell_out).with("df -P").and_return(mock_shell_out(0, @stdout, "")) - - @inode_stdout = <<-DFi -Filesystem Inodes IUsed IFree IUse% Mounted on -/dev/xvda1 1310720 107407 1203313 9% / -/dev/mapper/sys.vg-special.lv 124865 380 124485 1% /special -tmpfs 126922 273 126649 1% /run -none 126922 1 126921 1% /run/lock -none 126922 1 126921 1% /run/shm -DFi - allow(plugin).to receive(:shell_out).with("df -iP").and_return(mock_shell_out(0, @inode_stdout, "")) - end - - it "should run df -P and df -iP" do - expect(plugin).to receive(:shell_out).ordered.with("df -P").and_return(mock_shell_out(0, @stdout, "")) - expect(plugin).to receive(:shell_out).ordered.with("df -iP").and_return(mock_shell_out(0, @inode_stdout, "")) - plugin.run - end - - it "should set kb_size to value from df -P" do - plugin.run - expect(plugin[:filesystem2]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:kb_size]).to eq("97605057") - end - - it "should set kb_used to value from df -P" do - plugin.run - expect(plugin[:filesystem2]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:kb_used]).to eq("53563253") - end - - it "should set kb_available to value from df -P" do - plugin.run - expect(plugin[:filesystem2]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:kb_available]).to eq("44041805") - end - - it "should set percent_used to value from df -P" do - plugin.run - expect(plugin[:filesystem2]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:percent_used]).to eq("56%") - end - - it "should set mount to value from df -P" do - plugin.run - expect(plugin[:filesystem2]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:mount]).to eq("/special") - end - - it "should set total_inodes to value from df -iP" do - plugin.run - expect(plugin[:filesystem2]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:total_inodes]).to eq("124865") - end - - it "should set inodes_used to value from df -iP" do - plugin.run - expect(plugin[:filesystem2]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:inodes_used]).to eq("380") - end - - it "should set inodes_available to value from df -iP" do - plugin.run - expect(plugin[:filesystem2]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:inodes_available]).to eq("124485") - end - end - - describe "when gathering mounted filesystem data from mount" do - before(:each) do - @stdout = <<-MOUNT -/dev/mapper/sys.vg-root.lv on / type ext4 (rw,noatime,errors=remount-ro) -tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755) -proc on /proc type proc (rw,noexec,nosuid,nodev) -sysfs on /sys type sysfs (rw,noexec,nosuid,nodev) -udev on /dev type tmpfs (rw,mode=0755) -tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev) -devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620) -/dev/mapper/sys.vg-home.lv on /home type xfs (rw,noatime) -/dev/mapper/sys.vg-special.lv on /special type xfs (ro,noatime) -/dev/mapper/sys.vg-tmp.lv on /tmp type ext4 (rw,noatime) -/dev/mapper/sys.vg-usr.lv on /usr type ext4 (rw,noatime) -/dev/mapper/sys.vg-var.lv on /var type ext4 (rw,noatime) -/dev/md0 on /boot type ext3 (rw,noatime,errors=remount-ro) -fusectl on /sys/fs/fuse/connections type fusectl (rw) -binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev) -MOUNT - allow(plugin).to receive(:shell_out).with("mount").and_return(mock_shell_out(0, @stdout, "")) - end - - it "should run mount" do - expect(plugin).to receive(:shell_out).with("mount").and_return(mock_shell_out(0, @stdout, "")) - plugin.run - end - - it "should set mount to value from mount" do - plugin.run - expect(plugin[:filesystem2]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:mount]).to eq("/special") - end - - it "should set fs_type to value from mount" do - plugin.run - expect(plugin[:filesystem2]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:fs_type]).to eq("xfs") - end - - it "should set mount_options to an array of values from mount" do - plugin.run - expect(plugin[:filesystem2]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:mount_options]).to eq(%w{ro noatime}) - end - end - - describe "when gathering filesystem type data from blkid" do - before(:each) do - # blkid and lsblk output are coorelated with df/mount output, so the - # most full test of them actually requires we have both - @dfstdout = <<-DF -Filesystem 1024-blocks Used Available Capacity Mounted on -/dev/mapper/sys.vg-root.lv 4805760 378716 4182924 9% / -tmpfs 2030944 0 2030944 0% /lib/init/rw -udev 2025576 228 2025348 1% /dev -tmpfs 2030944 2960 2027984 1% /dev/shm -/dev/mapper/sys.vg-home.lv 97605056 53563252 44041804 55% /home -/dev/mapper/sys.vg-special.lv 97605057 53563253 44041805 56% /special -/dev/mapper/sys.vg-tmp.lv 1919048 46588 1774976 3% /tmp -/dev/mapper/sys.vg-usr.lv 19223252 5479072 12767696 31% /usr -/dev/mapper/sys.vg-var.lv 19223252 3436556 14810212 19% /var -/dev/md0 960492 36388 875312 4% /boot -DF - allow(plugin).to receive(:shell_out).with("df -P").and_return(mock_shell_out(0, @dfstdout, "")) - - @inode_stdout = <<-DFi -Filesystem Inodes IUsed IFree IUse% Mounted on -/dev/xvda1 1310720 107407 1203313 9% / -/dev/mapper/sys.vg-special.lv 124865 380 124485 1% /special -tmpfs 126922 273 126649 1% /run -none 126922 1 126921 1% /run/lock -none 126922 1 126921 1% /run/shm -DFi - allow(plugin).to receive(:shell_out).with("df -iP").and_return(mock_shell_out(0, @inode_stdout, "")) - - @stdout = <<-BLKID_TYPE -/dev/sdb1: LABEL=\"fuego:0\" UUID=\"bd1197e0-6997-1f3a-e27e-7801388308b5\" TYPE=\"linux_raid_member\" -/dev/sdb2: LABEL=\"fuego:1\" UUID=\"e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa\" TYPE=\"linux_raid_member\" -/dev/sda1: LABEL=\"fuego:0\" UUID=\"bd1197e0-6997-1f3a-e27e-7801388308b5\" TYPE=\"linux_raid_member\" -/dev/sda2: LABEL=\"fuego:1\" UUID=\"e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa\" TYPE=\"linux_raid_member\" -/dev/md0: LABEL=\"/boot\" UUID=\"37b8de8e-0fe3-4b5a-b9b4-dde33e19bb32\" TYPE=\"ext3\" -/dev/md1: UUID=\"YsIe0R-fj1y-LXTd-imla-opKo-OuIe-TBoxSK\" TYPE=\"LVM2_member\" -/dev/mapper/sys.vg-root.lv: LABEL=\"/\" UUID=\"7742d14b-80a3-4e97-9a32-478be9ea9aea\" TYPE=\"ext4\" -/dev/mapper/sys.vg-swap.lv: UUID=\"9bc2e515-8ddc-41c3-9f63-4eaebde9ce96\" TYPE=\"swap\" -/dev/mapper/sys.vg-tmp.lv: LABEL=\"/tmp\" UUID=\"74cf7eb9-428f-479e-9a4a-9943401e81e5\" TYPE=\"ext4\" -/dev/mapper/sys.vg-usr.lv: LABEL=\"/usr\" UUID=\"26ec33c5-d00b-4f88-a550-492def013bbc\" TYPE=\"ext4\" -/dev/mapper/sys.vg-var.lv: LABEL=\"/var\" UUID=\"6b559c35-7847-4ae2-b512-c99012d3f5b3\" TYPE=\"ext4\" -/dev/mapper/sys.vg-home.lv: LABEL=\"/home\" UUID=\"d6efda02-1b73-453c-8c74-7d8dee78fa5e\" TYPE=\"xfs\" -BLKID_TYPE - allow(plugin).to receive(:shell_out).with("blkid").and_return(mock_shell_out(0, @stdout, "")) - end - - it "should run blkid" do - plugin.run - end - - it "should set kb_size to value from blkid" do - plugin.run - expect(plugin[:filesystem2]["by_pair"]["/dev/md1,"][:fs_type]).to eq("LVM2_member") - expect(plugin[:filesystem2]["by_pair"]["/dev/sda2,"][:uuid]).to eq("e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa") - expect(plugin[:filesystem2]["by_pair"]["/dev/md0,/boot"][:label]).to eq("/boot") - end - end - - describe "when gathering filesystem type data from lsblk" do - before(:each) do - @dfstdout = <<-DF -Filesystem 1024-blocks Used Available Capacity Mounted on -/dev/mapper/sys.vg-root.lv 4805760 378716 4182924 9% / -tmpfs 2030944 0 2030944 0% /lib/init/rw -udev 2025576 228 2025348 1% /dev -tmpfs 2030944 2960 2027984 1% /dev/shm -/dev/mapper/sys.vg-home.lv 97605056 53563252 44041804 55% /home -/dev/mapper/sys.vg-special.lv 97605057 53563253 44041805 56% /special -/dev/mapper/sys.vg-tmp.lv 1919048 46588 1774976 3% /tmp -/dev/mapper/sys.vg-usr.lv 19223252 5479072 12767696 31% /usr -/dev/mapper/sys.vg-var.lv 19223252 3436556 14810212 19% /var -/dev/md0 960492 36388 875312 4% /boot -DF - allow(plugin).to receive(:shell_out).with("df -P").and_return(mock_shell_out(0, @dfstdout, "")) - - @inode_stdout = <<-DFi -Filesystem Inodes IUsed IFree IUse% Mounted on -/dev/xvda1 1310720 107407 1203313 9% / -/dev/mapper/sys.vg-special.lv 124865 380 124485 1% /special -tmpfs 126922 273 126649 1% /run -none 126922 1 126921 1% /run/lock -none 126922 1 126921 1% /run/shm -DFi - allow(plugin).to receive(:shell_out).with("df -iP").and_return(mock_shell_out(0, @inode_stdout, "")) - - allow(File).to receive(:exist?).with("/bin/lsblk").and_return(true) - @stdout = <<-BLKID_TYPE -NAME=\"sdb1\" UUID=\"bd1197e0-6997-1f3a-e27e-7801388308b5\" LABEL=\"fuego:0\" FSTYPE=\"LVM2_member\" -NAME=\"sdb2\" UUID=\"e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa\" LABEL=\"fuego:1\" FSTYPE=\"LVM2_member\" -NAME=\"sda1\" UUID=\"bd1197e0-6997-1f3a-e27e-7801388308b5\" LABEL=\"fuego:0\" FSTYPE=\"LVM2_member\" -NAME=\"sda2\" UUID=\"e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa\" LABEL=\"fuego:1\" FSTYPE=\"LVM2_member\" -NAME=\"md0\" UUID=\"37b8de8e-0fe3-4b5a-b9b4-dde33e19bb32\" LABEL=\"/boot\" FSTYPE=\"ext3\" -NAME=\"md1\" UUID=\"YsIe0R-fj1y-LXTd-imla-opKo-OuIe-TBoxSK\" LABEL=\"\" FSTYPE=\"LVM2_member\" -NAME=\"sys.vg-root.lv\" UUID=\"7742d14b-80a3-4e97-9a32-478be9ea9aea\" LABEL=\"/\" FSTYPE=\"ext4\" -NAME=\"sys.vg-swap.lv\" UUID=\"9bc2e515-8ddc-41c3-9f63-4eaebde9ce96\" LABEL=\"\" FSTYPE=\"swap\" -NAME=\"sys.vg-tmp.lv\" UUID=\"74cf7eb9-428f-479e-9a4a-9943401e81e5\" LABEL=\"/tmp\" FSTYPE=\"ext4\" -NAME=\"sys.vg-usr.lv\" UUID=\"26ec33c5-d00b-4f88-a550-492def013bbc\" LABEL=\"/usr\" FSTYPE=\"ext4\" -NAME=\"sys.vg-var.lv\" UUID=\"6b559c35-7847-4ae2-b512-c99012d3f5b3\" LABEL=\"/var\" FSTYPE=\"ext4\" -NAME=\"sys.vg-home.lv\" UUID=\"d6efda02-1b73-453c-8c74-7d8dee78fa5e\" LABEL=\"/home\" FSTYPE=\"xfs\" -NAME=\"debian--7-root (dm-0)\" UUID=\"09187faa-3512-4505-81af-7e86d2ccb99a\" LABEL=\"root\" FSTYPE=\"ext4\" -BLKID_TYPE - allow(plugin).to receive(:shell_out). - with("lsblk -n -P -o NAME,UUID,LABEL,FSTYPE"). - and_return(mock_shell_out(0, @stdout, "")) - end - - it "should run lsblk -n -P -o NAME,UUID,LABEL,FSTYPE" do - plugin.run - end - - it "should set kb_size to value from lsblk -n -P -o NAME,UUID,LABEL,FSTYPE" do - plugin.run - expect(plugin[:filesystem2]["by_pair"]["/dev/md1,"][:fs_type]).to eq("LVM2_member") - expect(plugin[:filesystem2]["by_pair"]["/dev/sda2,"][:uuid]).to eq("e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa") - expect(plugin[:filesystem2]["by_pair"]["/dev/md0,/boot"][:label]).to eq("/boot") - end - - it "should ignore extra info in name and set label to value from lsblk -n -P -o NAME,UUID,LABEL,FSTYPE" do - plugin.run - expect(plugin[:filesystem2]["by_pair"]["/dev/mapper/debian--7-root,"][:label]).to eq("root") - end - - end - - describe "when gathering data from /proc/mounts" do - before(:each) do - allow(File).to receive(:exist?).with("/proc/mounts").and_return(true) - @double_file = double("/proc/mounts") - @mounts = <<-MOUNTS -rootfs / rootfs rw 0 0 -none /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0 -none /proc proc rw,nosuid,nodev,noexec,relatime 0 0 -none /dev devtmpfs rw,relatime,size=2025576k,nr_inodes=506394,mode=755 0 0 -none /dev/pts devpts rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000 0 0 -/dev/mapper/sys.vg-root.lv / ext4 rw,noatime,errors=remount-ro,barrier=1,data=ordered 0 0 -tmpfs /lib/init/rw tmpfs rw,nosuid,relatime,mode=755 0 0 -tmpfs /dev/shm tmpfs rw,nosuid,nodev,relatime 0 0 -/dev/mapper/sys.vg-home.lv /home xfs rw,noatime,attr2,noquota 0 0 -/dev/mapper/sys.vg-special.lv /special xfs ro,noatime,attr2,noquota 0 0 -/dev/mapper/sys.vg-tmp.lv /tmp ext4 rw,noatime,barrier=1,data=ordered 0 0 -/dev/mapper/sys.vg-usr.lv /usr ext4 rw,noatime,barrier=1,data=ordered 0 0 -/dev/mapper/sys.vg-var.lv /var ext4 rw,noatime,barrier=1,data=ordered 0 0 -/dev/md0 /boot ext3 rw,noatime,errors=remount-ro,data=ordered 0 0 -fusectl /sys/fs/fuse/connections fusectl rw,relatime 0 0 -binfmt_misc /proc/sys/fs/binfmt_misc binfmt_misc rw,nosuid,nodev,noexec,relatime 0 0 -MOUNTS - @counter = 0 - allow(@double_file).to receive(:read_nonblock) do - @counter += 1 - raise EOFError if @counter == 2 - @mounts - end - allow(@double_file).to receive(:close) - allow(File).to receive(:open).with("/proc/mounts").and_return(@double_file) - end - - it "should set mount to value from /proc/mounts" do - plugin.run - expect(plugin[:filesystem2]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:mount]).to eq("/special") - end - - it "should set fs_type to value from /proc/mounts" do - plugin.run - expect(plugin[:filesystem2]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:fs_type]).to eq("xfs") - end - - it "should set mount_options to an array of values from /proc/mounts" do - plugin.run - expect(plugin[:filesystem2]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:mount_options]).to eq(%w{ro noatime attr2 noquota}) - end - end - - describe "when gathering filesystem data with devices mounted more than once" do - before(:each) do - # there's a few different examples one can run into in this output: - # 1. A device physically mounted in more than one place: /home and /home2 - # 2. A bind-mounted directory, which shows up as the same device in a - # subdir: / and /var/chroot - # 3. tmpfs in multiple places. - @dfstdout = <<-DF -Filesystem 1024-blocks Used Available Capacity Mounted on -/dev/mapper/sys.vg-root.lv 4805760 378716 4182924 9% / -tmpfs 2030944 0 2030944 0% /lib/init/rw -udev 2025576 228 2025348 1% /dev -tmpfs 2030944 2960 2027984 1% /dev/shm -/dev/mapper/sys.vg-home.lv 97605056 53563252 44041804 55% /home -/dev/mapper/sys.vg-home.lv 97605056 53563252 44041804 55% /home2 -/dev/mapper/sys.vg-root.lv 4805760 378716 4182924 9% /var/chroot -DF - allow(plugin).to receive(:shell_out).with("df -P").and_return(mock_shell_out(0, @dfstdout, "")) - - @inode_stdout = <<-DFi -Filesystem Inodes IUsed IFree IUse% Mounted on -/dev/mapper/sys.vg-root.lv 1310720 107407 1203313 9% / -tmpfs 126922 273 126649 1% /lib/init/rw -none 126922 1 126921 1% /dev/shm -udev 126922 1 126921 1% /dev -/dev/mapper/sys.vg-home.lv 60891136 4696030 56195106 8% /home -/dev/mapper/sys.vg-home.lv 60891136 4696030 56195106 8% /home2 -/dev/mapper/sys.vg-root.lv 1310720 107407 1203313 9% /var/chroot -DFi - allow(plugin).to receive(:shell_out).with("df -iP").and_return(mock_shell_out(0, @inode_stdout, "")) - - allow(File).to receive(:exist?).with("/bin/lsblk").and_return(true) - @stdout = <<-BLKID_TYPE -NAME=\"/dev/mapper/sys.vg-root.lv\" UUID=\"7742d14b-80a3-4e97-9a32-478be9ea9aea\" LABEL=\"/\" FSTYPE=\"ext4\" -NAME=\"/dev/mapper/sys.vg-home.lv\" UUID=\"d6efda02-1b73-453c-8c74-7d8dee78fa5e\" LABEL=\"/home\" FSTYPE=\"xfs\" -BLKID_TYPE - allow(plugin).to receive(:shell_out). - with("lsblk -n -P -o NAME,UUID,LABEL,FSTYPE"). - and_return(mock_shell_out(0, @stdout, "")) - end - - it "should provide a devices view with all mountpoints" do - plugin.run - expect(plugin[:filesystem2]["by_device"]["/dev/mapper/sys.vg-root.lv"][:mounts]).to eq(["/", "/var/chroot"]) - expect(plugin[:filesystem2]["by_device"]["/dev/mapper/sys.vg-home.lv"][:mounts]).to eq(["/home", "/home2"]) - expect(plugin[:filesystem2]["by_device"]["tmpfs"][:mounts]).to eq(["/lib/init/rw", "/dev/shm"]) - end - end - - describe "when gathering filesystem data with double-mounts" do - before(:each) do - @dfstdout = <<-DF -Filesystem 1024-blocks Used Available Capacity Mounted on -/dev/mapper/sys.vg-root.lv 4805760 378716 4182924 9% / -tmpfs 2030944 0 2030944 0% /lib/init/rw -udev 2025576 228 2025348 1% /dev -tmpfs 2030944 2960 2027984 1% /dev/shm -/dev/mapper/sys.vg-home.lv 97605056 53563252 44041804 55% /home -/dev/sdb1 97605056 53563252 44041804 55% /mnt -/dev/sdc1 4805760 378716 4182924 9% /mnt -DF - allow(plugin).to receive(:shell_out).with("df -P").and_return(mock_shell_out(0, @dfstdout, "")) - - @inode_stdout = <<-DFi -Filesystem Inodes IUsed IFree IUse% Mounted on -/dev/mapper/sys.vg-root.lv 1310720 107407 1203313 9% / -tmpfs 126922 273 126649 1% /lib/init/rw -none 126922 1 126921 1% /dev/shm -udev 126922 1 126921 1% /dev -/dev/mapper/sys.vg-home.lv 60891136 4696030 56195106 8% /home -/dev/sdb1 60891136 4696030 56195106 8% /mnt -/dev/sdc1 1310720 107407 1203313 9% /mnt -DFi - allow(plugin).to receive(:shell_out).with("df -iP").and_return(mock_shell_out(0, @inode_stdout, "")) - - allow(File).to receive(:exist?).with("/bin/lsblk").and_return(true) - @stdout = <<-BLKID_TYPE -NAME=\"/dev/mapper/sys.vg-root.lv\" UUID=\"7742d14b-80a3-4e97-9a32-478be9ea9aea\" LABEL=\"/\" FSTYPE=\"ext4\" -NAME=\"/dev/sdb1\" UUID=\"6b559c35-7847-4ae2-b512-c99012d3f5b3\" LABEL=\"/mnt\" FSTYPE=\"ext4\" -NAME=\"/dev/sdc1\" UUID=\"7f1e51bf-3608-4351-b7cd-379e39cff36a\" LABEL=\"/mnt\" FSTYPE=\"ext4\" -NAME=\"/dev/mapper/sys.vg-home.lv\" UUID=\"d6efda02-1b73-453c-8c74-7d8dee78fa5e\" LABEL=\"/home\" FSTYPE=\"xfs\" -BLKID_TYPE - allow(plugin).to receive(:shell_out). - with("lsblk -n -P -o NAME,UUID,LABEL,FSTYPE"). - and_return(mock_shell_out(0, @stdout, "")) - end - - it "should provide a mounts view with all devices" do - plugin.run - expect(plugin[:filesystem2]["by_mountpoint"]["/mnt"][:devices]).to eq(["/dev/sdb1", "/dev/sdc1"]) - end - end -end diff -Nru ohai-8.21.0/spec/unit/plugins/linux/filesystem_spec.rb ohai-13.8.0/spec/unit/plugins/linux/filesystem_spec.rb --- ohai-8.21.0/spec/unit/plugins/linux/filesystem_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/linux/filesystem_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,26 +16,24 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Linux filesystem plugin" do - let(:plugin) { get_plugin("linux/filesystem") } + let (:plugin) { get_plugin("linux/filesystem") } before(:each) do allow(plugin).to receive(:collect_os).and_return(:linux) allow(plugin).to receive(:shell_out).with("df -P").and_return(mock_shell_out(0, "", "")) allow(plugin).to receive(:shell_out).with("df -iP").and_return(mock_shell_out(0, "", "")) allow(plugin).to receive(:shell_out).with("mount").and_return(mock_shell_out(0, "", "")) - allow(File).to receive(:exist?).with("/bin/lsblk").and_return(false) - allow(plugin).to receive(:shell_out).with("blkid -s TYPE").and_return(mock_shell_out(0, "", "")) - allow(plugin).to receive(:shell_out).with("blkid -s UUID").and_return(mock_shell_out(0, "", "")) - allow(plugin).to receive(:shell_out).with("blkid -s LABEL").and_return(mock_shell_out(0, "", "")) + allow(plugin).to receive(:which).with("lsblk").and_return(nil) + allow(plugin).to receive(:which).with("df").and_return("/bin/df") + allow(plugin).to receive(:which).with("mount").and_return("/bin/mount") + allow(plugin).to receive(:which).with("blkid").and_return("/sbin/blkid") + allow(plugin).to receive(:shell_out).with("/sbin/blkid", timeout: 60).and_return(mock_shell_out(0, "", "")) - allow(plugin).to receive(:shell_out).with("lsblk -P -n -o NAME,FSTYPE"). - and_return(mock_shell_out(0, "", "")) - allow(plugin).to receive(:shell_out).with("lsblk -P -n -o NAME,UUID"). - and_return(mock_shell_out(0, "", "")) - allow(plugin).to receive(:shell_out).with("lsblk -P -n -o NAME,LABEL"). + allow(plugin).to receive(:shell_out). + with("lsblk -n -P -o NAME,UUID,LABEL,FSTYPE", timeout: 60). and_return(mock_shell_out(0, "", "")) allow(File).to receive(:exist?).with("/proc/mounts").and_return(false) @@ -57,6 +55,11 @@ end end + it "sets both filesystem and filesystem2 attributes" do + plugin.run + expect(plugin[:filesystem]).to eq(plugin[:filesystem2]) + end + describe "when gathering filesystem usage data from df" do before(:each) do @stdout = <<-DF @@ -93,42 +96,42 @@ it "should set kb_size to value from df -P" do plugin.run - expect(plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:kb_size]).to eq("97605057") + expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:kb_size]).to eq("97605057") end it "should set kb_used to value from df -P" do plugin.run - expect(plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:kb_used]).to eq("53563253") + expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:kb_used]).to eq("53563253") end it "should set kb_available to value from df -P" do plugin.run - expect(plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:kb_available]).to eq("44041805") + expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:kb_available]).to eq("44041805") end it "should set percent_used to value from df -P" do plugin.run - expect(plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:percent_used]).to eq("56%") + expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:percent_used]).to eq("56%") end it "should set mount to value from df -P" do plugin.run - expect(plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount]).to eq("/special") + expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:mount]).to eq("/special") end it "should set total_inodes to value from df -iP" do plugin.run - expect(plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:total_inodes]).to eq("124865") + expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:total_inodes]).to eq("124865") end it "should set inodes_used to value from df -iP" do plugin.run - expect(plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:inodes_used]).to eq("380") + expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:inodes_used]).to eq("380") end it "should set inodes_available to value from df -iP" do plugin.run - expect(plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:inodes_available]).to eq("124485") + expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:inodes_available]).to eq("124485") end end @@ -161,228 +164,229 @@ it "should set mount to value from mount" do plugin.run - expect(plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount]).to eq("/special") + expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:mount]).to eq("/special") end it "should set fs_type to value from mount" do plugin.run - expect(plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:fs_type]).to eq("xfs") + expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:fs_type]).to eq("xfs") end it "should set mount_options to an array of values from mount" do plugin.run - expect(plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount_options]).to eq(%w{ro noatime}) + expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:mount_options]).to eq(%w{ro noatime}) end end describe "when gathering filesystem type data from blkid" do before(:each) do - @stdout = <<-BLKID_TYPE -/dev/sdb1: TYPE=\"linux_raid_member\" -/dev/sdb2: TYPE=\"linux_raid_member\" -/dev/sda1: TYPE=\"linux_raid_member\" -/dev/sda2: TYPE=\"linux_raid_member\" -/dev/md0: TYPE=\"ext3\" -/dev/md1: TYPE=\"LVM2_member\" -/dev/mapper/sys.vg-root.lv: TYPE=\"ext4\" -/dev/mapper/sys.vg-swap.lv: TYPE=\"swap\" -/dev/mapper/sys.vg-tmp.lv: TYPE=\"ext4\" -/dev/mapper/sys.vg-usr.lv: TYPE=\"ext4\" -/dev/mapper/sys.vg-var.lv: TYPE=\"ext4\" -/dev/mapper/sys.vg-home.lv: TYPE=\"xfs\" -/dev/mapper/debian--7-root: TYPE=\"ext4\" -BLKID_TYPE - allow(plugin).to receive(:shell_out).with("blkid -s TYPE").and_return(mock_shell_out(0, @stdout, "")) - end - - it "should run blkid -s TYPE" do - expect(plugin).to receive(:shell_out).with("blkid -s TYPE").and_return(mock_shell_out(0, @stdout, "")) - plugin.run - end + # blkid and lsblk output are coorelated with df/mount output, so the + # most full test of them actually requires we have both + @dfstdout = <<-DF +Filesystem 1024-blocks Used Available Capacity Mounted on +/dev/mapper/sys.vg-root.lv 4805760 378716 4182924 9% / +tmpfs 2030944 0 2030944 0% /lib/init/rw +udev 2025576 228 2025348 1% /dev +tmpfs 2030944 2960 2027984 1% /dev/shm +/dev/mapper/sys.vg-home.lv 97605056 53563252 44041804 55% /home +/dev/mapper/sys.vg-special.lv 97605057 53563253 44041805 56% /special +/dev/mapper/sys.vg-tmp.lv 1919048 46588 1774976 3% /tmp +/dev/mapper/sys.vg-usr.lv 19223252 5479072 12767696 31% /usr +/dev/mapper/sys.vg-var.lv 19223252 3436556 14810212 19% /var +/dev/md0 960492 36388 875312 4% /boot +DF + allow(plugin).to receive(:shell_out).with("df -P").and_return(mock_shell_out(0, @dfstdout, "")) - it "should set fs_type to value from blkid -s TYPE" do - plugin.run - expect(plugin[:filesystem]["/dev/md1"][:fs_type]).to eq("LVM2_member") - end - end + @inode_stdout = <<-DFi +Filesystem Inodes IUsed IFree IUse% Mounted on +/dev/xvda1 1310720 107407 1203313 9% / +/dev/mapper/sys.vg-special.lv 124865 380 124485 1% /special +tmpfs 126922 273 126649 1% /run +none 126922 1 126921 1% /run/lock +none 126922 1 126921 1% /run/shm +DFi + allow(plugin).to receive(:shell_out).with("df -iP").and_return(mock_shell_out(0, @inode_stdout, "")) - describe "when gathering filesystem type data from lsblk" do - before(:each) do - allow(File).to receive(:exist?).with("/bin/lsblk").and_return(true) @stdout = <<-BLKID_TYPE -NAME="sdb1" FSTYPE="linux_raid_member" -NAME="sdb2" FSTYPE="linux_raid_member" -NAME="sda1" FSTYPE="linux_raid_member" -NAME="sda2" FSTYPE="linux_raid_member" -NAME="md0" FSTYPE="ext3" -NAME="md1" FSTYPE="LVM2_member" -NAME="sys.vg-root.lv" FSTYPE="ext4" -NAME="sys.vg-swap.lv" FSTYPE="swap" -NAME="sys.vg-tmp.lv" FSTYPE="ext4" -NAME="sys.vg-usr.lv" FSTYPE="ext4" -NAME="sys.vg-var.lv" FSTYPE="ext4" -NAME="sys.vg-home.lv" FSTYPE="xfs" -NAME="debian--7-root (dm-0)" FSTYPE="ext4" +/dev/sdb1: LABEL=\"fuego:0\" UUID=\"bd1197e0-6997-1f3a-e27e-7801388308b5\" TYPE=\"linux_raid_member\" +/dev/sdb2: LABEL=\"fuego:1\" UUID=\"e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa\" TYPE=\"linux_raid_member\" +/dev/sda1: LABEL=\"fuego:0\" UUID=\"bd1197e0-6997-1f3a-e27e-7801388308b5\" TYPE=\"linux_raid_member\" +/dev/sda2: LABEL=\"fuego:1\" UUID=\"e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa\" TYPE=\"linux_raid_member\" +/dev/md0: LABEL=\"/boot\" UUID=\"37b8de8e-0fe3-4b5a-b9b4-dde33e19bb32\" TYPE=\"ext3\" +/dev/md1: UUID=\"YsIe0R-fj1y-LXTd-imla-opKo-OuIe-TBoxSK\" TYPE=\"LVM2_member\" +/dev/mapper/sys.vg-root.lv: LABEL=\"/\" UUID=\"7742d14b-80a3-4e97-9a32-478be9ea9aea\" TYPE=\"ext4\" +/dev/mapper/sys.vg-swap.lv: UUID=\"9bc2e515-8ddc-41c3-9f63-4eaebde9ce96\" TYPE=\"swap\" +/dev/mapper/sys.vg-tmp.lv: LABEL=\"/tmp\" UUID=\"74cf7eb9-428f-479e-9a4a-9943401e81e5\" TYPE=\"ext4\" +/dev/mapper/sys.vg-usr.lv: LABEL=\"/usr\" UUID=\"26ec33c5-d00b-4f88-a550-492def013bbc\" TYPE=\"ext4\" +/dev/mapper/sys.vg-var.lv: LABEL=\"/var\" UUID=\"6b559c35-7847-4ae2-b512-c99012d3f5b3\" TYPE=\"ext4\" +/dev/mapper/sys.vg-home.lv: LABEL=\"/home\" UUID=\"d6efda02-1b73-453c-8c74-7d8dee78fa5e\" TYPE=\"xfs\" BLKID_TYPE - allow(plugin).to receive(:shell_out).with("lsblk -P -n -o NAME,FSTYPE"). - and_return(mock_shell_out(0, @stdout, "")) - end - - it "should run lsblk -P -n -o NAME,FSTYPE" do - expect(plugin).to receive(:shell_out).with("lsblk -P -n -o NAME,FSTYPE"). - and_return(mock_shell_out(0, @stdout, "")) - plugin.run + allow(plugin).to receive(:shell_out).with("/sbin/blkid", timeout: 60).and_return(mock_shell_out(0, @stdout, "")) end - it "should set fs_type to value from lsblk -P -n -o NAME,FSTYPE" do + it "should run blkid" do plugin.run - expect(plugin[:filesystem]["/dev/md1"][:fs_type]).to eq("LVM2_member") end - it "should ignore extra info in name and set fs_type to value from lsblk -P -n -o NAME,FSTYPE" do + it "should set kb_size to value from blkid" do plugin.run - expect(plugin[:filesystem]["/dev/mapper/debian--7-root"][:fs_type]).to eq("ext4") + expect(plugin[:filesystem]["by_pair"]["/dev/md1,"][:fs_type]).to eq("LVM2_member") + expect(plugin[:filesystem]["by_pair"]["/dev/sda2,"][:uuid]).to eq("e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa") + expect(plugin[:filesystem]["by_pair"]["/dev/md0,/boot"][:label]).to eq("/boot") end end - describe "when gathering filesystem uuid data from blkid" do + describe "when gathering filesystem type data from lsblk" do before(:each) do - @stdout = <<-BLKID_UUID -/dev/sdb1: UUID=\"bd1197e0-6997-1f3a-e27e-7801388308b5\" -/dev/sdb2: UUID=\"e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa\" -/dev/sda1: UUID=\"bd1197e0-6997-1f3a-e27e-7801388308b5\" -/dev/sda2: UUID=\"e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa\" -/dev/md0: UUID=\"37b8de8e-0fe3-4b5a-b9b4-dde33e19bb32\" -/dev/md1: UUID=\"YsIe0R-fj1y-LXTd-imla-opKo-OuIe-TBoxSK\" -/dev/mapper/sys.vg-root.lv: UUID=\"7742d14b-80a3-4e97-9a32-478be9ea9aea\" -/dev/mapper/sys.vg-swap.lv: UUID=\"9bc2e515-8ddc-41c3-9f63-4eaebde9ce96\" -/dev/mapper/sys.vg-tmp.lv: UUID=\"74cf7eb9-428f-479e-9a4a-9943401e81e5\" -/dev/mapper/sys.vg-usr.lv: UUID=\"26ec33c5-d00b-4f88-a550-492def013bbc\" -/dev/mapper/sys.vg-var.lv: UUID=\"6b559c35-7847-4ae2-b512-c99012d3f5b3\" -/dev/mapper/sys.vg-home.lv: UUID=\"d6efda02-1b73-453c-8c74-7d8dee78fa5e\" -/dev/mapper/debian--7-root: UUID=\"09187faa-3512-4505-81af-7e86d2ccb99a\" -BLKID_UUID - allow(plugin).to receive(:shell_out).with("blkid -s UUID").and_return(mock_shell_out(0, @stdout, "")) - end - - it "should run blkid -s UUID" do - expect(plugin).to receive(:shell_out).with("blkid -s UUID").and_return(mock_shell_out(0, @stdout, "")) - plugin.run - end + @dfstdout = <<-DF +Filesystem 1024-blocks Used Available Capacity Mounted on +/dev/mapper/sys.vg-root.lv 4805760 378716 4182924 9% / +tmpfs 2030944 0 2030944 0% /lib/init/rw +udev 2025576 228 2025348 1% /dev +tmpfs 2030944 2960 2027984 1% /dev/shm +/dev/mapper/sys.vg-home.lv 97605056 53563252 44041804 55% /home +/dev/mapper/sys.vg-special.lv 97605057 53563253 44041805 56% /special +/dev/mapper/sys.vg-tmp.lv 1919048 46588 1774976 3% /tmp +/dev/mapper/sys.vg-usr.lv 19223252 5479072 12767696 31% /usr +/dev/mapper/sys.vg-var.lv 19223252 3436556 14810212 19% /var +/dev/md0 960492 36388 875312 4% /boot +DF + allow(plugin).to receive(:shell_out).with("df -P").and_return(mock_shell_out(0, @dfstdout, "")) - it "should set uuid to value from blkid -s UUID" do - plugin.run - expect(plugin[:filesystem]["/dev/sda2"][:uuid]).to eq("e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa") - end - end + @inode_stdout = <<-DFi +Filesystem Inodes IUsed IFree IUse% Mounted on +/dev/xvda1 1310720 107407 1203313 9% / +/dev/mapper/sys.vg-special.lv 124865 380 124485 1% /special +tmpfs 126922 273 126649 1% /run +none 126922 1 126921 1% /run/lock +none 126922 1 126921 1% /run/shm +DFi + allow(plugin).to receive(:shell_out).with("df -iP").and_return(mock_shell_out(0, @inode_stdout, "")) - describe "when gathering filesystem uuid data from lsblk" do - before(:each) do - allow(File).to receive(:exist?).with("/bin/lsblk").and_return(true) - @stdout = <<-BLKID_UUID -NAME="sdb1" UUID="bd1197e0-6997-1f3a-e27e-7801388308b5" -NAME="sdb2" UUID="e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa" -NAME="sda1" UUID="bd1197e0-6997-1f3a-e27e-7801388308b5" -NAME="sda2" UUID="e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa" -NAME="md0" UUID="37b8de8e-0fe3-4b5a-b9b4-dde33e19bb32" -NAME="md1" UUID="YsIe0R-fj1y-LXTd-imla-opKo-OuIe-TBoxSK" -NAME="sys.vg-root.lv" UUID="7742d14b-80a3-4e97-9a32-478be9ea9aea" -NAME="sys.vg-swap.lv" UUID="9bc2e515-8ddc-41c3-9f63-4eaebde9ce96" -NAME="sys.vg-tmp.lv" UUID="74cf7eb9-428f-479e-9a4a-9943401e81e5" -NAME="sys.vg-usr.lv" UUID="26ec33c5-d00b-4f88-a550-492def013bbc" -NAME="sys.vg-var.lv" UUID="6b559c35-7847-4ae2-b512-c99012d3f5b3" -NAME="sys.vg-home.lv" UUID="d6efda02-1b73-453c-8c74-7d8dee78fa5e" -NAME="debian--7-root (dm-0)" UUID="09187faa-3512-4505-81af-7e86d2ccb99a" -BLKID_UUID - allow(plugin).to receive(:shell_out).with("lsblk -P -n -o NAME,UUID"). + allow(plugin).to receive(:which).with("lsblk").and_return("/sbin/lsblk") + allow(plugin).to receive(:which).with("blkid").and_return(nil) + @stdout = <<-BLKID_TYPE +NAME=\"sdb1\" UUID=\"bd1197e0-6997-1f3a-e27e-7801388308b5\" LABEL=\"fuego:0\" FSTYPE=\"LVM2_member\" +NAME=\"sdb2\" UUID=\"e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa\" LABEL=\"fuego:1\" FSTYPE=\"LVM2_member\" +NAME=\"sda1\" UUID=\"bd1197e0-6997-1f3a-e27e-7801388308b5\" LABEL=\"fuego:0\" FSTYPE=\"LVM2_member\" +NAME=\"sda2\" UUID=\"e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa\" LABEL=\"fuego:1\" FSTYPE=\"LVM2_member\" +NAME=\"md0\" UUID=\"37b8de8e-0fe3-4b5a-b9b4-dde33e19bb32\" LABEL=\"/boot\" FSTYPE=\"ext3\" +NAME=\"md1\" UUID=\"YsIe0R-fj1y-LXTd-imla-opKo-OuIe-TBoxSK\" LABEL=\"\" FSTYPE=\"LVM2_member\" +NAME=\"sys.vg-root.lv\" UUID=\"7742d14b-80a3-4e97-9a32-478be9ea9aea\" LABEL=\"/\" FSTYPE=\"ext4\" +NAME=\"sys.vg-swap.lv\" UUID=\"9bc2e515-8ddc-41c3-9f63-4eaebde9ce96\" LABEL=\"\" FSTYPE=\"swap\" +NAME=\"sys.vg-tmp.lv\" UUID=\"74cf7eb9-428f-479e-9a4a-9943401e81e5\" LABEL=\"/tmp\" FSTYPE=\"ext4\" +NAME=\"sys.vg-usr.lv\" UUID=\"26ec33c5-d00b-4f88-a550-492def013bbc\" LABEL=\"/usr\" FSTYPE=\"ext4\" +NAME=\"sys.vg-var.lv\" UUID=\"6b559c35-7847-4ae2-b512-c99012d3f5b3\" LABEL=\"/var\" FSTYPE=\"ext4\" +NAME=\"sys.vg-home.lv\" UUID=\"d6efda02-1b73-453c-8c74-7d8dee78fa5e\" LABEL=\"/home\" FSTYPE=\"xfs\" +NAME=\"debian--7-root (dm-0)\" UUID=\"09187faa-3512-4505-81af-7e86d2ccb99a\" LABEL=\"root\" FSTYPE=\"ext4\" +BLKID_TYPE + allow(plugin).to receive(:shell_out). + with("/sbin/lsblk -n -P -o NAME,UUID,LABEL,FSTYPE", timeout: 60). and_return(mock_shell_out(0, @stdout, "")) end - it "should run lsblk -P -n -o NAME,UUID" do - expect(plugin).to receive(:shell_out).with("lsblk -P -n -o NAME,UUID"). - and_return(mock_shell_out(0, @stdout, "")) + it "should run lsblk -n -P -o NAME,UUID,LABEL,FSTYPE" do plugin.run end - it "should set uuid to value from lsblk -P -n -o NAME,UUID" do + it "should set kb_size to value from lsblk -n -P -o NAME,UUID,LABEL,FSTYPE" do plugin.run - expect(plugin[:filesystem]["/dev/sda2"][:uuid]).to eq( - "e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa" - ) + expect(plugin[:filesystem]["by_pair"]["/dev/md1,"][:fs_type]).to eq("LVM2_member") + expect(plugin[:filesystem]["by_pair"]["/dev/sda2,"][:uuid]).to eq("e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa") + expect(plugin[:filesystem]["by_pair"]["/dev/md0,/boot"][:label]).to eq("/boot") end - it "should ignore extra info in name and set uuid to value from lsblk -P -n -o NAME,UUID" do + it "should ignore extra info in name and set label to value from lsblk -n -P -o NAME,UUID,LABEL,FSTYPE" do plugin.run - expect(plugin[:filesystem]["/dev/mapper/debian--7-root"][:uuid]).to eq( - "09187faa-3512-4505-81af-7e86d2ccb99a" - ) + expect(plugin[:filesystem]["by_pair"]["/dev/mapper/debian--7-root,"][:label]).to eq("root") end + end - describe "when gathering filesystem label data from blkid" do + describe "when gathering filesystem type data from both lsblk and blkid" do before(:each) do - @stdout = <<-BLKID_LABEL -/dev/sda1: LABEL=\"fuego:0\" -/dev/sda2: LABEL=\"fuego:1\" -/dev/sdb1: LABEL=\"fuego:0\" -/dev/sdb2: LABEL=\"fuego:1\" -/dev/md0: LABEL=\"/boot\" -/dev/mapper/sys.vg-root.lv: LABEL=\"/\" -/dev/mapper/sys.vg-tmp.lv: LABEL=\"/tmp\" -/dev/mapper/sys.vg-usr.lv: LABEL=\"/usr\" -/dev/mapper/sys.vg-var.lv: LABEL=\"/var\" -/dev/mapper/sys.vg-home.lv: LABEL=\"/home\" -/dev/mapper/debian--7-root: LABEL=\"root\" -BLKID_LABEL - allow(plugin).to receive(:shell_out).with("blkid -s LABEL").and_return(mock_shell_out(0, @stdout, "")) - end - - it "should run blkid -s LABEL" do - expect(plugin).to receive(:shell_out).with("blkid -s LABEL").and_return(mock_shell_out(0, @stdout, "")) - plugin.run - end + @dfstdout = <<-DF +Filesystem 1024-blocks Used Available Capacity Mounted on +/dev/mapper/sys.vg-root.lv 4805760 378716 4182924 9% / +tmpfs 2030944 0 2030944 0% /lib/init/rw +udev 2025576 228 2025348 1% /dev +tmpfs 2030944 2960 2027984 1% /dev/shm +/dev/mapper/sys.vg-home.lv 97605056 53563252 44041804 55% /home +/dev/mapper/sys.vg-special.lv 97605057 53563253 44041805 56% /special +/dev/mapper/sys.vg-tmp.lv 1919048 46588 1774976 3% /tmp +/dev/mapper/sys.vg-usr.lv 19223252 5479072 12767696 31% /usr +/dev/mapper/sys.vg-var.lv 19223252 3436556 14810212 19% /var +/dev/md0 960492 36388 875312 4% /boot +DF + allow(plugin).to receive(:shell_out).with("df -P").and_return(mock_shell_out(0, @dfstdout, "")) - it "should set label to value from blkid -s LABEL" do - plugin.run - expect(plugin[:filesystem]["/dev/md0"][:label]).to eq("/boot") - end - end + @inode_stdout = <<-DFi +Filesystem Inodes IUsed IFree IUse% Mounted on +/dev/xvda1 1310720 107407 1203313 9% / +/dev/mapper/sys.vg-special.lv 124865 380 124485 1% /special +tmpfs 126922 273 126649 1% /run +none 126922 1 126921 1% /run/lock +none 126922 1 126921 1% /run/shm +DFi + allow(plugin).to receive(:shell_out).with("df -iP").and_return(mock_shell_out(0, @inode_stdout, "")) - describe "when gathering filesystem label data from lsblk" do - before(:each) do - allow(File).to receive(:exist?).with("/bin/lsblk").and_return(true) - @stdout = <<-BLKID_LABEL -NAME="sda1" LABEL="fuego:0" -NAME="sda2" LABEL="fuego:1" -NAME="sdb1" LABEL="fuego:0" -NAME="sdb2" LABEL="fuego:1" -NAME="md0" LABEL="/boot" -NAME="sys.vg-root.lv" LABEL="/" -NAME="sys.vg-tmp.lv" LABEL="/tmp" -NAME="sys.vg-usr.lv" LABEL="/usr" -NAME="sys.vg-var.lv" LABEL="/var" -NAME="sys.vg-home.lv" LABEL="/home" -NAME="debian--7-root (dm-0)" LABEL="root" -BLKID_LABEL - allow(plugin).to receive(:shell_out).with("lsblk -P -n -o NAME,LABEL"). + allow(plugin).to receive(:which).with("lsblk").and_return("/sbin/lsblk") + allow(plugin).to receive(:which).with("blkid").and_return("/sbin/blkid") + @stdout = <<-BLKID_TYPE +NAME=\"sdb1\" UUID=\"bd1197e0-6997-1f3a-e27e-7801388308b5\" LABEL=\"fuego:0\" FSTYPE=\"LVM2_member\" +NAME=\"sdb2\" UUID=\"e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa\" LABEL=\"fuego:1\" FSTYPE=\"LVM2_member\" +NAME=\"sda1\" UUID=\"bd1197e0-6997-1f3a-e27e-7801388308b5\" LABEL=\"fuego:0\" FSTYPE=\"LVM2_member\" +NAME=\"sda2\" UUID=\"e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa\" LABEL=\"fuego:1\" FSTYPE=\"LVM2_member\" +NAME=\"md0\" UUID=\"37b8de8e-0fe3-4b5a-b9b4-dde33e19bb32\" LABEL=\"/boot\" FSTYPE=\"ext3\" +NAME=\"md1\" UUID=\"YsIe0R-fj1y-LXTd-imla-opKo-OuIe-TBoxSK\" LABEL=\"\" FSTYPE=\"LVM2_member\" +NAME=\"sys.vg-root.lv\" UUID=\"7742d14b-80a3-4e97-9a32-478be9ea9aea\" LABEL=\"/\" +NAME=\"sys.vg-swap.lv\" UUID=\"9bc2e515-8ddc-41c3-9f63-4eaebde9ce96\" LABEL=\"\" FSTYPE=\"swap\" +NAME=\"sys.vg-tmp.lv\" UUID=\"74cf7eb9-428f-479e-9a4a-9943401e81e5\" LABEL=\"/tmp\" FSTYPE=\"ext4\" +NAME=\"sys.vg-usr.lv\" UUID=\"26ec33c5-d00b-4f88-a550-492def013bbc\" LABEL=\"/usr\" +NAME=\"sys.vg-var.lv\" UUID=\"6b559c35-7847-4ae2-b512-c99012d3f5b3\" LABEL=\"/var\" FSTYPE=\"ext4\" +NAME=\"sys.vg-home.lv\" UUID=\"d6efda02-1b73-453c-8c74-7d8dee78fa5e\" LABEL=\"/BADhome\" FSTYPE=\"xfs\" +NAME=\"debian--7-root (dm-0)\" UUID=\"09187faa-3512-4505-81af-7e86d2ccb99a\" LABEL=\"root\" FSTYPE=\"ext4\" +BLKID_TYPE + allow(plugin).to receive(:shell_out). + with("/sbin/lsblk -n -P -o NAME,UUID,LABEL,FSTYPE", timeout: 60). and_return(mock_shell_out(0, @stdout, "")) + @stdout = <<-BLKID_TYPE +/dev/sdb1: LABEL=\"fuego:0\" TYPE=\"linux_raid_member\" +/dev/sdb2: LABEL=\"fuego:1\" TYPE=\"linux_raid_member\" +/dev/sda1: LABEL=\"fuego:0\" UUID=\"bd1197e0-6997-1f3a-e27e-7801388308b5\" TYPE=\"linux_raid_member\" +/dev/sda2: LABEL=\"fuego:1\" UUID=\"e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa\" TYPE=\"linux_raid_member\" +/dev/md0: LABEL=\"/boot\" UUID=\"37b8de8e-0fe3-4b5a-b9b4-dde33e19bb32\" TYPE=\"ext3\" +/dev/md1: UUID=\"YsIe0R-fj1y-LXTd-imla-opKo-OuIe-TBoxSK\" TYPE=\"LVM2_member\" +/dev/mapper/sys.vg-root.lv: LABEL=\"/\" UUID=\"7742d14b-80a3-4e97-9a32-478be9ea9aea\" TYPE=\"ext4\" +/dev/mapper/sys.vg-swap.lv: UUID=\"9bc2e515-8ddc-41c3-9f63-4eaebde9ce96\" TYPE=\"swap\" +/dev/mapper/sys.vg-tmp.lv: LABEL=\"/tmp\" UUID=\"74cf7eb9-428f-479e-9a4a-9943401e81e5\" TYPE=\"ext4\" +/dev/mapper/sys.vg-usr.lv: LABEL=\"/usr\" UUID=\"26ec33c5-d00b-4f88-a550-492def013bbc\" TYPE=\"ext4\" +/dev/mapper/sys.vg-var.lv: LABEL=\"/var\" UUID=\"6b559c35-7847-4ae2-b512-c99012d3f5b3\" TYPE=\"ext4\" +/dev/mapper/sys.vg-home.lv: LABEL=\"/home\" UUID=\"d6efda02-1b73-453c-8c74-7d8dee78fa5e\" TYPE=\"xfs\" +BLKID_TYPE + allow(plugin).to receive(:shell_out).with("/sbin/blkid", timeout: 60).and_return(mock_shell_out(0, @stdout, "")) end - it "should run lsblk -P -n -o NAME,LABEL" do - expect(plugin).to receive(:shell_out).with("lsblk -P -n -o NAME,LABEL"). - and_return(mock_shell_out(0, @stdout, "")) + it "should fill in missing FS data from lsblk using blkid" do plugin.run + pairs = plugin[:filesystem]["by_pair"] + expect(pairs["/dev/mapper/sys.vg-root.lv,/"]["fs_type"]).to eq("ext4") + expect(pairs["/dev/mapper/sys.vg-usr.lv,/usr"]["fs_type"]).to eq("ext4") end - it "should set label to value from lsblk -P -n -o NAME,LABEL" do + it "should fill in missing FS data from blkid using lsblk" do plugin.run - expect(plugin[:filesystem]["/dev/md0"][:label]).to eq("/boot") + pairs = plugin[:filesystem]["by_pair"] + expect(pairs["/dev/sdb1,"]["uuid"]).to eq("bd1197e0-6997-1f3a-e27e-7801388308b5") + expect(pairs["/dev/sdb2,"]["uuid"]).to eq("e36d933e-e5b9-cfe5-6845-1f84d0f7fbfa") end - it "should ignore extra info in name and set label to value from lsblk -P -n -o NAME,LABEL" do + it "should prefer lsblk data to blkid data when they conflict" do plugin.run - expect(plugin[:filesystem]["/dev/mapper/debian--7-root"][:label]).to eq("root") + pairs = plugin[:filesystem]["by_pair"] + expect(pairs["/dev/mapper/sys.vg-home.lv,/home"]["label"]).to eq("/home") end + end describe "when gathering data from /proc/mounts" do @@ -419,18 +423,131 @@ it "should set mount to value from /proc/mounts" do plugin.run - expect(plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount]).to eq("/special") + expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:mount]).to eq("/special") end it "should set fs_type to value from /proc/mounts" do plugin.run - expect(plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:fs_type]).to eq("xfs") + expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:fs_type]).to eq("xfs") end it "should set mount_options to an array of values from /proc/mounts" do plugin.run - expect(plugin[:filesystem]["/dev/mapper/sys.vg-special.lv"][:mount_options]).to eq(%w{ro noatime attr2 noquota}) + expect(plugin[:filesystem]["by_pair"]["/dev/mapper/sys.vg-special.lv,/special"][:mount_options]).to eq(%w{ro noatime attr2 noquota}) end end + describe "when gathering filesystem data with devices mounted more than once" do + before(:each) do + # there's a few different examples one can run into in this output: + # 1. A device physically mounted in more than one place: /home and /home2 + # 2. A bind-mounted directory, which shows up as the same device in a + # subdir: / and /var/chroot + # 3. tmpfs in multiple places. + @dfstdout = <<-DF +Filesystem 1024-blocks Used Available Capacity Mounted on +/dev/mapper/sys.vg-root.lv 4805760 378716 4182924 9% / +tmpfs 2030944 0 2030944 0% /lib/init/rw +udev 2025576 228 2025348 1% /dev +tmpfs 2030944 2960 2027984 1% /dev/shm +/dev/mapper/sys.vg-home.lv 97605056 53563252 44041804 55% /home +/dev/mapper/sys.vg-home.lv 97605056 53563252 44041804 55% /home2 +/dev/mapper/sys.vg-root.lv 4805760 378716 4182924 9% /var/chroot +DF + allow(plugin).to receive(:shell_out).with("df -P").and_return(mock_shell_out(0, @dfstdout, "")) + + @inode_stdout = <<-DFi +Filesystem Inodes IUsed IFree IUse% Mounted on +/dev/mapper/sys.vg-root.lv 1310720 107407 1203313 9% / +tmpfs 126922 273 126649 1% /lib/init/rw +none 126922 1 126921 1% /dev/shm +udev 126922 1 126921 1% /dev +/dev/mapper/sys.vg-home.lv 60891136 4696030 56195106 8% /home +/dev/mapper/sys.vg-home.lv 60891136 4696030 56195106 8% /home2 +/dev/mapper/sys.vg-root.lv 1310720 107407 1203313 9% /var/chroot +DFi + allow(plugin).to receive(:shell_out).with("df -iP").and_return(mock_shell_out(0, @inode_stdout, "")) + + allow(plugin).to receive(:which).with("lsblk").and_return("/sbin/lsblk") + allow(plugin).to receive(:which).with("blkid").and_return(nil) + @stdout = <<-BLKID_TYPE +NAME=\"/dev/mapper/sys.vg-root.lv\" UUID=\"7742d14b-80a3-4e97-9a32-478be9ea9aea\" LABEL=\"/\" FSTYPE=\"ext4\" +NAME=\"/dev/mapper/sys.vg-home.lv\" UUID=\"d6efda02-1b73-453c-8c74-7d8dee78fa5e\" LABEL=\"/home\" FSTYPE=\"xfs\" +BLKID_TYPE + allow(plugin).to receive(:shell_out). + with("/sbin/lsblk -n -P -o NAME,UUID,LABEL,FSTYPE", timeout: 60). + and_return(mock_shell_out(0, @stdout, "")) + end + + it "should provide a devices view with all mountpoints" do + plugin.run + expect(plugin[:filesystem]["by_device"]["/dev/mapper/sys.vg-root.lv"][:mounts]).to eq(["/", "/var/chroot"]) + expect(plugin[:filesystem]["by_device"]["/dev/mapper/sys.vg-home.lv"][:mounts]).to eq(["/home", "/home2"]) + expect(plugin[:filesystem]["by_device"]["tmpfs"][:mounts]).to eq(["/lib/init/rw", "/dev/shm"]) + end + end + + describe "when gathering filesystem data with double-mounts" do + before(:each) do + @dfstdout = <<-DF +Filesystem 1024-blocks Used Available Capacity Mounted on +/dev/mapper/sys.vg-root.lv 4805760 378716 4182924 9% / +tmpfs 2030944 0 2030944 0% /lib/init/rw +udev 2025576 228 2025348 1% /dev +tmpfs 2030944 2960 2027984 1% /dev/shm +/dev/mapper/sys.vg-home.lv 97605056 53563252 44041804 55% /home +/dev/sdb1 97605056 53563252 44041804 55% /mnt +/dev/sdc1 4805760 378716 4182924 9% /mnt +DF + allow(plugin).to receive(:shell_out).with("df -P").and_return(mock_shell_out(0, @dfstdout, "")) + + @inode_stdout = <<-DFi +Filesystem Inodes IUsed IFree IUse% Mounted on +/dev/mapper/sys.vg-root.lv 1310720 107407 1203313 9% / +tmpfs 126922 273 126649 1% /lib/init/rw +none 126922 1 126921 1% /dev/shm +udev 126922 1 126921 1% /dev +/dev/mapper/sys.vg-home.lv 60891136 4696030 56195106 8% /home +/dev/sdb1 60891136 4696030 56195106 8% /mnt +/dev/sdc1 1310720 107407 1203313 9% /mnt +DFi + allow(plugin).to receive(:shell_out).with("df -iP").and_return(mock_shell_out(0, @inode_stdout, "")) + + allow(plugin).to receive(:which).with("lsblk").and_return("/sbin/lsblk") + allow(plugin).to receive(:which).with("blkid").and_return(nil) + @stdout = <<-BLKID_TYPE +NAME=\"/dev/mapper/sys.vg-root.lv\" UUID=\"7742d14b-80a3-4e97-9a32-478be9ea9aea\" LABEL=\"/\" FSTYPE=\"ext4\" +NAME=\"/dev/sdb1\" UUID=\"6b559c35-7847-4ae2-b512-c99012d3f5b3\" LABEL=\"/mnt\" FSTYPE=\"ext4\" +NAME=\"/dev/sdc1\" UUID=\"7f1e51bf-3608-4351-b7cd-379e39cff36a\" LABEL=\"/mnt\" FSTYPE=\"ext4\" +NAME=\"/dev/mapper/sys.vg-home.lv\" UUID=\"d6efda02-1b73-453c-8c74-7d8dee78fa5e\" LABEL=\"/home\" FSTYPE=\"xfs\" +BLKID_TYPE + allow(plugin).to receive(:shell_out). + with("/sbin/lsblk -n -P -o NAME,UUID,LABEL,FSTYPE", timeout: 60). + and_return(mock_shell_out(0, @stdout, "")) + end + + it "should provide a mounts view with all devices" do + plugin.run + expect(plugin[:filesystem]["by_mountpoint"]["/mnt"][:devices]).to eq(["/dev/sdb1", "/dev/sdc1"]) + end + end + + %w{df mount}.each do |command| + describe "when :allow_partial_data set, #{command} does not exist" do + before do + Ohai.config[:plugin][:filesystem][:allow_partial_data] = true + end + + after do + Ohai.config[:plugin][:filesystem][:allow_partial_data] = false + end + + it "logs warning about #{command} missing" do + Ohai.config[:plugin][:filesystem][:allow_partial_data] = true + allow(plugin).to receive(:shell_out).with(/#{command}/).and_raise(Ohai::Exceptions::Exec) + expect(Ohai::Log).to receive(:warn).with("Plugin Filesystem: #{command} binary is not available. Some data will not be available.") + plugin.run + end + end + end end diff -Nru ohai-8.21.0/spec/unit/plugins/linux/fips_spec.rb ohai-13.8.0/spec/unit/plugins/linux/fips_spec.rb --- ohai-8.21.0/spec/unit/plugins/linux/fips_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/linux/fips_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "plugin fips" do let(:enabled) { "0" } diff -Nru ohai-8.21.0/spec/unit/plugins/linux/hostnamectl_spec.rb ohai-13.8.0/spec/unit/plugins/linux/hostnamectl_spec.rb --- ohai-8.21.0/spec/unit/plugins/linux/hostnamectl_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/linux/hostnamectl_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Linux hostnamectl plugin" do let(:plugin) { get_plugin("linux/hostnamectl") } diff -Nru ohai-8.21.0/spec/unit/plugins/linux/hostname_spec.rb ohai-13.8.0/spec/unit/plugins/linux/hostname_spec.rb --- ohai-8.21.0/spec/unit/plugins/linux/hostname_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/linux/hostname_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Linux hostname plugin" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/linux/kernel_spec.rb ohai-13.8.0/spec/unit/plugins/linux/kernel_spec.rb --- ohai-8.21.0/spec/unit/plugins/linux/kernel_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/linux/kernel_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -17,7 +17,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Linux kernel plugin" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/linux/lsb_spec.rb ohai-13.8.0/spec/unit/plugins/linux/lsb_spec.rb --- ohai-8.21.0/spec/unit/plugins/linux/lsb_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/linux/lsb_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" # We do not alter case for lsb attributes and consume them as provided @@ -35,6 +35,7 @@ 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 "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 }) diff -Nru ohai-8.21.0/spec/unit/plugins/linux/lspci_spec.rb ohai-13.8.0/spec/unit/plugins/linux/lspci_spec.rb --- ohai-8.21.0/spec/unit/plugins/linux/lspci_spec.rb 1970-01-01 00:00:00.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/linux/lspci_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -0,0 +1,131 @@ +# +# Author:: Phil Dibowitz +# Copyright:: Copyright (c) 2017 Facebook, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require_relative "../../../spec_helper.rb" + +describe Ohai::System, "Linux lspci plugin" do + let (:plugin) { get_plugin("linux/lspci") } + + before(:each) do + @stdout = < raid10 sdh[5] sdg[4] sdf[3] sde[2] sdd[1] sdc[0]"). + and_yield(" 2929893888 blocks super 1.2 256K chunks 2 near-copies [6/6] [UUUUUU]") + allow(File).to receive(:open).with("/proc/mdstat").and_return(new_mdstat) + + @plugin.run + expect(@plugin[:mdadm][:md0][:members].sort).to eq( + %w{sdc sdd sde sdf sdg sdh} + ) + end + + it "should accurately report inactive arrays" do + new_mdstat = double("/proc/mdstat_inactive") + allow(new_mdstat).to receive(:each). + and_yield("Personalities :"). + and_yield("md0 : inactive nvme2n1p3[2](S)") + allow(File).to receive(:open).with("/proc/mdstat").and_return(new_mdstat) + @plugin.run + expect(@plugin[:mdadm][:md0][:spares]).to eq(%w{nvme2n1p3}) + end + + it "should report journal devices" do + new_mdstat = double("/proc/mdstat_journal") + allow(new_mdstat).to receive(:each). + and_yield("Personalies : [raid6]"). + and_yield("md0 : active (somecraphere) e - puts "The linux network plugin spec tests will fail without the 'ipaddress' library/gem.\n\n" - raise e -end +require_relative "../../../spec_helper.rb" +require "ipaddress" describe Ohai::System, "Linux Network Plugin" do let(:plugin) { get_plugin("linux/network") } @@ -240,6 +234,10 @@ valid_lft forever preferred_lft forever 13: fwdintf: mtu 1496 qdisc pfifo_fast state UNKNOWN group default qlen 1000 link/ether 00:00:00:00:00:0a brd ff:ff:ff:ff:ff:ff +14: ip6tnl0@NONE: mtu 1452 qdisc noqueue state UNKNOWN group default qlen 1 + link/tunnel6 :: brd :: + inet6 fe80::f47a:2aff:fef0:c6ef/64 scope link + valid_lft forever preferred_lft forever EOM end @@ -300,6 +298,13 @@ 0 0 0 0 0 0 TX: bytes packets errors dropped carrier collsns 140 2 0 1 0 0 +14: ip6tnl0@NONE: mtu 1452 qdisc noop state DOWN mode DEFAULT group default qlen 1 + link/tunnel6 :: brd :: promiscuity 0 + ip6tnl ip6ip6 remote :: local :: encaplimit 0 hoplimit 0 tclass 0x00 flowlabel 0x00000 (flowinfo 0x00000000) addrgenmode eui64 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 + RX: bytes packets errors dropped overrun mcast + 0 0 0 0 0 0 + TX: bytes packets errors dropped carrier collsns + 0 0 0 0 0 0 EOM end @@ -383,26 +388,6 @@ allow(plugin).to receive(:shell_out).with(/ethtool [^\-]/).and_return(mock_shell_out(0, linux_ethtool, "")) end - describe "#iproute2_binary_available?" do - ["/sbin/ip", "/usr/bin/ip", "/bin/ip"].each do |path| - it "accepts #{path}" do - allow(File).to receive(:exist?).and_return(false) - allow(File).to receive(:exist?).with(path).and_return(true) - expect(plugin.iproute2_binary_available?).to be_truthy - end - end - end - - describe "#find_ethtool_binary" do - ["/sbin/ethtool", "/usr/sbin/ethtool"].each do |path| - it "accepts #{path}" do - allow(File).to receive(:exist?).and_return(false) - allow(File).to receive(:exist?).with(path).and_return(true) - expect(plugin.find_ethtool_binary).to end_with("/ethtool") - end - end - end - describe "#interface_has_no_addresses_in_family?" do context "when interface has no addresses" do let(:iface) { {} } @@ -561,8 +546,8 @@ %w{ifconfig iproute2}.each do |network_method| describe "gathering IP layer address info via #{network_method}" do before(:each) do - allow(plugin).to receive(:iproute2_binary_available?).and_return( network_method == "iproute2" ) - allow(plugin).to receive(:find_ethtool_binary).and_return( "/sbin/ethtool" ) + allow(plugin).to receive(:which).with("ip").and_return( network_method == "iproute2" ? "/sbin/ip" : false ) + allow(plugin).to receive(:which).with("ethtool").and_return( "/sbin/ethtool" ) plugin.run end @@ -572,7 +557,11 @@ end it "detects the interfaces" do - expect(plugin["network"]["interfaces"].keys.sort).to eq(["eth0", "eth0.11", "eth0.151", "eth0.152", "eth0.153", "eth0:5", "eth3", "foo:veth0@eth0", "fwdintf", "lo", "ovs-system", "tun0", "venet0", "venet0:0", "xapi1"]) + if network_method == "iproute2" + expect(plugin["network"]["interfaces"].keys.sort).to eq(["eth0", "eth0.11", "eth0.151", "eth0.152", "eth0.153", "eth0:5", "eth3", "foo:veth0@eth0", "fwdintf", "ip6tnl0", "lo", "ovs-system", "tun0", "venet0", "venet0:0", "xapi1"]) + else + expect(plugin["network"]["interfaces"].keys.sort).to eq(["eth0", "eth0.11", "eth0.151", "eth0.152", "eth0.153", "eth0:5", "eth3", "foo:veth0@eth0", "fwdintf", "lo", "ovs-system", "tun0", "venet0", "venet0:0", "xapi1"]) + end end it "detects the layer one details of an ethernet interface" do @@ -676,11 +665,32 @@ expect(plugin["network"]["interfaces"]["eth0"]["arp"]["10.116.201.1"]).to eq("fe:ff:ff:ff:ff:ff") end + if network_method == "iproute2" + it "detects the tunnel information" do + expect(plugin["network"]["interfaces"]["ip6tnl0"]["tunnel_info"]).to eq( + { + "proto" => "ip6ip6", + "remote" => "::", + "local" => "::", + "encaplimit" => "0", + "hoplimit" => "0", + "tclass" => "0x00", + "flowlabel" => "0x00000", + "addrgenmode" => "eui64", + "numtxqueues" => "1", + "numrxqueues" => "1", + "gso_max_size" => "65536", + "gso_max_segs" => "65535", + } + ) + end + end end describe "gathering interface counters via #{network_method}" do before(:each) do - allow(plugin).to receive(:iproute2_binary_available?).and_return( network_method == "iproute2" ) + allow(plugin).to receive(:which).with("ip").and_return(network_method == "iproute2" ? "/sbin/ip" : false) + allow(plugin).to receive(:which).with("ethtool").and_return("/sbin/ethtool") plugin.run end @@ -718,7 +728,8 @@ describe "setting the node's default IP address attribute with #{network_method}" do before(:each) do - allow(plugin).to receive(:iproute2_binary_available?).and_return( network_method == "iproute2" ) + allow(plugin).to receive(:which).with("ip").and_return(network_method == "iproute2" ? "/sbin/ip" : false) + allow(plugin).to receive(:which).with("ethtool").and_return("/sbin/ethtool") plugin.run end @@ -796,9 +807,9 @@ describe "for newer network features using iproute2 only" do before(:each) do - allow(File).to receive(:exist?).with("/sbin/ip").and_return(true) # iproute2 only + allow(plugin).to receive(:which).with("ip").and_return("/sbin/ip") + allow(plugin).to receive(:which).with("ethtool").and_return( "/sbin/ethtool" ) allow(File).to receive(:exist?).with("/proc/net/if_inet6").and_return(true) # ipv6 is enabled - allow(File).to receive(:exist?).with("/sbin/ethtool").and_return(true) # ethtool is available plugin.run end @@ -1325,7 +1336,7 @@ end it "logs a message and skips previously unseen interfaces in 'ip route show'" do - expect(Ohai::Log).to receive(:debug).with("Skipping previously unseen interface from 'ip route show': virbr0").once + expect(Ohai::Log).to receive(:debug).with(/Skipping previously unseen interface from 'ip route show': virbr0/).once allow(Ohai::Log).to receive(:debug) # Catches the 'Loading plugin network' type messages plugin.run end diff -Nru ohai-8.21.0/spec/unit/plugins/linux/platform_spec.rb ohai-13.8.0/spec/unit/plugins/linux/platform_spec.rb --- ohai-8.21.0/spec/unit/plugins/linux/platform_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/linux/platform_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -1,6 +1,6 @@ # # Author:: Adam Jacob () -# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. +# Copyright:: Copyright (c) 2008-2017, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,8 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Linux plugin platform" do @@ -36,7 +35,10 @@ let(:have_parallels_release) { false } let(:have_raspi_config) { false } let(:have_os_release) { false } + let(:have_usr_lib_os_release) { false } let(:have_cisco_release) { false } + let(:have_f5_release) { false } + let(:have_cumulus_dir) { false } before(:each) do @plugin = get_plugin("linux/platform") @@ -57,7 +59,10 @@ 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(:exist?).with("/etc/f5-release").and_return(have_f5_release) + allow(File).to receive(:exist?).with("/usr/lib/os-release").and_return(have_usr_lib_os_release) allow(File).to receive(:exist?).with("/etc/shared/os-release").and_return(have_cisco_release) + allow(Dir).to receive(:exist?).with("/etc/cumulus").and_return(have_cumulus_dir) allow(File).to receive(:read).with("PLEASE STUB ALL File.read CALLS") end @@ -112,7 +117,7 @@ @plugin[:lsb][:release] = "2011.09" @plugin.run expect(@plugin[:platform]).to eq("amazon") - expect(@plugin[:platform_family]).to eq("rhel") + expect(@plugin[:platform_family]).to eq("amazon") end it "should set platform to scientific when [:lsb][:id] contains ScientificSL" do @@ -171,6 +176,41 @@ expect(@plugin[:platform_family]).to eq("debian") end end + + context "on cumulus" do + + let(:have_cumulus_dir) { true } + let(:cumulus_release_content) do + <<-OS_RELEASE +NAME="Cumulus Linux" +VERSION_ID=3.1.2 +VERSION="Cumulus Linux 3.1.2" +PRETTY_NAME="Cumulus Linux" +ID=cumulus-linux +ID_LIKE=debian +CPE_NAME=cpe:/o:cumulusnetworks:cumulus_linux:3.1.2 +HOME_URL="http://www.cumulusnetworks.com/" +SUPPORT_URL="http://support.cumulusnetworks.com/" + +OS_RELEASE + end + + before(:each) do + expect(File).to receive(:read).with("/etc/cumulus/etc.replace/os-release").and_return(cumulus_release_content) + end + + # Cumulus is a debian derivative + it "should detect Cumulus as itself with debian as the family" do + @plugin.run + expect(@plugin[:platform]).to eq("cumulus") + expect(@plugin[:platform_family]).to eq("debian") + end + + it "should detect Cumulus platform_version" do + @plugin.run + expect(@plugin[:platform_version]).to eq("3.1.2") + end + end end describe "on slackware" do @@ -187,6 +227,12 @@ expect(@plugin[:platform]).to eq("slackware") expect(@plugin[:platform_family]).to eq("slackware") end + + it "should set platform_version on slackware" do + expect(File).to receive(:read).with("/etc/slackware-version").and_return("Slackware 12.0.0") + @plugin.run + expect(@plugin[:platform_version]).to eq("12.0.0") + end end describe "on arch" do @@ -265,6 +311,23 @@ end end + describe "on f5 big-ip" do + + let(:have_f5_release) { true } + + before(:each) do + @plugin.lsb = nil + end + + it "should set platform to bigip" do + expect(File).to receive(:read).with("/etc/f5-release").and_return("BIG-IP release 13.0.0 (Final)") + @plugin.run + expect(@plugin[:platform]).to eq("bigip") + expect(@plugin[:platform_family]).to eq("rhel") + expect(@plugin[:platform_version]).to eq("13.0.0") + end + end + describe "on exherbo" do let(:have_exherbo_release) { true } @@ -316,7 +379,7 @@ it "should set the platform_family to rhel if the LSB name is amazon-ish" do @plugin[:lsb][:id] = "Amazon" @plugin.run - expect(@plugin[:platform_family]).to eq("rhel") + expect(@plugin[:platform_family]).to eq("amazon") end it "should set the platform_family to fedora if the LSB name is fedora-ish" do @@ -387,6 +450,14 @@ expect(@plugin[:platform_version].to_i).to eq(13) end + it "should read the platform as clearos and version as 7.3" do + expect(File).to receive(:read).with("/etc/redhat-release").and_return("ClearOS release 7.3.0 (Final)") + @plugin.run + expect(@plugin[:platform]).to eq("clearos") + expect(@plugin[:platform_family]).to eq("rhel") + expect(@plugin[:platform_version].to_f).to eq(7.3) + end + # 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 @@ -811,4 +882,35 @@ expect(@plugin[:platform_version]).to eq("6.0.0.14I") end end + + describe "on clearlinux" do + let(:have_usr_lib_os_release) { true } + let(:usr_lib_os_release_content) do + <<-CLEARLINUX_RELEASE +NAME="Clear Linux Software for Intel Architecture" +VERSION=1 +ID=clear-linux-os +VERSION_ID=16140 +PRETTY_NAME="Clear Linux OS for Intel Architecture" +ANSI_COLOR="1;35" +HOME_URL="https://clearlinux.org" +SUPPORT_URL="https://clearlinux.org" +BUG_REPORT_URL="mailto:dev@lists.clearlinux.org" +PRIVACY_POLICY_URL="http://www.intel.com/privacy" +CLEARLINUX_RELEASE + end + + before do + expect(File).to receive(:read).with("/usr/lib/os-release").and_return(usr_lib_os_release_content) + end + + it "should set platform to clearlinux and platform_family to clearlinux" do + @plugin.lsb = nil + @plugin.run + + expect(@plugin[:platform]).to eq("clearlinux") + expect(@plugin[:platform_family]).to eq("clearlinux") + expect(@plugin[:platform_version]).to eq("16140") + end + end end diff -Nru ohai-8.21.0/spec/unit/plugins/linux/sessions_spec.rb ohai-13.8.0/spec/unit/plugins/linux/sessions_spec.rb --- ohai-8.21.0/spec/unit/plugins/linux/sessions_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/linux/sessions_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Linux sessions plugin" do let(:plugin) { get_plugin("linux/sessions") } diff -Nru ohai-8.21.0/spec/unit/plugins/linux/systemd_paths_spec.rb ohai-13.8.0/spec/unit/plugins/linux/systemd_paths_spec.rb --- ohai-8.21.0/spec/unit/plugins/linux/systemd_paths_spec.rb 1970-01-01 00:00:00.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/linux/systemd_paths_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -0,0 +1,122 @@ +# +# Author:: Davide Cavalca +# Copyright:: Copyright (c) 2017 Facebook +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS"BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") + +describe Ohai::System, "Linux systemd paths plugin" do + let(:plugin) { get_plugin("linux/systemd_paths") } + + before(:each) do + allow(plugin).to receive(:collect_os).and_return(:linux) + end + + it "should populate systemd_paths if systemd-path is found" do + systemd_path_out = <<-SYSTEMD_PATH_OUT +temporary: /tmp +temporary-large: /var/tmp +system-binaries: /usr/bin +system-include: /usr/include +system-library-private: /usr/lib +system-library-arch: /usr/lib/x86_64-linux-gnu +system-shared: /usr/share +system-configuration-factory: /usr/share/factory/etc +system-state-factory: /usr/share/factory/var +system-configuration: /etc +system-runtime: /run +system-runtime-logs: /run/log +system-state-private: /var/lib +system-state-logs: /var/log +system-state-cache: /var/cache +system-state-spool: /var/spool +user-binaries: /home/foo/.local/bin +user-library-private: /home/foo/.local/lib +user-library-arch: /home/foo/.local/lib/x86_64-linux-gnu +user-shared: /home/foo/.local/share +user-configuration: /home/foo/.config +user-runtime: /run/user/1000 +user-state-cache: /home/foo/.cache +user: /home/foo +user-documents: /home/foo/Documents +user-music: /home/foo/Music +user-pictures: /home/foo/Pictures +user-videos: /home/foo/Videos +user-download: /home/foo/Downloads +user-public: /home/foo/Public +user-templates: /home/foo/Templates +user-desktop: /home/foo/Desktop +search-binaries: /home/foo/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/opt/facebook/bin:/home/foo/.rvm/bin:/home/foo/.rvm/bin +search-library-private: /home/foo/.local/lib:/usr/local/lib:/usr/lib:/lib +search-library-arch: /home/foo/.local/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu:/lib/x86_64-linux-gnu +search-shared: /home/foo/.local/share:/usr/share/gnome:/home/foo/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share +search-configuration-factory: /usr/local/share/factory/etc:/usr/share/factory/etc +search-state-factory: /usr/local/share/factory/var:/usr/share/factory/var +search-configuration: /home/foo/.config:/etc +SYSTEMD_PATH_OUT + + allow(plugin).to receive(:which).with("systemd-path").and_return("/bin/systemd-path") + allow(plugin).to receive(:shell_out).with("/bin/systemd-path").and_return(mock_shell_out(0, systemd_path_out, "")) + plugin.run + expect(plugin[:systemd_paths].to_hash).to eq({ + "search-binaries" => "/home/foo/bin", + "search-configuration" => "/home/foo/.config", + "search-configuration-factory" => "/usr/local/share/factory/etc", + "search-library-arch" => "/home/foo/.local/lib/x86_64-linux-gnu", + "search-library-private" => "/home/foo/.local/lib", + "search-shared" => "/home/foo/.local/share", + "search-state-factory" => "/usr/local/share/factory/var", + "system-binaries" => "/usr/bin", + "system-configuration" => "/etc", + "system-configuration-factory" => "/usr/share/factory/etc", + "system-include" => "/usr/include", + "system-library-arch" => "/usr/lib/x86_64-linux-gnu", + "system-library-private" => "/usr/lib", + "system-runtime" => "/run", + "system-runtime-logs" => "/run/log", + "system-shared" => "/usr/share", + "system-state-cache" => "/var/cache", + "system-state-factory" => "/usr/share/factory/var", + "system-state-logs" => "/var/log", + "system-state-private" => "/var/lib", + "system-state-spool" => "/var/spool", + "temporary" => "/tmp", + "temporary-large" => "/var/tmp", + "user" => "/home/foo", + "user-binaries" => "/home/foo/.local/bin", + "user-configuration" => "/home/foo/.config", + "user-desktop" => "/home/foo/Desktop", + "user-documents" => "/home/foo/Documents", + "user-download" => "/home/foo/Downloads", + "user-library-arch" => "/home/foo/.local/lib/x86_64-linux-gnu", + "user-library-private" => "/home/foo/.local/lib", + "user-music" => "/home/foo/Music", + "user-pictures" => "/home/foo/Pictures", + "user-public" => "/home/foo/Public", + "user-runtime" => "/run/user/1000", + "user-shared" => "/home/foo/.local/share", + "user-state-cache" => "/home/foo/.cache", + "user-templates" => "/home/foo/Templates", + "user-videos" => "/home/foo/Videos", + }) + end + + it "should not populate systemd paths if systemd-path is not found" do + allow(plugin).to receive(:which).with("systemd-path").and_return(false) + plugin.run + expect(plugin[:systemd_paths]).to be(nil) + end +end diff -Nru ohai-8.21.0/spec/unit/plugins/linux/uptime_spec.rb ohai-13.8.0/spec/unit/plugins/linux/uptime_spec.rb --- ohai-8.21.0/spec/unit/plugins/linux/uptime_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/linux/uptime_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Linux plugin uptime" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/linux/virtualization_spec.rb ohai-13.8.0/spec/unit/plugins/linux/virtualization_spec.rb --- ohai-8.21.0/spec/unit/plugins/linux/virtualization_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/linux/virtualization_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Linux virtualization platform" do let(:plugin) { get_plugin("linux/virtualization") } @@ -40,10 +40,11 @@ allow(File).to receive(:exist?).with("/sys/devices/virtual/misc/kvm").and_return(false) allow(File).to receive(:exist?).with("/dev/lxd/sock").and_return(false) allow(File).to receive(:exist?).with("/var/lib/lxd/devlxd").and_return(false) + allow(File).to receive(:exist?).with("/proc/1/environ").and_return(false) # default the which wrappers to nil - allow(plugin).to receive(:lxc_version_exists?).and_return(false) - allow(plugin).to receive(:docker_exists?).and_return(false) + allow(plugin).to receive(:which).with("lxc-version").and_return(nil) + allow(plugin).to receive(:which).with("lxc-start").and_return(nil) allow(plugin).to receive(:nova_exists?).and_return(false) end @@ -345,6 +346,25 @@ expect(plugin[:virtualization][:systems][:bhyve]).to eq("guest") end + it "sets veertu guest if dmidecode detects Veertu" do + veertu_dmidecode = <<-VEERTU +System Information + Manufacturer: Veertu + Product Name: Veertu + Version: Not Specified + Serial Number: Not Specified + UUID: Not Settable + Wake-up Type: Power Switch + SKU Number: Not Specified + Family: Not Specified +VEERTU + allow(plugin).to receive(:shell_out).with("dmidecode").and_return(mock_shell_out(0, veertu_dmidecode, "")) + plugin.run + expect(plugin[:virtualization][:system]).to eq("veertu") + expect(plugin[:virtualization][:role]).to eq("guest") + expect(plugin[:virtualization][:systems][:veertu]).to eq("guest") + end + it "should run dmidecode and not set virtualization if nothing is detected" do allow(plugin).to receive(:shell_out).with("dmidecode").and_return(mock_shell_out(0, "", "")) plugin.run @@ -534,6 +554,7 @@ 2:cpu:/Charlie 1:cpuset:/Charlie CGROUP + allow(File).to receive(:read).with("/proc/1/environ").and_return("") expect(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true) allow(File).to receive(:read).with("/proc/self/cgroup").and_return(self_cgroup) plugin.run @@ -554,10 +575,19 @@ CGROUP expect(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true) allow(File).to receive(:read).with("/proc/self/cgroup").and_return(self_cgroup) + allow(File).to receive(:read).with("/proc/1/environ").and_return("") end it "sets lxc host if lxc-version exists" do - allow(plugin).to receive(:lxc_version_exists?).and_return("/usr/bin/lxc-version") + allow(plugin).to receive(:which).with("lxc-start").and_return("/usr/bin/lxc-version") + plugin.run + expect(plugin[:virtualization][:system]).to eq("lxc") + expect(plugin[:virtualization][:role]).to eq("host") + expect(plugin[:virtualization][:systems][:lxc]).to eq("host") + end + + it "sets lxc host if lxc-start exists" do + allow(plugin).to receive(:which).with("lxc-start").and_return("/usr/bin/lxc-start") plugin.run expect(plugin[:virtualization][:system]).to eq("lxc") expect(plugin[:virtualization][:role]).to eq("host") @@ -565,7 +595,7 @@ end it "does not set the old virtualization attributes if they are already set" do - allow(plugin).to receive(:lxc_version_exists?).and_return("/usr/bin/lxc-version") + allow(plugin).to receive(:which).with("lxc-version").and_return("/usr/bin/lxc-version") plugin[:virtualization] = Mash.new plugin[:virtualization][:system] = "the cloud" plugin[:virtualization][:role] = "cumulonimbus" @@ -574,14 +604,21 @@ expect(plugin[:virtualization][:role]).not_to eq("host") end - it "does not set lxc host if lxc-version does not exist" do - allow(plugin).to receive(:lxc_version_exists?).and_return(false) + it "does not set lxc host if neither lxc-version nor lxc-start exists" do plugin.run expect(plugin[:virtualization][:system]).to be_nil expect(plugin[:virtualization][:role]).to be_nil expect(plugin[:virtualization]).to eq({ "systems" => {} }) end + it "sets lxc guest if /proc/1/environ has lxccontainer string in it" do + one_environ = "container=lxccontainer_ttys=/dev/pts/0 /dev/pts/1 /dev/pts/2 /dev/pts/3".chomp + allow(File).to receive(:read).with("/proc/1/environ").and_return(one_environ) + plugin.run + expect(plugin[:virtualization][:system]).to eq("lxc") + expect(plugin[:virtualization][:role]).to eq("guest") + end + end it "does not set virtualization if /proc/self/cgroup isn't there" do @@ -591,6 +628,18 @@ end end + describe "when we are checking for systemd-nspawn" do + it "sets nspawn guest if /proc/1/environ has nspawn string in it" do + allow(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true) + one_environ = "container=systemd-nspawn_ttys=/dev/pts/0 /dev/pts/1 /dev/pts/2 /dev/pts/3".chomp + allow(File).to receive(:read).with("/proc/1/environ").and_return(one_environ) + allow(File).to receive(:read).with("/proc/self/cgroup").and_return("") + plugin.run + expect(plugin[:virtualization][:system]).to eq("nspawn") + expect(plugin[:virtualization][:role]).to eq("guest") + end + end + describe "when we are checking for docker" do it "sets docker guest if /proc/self/cgroup exist and there are /docker/ mounts" do self_cgroup = <<-CGROUP @@ -630,6 +679,30 @@ expect(plugin[:virtualization][:systems][:docker]).to eq("guest") end + it "sets docker guest if /proc/self/cgroup exist and there are /docker/docker-ce/ mounts" do + self_cgroup = <<-CGROUP +13:name=systemd:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468 +12:pids:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468 +11:hugetlb:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468 +10:net_prio:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468 +9:perf_event:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468 +8:net_cls:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468 +7:freezer:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468 +6:devices:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468 +5:memory:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468 +4:blkio:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468 +3:cpuacct:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468 +2:cpu:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468 +1:cpuset:/docker-ce/docker/b15b85d19304436488a78d06afeb108d94b20bb6898d852b65cad51bd7dc9468 +CGROUP + allow(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true) + allow(File).to receive(:read).with("/proc/self/cgroup").and_return(self_cgroup) + plugin.run + expect(plugin[:virtualization][:system]).to eq("docker") + expect(plugin[:virtualization][:role]).to eq("guest") + expect(plugin[:virtualization][:systems][:docker]).to eq("guest") + end + # Relevant at least starting docker 1.6.2, kernel 4.0.5 & systemd 224-1. # Doi not exactly know which software/version really matters here. it "should set docker guest if /proc/self/cgroup exists and there are /system.slice/docker- mounts (systemd managed cgroup)" do @@ -664,6 +737,7 @@ CGROUP allow(File).to receive(:exist?).with("/proc/self/cgroup").and_return(true) allow(File).to receive(:read).with("/proc/self/cgroup").and_return(self_cgroup) + allow(File).to receive(:read).with("/proc/1/environ").and_return("") plugin.run expect(plugin[:virtualization]).to eq({ "systems" => {} }) end @@ -689,7 +763,6 @@ end it "does not set the old virtualization attributes if they are already set" do - allow(plugin).to receive(:docker_exists?).and_return("/usr/bin/docker") plugin[:virtualization] = Mash.new plugin[:virtualization][:system] = "the cloud" plugin[:virtualization][:role] = "cumulonimbus" @@ -699,7 +772,6 @@ end it "does not set docker host if docker does not exist" do - allow(plugin).to receive(:docker_exists?).and_return(false) plugin.run expect(plugin[:virtualization][:system]).to be_nil expect(plugin[:virtualization][:role]).to be_nil diff -Nru ohai-8.21.0/spec/unit/plugins/lua_spec.rb ohai-13.8.0/spec/unit/plugins/lua_spec.rb --- ohai-8.21.0/spec/unit/plugins/lua_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/lua_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -18,7 +18,7 @@ # limitations under the License. # -require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb")) +require_relative "../../spec_helper.rb" describe Ohai::System, "plugin lua" do @@ -26,8 +26,8 @@ before(:each) do plugin[:languages] = Mash.new - @stderr = "Lua 5.1.2 Copyright (C) 1994-2008 Lua.org, PUC-Rio\n" - allow(plugin).to receive(:shell_out).with("lua -v").and_return(mock_shell_out(0, "", @stderr)) + @message = "Lua 5.1.2 Copyright (C) 1994-2008 Lua.org, PUC-Rio\n" + allow(plugin).to receive(:shell_out).with("lua -v").and_return(mock_shell_out(0, "", @message)) end it "gets the lua version from running lua -v" do @@ -51,4 +51,10 @@ plugin.run expect(plugin.languages).not_to have_key(:lua) end + + it "sets languages[:lua][:version] when 'lua -v' returns output on stdout not stderr" do + allow(plugin).to receive(:shell_out).with("lua -v").and_return(mock_shell_out(0, @message, "")) + plugin.run + expect(plugin.languages[:lua][:version]).to eql("5.1.2") + end end diff -Nru ohai-8.21.0/spec/unit/plugins/mono_spec.rb ohai-13.8.0/spec/unit/plugins/mono_spec.rb --- ohai-8.21.0/spec/unit/plugins/mono_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/mono_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb")) +require_relative "../../spec_helper.rb" describe Ohai::System, "plugin mono" do let(:plugin) { get_plugin("mono") } diff -Nru ohai-8.21.0/spec/unit/plugins/netbsd/hostname_spec.rb ohai-13.8.0/spec/unit/plugins/netbsd/hostname_spec.rb --- ohai-8.21.0/spec/unit/plugins/netbsd/hostname_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/netbsd/hostname_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "NetBSD hostname plugin" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/netbsd/kernel_spec.rb ohai-13.8.0/spec/unit/plugins/netbsd/kernel_spec.rb --- ohai-8.21.0/spec/unit/plugins/netbsd/kernel_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/netbsd/kernel_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "NetBSD kernel plugin" do before(:each) do @@ -25,7 +25,7 @@ allow(@plugin).to receive(:init_kernel).and_return({}) allow(@plugin).to receive(:shell_out).with("uname -i").and_return(mock_shell_out(0, "foo", "")) allow(@plugin).to receive(:shell_out).with("sysctl kern.securelevel").and_return(mock_shell_out(0, "kern.securelevel: 1\n", "")) - allow(@plugin).to receive(:shell_out).with("#{ Ohai.abs_path( "/usr/bin/modstat" )}").and_return(mock_shell_out(0, " 1 7 0xc0400000 97f830 kernel", "")) + allow(@plugin).to receive(:shell_out).with("#{Ohai.abs_path( "/usr/bin/modstat" )}").and_return(mock_shell_out(0, " 1 7 0xc0400000 97f830 kernel", "")) end it "should set the kernel_os to the kernel_name value" do diff -Nru ohai-8.21.0/spec/unit/plugins/netbsd/platform_spec.rb ohai-13.8.0/spec/unit/plugins/netbsd/platform_spec.rb --- ohai-8.21.0/spec/unit/plugins/netbsd/platform_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/netbsd/platform_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "NetBSD plugin platform" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/network_spec.rb ohai-13.8.0/spec/unit/plugins/network_spec.rb --- ohai-8.21.0/spec/unit/plugins/network_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/network_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" def it_doesnt_fail it "doesnt fail" do @@ -367,7 +367,7 @@ end it "informs about this setup" do - expect(Ohai::Log).to receive(:debug).with(/^ipaddress and ip6address are set from different interfaces/) + expect(Ohai::Log).to receive(:debug).with(/ipaddress and ip6address are set from different interfaces/) allow(Ohai::Log).to receive(:debug) @plugin.run end @@ -396,7 +396,7 @@ end it "informs about this setup" do - expect(Ohai::Log).to receive(:debug).with(/^ipaddress and ip6address are set from different interfaces/) + expect(Ohai::Log).to receive(:debug).with(/ipaddress and ip6address are set from different interfaces/) allow(Ohai::Log).to receive(:debug) @plugin.run end @@ -421,8 +421,8 @@ end it "warns about this conflict" do - expect(Ohai::Log).to receive(:debug).with(/^\[inet\] no ipaddress\/mask on eth1/).once - expect(Ohai::Log).to receive(:debug).with(/^\[inet6\] no ipaddress\/mask on eth1/).once + expect(Ohai::Log).to receive(:debug).with(/\[inet\] no ipaddress\/mask on eth1/).once + expect(Ohai::Log).to receive(:debug).with(/\[inet6\] no ipaddress\/mask on eth1/).once allow(Ohai::Log).to receive(:debug) @plugin.run end @@ -460,11 +460,11 @@ end it "warns about this conflict" do - expect(Ohai::Log).to receive(:warn).with(/^unable to detect ipaddress/).once - expect(Ohai::Log).to receive(:warn).with(/^\[inet\] no ip address on eth0/).once - expect(Ohai::Log).to receive(:debug).with(/^unable to detect ip6address/).once - expect(Ohai::Log).to receive(:debug).with(/^unable to detect macaddress/).twice # for each family - expect(Ohai::Log).to receive(:warn).with(/^\[inet6\] no ip address on eth0/).once + expect(Ohai::Log).to receive(:warn).with(/unable to detect ipaddress/).once + expect(Ohai::Log).to receive(:warn).with(/\[inet\] no ip address on eth0/).once + expect(Ohai::Log).to receive(:debug).with(/unable to detect ip6address/).once + expect(Ohai::Log).to receive(:debug).with(/unable to detect macaddress/).twice # for each family + expect(Ohai::Log).to receive(:warn).with(/\[inet6\] no ip address on eth0/).once @plugin.run end end @@ -491,9 +491,9 @@ end it "should warn about it" do - expect(Ohai::Log).to receive(:warn).with(/^unable to detect ipaddress/).once - expect(Ohai::Log).to receive(:debug).with(/^unable to detect macaddress/).twice # for each family - expect(Ohai::Log).to receive(:debug).with(/^unable to detect ip6address/).once + expect(Ohai::Log).to receive(:warn).with(/unable to detect ipaddress/).once + expect(Ohai::Log).to receive(:debug).with(/unable to detect macaddress/).twice # for each family + expect(Ohai::Log).to receive(:debug).with(/unable to detect ip6address/).once @plugin.run end end @@ -643,8 +643,8 @@ it_populates_ipaddress_attributes it "picks {ip,mac,ip6}address from the first interface" do - expect(Ohai::Log).to receive(:debug).with(/^\[inet\] no default interface/).once - expect(Ohai::Log).to receive(:debug).with(/^\[inet6\] no default interface/).once + expect(Ohai::Log).to receive(:debug).with(/\[inet\] no default interface/).once + expect(Ohai::Log).to receive(:debug).with(/\[inet6\] no default interface/).once allow(Ohai::Log).to receive(:debug) @plugin.run expect(@plugin["ipaddress"]).to eq("192.168.99.11") @@ -666,8 +666,8 @@ it_populates_ipaddress_attributes it "prefers global scope addressses to set {ip,mac,ip6}address" do - expect(Ohai::Log).to receive(:debug).with(/^\[inet\] no default interface/).once - expect(Ohai::Log).to receive(:debug).with(/^\[inet6\] no default interface/).once + expect(Ohai::Log).to receive(:debug).with(/\[inet\] no default interface/).once + expect(Ohai::Log).to receive(:debug).with(/\[inet6\] no default interface/).once allow(Ohai::Log).to receive(:debug) @plugin.run expect(@plugin["ipaddress"]).to eq("192.168.99.11") @@ -795,10 +795,10 @@ end it "warns about not being able to set {ip,mac}address (ipv4)" do - expect(Ohai::Log).to receive(:warn).with(/^unable to detect ipaddress/).once - expect(Ohai::Log).to receive(:debug).with(/^unable to detect macaddress/) # for ipv4 - expect(Ohai::Log).to receive(:debug).with(/^setting macaddress to/) # for ipv6 - expect(Ohai::Log).to receive(:debug).with(/^\[inet6\] Using default interface eth0 and default gateway/) # for ipv6 + expect(Ohai::Log).to receive(:warn).with(/unable to detect ipaddress/).once + expect(Ohai::Log).to receive(:debug).with(/unable to detect macaddress/) # for ipv4 + expect(Ohai::Log).to receive(:debug).with(/setting macaddress to/) # for ipv6 + expect(Ohai::Log).to receive(:debug).with(/\[inet6\] Using default interface eth0 and default gateway/) # for ipv6 @plugin.run end @@ -810,7 +810,7 @@ end it "informs about macaddress being set using the ipv6 setup" do - expect(Ohai::Log).to receive(:debug).with(/^setting macaddress to '00:16:3E:2F:36:79'/) + expect(Ohai::Log).to receive(:debug).with(/setting macaddress to '00:16:3E:2F:36:79'/) allow(Ohai::Log).to receive(:debug) @plugin.run end @@ -842,7 +842,7 @@ end it "informs about macaddress being set using the ipv6 setup" do - expect(Ohai::Log).to receive(:debug).with(/^setting macaddress to '00:16:3E:2F:36:79'/) + expect(Ohai::Log).to receive(:debug).with(/setting macaddress to '00:16:3E:2F:36:79'/) allow(Ohai::Log).to receive(:debug) @plugin.run end @@ -962,7 +962,7 @@ end it "warns about not being able to set ipaddress" do - expect(Ohai::Log).to receive(:warn).with(/^unable to detect ipaddress/).once + expect(Ohai::Log).to receive(:warn).with(/unable to detect ipaddress/).once @plugin.run end diff -Nru ohai-8.21.0/spec/unit/plugins/nodejs_spec.rb ohai-13.8.0/spec/unit/plugins/nodejs_spec.rb --- ohai-8.21.0/spec/unit/plugins/nodejs_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/nodejs_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -18,7 +18,7 @@ # limitations under the License. # -require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb")) +require_relative "../../spec_helper.rb" describe Ohai::System, "plugin nodejs" do diff -Nru ohai-8.21.0/spec/unit/plugins/ohai_spec.rb ohai-13.8.0/spec/unit/plugins/ohai_spec.rb --- ohai-8.21.0/spec/unit/plugins/ohai_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/ohai_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -18,7 +18,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" describe Ohai::System, "plugin ohai" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/ohai_time_spec.rb ohai-13.8.0/spec/unit/plugins/ohai_time_spec.rb --- ohai-8.21.0/spec/unit/plugins/ohai_time_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/ohai_time_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" describe Ohai::System, "plugin ohai_time" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/openbsd/hostname_spec.rb ohai-13.8.0/spec/unit/plugins/openbsd/hostname_spec.rb --- ohai-8.21.0/spec/unit/plugins/openbsd/hostname_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/openbsd/hostname_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "OpenBSD hostname plugin" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/openbsd/kernel_spec.rb ohai-13.8.0/spec/unit/plugins/openbsd/kernel_spec.rb --- ohai-8.21.0/spec/unit/plugins/openbsd/kernel_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/openbsd/kernel_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "OpenBSD kernel plugin" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/openbsd/platform_spec.rb ohai-13.8.0/spec/unit/plugins/openbsd/platform_spec.rb --- ohai-8.21.0/spec/unit/plugins/openbsd/platform_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/openbsd/platform_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "OpenBSD plugin platform" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/openstack_spec.rb ohai-13.8.0/spec/unit/plugins/openstack_spec.rb --- ohai-8.21.0/spec/unit/plugins/openstack_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/openstack_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,10 +16,9 @@ # limitations under the License. # -require "spec_helper" -require "ohai/plugins/openstack" +require_relative "../../spec_helper.rb" -describe "OpenStack Plugin" do +describe Ohai::System, "plugin openstack" do let(:plugin) { get_plugin("openstack") } @@ -38,7 +37,7 @@ context "when DMI data is Openstack" do context "and the metadata service is not available" do before do - allow(plugin).to receive(:can_metadata_connect?). + allow(plugin).to receive(:can_socket_connect?). with(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80). and_return(false) plugin[:dmi] = { :system => { :all_records => [ { :Manufacturer => "OpenStack Foundation" } ] } } @@ -58,7 +57,7 @@ context "when running on dreamhost" do it "sets openstack provider attribute to dreamhost" do plugin["etc"] = { "passwd" => { "dhc-user" => {} } } - allow(plugin).to receive(:can_metadata_connect?). + allow(plugin).to receive(:can_socket_connect?). with(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80). and_return(false) plugin[:dmi] = { :system => { :all_records => [ { :Manufacturer => "OpenStack Foundation" } ] } } @@ -70,7 +69,7 @@ context "when the hint is present" do context "and the metadata service is not available" do before do - allow(plugin).to receive(:can_metadata_connect?). + allow(plugin).to receive(:can_socket_connect?). with(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80). and_return(false) allow(plugin).to receive(:hint?).with("openstack").and_return(true) @@ -161,7 +160,7 @@ }' end - let(:http_client) { double("Net::HTTP", :read_timeout= => nil) } + let(:http_client) { double("Net::HTTP", { :read_timeout= => nil, :keep_alive_timeout= => nil } ) } def allow_get(url, response_body) allow(http_client).to receive(:get). @@ -177,7 +176,7 @@ before do allow(plugin).to receive(:hint?).with("openstack").and_return(true) - allow(plugin).to receive(:can_metadata_connect?). + allow(plugin).to receive(:can_socket_connect?). with(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80). and_return(true) diff -Nru ohai-8.21.0/spec/unit/plugins/os_spec.rb ohai-13.8.0/spec/unit/plugins/os_spec.rb --- ohai-8.21.0/spec/unit/plugins/os_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/os_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" ORIGINAL_CONFIG_HOST_OS = ::RbConfig::CONFIG["host_os"] diff -Nru ohai-8.21.0/spec/unit/plugins/packages_spec.rb ohai-13.8.0/spec/unit/plugins/packages_spec.rb --- ohai-8.21.0/spec/unit/plugins/packages_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/packages_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -17,7 +17,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" describe Ohai::System, "plugin packages" do context "on debian" do @@ -102,6 +102,43 @@ end end + context "on arch" do + let(:plugin) do + get_plugin("packages").tap do |plugin| + plugin[:platform_family] = "arch" + end + end + + let(:stdout) do + File.read(File.join(SPEC_PLUGIN_PATH, "pacman.output")) + end + + before(:each) do + allow(plugin).to receive(:collect_os).and_return(:linux) + allow(plugin).to receive(:shell_out).with("LANG=C pacman -Qi").and_return(mock_shell_out(0, stdout, "")) + plugin.run + end + + it "calls LANG=C pacman -Qi" do + expect(plugin).to receive(:shell_out) + .with("LANG=C pacman -Qi") + .and_return(mock_shell_out(0, stdout, "")) + plugin.run + end + + it "gets packages and versions/release - normal case" do + expect(plugin[:packages]["acl"][:version]).to eq("2.2.52-3") + expect(plugin[:packages]["acl"][:installdate]).to eq("1500780345") + expect(plugin[:packages]["acl"][:arch]).to eq("x86_64") + end + + it "gets packages and versions/release - multiline optdeps" do + expect(plugin[:packages]["abcde"][:version]).to eq("2.8.1-2") + expect(plugin[:packages]["abcde"][:installdate]).to eq("1493998583") + expect(plugin[:packages]["abcde"][:arch]).to eq("any") + end + end + context "on windows", :windows_only do let(:plugin) do @@ -210,6 +247,10 @@ it "gets packages with version" do expect(plugin[:packages]["chef"][:version]).to eq("12.5.1.1") end + + it "properly parses package names for RPMs" do + expect(plugin[:packages]["wget"][:version]).to eq("1.9.1-3") + end end context "on freebsd" do diff -Nru ohai-8.21.0/spec/unit/plugins/passwd_spec.rb ohai-13.8.0/spec/unit/plugins/passwd_spec.rb --- ohai-8.21.0/spec/unit/plugins/passwd_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/passwd_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -1,4 +1,20 @@ -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +# +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require_relative "../../spec_helper.rb" describe Ohai::System, "plugin etc", :unix_only do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/perl_spec.rb ohai-13.8.0/spec/unit/plugins/perl_spec.rb --- ohai-8.21.0/spec/unit/plugins/perl_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/perl_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -17,7 +17,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" describe Ohai::System, "plugin perl" do let(:plugin) { get_plugin("perl") } diff -Nru ohai-8.21.0/spec/unit/plugins/php_spec.rb ohai-13.8.0/spec/unit/plugins/php_spec.rb --- ohai-8.21.0/spec/unit/plugins/php_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/php_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -18,7 +18,7 @@ # limitations under the License. # -require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb")) +require_relative "../../spec_helper.rb" describe Ohai::System, "plugin php" do let(:plugin) { get_plugin("php") } diff -Nru ohai-8.21.0/spec/unit/plugins/platform_spec.rb ohai-13.8.0/spec/unit/plugins/platform_spec.rb --- ohai-8.21.0/spec/unit/plugins/platform_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/platform_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" describe Ohai::System, "plugin platform" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/powershell_spec.rb ohai-13.8.0/spec/unit/plugins/powershell_spec.rb --- ohai-8.21.0/spec/unit/plugins/powershell_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/powershell_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -15,7 +15,7 @@ # limitations under the License. # -require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb")) +require_relative "../../spec_helper.rb" describe Ohai::System, "plugin powershell" do let(:plugin) { get_plugin("powershell") } @@ -45,7 +45,7 @@ END compat_version_array = ["1.0", "2.0", "3.0", "4.0"] - allow(plugin).to receive(:shell_out).with(anything()).and_return(mock_shell_out(0, v4_output, "")) + allow(plugin).to receive(:shell_out).with(anything).and_return(mock_shell_out(0, v4_output, "")) allow(plugin).to receive(:parse_compatible_versions).and_return(compat_version_array) plugin.run expect(plugin.languages[:powershell][:version]).to eql("4.0") diff -Nru ohai-8.21.0/spec/unit/plugins/python_spec.rb ohai-13.8.0/spec/unit/plugins/python_spec.rb --- ohai-8.21.0/spec/unit/plugins/python_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/python_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -17,7 +17,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" describe Ohai::System, "plugin python" do let(:stdout) { "2.5.2 (r252:60911, Jan 4 2009, 17:40:26)\n[GCC 4.3.2]\n" } diff -Nru ohai-8.21.0/spec/unit/plugins/rackspace_spec.rb ohai-13.8.0/spec/unit/plugins/rackspace_spec.rb --- ohai-8.21.0/spec/unit/plugins/rackspace_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/rackspace_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,8 +16,7 @@ # require "resolv" - -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" describe Ohai::System, "plugin rackspace" do let(:plugin) { get_plugin("rackspace") } @@ -152,7 +151,7 @@ expect(Ohai::Log). to receive(:debug). - with("rackspace plugin: Unable to find xenstore-ls, cannot capture " \ + with("Plugin Rackspace: Unable to find xenstore-ls, cannot capture " \ "region information for Rackspace cloud") plugin.run @@ -175,7 +174,7 @@ expect(Ohai::Log). to receive(:debug). - with("rackspace plugin: Unable to find xenstore-read, cannot capture " \ + with("Plugin Rackspace: Unable to find xenstore-read, cannot capture " \ "instance ID information for Rackspace cloud") plugin.run @@ -224,6 +223,18 @@ end end + describe "with Rackspace windows manufacturer data" do + it "has rackspace attribute" do + plugin.run + expect(plugin[:rackspace]).not_to be_nil + end + + before(:each) do + allow(plugin).to receive(:hint?).with("rackspace").and_return(false) + allow(plugin).to receive(:has_rackspace_manufacturer?).and_return(true) + end + end + describe "xenstore provider returns rackspace" do it_behaves_like "rackspace" @@ -267,7 +278,7 @@ expect(Ohai::Log). to receive(:debug). - with("rackspace plugin: Unable to capture custom private networking " \ + with("Plugin Rackspace: Unable to capture custom private networking " \ "information for Rackspace cloud") plugin.run diff -Nru ohai-8.21.0/spec/unit/plugins/root_group_spec.rb ohai-13.8.0/spec/unit/plugins/root_group_spec.rb --- ohai-8.21.0/spec/unit/plugins/root_group_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/root_group_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,8 +16,8 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") -require File.expand_path(File.dirname(__FILE__) + "/../../../lib/ohai/util/win32/group_helper.rb") +require_relative "../../spec_helper.rb" +require "ohai/util/win32/group_helper" describe Ohai::System, "root_group" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/ruby_spec.rb ohai-13.8.0/spec/unit/plugins/ruby_spec.rb --- ohai-8.21.0/spec/unit/plugins/ruby_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/ruby_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" ruby_bin = File.join(::RbConfig::CONFIG["bindir"], ::RbConfig::CONFIG["ruby_install_name"]) diff -Nru ohai-8.21.0/spec/unit/plugins/rust_spec.rb ohai-13.8.0/spec/unit/plugins/rust_spec.rb --- ohai-8.21.0/spec/unit/plugins/rust_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/rust_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -14,7 +14,7 @@ # limitations under the License. # -require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb")) +require_relative "../../spec_helper.rb" describe Ohai::System, "plugin rust" do let(:stdout) { "rustc 1.0.0-nightly (29bd9a06e 2015-01-20 23:03:09 +0000)" } diff -Nru ohai-8.21.0/spec/unit/plugins/scala_spec.rb ohai-13.8.0/spec/unit/plugins/scala_spec.rb --- ohai-8.21.0/spec/unit/plugins/scala_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/scala_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -15,7 +15,7 @@ # limitations under the License. # -require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb")) +require_relative "../../spec_helper.rb" describe Ohai::System, "plugin scala" do @@ -26,15 +26,11 @@ end let(:scala_out) { "Scala code runner version 2.11.6 -- Copyright 2002-2013, LAMP/EPFL" } - let(:sbt_out) { "sbt launcher version 0.13.8" } def setup_plugin allow(plugin).to receive(:shell_out) .with("scala -version") .and_return(mock_shell_out(0, "", scala_out)) - allow(plugin).to receive(:shell_out) - .with("sbt --version") - .and_return(mock_shell_out(0, sbt_out, "")) end context "if scala is installed" do @@ -48,45 +44,15 @@ end end - context "if sbt is installed" do - - before(:each) do - setup_plugin - plugin.run - end - - it "sets languages[:scala][:sbt][:version]" do - expect(plugin[:languages][:scala][:sbt][:version]).to eql("0.13.8") - end - end - - context "if scala/sbt are not installed" do - + context "if scala is not installed" do before(:each) do allow(plugin).to receive(:shell_out) .and_raise( Ohai::Exceptions::Exec ) plugin.run end - it "does NOT set the languages[:scala] if scala/sbts commands fails" do + it "does NOT set the languages[:scala] if scala commands fails" do expect(plugin[:languages]).not_to have_key(:scala) end end - - context "if sbt is not installed" do - before(:each) do - allow(plugin).to receive(:shell_out) - .with("scala -version") - .and_return(mock_shell_out(0, "", scala_out)) - - allow(plugin).to receive(:shell_out) - .with("sbt --version") - .and_raise( Ohai::Exceptions::Exec ) - plugin.run - end - - it "does NOT set the languages[:scala][:sbt] if sbt command fails" do - expect(plugin[:languages][:scala]).not_to have_key(:sbt) - end - end end diff -Nru ohai-8.21.0/spec/unit/plugins/shard_spec.rb ohai-13.8.0/spec/unit/plugins/shard_spec.rb --- ohai-8.21.0/spec/unit/plugins/shard_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/shard_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -17,7 +17,7 @@ # require "digest/md5" -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" describe Ohai::System, "shard plugin" do let(:plugin) { get_plugin("shard") } diff -Nru ohai-8.21.0/spec/unit/plugins/shells_spec.rb ohai-13.8.0/spec/unit/plugins/shells_spec.rb --- ohai-8.21.0/spec/unit/plugins/shells_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/shells_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -15,7 +15,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" describe Ohai::System, "plugin shells" do let(:plugin) { get_plugin("shells") } diff -Nru ohai-8.21.0/spec/unit/plugins/sigar/network_route_spec.rb ohai-13.8.0/spec/unit/plugins/sigar/network_route_spec.rb --- ohai-8.21.0/spec/unit/plugins/sigar/network_route_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/sigar/network_route_spec.rb 1970-01-01 00:00:00.000000000 +0000 @@ -1,148 +0,0 @@ -# -# Author:: Toomas Pelberg () -# Copyright:: Copyright (c) 2011-2016 Chef Software, Inc. -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") - -sigar_available = begin - require "sigar" - true -rescue LoadError - false -end - -require "ohai" - -describe Ohai::System, "Sigar network route plugin" do - - if sigar_available - - before(:each) do - @ohai = Ohai::System.new - @plugin = get_plugin("sigar/network", @ohai) - allow(@plugin).to receive(:collect_os).and_return(:sigar) - @sigar = double("Sigar") - @net_info_conf = { - :default_gateway => "192.168.1.254", - :default_gateway_interface => "eth0", - :primary_dns => "192.168.1.254", - :secondary_dns => "8.8.8.8", - :host_name => "localhost", - } - net_info = double("Sigar::NetInfo") - @net_info_conf.each_pair do |k, v| - allow(net_info).to receive(k).and_return(v) - end - @net_route_conf = { - :destination => "192.168.1.0", - :gateway => "0.0.0.0", - :mask => "255.255.255.0", - :flags => 1, - :refcnt => 0, - :use => 0, - :metric => 0, - :mtu => 0, - :window => 0, - :irtt => 0, - :ifname => "eth0", - } - net_route = double("Sigar::NetRoute") - @net_route_conf.each_pair do |k, v| - allow(net_route).to receive(k).and_return(v) - end - @net_interface_conf = { - :flags => 2115, - :destination => "192.168.1.1", - :mtu => 1500, - :type => "Ethernet", - :hwaddr => "00:11:22:33:44:55:66", - :address => "192.168.1.1", - :broadcast => "192.168.1.255", - :netmask => "255.255.255.0", - :address6 => nil, - :tx_queue_len => 1000, - :prefix6_length => 0, - } - net_conf = double("Sigar::NetConf") - @net_interface_conf.each_pair do |k, v| - allow(net_conf).to receive(k).and_return(v) - end - @net_interface_stat = { - :rx_bytes => 1369035618, - :rx_dropped => 0, - :rx_errors => 0, - :rx_frame => 0, - :rx_overruns => 0, - :rx_packets => 7271669, - :speed => -1, - :tx_bytes => 3482843666, - :tx_carrier => 0, - :tx_collisions => 0, - :tx_dropped => 0, - :tx_errors => 0, - :tx_overruns => 0, - :tx_packets => 4392794, - } - net_stat = double("Sigar::NetStat") - @net_interface_stat.each_pair do |k, v| - allow(net_stat).to receive(k).and_return(v) - end - @net_arp_conf = { - :address => "192.168.1.5", - :flags => 2, - :hwaddr => "00:15:62:96:01:D0", - :ifname => "eth0", - :type => "ether", - } - net_arp = double("Sigar::NetArp") - @net_arp_conf.each_pair do |k, v| - allow(net_arp).to receive(k).and_return(v) - end - allow(@sigar).to receive(:fqdn).and_return("localhost.localdomain") - expect(@sigar).to receive(:net_info).once.times.and_return(net_info) - expect(@sigar).to receive(:net_interface_list).once.and_return(["eth0"]) - expect(@sigar).to receive(:net_interface_config).with("eth0").and_return(net_conf) - expect(@sigar).to receive(:net_interface_stat).with("eth0").and_return(net_stat) - expect(@sigar).to receive(:arp_list).once.and_return([net_arp]) - - # Since we double net_route_list here, flags never gets called - expect(@sigar).to receive(:net_route_list).once.and_return([net_route]) - expect(Sigar).to receive(:new).once.and_return(@sigar) - - @plugin.run - end - - it "should set the routes" do - expect(@plugin[:network][:interfaces][:eth0]).to have_key(:route) - end - - it "should set the route details" do - @net_route_conf.each_pair do |k, v| - # Work around the above doubleing of net_route_list skipping the call to flags() - if k == :flags - v = "U" - @plugin[:network][:interfaces][:eth0][:route]["192.168.1.0"][k] = v - end - expect(@plugin[:network][:interfaces][:eth0][:route]["192.168.1.0"]).to have_key(k) - expect(@plugin[:network][:interfaces][:eth0][:route]["192.168.1.0"][k]).to eql(v) - end - end - - else - pending "Sigar not available, skipping sigar tests" - end -end diff -Nru ohai-8.21.0/spec/unit/plugins/softlayer_spec.rb ohai-13.8.0/spec/unit/plugins/softlayer_spec.rb --- ohai-8.21.0/spec/unit/plugins/softlayer_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/softlayer_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -17,7 +17,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" describe Ohai::System, "plugin softlayer" do let(:plugin) { get_plugin("softlayer") } diff -Nru ohai-8.21.0/spec/unit/plugins/solaris2/cpu_spec.rb ohai-13.8.0/spec/unit/plugins/solaris2/cpu_spec.rb --- ohai-8.21.0/spec/unit/plugins/solaris2/cpu_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/solaris2/cpu_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -14,7 +14,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Solaris2.X cpu plugin" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/solaris2/dmi_spec.rb ohai-13.8.0/spec/unit/plugins/solaris2/dmi_spec.rb --- ohai-8.21.0/spec/unit/plugins/solaris2/dmi_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/solaris2/dmi_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" SOLARIS_DMI_OUT = <<-EOS ID SIZE TYPE diff -Nru ohai-8.21.0/spec/unit/plugins/solaris2/hostname_spec.rb ohai-13.8.0/spec/unit/plugins/solaris2/hostname_spec.rb --- ohai-8.21.0/spec/unit/plugins/solaris2/hostname_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/solaris2/hostname_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Solaris2.X hostname plugin" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/solaris2/kernel_spec.rb ohai-13.8.0/spec/unit/plugins/solaris2/kernel_spec.rb --- ohai-8.21.0/spec/unit/plugins/solaris2/kernel_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/solaris2/kernel_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Solaris2.X kernel plugin" do # NOTE: Solaris will report the same module loaded multiple times diff -Nru ohai-8.21.0/spec/unit/plugins/solaris2/memory_spec.rb ohai-13.8.0/spec/unit/plugins/solaris2/memory_spec.rb --- ohai-8.21.0/spec/unit/plugins/solaris2/memory_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/solaris2/memory_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -14,7 +14,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Solaris2.X memory plugin" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/solaris2/network_spec.rb ohai-13.8.0/spec/unit/plugins/solaris2/network_spec.rb --- ohai-8.21.0/spec/unit/plugins/solaris2/network_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/solaris2/network_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Solaris2.X network plugin" do @@ -69,9 +69,7 @@ eri0: flags=1004843 mtu 1500 \ index 2 inet 172.17.128.208 netmask ffffff00 broadcast 172.17.128.255 -ip6.tun0: flags=10008d1 \ -mtu 1460 - index 3 +ip6.tun0: flags=10008d1 mtu 1460 index 3 inet6 tunnel src fe80::1 tunnel dst fe80::2 tunnel security settings --> use 'ipsecconf -ln -i ip.tun1' tunnel hop limit 60 tunnel encapsulation limit 4 @@ -80,8 +78,7 @@ usesrc vni0 inet6 fe80::203:baff:fe17:4be0/10 ether 0:3:ba:17:4b:e0 -vni0: flags=2002210041 mtu 0 - index 5 +vni0: flags=2002210041 mtu 1460 index 5 srcof qfe1 inet6 fe80::203:baff:fe17:4444/128 ENDIFCONFIG @@ -176,7 +173,7 @@ end it "finds the default interface for a solaris 11 zone" do - expect(@plugin[:network][:default_interface]).to eq("net1") + expect(@plugin[:network][:default_interface]).to eq("net1:1") end end diff -Nru ohai-8.21.0/spec/unit/plugins/solaris2/platform_spec.rb ohai-13.8.0/spec/unit/plugins/solaris2/platform_spec.rb --- ohai-8.21.0/spec/unit/plugins/solaris2/platform_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/solaris2/platform_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Solaris plugin platform" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/solaris2/virtualization_spec.rb ohai-13.8.0/spec/unit/plugins/solaris2/virtualization_spec.rb --- ohai-8.21.0/spec/unit/plugins/solaris2/virtualization_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/solaris2/virtualization_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Solaris virtualization platform" do before(:each) do @@ -34,7 +34,7 @@ allow(File).to receive(:exist?).with("/usr/sbin/smbios").and_return(false) allow(File).to receive(:exist?).with("/usr/sbin/zoneadm").and_return(false) allow(@plugin).to receive(:shell_out).with("/usr/sbin/smbios").and_return(mock_shell_out(0, "", "")) - allow(@plugin).to receive(:shell_out).with("#{ Ohai.abs_path( "/usr/sbin/psrinfo" )} -pv").and_return(mock_shell_out(0, "", "")) + allow(@plugin).to receive(:shell_out).with("#{Ohai.abs_path( "/usr/sbin/psrinfo" )} -pv").and_return(mock_shell_out(0, "", "")) end describe "when we are checking for kvm" do @@ -43,12 +43,12 @@ end it "should run psrinfo -pv" do - expect(@plugin).to receive(:shell_out).with("#{ Ohai.abs_path( "/usr/sbin/psrinfo" )} -pv") + expect(@plugin).to receive(:shell_out).with("#{Ohai.abs_path( "/usr/sbin/psrinfo" )} -pv") @plugin.run end it "Should set kvm guest if psrinfo -pv contains QEMU Virtual CPU" do - allow(@plugin).to receive(:shell_out).with("#{ Ohai.abs_path( "/usr/sbin/psrinfo" )} -pv").and_return(mock_shell_out(0, "QEMU Virtual CPU", "")) + allow(@plugin).to receive(:shell_out).with("#{Ohai.abs_path( "/usr/sbin/psrinfo" )} -pv").and_return(mock_shell_out(0, "QEMU Virtual CPU", "")) @plugin.run expect(@plugin[:virtualization][:system]).to eq("kvm") expect(@plugin[:virtualization][:role]).to eq("guest") @@ -56,7 +56,7 @@ end it "should not set virtualization if kvm isn't there" do - expect(@plugin).to receive(:shell_out).with("#{ Ohai.abs_path( "/usr/sbin/psrinfo" )} -pv").and_return(mock_shell_out(0, @psrinfo_pv, "")) + expect(@plugin).to receive(:shell_out).with("#{Ohai.abs_path( "/usr/sbin/psrinfo" )} -pv").and_return(mock_shell_out(0, @psrinfo_pv, "")) @plugin.run expect(@plugin[:virtualization][:systems]).to eq({}) end diff -Nru ohai-8.21.0/spec/unit/plugins/solaris2/zpools_spec.rb ohai-13.8.0/spec/unit/plugins/solaris2/zpools_spec.rb --- ohai-8.21.0/spec/unit/plugins/solaris2/zpools_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/solaris2/zpools_spec.rb 1970-01-01 00:00:00.000000000 +0000 @@ -1,153 +0,0 @@ -# License:: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") - -describe Ohai::System, "Solaris 2.x zpool plugin" do - before(:each) do - @plugin = get_plugin("solaris2/zpools") - allow(@plugin).to receive(:collect_os).and_return(:solaris2) - - @zpool_status_rpool = <<-EOSR -pool: rpool -state: ONLINE -scan: resilvered 65.6G in 0h8m with 0 errors on Fri Jun 6 14:22:40 2014 -config: - - NAME STATE READ WRITE CKSUM - rpool ONLINE 0 0 0 - mirror-0 ONLINE 0 0 0 - c3t5d0s0 ONLINE 0 0 0 - c3t4d0s0 ONLINE 0 0 0 - -errors: No known data errors -EOSR - - @zpool_status_tank = <<-EOST -pool: tank -state: ONLINE -scan: scrub repaired 0 in 0h0m with 0 errors on Fri Jun 6 14:43:40 2014 -config: - - NAME STATE READ WRITE CKSUM - tank ONLINE 0 0 0 - raidz2-0 ONLINE 0 0 0 - c1t50014EE209D1DBA9d0 ONLINE 0 0 0 - c1t50014EE20A0ECED2d0 ONLINE 0 0 0 - c1t50014EE20A106BFFd0 ONLINE 0 0 0 - c1t50014EE20A1423E8d0 ONLINE 0 0 0 - c1t50014EE20A145447d0 ONLINE 0 0 0 - c1t50014EE20A29EE56d0 ONLINE 0 0 0 - raidz2-1 ONLINE 0 0 0 - c1t50014EE20A2B984Cd0 ONLINE 0 0 0 - c1t50014EE20A2BBC78d0 ONLINE 0 0 0 - c1t50014EE20A2BDCA9d0 ONLINE 0 0 0 - c1t50014EE25F697DC4d0 ONLINE 0 0 0 - c1t50014EE25F698BECd0 ONLINE 0 0 0 - c1t50014EE25F6998DAd0 ONLINE 0 0 0 -EOST - @zpool_out = <<-EOZO -rpool 109G 66.2G 42.8G 60% 1.00x ONLINE 34 -tank 130T 4.91M 130T 0% 1.00x ONLINE 34 -EOZO - allow(@plugin).to receive(:shell_out).with("zpool list -H -o name,size,alloc,free,cap,dedup,health,version").and_return(mock_shell_out(0, @zpool_out, "")) - allow(@plugin).to receive(:shell_out).with("su adm -c \"zpool status rpool\"").and_return(mock_shell_out(0, @zpool_status_rpool, "")) - allow(@plugin).to receive(:shell_out).with("su adm -c \"zpool status tank\"").and_return(mock_shell_out(0, @zpool_status_tank, "")) - end - - describe "On Solaris2 Common" do - it "Should have entries for both zpools" do - @plugin.run - expect(@plugin[:zpools][:rpool]).to be - expect(@plugin[:zpools][:tank]).to be - end - - it "Should have the correct pool size" do - @plugin.run - expect(@plugin[:zpools][:rpool][:pool_size]).to match("109G") - expect(@plugin[:zpools][:tank][:pool_size]).to match("130T") - end - - it "Should have the correct pool allocated size" do - @plugin.run - expect(@plugin[:zpools][:rpool][:pool_allocated]).to match("66.2G") - expect(@plugin[:zpools][:tank][:pool_allocated]).to match("4.91M") - end - - it "Should have the correct pool free size" do - @plugin.run - expect(@plugin[:zpools][:rpool][:pool_free]).to match("42.8G") - expect(@plugin[:zpools][:tank][:pool_free]).to match("130T") - end - - it "Should have the correct capacity_used" do - @plugin.run - expect(@plugin[:zpools][:rpool][:capacity_used]).to match("60%") - expect(@plugin[:zpools][:tank][:capacity_used]).to match("0%") - end - - it "Should have the correct dedup_factor" do - @plugin.run - expect(@plugin[:zpools][:rpool][:dedup_factor]).to match("1.00x") - expect(@plugin[:zpools][:tank][:dedup_factor]).to match("1.00x") - end - - it "Should have the correct health" do - @plugin.run - expect(@plugin[:zpools][:rpool][:health]).to match("ONLINE") - expect(@plugin[:zpools][:tank][:health]).to match("ONLINE") - end - - it "Should have the correct number of devices" do - @plugin.run - expect(@plugin[:zpools][:rpool][:devices].keys.size).to match(2) - expect(@plugin[:zpools][:tank][:devices].keys.size).to match(12) - end - end - - describe "On OmniOS_151006" do - before(:each) do - @zpool_out = <<-EOZO -rpool 109G 66.2G 42.8G 60% 1.00x ONLINE - -tank 130T 4.91M 130T 0% 1.00x ONLINE - -EOZO - allow(@plugin).to receive(:shell_out).with("zpool list -H -o name,size,alloc,free,cap,dedup,health,version").and_return(mock_shell_out(0, @zpool_out, "")) - end - - it "Won't have a version number" do - @plugin.run - expect(@plugin[:zpools][:rpool][:zpool_version]).to match("-") - expect(@plugin[:zpools][:tank][:zpool_version]).to match("-") - end - - end - - describe "On Solaris_11.1" do - before(:each) do - @zpool_out = <<-EOZO -rpool 109G 66.2G 42.8G 60% 1.00x ONLINE 34 -tank 130T 4.91M 130T 0% 1.00x ONLINE 34 -EOZO - allow(@plugin).to receive(:shell_out).with("zpool list -H -o name,size,alloc,free,cap,dedup,health,version").and_return(mock_shell_out(0, @zpool_out, "")) - end - - it "Should have a version number" do - @plugin.run - expect(@plugin[:zpools][:rpool][:zpool_version]).to match("34") - expect(@plugin[:zpools][:tank][:zpool_version]).to match("34") - end - - end -end diff -Nru ohai-8.21.0/spec/unit/plugins/ssh_host_keys_spec.rb ohai-13.8.0/spec/unit/plugins/ssh_host_keys_spec.rb --- ohai-8.21.0/spec/unit/plugins/ssh_host_keys_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/ssh_host_keys_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb")) +require_relative "../../spec_helper.rb" describe Ohai::System, "ssh_host_key plugin" do diff -Nru ohai-8.21.0/spec/unit/plugins/sysconf_spec.rb ohai-13.8.0/spec/unit/plugins/sysconf_spec.rb --- ohai-8.21.0/spec/unit/plugins/sysconf_spec.rb 1970-01-01 00:00:00.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/sysconf_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -0,0 +1,679 @@ +# +# Author:: Davide Cavalca +# Copyright:: Copyright (c) 2016 Facebook +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require_relative "../../spec_helper.rb" + +describe Ohai::System, "sysconf plugin", :unix_only do + let(:plugin) { get_plugin("sysconf") } + + it "should populate sysconf if getconf is found" do + getconf_out = <<-GETCONF_OUT +LINK_MAX 65000 +_POSIX_LINK_MAX 65000 +MAX_CANON 255 +_POSIX_MAX_CANON 255 +MAX_INPUT 255 +_POSIX_MAX_INPUT 255 +NAME_MAX 255 +_POSIX_NAME_MAX 255 +PATH_MAX 4096 +_POSIX_PATH_MAX 4096 +PIPE_BUF 4096 +_POSIX_PIPE_BUF 4096 +SOCK_MAXBUF +_POSIX_ASYNC_IO +_POSIX_CHOWN_RESTRICTED 1 +_POSIX_NO_TRUNC 1 +_POSIX_PRIO_IO +_POSIX_SYNC_IO +_POSIX_VDISABLE 0 +ARG_MAX 2097152 +ATEXIT_MAX 2147483647 +CHAR_BIT 8 +CHAR_MAX 127 +CHAR_MIN -128 +CHILD_MAX 63672 +CLK_TCK 100 +INT_MAX 2147483647 +INT_MIN -2147483648 +IOV_MAX 1024 +LOGNAME_MAX 256 +LONG_BIT 64 +MB_LEN_MAX 16 +NGROUPS_MAX 65536 +NL_ARGMAX 4096 +NL_LANGMAX 2048 +NL_MSGMAX 2147483647 +NL_NMAX 2147483647 +NL_SETMAX 2147483647 +NL_TEXTMAX 2147483647 +NSS_BUFLEN_GROUP 1024 +NSS_BUFLEN_PASSWD 1024 +NZERO 20 +OPEN_MAX 1024 +PAGESIZE 4096 +PAGE_SIZE 4096 +PASS_MAX 8192 +PTHREAD_DESTRUCTOR_ITERATIONS 4 +PTHREAD_KEYS_MAX 1024 +PTHREAD_STACK_MIN 16384 +PTHREAD_THREADS_MAX +SCHAR_MAX 127 +SCHAR_MIN -128 +SHRT_MAX 32767 +SHRT_MIN -32768 +SSIZE_MAX 32767 +TTY_NAME_MAX 32 +TZNAME_MAX 6 +UCHAR_MAX 255 +UINT_MAX 4294967295 +UIO_MAXIOV 1024 +ULONG_MAX 18446744073709551615 +USHRT_MAX 65535 +WORD_BIT 32 +_AVPHYS_PAGES 2101393 +_NPROCESSORS_CONF 8 +_NPROCESSORS_ONLN 8 +_PHYS_PAGES 4096040 +_POSIX_ARG_MAX 2097152 +_POSIX_ASYNCHRONOUS_IO 200809 +_POSIX_CHILD_MAX 63672 +_POSIX_FSYNC 200809 +_POSIX_JOB_CONTROL 1 +_POSIX_MAPPED_FILES 200809 +_POSIX_MEMLOCK 200809 +_POSIX_MEMLOCK_RANGE 200809 +_POSIX_MEMORY_PROTECTION 200809 +_POSIX_MESSAGE_PASSING 200809 +_POSIX_NGROUPS_MAX 65536 +_POSIX_OPEN_MAX 1024 +_POSIX_PII +_POSIX_PII_INTERNET +_POSIX_PII_INTERNET_DGRAM +_POSIX_PII_INTERNET_STREAM +_POSIX_PII_OSI +_POSIX_PII_OSI_CLTS +_POSIX_PII_OSI_COTS +_POSIX_PII_OSI_M +_POSIX_PII_SOCKET +_POSIX_PII_XTI +_POSIX_POLL +_POSIX_PRIORITIZED_IO 200809 +_POSIX_PRIORITY_SCHEDULING 200809 +_POSIX_REALTIME_SIGNALS 200809 +_POSIX_SAVED_IDS 1 +_POSIX_SELECT +_POSIX_SEMAPHORES 200809 +_POSIX_SHARED_MEMORY_OBJECTS 200809 +_POSIX_SSIZE_MAX 32767 +_POSIX_STREAM_MAX 16 +_POSIX_SYNCHRONIZED_IO 200809 +_POSIX_THREADS 200809 +_POSIX_THREAD_ATTR_STACKADDR 200809 +_POSIX_THREAD_ATTR_STACKSIZE 200809 +_POSIX_THREAD_PRIORITY_SCHEDULING 200809 +_POSIX_THREAD_PRIO_INHERIT 200809 +_POSIX_THREAD_PRIO_PROTECT 200809 +_POSIX_THREAD_ROBUST_PRIO_INHERIT +_POSIX_THREAD_ROBUST_PRIO_PROTECT +_POSIX_THREAD_PROCESS_SHARED 200809 +_POSIX_THREAD_SAFE_FUNCTIONS 200809 +_POSIX_TIMERS 200809 +TIMER_MAX +_POSIX_TZNAME_MAX 6 +_POSIX_VERSION 200809 +_T_IOV_MAX +_XOPEN_CRYPT 1 +_XOPEN_ENH_I18N 1 +_XOPEN_LEGACY 1 +_XOPEN_REALTIME 1 +_XOPEN_REALTIME_THREADS 1 +_XOPEN_SHM 1 +_XOPEN_UNIX 1 +_XOPEN_VERSION 700 +_XOPEN_XCU_VERSION 4 +_XOPEN_XPG2 1 +_XOPEN_XPG3 1 +_XOPEN_XPG4 1 +BC_BASE_MAX 99 +BC_DIM_MAX 2048 +BC_SCALE_MAX 99 +BC_STRING_MAX 1000 +CHARCLASS_NAME_MAX 2048 +COLL_WEIGHTS_MAX 255 +EQUIV_CLASS_MAX +EXPR_NEST_MAX 32 +LINE_MAX 2048 +POSIX2_BC_BASE_MAX 99 +POSIX2_BC_DIM_MAX 2048 +POSIX2_BC_SCALE_MAX 99 +POSIX2_BC_STRING_MAX 1000 +POSIX2_CHAR_TERM 200809 +POSIX2_COLL_WEIGHTS_MAX 255 +POSIX2_C_BIND 200809 +POSIX2_C_DEV 200809 +POSIX2_C_VERSION 200809 +POSIX2_EXPR_NEST_MAX 32 +POSIX2_FORT_DEV +POSIX2_FORT_RUN +_POSIX2_LINE_MAX 2048 +POSIX2_LINE_MAX 2048 +POSIX2_LOCALEDEF 200809 +POSIX2_RE_DUP_MAX 32767 +POSIX2_SW_DEV 200809 +POSIX2_UPE +POSIX2_VERSION 200809 +RE_DUP_MAX 32767 +PATH /bin:/usr/bin +CS_PATH /bin:/usr/bin +LFS_CFLAGS +LFS_LDFLAGS +LFS_LIBS +LFS_LINTFLAGS +LFS64_CFLAGS -D_LARGEFILE64_SOURCE +LFS64_LDFLAGS +LFS64_LIBS +LFS64_LINTFLAGS -D_LARGEFILE64_SOURCE +_XBS5_WIDTH_RESTRICTED_ENVS XBS5_LP64_OFF64 +XBS5_WIDTH_RESTRICTED_ENVS XBS5_LP64_OFF64 +_XBS5_ILP32_OFF32 +XBS5_ILP32_OFF32_CFLAGS +XBS5_ILP32_OFF32_LDFLAGS +XBS5_ILP32_OFF32_LIBS +XBS5_ILP32_OFF32_LINTFLAGS +_XBS5_ILP32_OFFBIG +XBS5_ILP32_OFFBIG_CFLAGS +XBS5_ILP32_OFFBIG_LDFLAGS +XBS5_ILP32_OFFBIG_LIBS +XBS5_ILP32_OFFBIG_LINTFLAGS +_XBS5_LP64_OFF64 1 +XBS5_LP64_OFF64_CFLAGS -m64 +XBS5_LP64_OFF64_LDFLAGS -m64 +XBS5_LP64_OFF64_LIBS +XBS5_LP64_OFF64_LINTFLAGS +_XBS5_LPBIG_OFFBIG +XBS5_LPBIG_OFFBIG_CFLAGS +XBS5_LPBIG_OFFBIG_LDFLAGS +XBS5_LPBIG_OFFBIG_LIBS +XBS5_LPBIG_OFFBIG_LINTFLAGS +_POSIX_V6_ILP32_OFF32 +POSIX_V6_ILP32_OFF32_CFLAGS +POSIX_V6_ILP32_OFF32_LDFLAGS +POSIX_V6_ILP32_OFF32_LIBS +POSIX_V6_ILP32_OFF32_LINTFLAGS +_POSIX_V6_WIDTH_RESTRICTED_ENVS POSIX_V6_LP64_OFF64 +POSIX_V6_WIDTH_RESTRICTED_ENVS POSIX_V6_LP64_OFF64 +_POSIX_V6_ILP32_OFFBIG +POSIX_V6_ILP32_OFFBIG_CFLAGS +POSIX_V6_ILP32_OFFBIG_LDFLAGS +POSIX_V6_ILP32_OFFBIG_LIBS +POSIX_V6_ILP32_OFFBIG_LINTFLAGS +_POSIX_V6_LP64_OFF64 1 +POSIX_V6_LP64_OFF64_CFLAGS -m64 +POSIX_V6_LP64_OFF64_LDFLAGS -m64 +POSIX_V6_LP64_OFF64_LIBS +POSIX_V6_LP64_OFF64_LINTFLAGS +_POSIX_V6_LPBIG_OFFBIG +POSIX_V6_LPBIG_OFFBIG_CFLAGS +POSIX_V6_LPBIG_OFFBIG_LDFLAGS +POSIX_V6_LPBIG_OFFBIG_LIBS +POSIX_V6_LPBIG_OFFBIG_LINTFLAGS +_POSIX_V7_ILP32_OFF32 +POSIX_V7_ILP32_OFF32_CFLAGS +POSIX_V7_ILP32_OFF32_LDFLAGS +POSIX_V7_ILP32_OFF32_LIBS +POSIX_V7_ILP32_OFF32_LINTFLAGS +_POSIX_V7_WIDTH_RESTRICTED_ENVS POSIX_V7_LP64_OFF64 +POSIX_V7_WIDTH_RESTRICTED_ENVS POSIX_V7_LP64_OFF64 +_POSIX_V7_ILP32_OFFBIG +POSIX_V7_ILP32_OFFBIG_CFLAGS +POSIX_V7_ILP32_OFFBIG_LDFLAGS +POSIX_V7_ILP32_OFFBIG_LIBS +POSIX_V7_ILP32_OFFBIG_LINTFLAGS +_POSIX_V7_LP64_OFF64 1 +POSIX_V7_LP64_OFF64_CFLAGS -m64 +POSIX_V7_LP64_OFF64_LDFLAGS -m64 +POSIX_V7_LP64_OFF64_LIBS +POSIX_V7_LP64_OFF64_LINTFLAGS +_POSIX_V7_LPBIG_OFFBIG +POSIX_V7_LPBIG_OFFBIG_CFLAGS +POSIX_V7_LPBIG_OFFBIG_LDFLAGS +POSIX_V7_LPBIG_OFFBIG_LIBS +POSIX_V7_LPBIG_OFFBIG_LINTFLAGS +_POSIX_ADVISORY_INFO 200809 +_POSIX_BARRIERS 200809 +_POSIX_BASE +_POSIX_C_LANG_SUPPORT +_POSIX_C_LANG_SUPPORT_R +_POSIX_CLOCK_SELECTION 200809 +_POSIX_CPUTIME 200809 +_POSIX_THREAD_CPUTIME 200809 +_POSIX_DEVICE_SPECIFIC +_POSIX_DEVICE_SPECIFIC_R +_POSIX_FD_MGMT +_POSIX_FIFO +_POSIX_PIPE +_POSIX_FILE_ATTRIBUTES +_POSIX_FILE_LOCKING +_POSIX_FILE_SYSTEM +_POSIX_MONOTONIC_CLOCK 200809 +_POSIX_MULTI_PROCESS +_POSIX_SINGLE_PROCESS +_POSIX_NETWORKING +_POSIX_READER_WRITER_LOCKS 200809 +_POSIX_SPIN_LOCKS 200809 +_POSIX_REGEXP 1 +_REGEX_VERSION +_POSIX_SHELL 1 +_POSIX_SIGNALS +_POSIX_SPAWN 200809 +_POSIX_SPORADIC_SERVER +_POSIX_THREAD_SPORADIC_SERVER +_POSIX_SYSTEM_DATABASE +_POSIX_SYSTEM_DATABASE_R +_POSIX_TIMEOUTS 200809 +_POSIX_TYPED_MEMORY_OBJECTS +_POSIX_USER_GROUPS +_POSIX_USER_GROUPS_R +POSIX2_PBS +POSIX2_PBS_ACCOUNTING +POSIX2_PBS_LOCATE +POSIX2_PBS_TRACK +POSIX2_PBS_MESSAGE +SYMLOOP_MAX +STREAM_MAX 16 +AIO_LISTIO_MAX +AIO_MAX +AIO_PRIO_DELTA_MAX 20 +DELAYTIMER_MAX 2147483647 +HOST_NAME_MAX 64 +LOGIN_NAME_MAX 256 +MQ_OPEN_MAX +MQ_PRIO_MAX 32768 +_POSIX_DEVICE_IO +_POSIX_TRACE +_POSIX_TRACE_EVENT_FILTER +_POSIX_TRACE_INHERIT +_POSIX_TRACE_LOG +RTSIG_MAX 32 +SEM_NSEMS_MAX +SEM_VALUE_MAX 2147483647 +SIGQUEUE_MAX 63672 +FILESIZEBITS 64 +POSIX_ALLOC_SIZE_MIN 4096 +POSIX_REC_INCR_XFER_SIZE +POSIX_REC_MAX_XFER_SIZE +POSIX_REC_MIN_XFER_SIZE 4096 +POSIX_REC_XFER_ALIGN 4096 +SYMLINK_MAX +GNU_LIBC_VERSION glibc 2.24 +GNU_LIBPTHREAD_VERSION NPTL 2.24 +POSIX2_SYMLINKS 1 +LEVEL1_ICACHE_SIZE 32768 +LEVEL1_ICACHE_ASSOC 8 +LEVEL1_ICACHE_LINESIZE 64 +LEVEL1_DCACHE_SIZE 32768 +LEVEL1_DCACHE_ASSOC 8 +LEVEL1_DCACHE_LINESIZE 64 +LEVEL2_CACHE_SIZE 262144 +LEVEL2_CACHE_ASSOC 4 +LEVEL2_CACHE_LINESIZE 64 +LEVEL3_CACHE_SIZE 8388608 +LEVEL3_CACHE_ASSOC 16 +LEVEL3_CACHE_LINESIZE 64 +LEVEL4_CACHE_SIZE 0 +LEVEL4_CACHE_ASSOC 0 +LEVEL4_CACHE_LINESIZE 0 +IPV6 200809 +RAW_SOCKETS 200809 +_POSIX_IPV6 200809 +_POSIX_RAW_SOCKETS 200809 +GETCONF_OUT + allow(plugin).to receive(:which).with("getconf").and_return("/usr/bin/getconf") + allow(plugin).to receive(:shell_out).with("/usr/bin/getconf -a").and_return(mock_shell_out(0, getconf_out, "")) + plugin.run + expect(plugin[:sysconf].to_hash).to eq({ + "LINK_MAX" => 65000, + "_POSIX_LINK_MAX" => 65000, + "MAX_CANON" => 255, + "_POSIX_MAX_CANON" => 255, + "MAX_INPUT" => 255, + "_POSIX_MAX_INPUT" => 255, + "NAME_MAX" => 255, + "_POSIX_NAME_MAX" => 255, + "PATH_MAX" => 4096, + "_POSIX_PATH_MAX" => 4096, + "PIPE_BUF" => 4096, + "_POSIX_PIPE_BUF" => 4096, + "SOCK_MAXBUF" => nil, + "_POSIX_ASYNC_IO" => nil, + "_POSIX_CHOWN_RESTRICTED" => 1, + "_POSIX_NO_TRUNC" => 1, + "_POSIX_PRIO_IO" => nil, + "_POSIX_SYNC_IO" => nil, + "_POSIX_VDISABLE" => 0, + "ARG_MAX" => 2097152, + "ATEXIT_MAX" => 2147483647, + "CHAR_BIT" => 8, + "CHAR_MAX" => 127, + "CHAR_MIN" => -128, + "CHILD_MAX" => 63672, + "CLK_TCK" => 100, + "INT_MAX" => 2147483647, + "INT_MIN" => -2147483648, + "IOV_MAX" => 1024, + "LOGNAME_MAX" => 256, + "LONG_BIT" => 64, + "MB_LEN_MAX" => 16, + "NGROUPS_MAX" => 65536, + "NL_ARGMAX" => 4096, + "NL_LANGMAX" => 2048, + "NL_MSGMAX" => 2147483647, + "NL_NMAX" => 2147483647, + "NL_SETMAX" => 2147483647, + "NL_TEXTMAX" => 2147483647, + "NSS_BUFLEN_GROUP" => 1024, + "NSS_BUFLEN_PASSWD" => 1024, + "NZERO" => 20, + "OPEN_MAX" => 1024, + "PAGESIZE" => 4096, + "PAGE_SIZE" => 4096, + "PASS_MAX" => 8192, + "PTHREAD_DESTRUCTOR_ITERATIONS" => 4, + "PTHREAD_KEYS_MAX" => 1024, + "PTHREAD_STACK_MIN" => 16384, + "PTHREAD_THREADS_MAX" => nil, + "SCHAR_MAX" => 127, + "SCHAR_MIN" => -128, + "SHRT_MAX" => 32767, + "SHRT_MIN" => -32768, + "SSIZE_MAX" => 32767, + "TTY_NAME_MAX" => 32, + "TZNAME_MAX" => 6, + "UCHAR_MAX" => 255, + "UINT_MAX" => 4294967295, + "UIO_MAXIOV" => 1024, + "ULONG_MAX" => 18446744073709551615, + "USHRT_MAX" => 65535, + "WORD_BIT" => 32, + "_AVPHYS_PAGES" => 2101393, + "_NPROCESSORS_CONF" => 8, + "_NPROCESSORS_ONLN" => 8, + "_PHYS_PAGES" => 4096040, + "_POSIX_ARG_MAX" => 2097152, + "_POSIX_ASYNCHRONOUS_IO" => 200809, + "_POSIX_CHILD_MAX" => 63672, + "_POSIX_FSYNC" => 200809, + "_POSIX_JOB_CONTROL" => 1, + "_POSIX_MAPPED_FILES" => 200809, + "_POSIX_MEMLOCK" => 200809, + "_POSIX_MEMLOCK_RANGE" => 200809, + "_POSIX_MEMORY_PROTECTION" => 200809, + "_POSIX_MESSAGE_PASSING" => 200809, + "_POSIX_NGROUPS_MAX" => 65536, + "_POSIX_OPEN_MAX" => 1024, + "_POSIX_PII" => nil, + "_POSIX_PII_INTERNET" => nil, + "_POSIX_PII_INTERNET_DGRAM" => nil, + "_POSIX_PII_INTERNET_STREAM" => nil, + "_POSIX_PII_OSI" => nil, + "_POSIX_PII_OSI_CLTS" => nil, + "_POSIX_PII_OSI_COTS" => nil, + "_POSIX_PII_OSI_M" => nil, + "_POSIX_PII_SOCKET" => nil, + "_POSIX_PII_XTI" => nil, + "_POSIX_POLL" => nil, + "_POSIX_PRIORITIZED_IO" => 200809, + "_POSIX_PRIORITY_SCHEDULING" => 200809, + "_POSIX_REALTIME_SIGNALS" => 200809, + "_POSIX_SAVED_IDS" => 1, + "_POSIX_SELECT" => nil, + "_POSIX_SEMAPHORES" => 200809, + "_POSIX_SHARED_MEMORY_OBJECTS" => 200809, + "_POSIX_SSIZE_MAX" => 32767, + "_POSIX_STREAM_MAX" => 16, + "_POSIX_SYNCHRONIZED_IO" => 200809, + "_POSIX_THREADS" => 200809, + "_POSIX_THREAD_ATTR_STACKADDR" => 200809, + "_POSIX_THREAD_ATTR_STACKSIZE" => 200809, + "_POSIX_THREAD_PRIORITY_SCHEDULING" => 200809, + "_POSIX_THREAD_PRIO_INHERIT" => 200809, + "_POSIX_THREAD_PRIO_PROTECT" => 200809, + "_POSIX_THREAD_ROBUST_PRIO_INHERIT" => nil, + "_POSIX_THREAD_ROBUST_PRIO_PROTECT" => nil, + "_POSIX_THREAD_PROCESS_SHARED" => 200809, + "_POSIX_THREAD_SAFE_FUNCTIONS" => 200809, + "_POSIX_TIMERS" => 200809, + "TIMER_MAX" => nil, + "_POSIX_TZNAME_MAX" => 6, + "_POSIX_VERSION" => 200809, + "_T_IOV_MAX" => nil, + "_XOPEN_CRYPT" => 1, + "_XOPEN_ENH_I18N" => 1, + "_XOPEN_LEGACY" => 1, + "_XOPEN_REALTIME" => 1, + "_XOPEN_REALTIME_THREADS" => 1, + "_XOPEN_SHM" => 1, + "_XOPEN_UNIX" => 1, + "_XOPEN_VERSION" => 700, + "_XOPEN_XCU_VERSION" => 4, + "_XOPEN_XPG2" => 1, + "_XOPEN_XPG3" => 1, + "_XOPEN_XPG4" => 1, + "BC_BASE_MAX" => 99, + "BC_DIM_MAX" => 2048, + "BC_SCALE_MAX" => 99, + "BC_STRING_MAX" => 1000, + "CHARCLASS_NAME_MAX" => 2048, + "COLL_WEIGHTS_MAX" => 255, + "EQUIV_CLASS_MAX" => nil, + "EXPR_NEST_MAX" => 32, + "LINE_MAX" => 2048, + "POSIX2_BC_BASE_MAX" => 99, + "POSIX2_BC_DIM_MAX" => 2048, + "POSIX2_BC_SCALE_MAX" => 99, + "POSIX2_BC_STRING_MAX" => 1000, + "POSIX2_CHAR_TERM" => 200809, + "POSIX2_COLL_WEIGHTS_MAX" => 255, + "POSIX2_C_BIND" => 200809, + "POSIX2_C_DEV" => 200809, + "POSIX2_C_VERSION" => 200809, + "POSIX2_EXPR_NEST_MAX" => 32, + "POSIX2_FORT_DEV" => nil, + "POSIX2_FORT_RUN" => nil, + "_POSIX2_LINE_MAX" => 2048, + "POSIX2_LINE_MAX" => 2048, + "POSIX2_LOCALEDEF" => 200809, + "POSIX2_RE_DUP_MAX" => 32767, + "POSIX2_SW_DEV" => 200809, + "POSIX2_UPE" => nil, + "POSIX2_VERSION" => 200809, + "RE_DUP_MAX" => 32767, + "PATH" => "/bin:/usr/bin", + "CS_PATH" => "/bin:/usr/bin", + "LFS_CFLAGS" => nil, + "LFS_LDFLAGS" => nil, + "LFS_LIBS" => nil, + "LFS_LINTFLAGS" => nil, + "LFS64_CFLAGS" => "-D_LARGEFILE64_SOURCE", + "LFS64_LDFLAGS" => nil, + "LFS64_LIBS" => nil, + "LFS64_LINTFLAGS" => "-D_LARGEFILE64_SOURCE", + "_XBS5_WIDTH_RESTRICTED_ENVS" => "XBS5_LP64_OFF64", + "XBS5_WIDTH_RESTRICTED_ENVS" => "XBS5_LP64_OFF64", + "_XBS5_ILP32_OFF32" => nil, + "XBS5_ILP32_OFF32_CFLAGS" => nil, + "XBS5_ILP32_OFF32_LDFLAGS" => nil, + "XBS5_ILP32_OFF32_LIBS" => nil, + "XBS5_ILP32_OFF32_LINTFLAGS" => nil, + "_XBS5_ILP32_OFFBIG" => nil, + "XBS5_ILP32_OFFBIG_CFLAGS" => nil, + "XBS5_ILP32_OFFBIG_LDFLAGS" => nil, + "XBS5_ILP32_OFFBIG_LIBS" => nil, + "XBS5_ILP32_OFFBIG_LINTFLAGS" => nil, + "_XBS5_LP64_OFF64" => 1, + "XBS5_LP64_OFF64_CFLAGS" => "-m64", + "XBS5_LP64_OFF64_LDFLAGS" => "-m64", + "XBS5_LP64_OFF64_LIBS" => nil, + "XBS5_LP64_OFF64_LINTFLAGS" => nil, + "_XBS5_LPBIG_OFFBIG" => nil, + "XBS5_LPBIG_OFFBIG_CFLAGS" => nil, + "XBS5_LPBIG_OFFBIG_LDFLAGS" => nil, + "XBS5_LPBIG_OFFBIG_LIBS" => nil, + "XBS5_LPBIG_OFFBIG_LINTFLAGS" => nil, + "_POSIX_V6_ILP32_OFF32" => nil, + "POSIX_V6_ILP32_OFF32_CFLAGS" => nil, + "POSIX_V6_ILP32_OFF32_LDFLAGS" => nil, + "POSIX_V6_ILP32_OFF32_LIBS" => nil, + "POSIX_V6_ILP32_OFF32_LINTFLAGS" => nil, + "_POSIX_V6_WIDTH_RESTRICTED_ENVS" => "POSIX_V6_LP64_OFF64", + "POSIX_V6_WIDTH_RESTRICTED_ENVS" => "POSIX_V6_LP64_OFF64", + "_POSIX_V6_ILP32_OFFBIG" => nil, + "POSIX_V6_ILP32_OFFBIG_CFLAGS" => nil, + "POSIX_V6_ILP32_OFFBIG_LDFLAGS" => nil, + "POSIX_V6_ILP32_OFFBIG_LIBS" => nil, + "POSIX_V6_ILP32_OFFBIG_LINTFLAGS" => nil, + "_POSIX_V6_LP64_OFF64" => 1, + "POSIX_V6_LP64_OFF64_CFLAGS" => "-m64", + "POSIX_V6_LP64_OFF64_LDFLAGS" => "-m64", + "POSIX_V6_LP64_OFF64_LIBS" => nil, + "POSIX_V6_LP64_OFF64_LINTFLAGS" => nil, + "_POSIX_V6_LPBIG_OFFBIG" => nil, + "POSIX_V6_LPBIG_OFFBIG_CFLAGS" => nil, + "POSIX_V6_LPBIG_OFFBIG_LDFLAGS" => nil, + "POSIX_V6_LPBIG_OFFBIG_LIBS" => nil, + "POSIX_V6_LPBIG_OFFBIG_LINTFLAGS" => nil, + "_POSIX_V7_ILP32_OFF32" => nil, + "POSIX_V7_ILP32_OFF32_CFLAGS" => nil, + "POSIX_V7_ILP32_OFF32_LDFLAGS" => nil, + "POSIX_V7_ILP32_OFF32_LIBS" => nil, + "POSIX_V7_ILP32_OFF32_LINTFLAGS" => nil, + "_POSIX_V7_WIDTH_RESTRICTED_ENVS" => "POSIX_V7_LP64_OFF64", + "POSIX_V7_WIDTH_RESTRICTED_ENVS" => "POSIX_V7_LP64_OFF64", + "_POSIX_V7_ILP32_OFFBIG" => nil, + "POSIX_V7_ILP32_OFFBIG_CFLAGS" => nil, + "POSIX_V7_ILP32_OFFBIG_LDFLAGS" => nil, + "POSIX_V7_ILP32_OFFBIG_LIBS" => nil, + "POSIX_V7_ILP32_OFFBIG_LINTFLAGS" => nil, + "_POSIX_V7_LP64_OFF64" => 1, + "POSIX_V7_LP64_OFF64_CFLAGS" => "-m64", + "POSIX_V7_LP64_OFF64_LDFLAGS" => "-m64", + "POSIX_V7_LP64_OFF64_LIBS" => nil, + "POSIX_V7_LP64_OFF64_LINTFLAGS" => nil, + "_POSIX_V7_LPBIG_OFFBIG" => nil, + "POSIX_V7_LPBIG_OFFBIG_CFLAGS" => nil, + "POSIX_V7_LPBIG_OFFBIG_LDFLAGS" => nil, + "POSIX_V7_LPBIG_OFFBIG_LIBS" => nil, + "POSIX_V7_LPBIG_OFFBIG_LINTFLAGS" => nil, + "_POSIX_ADVISORY_INFO" => 200809, + "_POSIX_BARRIERS" => 200809, + "_POSIX_BASE" => nil, + "_POSIX_C_LANG_SUPPORT" => nil, + "_POSIX_C_LANG_SUPPORT_R" => nil, + "_POSIX_CLOCK_SELECTION" => 200809, + "_POSIX_CPUTIME" => 200809, + "_POSIX_THREAD_CPUTIME" => 200809, + "_POSIX_DEVICE_SPECIFIC" => nil, + "_POSIX_DEVICE_SPECIFIC_R" => nil, + "_POSIX_FD_MGMT" => nil, + "_POSIX_FIFO" => nil, + "_POSIX_PIPE" => nil, + "_POSIX_FILE_ATTRIBUTES" => nil, + "_POSIX_FILE_LOCKING" => nil, + "_POSIX_FILE_SYSTEM" => nil, + "_POSIX_MONOTONIC_CLOCK" => 200809, + "_POSIX_MULTI_PROCESS" => nil, + "_POSIX_SINGLE_PROCESS" => nil, + "_POSIX_NETWORKING" => nil, + "_POSIX_READER_WRITER_LOCKS" => 200809, + "_POSIX_SPIN_LOCKS" => 200809, + "_POSIX_REGEXP" => 1, + "_REGEX_VERSION" => nil, + "_POSIX_SHELL" => 1, + "_POSIX_SIGNALS" => nil, + "_POSIX_SPAWN" => 200809, + "_POSIX_SPORADIC_SERVER" => nil, + "_POSIX_THREAD_SPORADIC_SERVER" => nil, + "_POSIX_SYSTEM_DATABASE" => nil, + "_POSIX_SYSTEM_DATABASE_R" => nil, + "_POSIX_TIMEOUTS" => 200809, + "_POSIX_TYPED_MEMORY_OBJECTS" => nil, + "_POSIX_USER_GROUPS" => nil, + "_POSIX_USER_GROUPS_R" => nil, + "POSIX2_PBS" => nil, + "POSIX2_PBS_ACCOUNTING" => nil, + "POSIX2_PBS_LOCATE" => nil, + "POSIX2_PBS_TRACK" => nil, + "POSIX2_PBS_MESSAGE" => nil, + "SYMLOOP_MAX" => nil, + "STREAM_MAX" => 16, + "AIO_LISTIO_MAX" => nil, + "AIO_MAX" => nil, + "AIO_PRIO_DELTA_MAX" => 20, + "DELAYTIMER_MAX" => 2147483647, + "HOST_NAME_MAX" => 64, + "LOGIN_NAME_MAX" => 256, + "MQ_OPEN_MAX" => nil, + "MQ_PRIO_MAX" => 32768, + "_POSIX_DEVICE_IO" => nil, + "_POSIX_TRACE" => nil, + "_POSIX_TRACE_EVENT_FILTER" => nil, + "_POSIX_TRACE_INHERIT" => nil, + "_POSIX_TRACE_LOG" => nil, + "RTSIG_MAX" => 32, + "SEM_NSEMS_MAX" => nil, + "SEM_VALUE_MAX" => 2147483647, + "SIGQUEUE_MAX" => 63672, + "FILESIZEBITS" => 64, + "POSIX_ALLOC_SIZE_MIN" => 4096, + "POSIX_REC_INCR_XFER_SIZE" => nil, + "POSIX_REC_MAX_XFER_SIZE" => nil, + "POSIX_REC_MIN_XFER_SIZE" => 4096, + "POSIX_REC_XFER_ALIGN" => 4096, + "SYMLINK_MAX" => nil, + "GNU_LIBC_VERSION" => "glibc 2.24", + "GNU_LIBPTHREAD_VERSION" => "NPTL 2.24", + "POSIX2_SYMLINKS" => 1, + "LEVEL1_ICACHE_SIZE" => 32768, + "LEVEL1_ICACHE_ASSOC" => 8, + "LEVEL1_ICACHE_LINESIZE" => 64, + "LEVEL1_DCACHE_SIZE" => 32768, + "LEVEL1_DCACHE_ASSOC" => 8, + "LEVEL1_DCACHE_LINESIZE" => 64, + "LEVEL2_CACHE_SIZE" => 262144, + "LEVEL2_CACHE_ASSOC" => 4, + "LEVEL2_CACHE_LINESIZE" => 64, + "LEVEL3_CACHE_SIZE" => 8388608, + "LEVEL3_CACHE_ASSOC" => 16, + "LEVEL3_CACHE_LINESIZE" => 64, + "LEVEL4_CACHE_SIZE" => 0, + "LEVEL4_CACHE_ASSOC" => 0, + "LEVEL4_CACHE_LINESIZE" => 0, + "IPV6" => 200809, + "RAW_SOCKETS" => 200809, + "_POSIX_IPV6" => 200809, + "_POSIX_RAW_SOCKETS" => 200809, + }) + end + + it "should not populate sysconf if getconf is not found" do + allow(plugin).to receive(:which).with("getconf").and_return(false) + plugin.run + expect(plugin[:sysconf]).to be(nil) + end +end diff -Nru ohai-8.21.0/spec/unit/plugins/timezone_spec.rb ohai-13.8.0/spec/unit/plugins/timezone_spec.rb --- ohai-8.21.0/spec/unit/plugins/timezone_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/timezone_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -15,7 +15,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb") +require_relative "../../spec_helper.rb" describe Ohai::System, "timezone plugin" do before(:each) do diff -Nru ohai-8.21.0/spec/unit/plugins/virtualbox_spec.rb ohai-13.8.0/spec/unit/plugins/virtualbox_spec.rb --- ohai-8.21.0/spec/unit/plugins/virtualbox_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/virtualbox_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -15,7 +15,7 @@ # limitations under the License. # -require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "/spec_helper.rb")) +require_relative "../../spec_helper.rb" vbox_output = < "Intel64 Family 6 Model 70 Stepping 1", + "name" => "Intel(R) Core(TM) i7-4500U CPU @ 1.80GHz", "deviceid" => "CPU0", "family" => 2, "manufacturer" => "GenuineIntel", @@ -75,6 +81,7 @@ "l2cachesize" => 64 }, { "description" => "Intel64 Family 6 Model 70 Stepping 1", + "name" => "Intel(R) Core(TM) i7-4500U CPU @ 1.80GHz", "deviceid" => "CPU1", "family" => 2, "manufacturer" => "GenuineIntel", diff -Nru ohai-8.21.0/spec/unit/plugins/windows/fips_spec.rb ohai-13.8.0/spec/unit/plugins/windows/fips_spec.rb --- ohai-8.21.0/spec/unit/plugins/windows/fips_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/windows/fips_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "plugin fips", :windows_only do let(:enabled) { 0 } diff -Nru ohai-8.21.0/spec/unit/plugins/windows/memory_spec.rb ohai-13.8.0/spec/unit/plugins/windows/memory_spec.rb --- ohai-8.21.0/spec/unit/plugins/windows/memory_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/windows/memory_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -14,7 +14,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Windows memory plugin", :windows_only do before do diff -Nru ohai-8.21.0/spec/unit/plugins/windows/uptime_spec.rb ohai-13.8.0/spec/unit/plugins/windows/uptime_spec.rb --- ohai-8.21.0/spec/unit/plugins/windows/uptime_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/windows/uptime_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -16,7 +16,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Windows plugin uptime" do diff -Nru ohai-8.21.0/spec/unit/plugins/windows/virtualization_spec.rb ohai-13.8.0/spec/unit/plugins/windows/virtualization_spec.rb --- ohai-8.21.0/spec/unit/plugins/windows/virtualization_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/windows/virtualization_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -18,7 +18,7 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb") +require_relative "../../../spec_helper.rb" describe Ohai::System, "Windows virtualization platform" do let(:plugin) { get_plugin("windows/virtualization") } @@ -173,6 +173,73 @@ end end + context "when running on hyper-v" do + it "system is hyper-v" do + allow_any_instance_of(WmiLite::Wmi).to receive(:instances_of).with("Win32_BIOS").and_return([{ "bioscharacteristics" => [4, 7, 9, 11, 12, 14, 15, 16, 17, 19, 22, 23, 24, 25, 26, 27, 28, 29, 30, 34, 36, 37, 40], + "biosversion" => ["VRTUAL - 4001628, BIOS Date: 04/28/16 13:00:17 Ver: 09.00.06, BIOS Date: 04/28/16 13:00:17 Ver: 09.00.06"], + "buildnumber" => nil, + "codeset" => nil, + "currentlanguage" => "enUS", + "description" => "BIOS Date: 04/28/16 13:00:17 Ver: 09.00.06", + "identificationcode" => nil, + "installablelanguages" => 1, + "installdate" => nil, + "languageedition" => nil, + "listoflanguages" => ["enUS"], + "manufacturer" => "American Megatrends Inc.", + "name" => "BIOS Date: 04/28/16 13:00:17 Ver: 09.00.06", + "othertargetos" => nil, + "primarybios" => true, + "releasedate" => "20160428000000.000000+000", + "serialnumber" => "1158-1757-7941-3855-2170-4122-00", + "smbiosbiosversion" => "090006", + "smbiosmajorversion" => 2, + "smbiosminorversion" => 3, + "smbiospresent" => true, + "softwareelementid" => "BIOS Date: 04/28/16 13:00:17 Ver: 09.00.06", + "softwareelementstate" => 3, + "status" => "OK", + "targetoperatingsystem" => 0, + "version" => "VRTUAL - 4001628", + }]) + plugin.run + expect(plugin[:virtualization][:system]).to eq("hyper-v") + expect(plugin[:virtualization][:role]).to eq("guest") + expect(plugin[:virtualization][:systems][:hyperv]).to eq("guest") + end + end + + context "when running on xen" do + it "system is xen" do + allow_any_instance_of(WmiLite::Wmi).to receive(:instances_of).with("Win32_BIOS").and_return([{ "smbiosbiosversion" => ["4.2.amazon"], + "manufacturer" => "Xen", + "name" => "Revision: 1.221", + "serialnumber" => "ec2b487f-d9ed-7d17-c7c0-1d4599d6c1da", + "version" => "Xen - 0", + }]) + plugin.run + expect(plugin[:virtualization][:system]).to eq("xen") + expect(plugin[:virtualization][:role]).to eq("guest") + expect(plugin[:virtualization][:systems][:xen]).to eq("guest") + end + end + + context "when running on veertu" do + it "system is veertu" do + allow_any_instance_of(WmiLite::Wmi).to receive(:instances_of).with("Win32_BIOS").and_return([{ "smbiosbiosversion" => ["Veertu"], + "manufacturer" => "Veertu", + "name" => "Default System BIOS", + "serialnumber" => "", + "version" => "Veertu - 1", + + }]) + plugin.run + expect(plugin[:virtualization][:system]).to eq("veertu") + expect(plugin[:virtualization][:role]).to eq("guest") + expect(plugin[:virtualization][:systems][:veertu]).to eq("guest") + end + end + context "when running on a hardware system" do it "does not set virtualization attributes" do allow_any_instance_of(WmiLite::Wmi).to receive(:instances_of).with("Win32_BIOS").and_return([{ "bioscharacteristics" => [7, 11, 12, 15, 16, 17, 19, 23, 24, 25, 26, 27, 28, 29, 32, 33, 40, 42, 43], diff -Nru ohai-8.21.0/spec/unit/plugins/zpools_spec.rb ohai-13.8.0/spec/unit/plugins/zpools_spec.rb --- ohai-8.21.0/spec/unit/plugins/zpools_spec.rb 1970-01-01 00:00:00.000000000 +0000 +++ ohai-13.8.0/spec/unit/plugins/zpools_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -0,0 +1,242 @@ +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require_relative "../../spec_helper.rb" + +describe Ohai::System, "zpools plugin" do + let(:plugin) { get_plugin("zpools") } + + context "on Linux" do + let(:zpool_status_tank) do + <<-EOST + pool: tank + state: ONLINE + scan: scrub repaired 0 in 0h0m with 0 errors on Fri Jun 6 14:43:40 2014 + config: + + NAME STATE READ WRITE CKSUM + tank ONLINE 0 0 0 + raidz2-0 ONLINE 0 0 0 + sdc ONLINE 0 0 0 + sdd ONLINE 0 0 0 + sde ONLINE 0 0 0 + sdf ONLINE 0 0 0 + sdg ONLINE 0 0 0 + sdh ONLINE 0 0 0 + raidz2-1 ONLINE 0 0 0 + sdi ONLINE 0 0 0 + sdj ONLINE 0 0 0 + sdk ONLINE 0 0 0 + sdl ONLINE 0 0 0 + sdm ONLINE 0 0 0 + sdn ONLINE 0 0 0 +EOST + end + let(:zpool_out) do + <<-EOZO +rpool 109G 66.2G 42.8G 60% 1.00x ONLINE - +tank 130T 4.91M 130T 0% 1.00x ONLINE - +EOZO + end + let(:zpool_status_rpool) do + <<-EOSR + pool: rpool + state: ONLINE + scan: none requested + config: + + NAME STATE READ WRITE CKSUM + rpool ONLINE 0 0 0 + mirror-0 ONLINE 0 0 0 + sda ONLINE 0 0 0 + sdb ONLINE 0 0 0 + + errors: No known data errors +EOSR + end + before do + allow(plugin).to receive(:platform_family).and_return("rhel") + allow(plugin).to receive(:collect_os).and_return(:linux) + allow(plugin).to receive(:shell_out).with("zpool list -H -o name,size,alloc,free,cap,dedup,health,version").and_return(mock_shell_out(0, zpool_out, "")) + allow(plugin).to receive(:shell_out).with("zpool status rpool").and_return(mock_shell_out(0, zpool_status_rpool, "")) + allow(plugin).to receive(:shell_out).with("zpool status tank").and_return(mock_shell_out(0, zpool_status_tank, "")) + end + + it "Has entries for both zpools" do + plugin.run + expect(plugin[:zpools][:rpool]).to be + expect(plugin[:zpools][:tank]).to be + end + + it "Has the correct pool size" do + plugin.run + expect(plugin[:zpools][:rpool][:pool_size]).to match("109G") + expect(plugin[:zpools][:tank][:pool_size]).to match("130T") + end + + it "Has the correct pool allocated size" do + plugin.run + expect(plugin[:zpools][:rpool][:pool_allocated]).to match("66.2G") + expect(plugin[:zpools][:tank][:pool_allocated]).to match("4.91M") + end + + it "Has the correct pool free size" do + plugin.run + expect(plugin[:zpools][:rpool][:pool_free]).to match("42.8G") + expect(plugin[:zpools][:tank][:pool_free]).to match("130T") + end + + it "Has the correct capacity_used" do + plugin.run + expect(plugin[:zpools][:rpool][:capacity_used]).to match("60%") + expect(plugin[:zpools][:tank][:capacity_used]).to match("0%") + end + + it "Has the correct dedup_factor" do + plugin.run + expect(plugin[:zpools][:rpool][:dedup_factor]).to match("1.00x") + expect(plugin[:zpools][:tank][:dedup_factor]).to match("1.00x") + end + + it "Has the correct health" do + plugin.run + expect(plugin[:zpools][:rpool][:health]).to match("ONLINE") + expect(plugin[:zpools][:tank][:health]).to match("ONLINE") + end + + it "Has the correct number of devices" do + plugin.run + expect(plugin[:zpools][:rpool][:devices].keys.size).to match(2) + expect(plugin[:zpools][:tank][:devices].keys.size).to match(12) + end + + it "Won't have a version number" do + plugin.run + expect(plugin[:zpools][:rpool][:zpool_version]).to be_nil + expect(plugin[:zpools][:tank][:zpool_version]).to be_nil + end + end + + context "on Solaris2" do + let(:zpool_status_tank) do + <<-EOST +pool: tank +state: ONLINE +scan: scrub repaired 0 in 0h0m with 0 errors on Fri Jun 6 14:43:40 2014 +config: + + NAME STATE READ WRITE CKSUM + tank ONLINE 0 0 0 + raidz2-0 ONLINE 0 0 0 + c1t50014EE209D1DBA9d0 ONLINE 0 0 0 + c1t50014EE20A0ECED2d0 ONLINE 0 0 0 + c1t50014EE20A106BFFd0 ONLINE 0 0 0 + c1t50014EE20A1423E8d0 ONLINE 0 0 0 + c1t50014EE20A145447d0 ONLINE 0 0 0 + c1t50014EE20A29EE56d0 ONLINE 0 0 0 + raidz2-1 ONLINE 0 0 0 + c1t50014EE20A2B984Cd0 ONLINE 0 0 0 + c1t50014EE20A2BBC78d0 ONLINE 0 0 0 + c1t50014EE20A2BDCA9d0 ONLINE 0 0 0 + c1t50014EE25F697DC4d0 ONLINE 0 0 0 + c1t50014EE25F698BECd0 ONLINE 0 0 0 + c1t50014EE25F6998DAd0 ONLINE 0 0 0 +EOST + end + let(:zpool_out) do + <<-EOZO +rpool 109G 66.2G 42.8G 60% 1.00x ONLINE 34 +tank 130T 4.91M 130T 0% 1.00x ONLINE 34 +EOZO + end + let(:zpool_status_rpool) do + <<-EOSR +pool: rpool +state: ONLINE +scan: resilvered 65.6G in 0h8m with 0 errors on Fri Jun 6 14:22:40 2014 +config: + + NAME STATE READ WRITE CKSUM + rpool ONLINE 0 0 0 + mirror-0 ONLINE 0 0 0 + c3t5d0s0 ONLINE 0 0 0 + c3t4d0s0 ONLINE 0 0 0 + +errors: No known data errors +EOSR + end + before do + allow(plugin).to receive(:platform_family).and_return("solaris2") + allow(plugin).to receive(:collect_os).and_return(:solaris2) + allow(plugin).to receive(:shell_out).with("zpool list -H -o name,size,alloc,free,cap,dedup,health,version").and_return(mock_shell_out(0, zpool_out, "")) + allow(plugin).to receive(:shell_out).with("su adm -c \"zpool status rpool\"").and_return(mock_shell_out(0, zpool_status_rpool, "")) + allow(plugin).to receive(:shell_out).with("su adm -c \"zpool status tank\"").and_return(mock_shell_out(0, zpool_status_tank, "")) + end + + it "Has entries for both zpools" do + plugin.run + expect(plugin[:zpools][:rpool]).to be + expect(plugin[:zpools][:tank]).to be + end + + it "Has the correct pool size" do + plugin.run + expect(plugin[:zpools][:rpool][:pool_size]).to match("109G") + expect(plugin[:zpools][:tank][:pool_size]).to match("130T") + end + + it "Has the correct pool allocated size" do + plugin.run + expect(plugin[:zpools][:rpool][:pool_allocated]).to match("66.2G") + expect(plugin[:zpools][:tank][:pool_allocated]).to match("4.91M") + end + + it "Has the correct pool free size" do + plugin.run + expect(plugin[:zpools][:rpool][:pool_free]).to match("42.8G") + expect(plugin[:zpools][:tank][:pool_free]).to match("130T") + end + + it "Has the correct capacity_used" do + plugin.run + expect(plugin[:zpools][:rpool][:capacity_used]).to match("60%") + expect(plugin[:zpools][:tank][:capacity_used]).to match("0%") + end + + it "Has the correct dedup_factor" do + plugin.run + expect(plugin[:zpools][:rpool][:dedup_factor]).to match("1.00x") + expect(plugin[:zpools][:tank][:dedup_factor]).to match("1.00x") + end + + it "Has the correct health" do + plugin.run + expect(plugin[:zpools][:rpool][:health]).to match("ONLINE") + expect(plugin[:zpools][:tank][:health]).to match("ONLINE") + end + + it "Has the correct number of devices" do + plugin.run + expect(plugin[:zpools][:rpool][:devices].keys.size).to match(2) + expect(plugin[:zpools][:tank][:devices].keys.size).to match(12) + end + + it "Has a version number" do + plugin.run + expect(plugin[:zpools][:rpool][:zpool_version]).to match("34") + expect(plugin[:zpools][:tank][:zpool_version]).to match("34") + end + end +end diff -Nru ohai-8.21.0/spec/unit/provides_map_spec.rb ohai-13.8.0/spec/unit/provides_map_spec.rb --- ohai-8.21.0/spec/unit/provides_map_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/provides_map_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -17,7 +17,7 @@ # limitations under the License # -require File.expand_path(File.dirname(__FILE__) + "/../spec_helper.rb") +require_relative "../spec_helper.rb" describe Ohai::ProvidesMap do diff -Nru ohai-8.21.0/spec/unit/runner_spec.rb ohai-13.8.0/spec/unit/runner_spec.rb --- ohai-8.21.0/spec/unit/runner_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/runner_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -17,7 +17,7 @@ # limitations under the License # -require File.expand_path(File.dirname(__FILE__) + "/../spec_helper.rb") +require_relative "../spec_helper.rb" describe Ohai::Runner, "run_plugin" do let(:safe_run) { true } diff -Nru ohai-8.21.0/spec/unit/system_spec.rb ohai-13.8.0/spec/unit/system_spec.rb --- ohai-8.21.0/spec/unit/system_spec.rb 2016-10-29 23:09:49.000000000 +0000 +++ ohai-13.8.0/spec/unit/system_spec.rb 2018-03-16 11:24:35.000000000 +0000 @@ -1,7 +1,7 @@ # # Author:: Adam Jacob () # Author:: Claire McQuin () -# Copyright:: Copyright (c) 2008-2016 Chef Software, Inc. +# Copyright:: Copyright (c) 2008-2017, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -17,13 +17,14 @@ # limitations under the License. # -require File.expand_path(File.dirname(__FILE__) + "/../spec_helper.rb") +require_relative "../spec_helper.rb" require "ohai/mixin/os" describe "Ohai::System" do extend IntegrationSupport - let(:ohai) { Ohai::System.new } + let(:ohai_external) {} + let(:ohai) { Ohai::System.new({ invoked_from_cli: true }) } describe "#initialize" do it "returns an Ohai::System object" do @@ -38,23 +39,12 @@ expect(ohai.v6_dependency_solver).to be_a_kind_of(Hash) end - it "merges deprecated config settings into the ohai config context" do - expect(Ohai::Log).to receive(:warn). - with(/Ohai::Config\[:disabled_plugins\] is deprecated/) - Ohai::Config[:disabled_plugins] = [ :Foo, :Baz ] - expect(Ohai::Config).to receive(:merge_deprecated_config). - and_call_original - Ohai::System.new - expect(Ohai.config[:disabled_plugins]).to eq([ :Foo, :Baz ]) - end - it "merges provided configuration options into the ohai config context" do config = { disabled_plugins: [ :Foo, :Baz ], directory: "/some/extra/plugins", + critical_plugins: [ :Foo, :Bar ], } - allow(Ohai::Config).to receive(:merge_deprecated_config) - expect(Ohai.config).to receive(:merge!).with(config).and_call_original Ohai::System.new(config) config.each do |option, value| expect(Ohai.config[option]).to eq(value) @@ -66,58 +56,36 @@ it "adds directory to plugin_path" do Ohai.config[:directory] = directory - Ohai::System.new + Ohai::System.new({ invoked_from_cli: true }) expect(Ohai.config[:plugin_path]).to include(directory) end end - shared_examples_for "appendable deprecated configuration option" do - it "logs a warning and configures the option on the ohai config context" do - Ohai::Config[option] << value - expect(Ohai::Log).to receive(:warn). - with(/Ohai::Config\[:#{option}\] is deprecated/) - Ohai::System.new - expect(Ohai.config[option]).to include(value) - end - end - - context "when a top-level hints_path is configured" do - include_examples "appendable deprecated configuration option" do - let(:option) { :hints_path } - let(:value) { "/path/to/hints" } - end - end - - context "when a top-level plugin_path is configured" do - include_examples "appendable deprecated configuration option" do - let(:option) { :plugin_path } - let(:value) { "/path/to/plugins" } - end - end - - context "first time configuration" do - before { allow(Ohai::Log).to receive(:configured?).and_return(false) } - + context "when testing the intializer that does way too much" do it "configures logging" do log_level = :debug Ohai.config[:log_level] = log_level - expect(Ohai::Log).to receive(:init).with(Ohai.config[:log_location]) expect(Ohai::Log).to receive(:level=).with(log_level) - Ohai::System.new + Ohai::System.new({ invoked_from_cli: true }) end it "resolves log_level when set to :auto" do expect(Ohai::Log).to receive(:level=).with(:info) - Ohai::System.new + Ohai::System.new({ invoked_from_cli: true }) end - end - context "after first time configuration" do - before { allow(Ohai::Log).to receive(:configured?).and_return(true) } + context "when called externally" do + it "does not configure logging" do + log_level = :debug + Ohai.config[:log_level] = log_level + expect(Ohai::Log).not_to receive(:level=).with(log_level) + Ohai::System.new + end - it "configures logging" do - expect(Ohai::Log).not_to receive(:init).with(Ohai.config[:log_location]) - Ohai::System.new + it "does not resolve log_level when set to :auto" do + expect(Ohai::Log).not_to receive(:level=).with(:info) + Ohai::System.new + end end end end @@ -199,6 +167,8 @@ ohai.all_plugins expect(ohai.data[:zoo]).to eq("animals") expect(ohai.data[:park]).to eq("plants") + expect(ohai.data[:zoo]).to be_frozen + expect(ohai.data[:park]).to be_frozen end describe "when using :disabled_plugins" do @@ -340,11 +310,22 @@ end EOF + with_plugin("fails.rb", <