ohai 15.1.5 → 15.2.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -1
  3. data/lib/ohai/common/dmi.rb +3 -0
  4. data/lib/ohai/dsl/plugin.rb +3 -0
  5. data/lib/ohai/dsl/plugin/versionvii.rb +4 -2
  6. data/lib/ohai/hints.rb +3 -1
  7. data/lib/ohai/loader.rb +7 -4
  8. data/lib/ohai/mash.rb +1 -1
  9. data/lib/ohai/mixin/constant_helper.rb +1 -0
  10. data/lib/ohai/mixin/ec2_metadata.rb +4 -3
  11. data/lib/ohai/mixin/gce_metadata.rb +2 -3
  12. data/lib/ohai/plugins/aix/kernel.rb +1 -1
  13. data/lib/ohai/plugins/aix/network.rb +3 -3
  14. data/lib/ohai/plugins/aix/virtualization.rb +4 -0
  15. data/lib/ohai/plugins/azure.rb +1 -0
  16. data/lib/ohai/plugins/cloud.rb +7 -4
  17. data/lib/ohai/plugins/cpu.rb +6 -6
  18. data/lib/ohai/plugins/darwin/network.rb +9 -4
  19. data/lib/ohai/plugins/digital_ocean.rb +2 -0
  20. data/lib/ohai/plugins/dmi.rb +1 -0
  21. data/lib/ohai/plugins/dragonflybsd/memory.rb +1 -1
  22. data/lib/ohai/plugins/dragonflybsd/network.rb +1 -0
  23. data/lib/ohai/plugins/ec2.rb +1 -0
  24. data/lib/ohai/plugins/eucalyptus.rb +1 -0
  25. data/lib/ohai/plugins/filesystem.rb +12 -2
  26. data/lib/ohai/plugins/freebsd/memory.rb +1 -1
  27. data/lib/ohai/plugins/freebsd/network.rb +1 -0
  28. data/lib/ohai/plugins/haskell.rb +4 -4
  29. data/lib/ohai/plugins/hostname.rb +2 -1
  30. data/lib/ohai/plugins/java.rb +1 -0
  31. data/lib/ohai/plugins/kernel.rb +10 -5
  32. data/lib/ohai/plugins/linode.rb +1 -1
  33. data/lib/ohai/plugins/linux/lspci.rb +3 -2
  34. data/lib/ohai/plugins/linux/network.rb +18 -7
  35. data/lib/ohai/plugins/linux/platform.rb +4 -8
  36. data/lib/ohai/plugins/netbsd/memory.rb +1 -1
  37. data/lib/ohai/plugins/netbsd/network.rb +1 -0
  38. data/lib/ohai/plugins/network.rb +2 -0
  39. data/lib/ohai/plugins/openbsd/memory.rb +1 -1
  40. data/lib/ohai/plugins/openbsd/network.rb +1 -0
  41. data/lib/ohai/plugins/openstack.rb +8 -14
  42. data/lib/ohai/plugins/packages.rb +29 -1
  43. data/lib/ohai/plugins/rackspace.rb +1 -0
  44. data/lib/ohai/plugins/scaleway.rb +1 -0
  45. data/lib/ohai/plugins/shard.rb +1 -1
  46. data/lib/ohai/plugins/solaris2/network.rb +3 -1
  47. data/lib/ohai/plugins/virtualbox.rb +5 -3
  48. data/lib/ohai/plugins/windows/network.rb +6 -0
  49. data/lib/ohai/provides_map.rb +26 -3
  50. data/lib/ohai/runner.rb +18 -5
  51. data/lib/ohai/system.rb +8 -0
  52. data/lib/ohai/util/win32.rb +4 -4
  53. data/lib/ohai/version.rb +1 -1
  54. data/spec/data/plugins/rpmquery.output +2 -0
  55. data/spec/functional/application_spec.rb +1 -1
  56. data/spec/functional/loader_spec.rb +1 -1
  57. data/spec/unit/dsl/plugin_spec.rb +15 -15
  58. data/spec/unit/plugin_config_spec.rb +3 -3
  59. data/spec/unit/plugins/docker_spec.rb +11 -11
  60. data/spec/unit/plugins/ec2_spec.rb +4 -2
  61. data/spec/unit/plugins/erlang_spec.rb +2 -2
  62. data/spec/unit/plugins/hostname_spec.rb +14 -10
  63. data/spec/unit/plugins/linux/filesystem_spec.rb +1 -0
  64. data/spec/unit/plugins/linux/lspci_spec.rb +2 -1
  65. data/spec/unit/plugins/linux/platform_spec.rb +5 -0
  66. data/spec/unit/plugins/network_spec.rb +3 -2
  67. data/spec/unit/plugins/openstack_spec.rb +31 -30
  68. data/spec/unit/plugins/packages_spec.rb +20 -0
  69. data/spec/unit/plugins/ruby_spec.rb +1 -1
  70. data/spec/unit/plugins/scsi_spec.rb +2 -1
  71. data/spec/unit/plugins/shard_spec.rb +1 -1
  72. data/spec/unit/plugins/windows/filesystem_spec.rb +2 -2
  73. data/spec/unit/plugins/windows/kernel_spec.rb +2 -2
  74. data/spec/unit/runner_spec.rb +2 -2
  75. data/spec/unit/system_spec.rb +3 -3
  76. metadata +2 -2
@@ -85,7 +85,7 @@ Ohai.plugin(:Memory) do
85
85
  so.stdout.lines do |line|
86
86
  # Device 1024-blocks Used Avail Capacity Priority
87
87
  # swap_device 1048824 0 1048824 0% 0
88
- if line =~ /^([\d\w\/]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+([\d\%]+)/
88
+ if line =~ %r{^([\d\w/]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+([\d\%]+)}
89
89
  mdev = $1
90
90
  memory[:swap][mdev] = Mash.new
91
91
  memory[:swap][mdev][:total] = $2
@@ -89,6 +89,7 @@ Ohai.plugin(:Network) do
89
89
  so.stdout.lines do |line|
90
90
  if line =~ /\((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\) at ([a-fA-F0-9\:]+) on ([0-9a-zA-Z\.\:\-]+)/
91
91
  next unless iface[$3] # this should never happen
92
+
92
93
  iface[$3][:arp] ||= Mash.new
93
94
  iface[$3][:arp][$1] = $2.downcase
94
95
  end
@@ -37,8 +37,10 @@ Ohai.plugin(:NetworkAddresses) do
37
37
  ipaddresses = []
38
38
  Mash[network["interfaces"]].each do |iface, iface_v|
39
39
  next if iface_v.nil? || !iface_v.key?("addresses")
40
+
40
41
  iface_v["addresses"].each do |addr, addr_v|
41
42
  next if addr_v.nil? || (not addr_v.key? "family") || addr_v["family"] != family
43
+
42
44
  ipaddresses << {
43
45
  ipaddress: addr_v["prefixlen"] ? IPAddress("#{addr}/#{addr_v["prefixlen"]}") : IPAddress("#{addr}/#{addr_v["netmask"]}"),
44
46
  scope: addr_v["scope"].nil? ? nil : addr_v["scope"].downcase,
@@ -85,7 +85,7 @@ Ohai.plugin(:Memory) do
85
85
  so.stdout.lines do |line|
86
86
  # Device 1024-blocks Used Avail Capacity Priority
87
87
  # swap_device 1048824 0 1048824 0% 0
88
- if line =~ /^([\d\w\/]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+([\d\%]+)/
88
+ if line =~ %r{^([\d\w/]+)\s+(\d+)\s+(\d+)\s+(\d+)\s+([\d\%]+)}
89
89
  mdev = $1
90
90
  memory[:swap][mdev] = Mash.new
91
91
  memory[:swap][mdev][:total] = $2
@@ -89,6 +89,7 @@ Ohai.plugin(:Network) do
89
89
  so.stdout.lines do |line|
90
90
  if line =~ /\((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\) at ([a-fA-F0-9\:]+) on ([0-9a-zA-Z\.\:\-]+)/
91
91
  next unless iface[$3] # this should never happen
92
+
92
93
  iface[$3][:arp] ||= Mash.new
93
94
  iface[$3][:arp][$1] = $2.downcase
94
95
  end
@@ -1,7 +1,7 @@
1
1
  #
2
2
  # Author:: Matt Ray (<matt@chef.io>)
3
3
  # Author:: Tim Smith (<tsmith@chef.io>)
4
- # Copyright:: Copyright (c) 2012-2016 Chef Software, Inc.
4
+ # Copyright:: Copyright (c) 2012-2019 Chef Software, Inc.
5
5
  # License:: Apache License, Version 2.0
6
6
  #
7
7
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,21 +23,14 @@ Ohai.plugin(:Openstack) do
23
23
  include Ohai::Mixin::HttpHelper
24
24
 
25
25
  provides "openstack"
26
- depends "dmi"
27
26
  depends "etc"
27
+ depends "virtualization"
28
28
 
29
- # do we have the openstack dmi data
30
- def openstack_dmi?
31
- # detect a manufacturer of OpenStack Foundation
32
- if get_attribute(:dmi, :system, :all_records, 0, :Manufacturer) =~ /OpenStack/
33
- logger.trace("Plugin Openstack: has_openstack_dmi? == true")
29
+ # use virtualization data
30
+ def openstack_virtualization?
31
+ if get_attribute(:virtualization, :system, :guest) == "openstack"
32
+ logger.trace("Plugin Openstack: has_openstack_virtualization? == true")
34
33
  true
35
- elsif get_attribute(:dmi, :system, :product_name) == "OpenStack Compute"
36
- logger.trace("Plugin Openstack: has_openstack_dmi? == true")
37
- true
38
- else
39
- logger.trace("Plugin Openstack: has_openstack_dmi? == false")
40
- false
41
34
  end
42
35
  end
43
36
 
@@ -55,12 +48,13 @@ Ohai.plugin(:Openstack) do
55
48
  # dreamhost systems have the dhc-user on them
56
49
  def openstack_provider
57
50
  return "dreamhost" if get_attribute("etc", "passwd", "dhc-user")
51
+
58
52
  "openstack"
59
53
  end
60
54
 
61
55
  collect_data do
62
56
  # fetch data if we look like openstack
63
- if openstack_hint? || openstack_dmi?
57
+ if openstack_hint? || openstack_virtualization?
64
58
  openstack Mash.new
65
59
  openstack[:provider] = openstack_provider
66
60
 
@@ -48,7 +48,34 @@ Ohai.plugin(:Packages) do
48
48
 
49
49
  pkgs.each do |pkg|
50
50
  name, epoch, version, release, installdate, arch = pkg.split
51
- packages[name] = { "epoch" => epoch, "version" => version, "release" => release, "installdate" => installdate, "arch" => arch }
51
+ if packages[name]
52
+ # We have more than one package with this exact name!
53
+ # Create an "versions" array for tracking all versions of packages with this name.
54
+ # The top-level package information will be the first one returned by rpm -qa,
55
+ # all versions go in this list, with the same information they'd normally have.
56
+ if packages[name]["versions"].nil?
57
+ # add the data of the first package to the list, so that all versions are in the list.
58
+ packages[name]["versions"] = []
59
+ packages[name]["versions"] << Mash.new({ "epoch" => packages[name]["epoch"],
60
+ "version" => packages[name]["version"],
61
+ "release" => packages[name]["release"],
62
+ "installdate" => packages[name]["installdate"],
63
+ "arch" => packages[name]["arch"] })
64
+ end
65
+ packages[name]["versions"] << Mash.new({ "epoch" => epoch, "version" => version, "release" => release, "installdate" => installdate, "arch" => arch }) # Add this package version to the list
66
+ # When this was originally written, it didn't account for multiple versions of the same package
67
+ # so it just kept clobbering the package data if it encountered multiple versions
68
+ # of the same package. As a result, the last duplicate returned by rpm -qa was what was present;
69
+ # here we clobber that data for compatibility. Note that we can't overwrite the entire hash
70
+ # without losing the versions array.
71
+ packages[name]["epoch"] = epoch
72
+ packages[name]["version"] = version
73
+ packages[name]["release"] = release
74
+ packages[name]["installdate"] = installdate
75
+ packages[name]["arch"] = arch
76
+ else
77
+ packages[name] = { "epoch" => epoch, "version" => version, "release" => release, "installdate" => installdate, "arch" => arch }
78
+ end
52
79
  end
53
80
 
54
81
  when "arch"
@@ -92,6 +119,7 @@ Ohai.plugin(:Packages) do
92
119
  pkg = reg.open(key)
93
120
  name = pkg["DisplayName"] rescue nil
94
121
  next if name.nil?
122
+
95
123
  package = packages[name] = Mash.new
96
124
  WINDOWS_ATTRIBUTE_ALIASES.each do |registry_attr, package_attr|
97
125
  value = pkg[registry_attr] rescue nil
@@ -49,6 +49,7 @@ Ohai.plugin(:Rackspace) do
49
49
  # false:: Otherwise
50
50
  def has_rackspace_manufacturer?
51
51
  return false unless RUBY_PLATFORM =~ /mswin|mingw32|windows/
52
+
52
53
  require "wmi-lite/wmi"
53
54
  wmi = WmiLite::Wmi.new
54
55
  if wmi.first_of("Win32_ComputerSystem")["PrimaryOwnerName"] == "Rackspace"
@@ -39,6 +39,7 @@ Ohai.plugin(:Scaleway) do
39
39
  def looks_like_scaleway?
40
40
  return true if hint?("scaleway")
41
41
  return true if has_scaleway_cmdline? && can_socket_connect?(Ohai::Mixin::ScalewayMetadata::SCALEWAY_METADATA_ADDR, 80)
42
+
42
43
  false
43
44
  end
44
45
 
@@ -31,7 +31,7 @@ Ohai.plugin(:ShardSeed) do
31
31
  def default_sources
32
32
  case collect_os
33
33
  when "linux", "darwin", "windows"
34
- [:machinename, :serial, :uuid]
34
+ %i{machinename serial uuid}
35
35
  else
36
36
  [:machinename]
37
37
  end
@@ -70,6 +70,7 @@ Ohai.plugin(:Network) do
70
70
  return "Ethernet" if ETHERNET_ENCAPS.include?(ifname)
71
71
  return "Ethernet" if ifname.eql?("net")
72
72
  return "Loopback" if ifname.eql?("lo")
73
+
73
74
  "Unknown"
74
75
  end
75
76
 
@@ -129,7 +130,7 @@ Ohai.plugin(:Network) do
129
130
  iface[cint][:addresses] ||= Mash.new
130
131
  iface[cint][:addresses][$1] = { "family" => "inet", "netmask" => $2.scanf("%2x" * 4) * ".", "broadcast" => $4 }
131
132
  end
132
- if line =~ /\s+inet6 ([a-f0-9\:]+)(\s*|(\%[a-z0-9]+)\s*)\/(\d+)\s*$/
133
+ if line =~ %r{\s+inet6 ([a-f0-9\:]+)(\s*|(\%[a-z0-9]+)\s*)/(\d+)\s*$}
133
134
  iface[cint][:addresses] ||= Mash.new
134
135
  iface[cint][:addresses][$1] = { "family" => "inet6", "prefixlen" => $4 }
135
136
  end
@@ -141,6 +142,7 @@ Ohai.plugin(:Network) do
141
142
  so.stdout.lines do |line|
142
143
  if line =~ /([0-9a-zA-Z]+)\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+(\w+)?\s+([a-zA-Z0-9\.\:\-]+)/
143
144
  next unless iface[arpname_to_ifname(iface, $1)] # this should never happen, except on solaris because sun hates you.
145
+
144
146
  iface[arpname_to_ifname(iface, $1)][:arp] ||= Mash.new
145
147
  iface[arpname_to_ifname(iface, $1)][:arp][$2] = $5
146
148
  end
@@ -87,6 +87,7 @@ Ohai.plugin(:Virtualbox) do
87
87
  hostfloppies hostonlyifs natnets
88
88
  }
89
89
  return nil unless supported_queries.include? query_type
90
+
90
91
  results = Mash.new
91
92
 
92
93
  so_cmd = "VBoxManage list --sorted #{query_type}"
@@ -103,8 +104,9 @@ Ohai.plugin(:Virtualbox) do
103
104
  # initialize a blank record hash
104
105
  record = Mash.new
105
106
  # parse the record block into key/value pairs
106
- blk.each_line() do |line|
107
+ blk.each_line do |line|
107
108
  next unless line.include? ":"
109
+
108
110
  # split the line into key/value pair
109
111
  key, right = line.split(":", 2)
110
112
 
@@ -144,9 +146,9 @@ Ohai.plugin(:Virtualbox) do
144
146
  virtualbox[:host][:version] = Regexp.last_match(1)
145
147
  when /VBoxRev, value: (\S*),/
146
148
  virtualbox[:host][:revision] = Regexp.last_match(1)
147
- when /GuestAdd\/VersionExt, value: (\S*),/
149
+ when %r{GuestAdd/VersionExt, value: (\S*),}
148
150
  virtualbox[:guest][:guest_additions_version] = Regexp.last_match(1)
149
- when /GuestAdd\/Revision, value: (\S*),/
151
+ when %r{GuestAdd/Revision, value: (\S*),}
150
152
  virtualbox[:guest][:guest_additions_revision] = Regexp.last_match(1)
151
153
  end
152
154
  end
@@ -22,6 +22,7 @@ Ohai.plugin(:Network) do
22
22
 
23
23
  def windows_encaps_lookup(encap)
24
24
  return "Ethernet" if encap.eql?("Ethernet 802.3")
25
+
25
26
  encap
26
27
  end
27
28
 
@@ -40,6 +41,7 @@ Ohai.plugin(:Network) do
40
41
  # that does not populate the deprecated win32_* WMI classes, then we should
41
42
  # grab data from the newer MSFT_* classes
42
43
  return msft_adapter_data if data[:addresses].count == 0
44
+
43
45
  data[:adapters] = wmi.instances_of("Win32_NetworkAdapter")
44
46
  data
45
47
  end
@@ -84,6 +86,7 @@ Ohai.plugin(:Network) do
84
86
  #
85
87
  def prefer_ipv4(addresses)
86
88
  return nil unless addresses.is_a?(Array)
89
+
87
90
  addresses.find { |ip| IPAddress.valid_ipv4?(ip) } ||
88
91
  addresses.find { |ip| IPAddress.valid_ipv6?(ip) }
89
92
  end
@@ -99,6 +102,7 @@ Ohai.plugin(:Network) do
99
102
  #
100
103
  def favored_default_route_windows(configuration)
101
104
  return nil unless configuration.is_a?(Hash)
105
+
102
106
  config = configuration.dup
103
107
 
104
108
  config.inject([]) do |arr, (k, v)|
@@ -143,6 +147,7 @@ Ohai.plugin(:Network) do
143
147
  adapter.wmi_ole_object.properties_.each do |p|
144
148
  # skip wmi class name fields which make no sense in ohai
145
149
  next if %w{creation_class_name system_creation_class_name}.include?(p.name.wmi_underscore)
150
+
146
151
  iface_instance[i][p.name.wmi_underscore.to_sym] = adapter[p.name.downcase]
147
152
  end
148
153
  end
@@ -204,6 +209,7 @@ Ohai.plugin(:Network) do
204
209
  cint = $2.downcase
205
210
  end
206
211
  next unless iface[cint]
212
+
207
213
  if line =~ /^\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\s+([a-fA-F0-9\:-]+)/
208
214
  iface[cint][:arp][$1] = $2.tr("-", ":").downcase
209
215
  end
@@ -31,8 +31,13 @@ module Ohai
31
31
  @map = Mash.new
32
32
  end
33
33
 
34
+ # @param [Ohai::DSL::Plugin] plugin
35
+ # @param [Array] provided_attributes
36
+ #
37
+ # @return void
38
+ #
34
39
  def set_providers_for(plugin, provided_attributes)
35
- unless plugin.kind_of?(Ohai::DSL::Plugin)
40
+ unless plugin.is_a?(Ohai::DSL::Plugin)
36
41
  raise ArgumentError, "set_providers_for only accepts Ohai Plugin classes (got: #{plugin})"
37
42
  end
38
43
 
@@ -48,13 +53,20 @@ module Ohai
48
53
  end
49
54
  end
50
55
 
56
+ #
51
57
  # gather plugins providing exactly the attributes listed
58
+ #
59
+ # @param [Array] attributes
60
+ #
61
+ # @return [Array] plugin names
62
+ #
52
63
  def find_providers_for(attributes)
53
64
  plugins = []
54
65
  attributes.each do |attribute|
55
66
  attrs = select_subtree(@map, attribute)
56
67
  raise Ohai::Exceptions::AttributeNotFound, "No such attribute: \'#{attribute}\'" unless attrs
57
68
  raise Ohai::Exceptions::ProviderNotFound, "Cannot find plugin providing attribute: \'#{attribute}\'" unless attrs[:_plugins]
69
+
58
70
  plugins += attrs[:_plugins]
59
71
  end
60
72
  plugins.uniq
@@ -67,6 +79,10 @@ module Ohai
67
79
  # If it can't find any, it looks for plugins that might
68
80
  # provide the parents of a given attribute and returns the
69
81
  # first parent found.
82
+ #
83
+ # @param [Array] attributes
84
+ #
85
+ # @return [Array] plugin names
70
86
  def deep_find_providers_for(attributes)
71
87
  plugins = []
72
88
  attributes.each do |attribute|
@@ -90,13 +106,19 @@ module Ohai
90
106
  # 'depends "languages"' statements in plugins.
91
107
  # It gathers plugins providing each of the attributes listed, or the
92
108
  # plugins providing the closest parent attribute
109
+ #
110
+ # @param [Array] attributes
111
+ #
112
+ # @return [Array] plugin names
93
113
  def find_closest_providers_for(attributes)
94
114
  plugins = []
95
115
  attributes.each do |attribute|
96
116
  parts = normalize_and_validate(attribute)
97
117
  raise Ohai::Exceptions::AttributeNotFound, "No such attribute: \'#{attribute}\'" unless @map[parts[0]]
118
+
98
119
  attrs = select_closest_subtree(@map, attribute)
99
120
  raise Ohai::Exceptions::ProviderNotFound, "Cannot find plugin providing attribute: \'#{attribute}\'" unless attrs
121
+
100
122
  plugins += attrs[:_plugins]
101
123
  end
102
124
  plugins.uniq
@@ -114,8 +136,8 @@ module Ohai
114
136
  private
115
137
 
116
138
  def normalize_and_validate(attribute)
117
- raise Ohai::Exceptions::AttributeSyntaxError, "Attribute contains duplicate '/' characters: #{attribute}" if attribute =~ /\/\/+/
118
- raise Ohai::Exceptions::AttributeSyntaxError, "Attribute contains a trailing '/': #{attribute}" if attribute =~ /\/$/
139
+ raise Ohai::Exceptions::AttributeSyntaxError, "Attribute contains duplicate '/' characters: #{attribute}" if attribute =~ %r{//+}
140
+ raise Ohai::Exceptions::AttributeSyntaxError, "Attribute contains a trailing '/': #{attribute}" if attribute =~ %r{/$}
119
141
 
120
142
  parts = attribute.split("/")
121
143
  parts.shift if parts.length != 0 && parts[0].length == 0 # attribute begins with a '/'
@@ -127,6 +149,7 @@ module Ohai
127
149
  parts = normalize_and_validate(attribute)
128
150
  parts.each do |part|
129
151
  return nil unless subtree[part]
152
+
130
153
  subtree = subtree[part]
131
154
  end
132
155
  subtree
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Claire McQuin (<claire@chef.io>)
3
- # Copyright:: Copyright (c) 2013-2016 Chef Software, Inc.
3
+ # Copyright:: Copyright (c) 2013-2019, Chef Software Inc.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License"); you
@@ -37,9 +37,14 @@ module Ohai
37
37
  # Runs plugins and any un-run dependencies.
38
38
  # If force is set to true, then this plugin and its dependencies
39
39
  # will be run even if they have been run before.
40
+ #
41
+ # @param [Ohai::DSL::Plugin] plugin
42
+ #
43
+ # @return void
44
+ #
40
45
  def run_plugin(plugin)
41
- elapsed = Benchmark.measure do
42
- unless plugin.kind_of?(Ohai::DSL::Plugin)
46
+ elapsed = Benchmark.realtime do
47
+ unless plugin.is_a?(Ohai::DSL::Plugin)
43
48
  raise Ohai::Exceptions::InvalidPlugin, "Invalid plugin #{plugin} (must be an Ohai::DSL::Plugin or subclass)"
44
49
  end
45
50
 
@@ -53,13 +58,17 @@ module Ohai
53
58
  raise
54
59
  rescue SystemExit # abort or exit from plug-in should exit Ohai with failure code
55
60
  raise
56
- rescue Exception, Errno::ENOENT => e
61
+ rescue Exception => e
57
62
  logger.trace("Plugin #{plugin.name} threw exception #{e.inspect} #{e.backtrace.join("\n")}")
58
63
  end
59
64
  end
60
- logger.trace("Plugin #{plugin.name} took #{elapsed.total} seconds to run.")
65
+ logger.trace("Plugin #{plugin.name} took #{elapsed} seconds to run.")
61
66
  end
62
67
 
68
+ # @param [Ohai::DSL::Plugin] plugin
69
+ #
70
+ # @return void
71
+ #
63
72
  def run_v7_plugin(plugin)
64
73
  return true if plugin.optional? &&
65
74
  !Ohai.config[:run_all_plugins] &&
@@ -94,6 +103,10 @@ module Ohai
94
103
  end
95
104
  end
96
105
 
106
+ # @param [Array] attributes
107
+ #
108
+ # @return [Array]
109
+ #
97
110
  def fetch_plugins(attributes)
98
111
  @provides_map.find_closest_providers_for(attributes)
99
112
  end
@@ -84,6 +84,7 @@ module Ohai
84
84
  # to run the system.
85
85
  #
86
86
  # @param [Array<String>] attribute_filter the attributes to run. All will be run if not specified
87
+ #
87
88
  # @return [void]
88
89
  def all_plugins(attribute_filter = nil)
89
90
  # Reset the system when all_plugins is called since this function
@@ -96,6 +97,7 @@ module Ohai
96
97
  end
97
98
 
98
99
  # load all plugins by calling Ohai::Loader.load_all
100
+ #
99
101
  # @see Ohai::Loader.load_all
100
102
  def load_plugins
101
103
  @loader.load_all
@@ -131,6 +133,10 @@ module Ohai
131
133
  freeze_strings!
132
134
  end
133
135
 
136
+ # @param [String] plugin_path
137
+ #
138
+ # @return [void]
139
+ #
134
140
  def run_additional_plugins(plugin_path)
135
141
  @loader.load_additional(plugin_path).each do |plugin|
136
142
  logger.trace "Running plugin #{plugin}"
@@ -160,6 +166,7 @@ module Ohai
160
166
  data = data[part]
161
167
  end
162
168
  raise ArgumentError, "I cannot find an attribute named #{a}!" if data.nil?
169
+
163
170
  case data
164
171
  when Hash, Mash, Array, Integer
165
172
  json_pretty_print(data)
@@ -184,6 +191,7 @@ module Ohai
184
191
  # make sure the directory config is an array since it could be a string set in client.rb
185
192
  Array(Ohai.config[:directory]).each do |dir|
186
193
  next if Ohai.config[:plugin_path].include?(dir)
194
+
187
195
  Ohai.config[:plugin_path] << dir
188
196
  end
189
197
  end