ohai 13.12.6 → 14.0.28

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -12
  3. data/README.md +7 -12
  4. data/Rakefile +16 -23
  5. data/docs/man/man1/ohai.1 +97 -0
  6. data/lib/ohai/application.rb +9 -4
  7. data/lib/ohai/common/dmi.rb +4 -16
  8. data/lib/ohai/config.rb +5 -1
  9. data/lib/ohai/dsl.rb +0 -1
  10. data/lib/ohai/dsl/plugin.rb +12 -16
  11. data/lib/ohai/dsl/plugin/versionvii.rb +17 -5
  12. data/lib/ohai/hints.rb +2 -2
  13. data/lib/ohai/loader.rb +21 -70
  14. data/lib/ohai/log.rb +1 -1
  15. data/lib/ohai/mixin/azure_metadata.rb +4 -4
  16. data/lib/ohai/mixin/command.rb +3 -3
  17. data/lib/ohai/mixin/dmi_decode.rb +0 -2
  18. data/lib/ohai/mixin/do_metadata.rb +1 -1
  19. data/lib/ohai/mixin/ec2_metadata.rb +8 -8
  20. data/lib/ohai/mixin/gce_metadata.rb +1 -5
  21. data/lib/ohai/mixin/http_helper.rb +3 -3
  22. data/lib/ohai/mixin/scaleway_metadata.rb +46 -0
  23. data/lib/ohai/mixin/softlayer_metadata.rb +3 -3
  24. data/lib/ohai/plugins/aix/filesystem.rb +1 -1
  25. data/lib/ohai/plugins/aix/memory.rb +1 -1
  26. data/lib/ohai/plugins/aix/network.rb +2 -2
  27. data/lib/ohai/plugins/aix/virtualization.rb +1 -1
  28. data/lib/ohai/plugins/azure.rb +5 -5
  29. data/lib/ohai/plugins/bsd/virtualization.rb +11 -11
  30. data/lib/ohai/plugins/c.rb +8 -8
  31. data/lib/ohai/plugins/chef.rb +2 -1
  32. data/lib/ohai/plugins/cloud.rb +0 -3
  33. data/lib/ohai/plugins/darwin/cpu.rb +2 -2
  34. data/lib/ohai/plugins/darwin/filesystem.rb +0 -2
  35. data/lib/ohai/plugins/darwin/hardware.rb +9 -3
  36. data/lib/ohai/plugins/darwin/network.rb +2 -2
  37. data/lib/ohai/plugins/darwin/system_profiler.rb +19 -19
  38. data/lib/ohai/plugins/darwin/virtualization.rb +10 -0
  39. data/lib/ohai/plugins/digital_ocean.rb +4 -4
  40. data/lib/ohai/plugins/dmi.rb +15 -14
  41. data/lib/ohai/plugins/docker.rb +57 -0
  42. data/lib/ohai/plugins/ec2.rb +11 -11
  43. data/lib/ohai/plugins/elixir.rb +1 -1
  44. data/lib/ohai/plugins/erlang.rb +2 -2
  45. data/lib/ohai/plugins/eucalyptus.rb +5 -5
  46. data/lib/ohai/plugins/gce.rb +2 -2
  47. data/lib/ohai/plugins/go.rb +1 -1
  48. data/lib/ohai/plugins/groovy.rb +1 -1
  49. data/lib/ohai/plugins/haskell.rb +4 -4
  50. data/lib/ohai/plugins/hostname.rb +6 -6
  51. data/lib/ohai/plugins/init_package.rb +1 -1
  52. data/lib/ohai/plugins/java.rb +1 -1
  53. data/lib/ohai/plugins/kernel.rb +109 -40
  54. data/lib/ohai/plugins/libvirt.rb +113 -0
  55. data/lib/ohai/plugins/linode.rb +4 -4
  56. data/lib/ohai/plugins/linux/block_device.rb +4 -4
  57. data/lib/ohai/plugins/linux/cpu.rb +3 -3
  58. data/lib/ohai/plugins/linux/filesystem.rb +4 -6
  59. data/lib/ohai/plugins/linux/lsb.rb +3 -3
  60. data/lib/ohai/plugins/linux/lspci.rb +2 -1
  61. data/lib/ohai/plugins/linux/machineid.rb +4 -4
  62. data/lib/ohai/plugins/linux/network.rb +16 -16
  63. data/lib/ohai/plugins/linux/platform.rb +4 -10
  64. data/lib/ohai/plugins/linux/sessions.rb +2 -1
  65. data/lib/ohai/plugins/linux/virtualization.rb +53 -31
  66. data/lib/ohai/plugins/lua.rb +1 -1
  67. data/lib/ohai/plugins/mono.rb +2 -2
  68. data/lib/ohai/plugins/network.rb +11 -11
  69. data/lib/ohai/plugins/nodejs.rb +1 -1
  70. data/lib/ohai/plugins/ohai.rb +0 -2
  71. data/lib/ohai/plugins/openstack.rb +7 -10
  72. data/lib/ohai/plugins/packages.rb +1 -1
  73. data/lib/ohai/plugins/passwd.rb +1 -0
  74. data/lib/ohai/plugins/perl.rb +1 -1
  75. data/lib/ohai/plugins/php.rb +1 -1
  76. data/lib/ohai/plugins/powershell.rb +1 -1
  77. data/lib/ohai/plugins/python.rb +1 -1
  78. data/lib/ohai/plugins/rackspace.rb +5 -5
  79. data/lib/ohai/plugins/root_group.rb +6 -9
  80. data/lib/ohai/plugins/ruby.rb +2 -2
  81. data/lib/ohai/plugins/rust.rb +1 -1
  82. data/lib/ohai/plugins/scala.rb +1 -1
  83. data/lib/ohai/plugins/scaleway.rb +56 -0
  84. data/lib/ohai/plugins/shard.rb +1 -0
  85. data/lib/ohai/plugins/softlayer.rb +2 -2
  86. data/lib/ohai/plugins/solaris2/cpu.rb +1 -1
  87. data/lib/ohai/plugins/solaris2/dmi.rb +13 -13
  88. data/lib/ohai/plugins/solaris2/network.rb +6 -6
  89. data/lib/ohai/plugins/solaris2/platform.rb +2 -2
  90. data/lib/ohai/plugins/ssh_host_key.rb +7 -7
  91. data/lib/ohai/plugins/uptime.rb +2 -7
  92. data/lib/ohai/plugins/virtualbox.rb +1 -1
  93. data/lib/ohai/plugins/vmware.rb +2 -2
  94. data/lib/ohai/plugins/windows/cpu.rb +2 -16
  95. data/lib/ohai/plugins/windows/network.rb +4 -2
  96. data/lib/ohai/plugins/zpools.rb +3 -3
  97. data/lib/ohai/provides_map.rb +1 -1
  98. data/lib/ohai/runner.rb +11 -14
  99. data/lib/ohai/system.rb +8 -71
  100. data/lib/ohai/util/file_helper.rb +2 -2
  101. data/lib/ohai/util/win32/group_helper.rb +0 -2
  102. data/lib/ohai/version.rb +1 -1
  103. data/ohai.gemspec +6 -5
  104. data/spec/functional/plugins/root_group_spec.rb +2 -2
  105. data/spec/functional/plugins/windows/uptime_spec.rb +0 -29
  106. data/spec/unit/dsl/plugin_spec.rb +14 -46
  107. data/spec/unit/loader_spec.rb +8 -70
  108. data/spec/unit/mixin/azure_metadata_spec.rb +9 -4
  109. data/spec/unit/mixin/command_spec.rb +11 -8
  110. data/spec/unit/mixin/ec2_metadata_spec.rb +5 -0
  111. data/spec/unit/mixin/softlayer_metadata_spec.rb +6 -1
  112. data/spec/unit/plugins/aix/filesystem_spec.rb +10 -10
  113. data/spec/unit/plugins/aix/network_spec.rb +1 -1
  114. data/spec/unit/plugins/aix/virtualization_spec.rb +3 -3
  115. data/spec/unit/plugins/cloud_spec.rb +0 -12
  116. data/spec/unit/plugins/darwin/cpu_spec.rb +2 -2
  117. data/spec/unit/plugins/darwin/filesystem_spec.rb +1 -6
  118. data/spec/unit/plugins/darwin/hardware_spec.rb +1 -1
  119. data/spec/unit/plugins/darwin/virtualization_spec.rb +8 -0
  120. data/spec/unit/plugins/dmi_spec.rb +17 -25
  121. data/spec/unit/plugins/docker_spec.rb +100 -0
  122. data/spec/unit/plugins/fail_spec.rb +3 -58
  123. data/spec/unit/plugins/haskell_spec.rb +1 -1
  124. data/spec/unit/plugins/init_package_spec.rb +1 -1
  125. data/spec/unit/plugins/kernel_spec.rb +0 -52
  126. data/spec/unit/plugins/linux/block_device_spec.rb +2 -2
  127. data/spec/unit/plugins/linux/filesystem_spec.rb +2 -7
  128. data/spec/unit/plugins/linux/lsb_spec.rb +5 -5
  129. data/spec/unit/plugins/linux/lspci_spec.rb +2 -2
  130. data/spec/unit/plugins/linux/machineid_spec.rb +5 -5
  131. data/spec/unit/plugins/linux/network_spec.rb +16 -16
  132. data/spec/unit/plugins/linux/platform_spec.rb +1 -17
  133. data/spec/unit/plugins/linux/virtualization_spec.rb +21 -1
  134. data/spec/unit/plugins/network_spec.rb +58 -58
  135. data/spec/unit/plugins/openstack_spec.rb +5 -24
  136. data/spec/unit/plugins/rackspace_spec.rb +6 -6
  137. data/spec/unit/plugins/root_group_spec.rb +1 -1
  138. data/spec/unit/plugins/ruby_spec.rb +1 -1
  139. data/spec/unit/plugins/rust_spec.rb +1 -1
  140. data/spec/unit/plugins/scala_spec.rb +1 -1
  141. data/spec/unit/plugins/scaleway_spec.rb +91 -0
  142. data/spec/unit/plugins/solaris2/cpu_spec.rb +3 -3
  143. data/spec/unit/plugins/solaris2/platform_spec.rb +2 -2
  144. data/spec/unit/plugins/ssh_host_keys_spec.rb +8 -8
  145. data/spec/unit/plugins/sysconf_spec.rb +1 -0
  146. data/spec/unit/plugins/windows/kernel_spec.rb +79 -0
  147. data/spec/unit/plugins/windows/uptime_spec.rb +8 -58
  148. data/spec/unit/provides_map_spec.rb +4 -4
  149. data/spec/unit/runner_spec.rb +15 -54
  150. data/spec/unit/system_spec.rb +35 -348
  151. data/spec/unit/util/file_helper_spec.rb +2 -0
  152. metadata +28 -28
  153. data/lib/ohai/dsl/plugin/versionvi.rb +0 -61
  154. data/lib/ohai/plugins/bsd/filesystem2.rb +0 -121
  155. data/lib/ohai/plugins/ip_scopes.rb +0 -67
  156. data/lib/ohai/plugins/virtualization.rb +0 -83
  157. data/spec/data/plugins/messages.rb +0 -8
  158. data/spec/data/plugins/v6message.rb +0 -2
  159. data/spec/unit/plugins/bsd/filesystem2_spec.rb +0 -126
  160. data/spec/unit/plugins/ip_scopes_spec.rb +0 -139
@@ -36,7 +36,7 @@ Ohai.plugin(:Network) do
36
36
  wmi = WmiLite::Wmi.new
37
37
  data[:addresses] = wmi.instances_of("Win32_NetworkAdapterConfiguration")
38
38
 
39
- # If we are running on windows nano or anothe roperating system from the future
39
+ # If we are running on windows nano or another operating system from the future
40
40
  # that does not populate the deprecated win32_* WMI classes, then we should
41
41
  # grab data from the newer MSFT_* classes
42
42
  return msft_adapter_data if data[:addresses].count == 0
@@ -81,11 +81,13 @@ Ohai.plugin(:Network) do
81
81
  i = adapter["index"] || adapter["InterfaceIndex"]
82
82
  iface_instance[i] = Mash.new
83
83
  adapter.wmi_ole_object.properties_.each do |p|
84
+ # skip wmi class name fields which make no sense in ohai
85
+ next if %w{creation_class_name system_creation_class_name}.include?(p.name.wmi_underscore)
84
86
  iface_instance[i][p.name.wmi_underscore.to_sym] = adapter[p.name.downcase]
85
87
  end
86
88
  end
87
89
 
88
- iface_instance.keys.each do |i|
90
+ iface_instance.each_key do |i|
89
91
  if iface_instance[i][:name] && iface_config[i] && iface_config[i][:ip_address][0]
90
92
  cint = sprintf("0x%x", (iface_instance[i][:interface_index] || iface_instance[i][:index]) ).downcase
91
93
  iface[cint] = Mash.new
@@ -33,7 +33,7 @@ Ohai.plugin(:Zpools) do
33
33
  so.stdout.lines do |line|
34
34
  case line
35
35
  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+|-)$/
36
- Ohai::Log.debug("Plugin Zpools: Parsing zpool list line: #{line.chomp}")
36
+ logger.trace("Plugin Zpools: Parsing zpool list line: #{line.chomp}")
37
37
  pools[$1] = Mash.new
38
38
  pools[$1][:pool_size] = sanitize_value($2)
39
39
  pools[$1][:pool_allocated] = sanitize_value($3)
@@ -51,7 +51,7 @@ Ohai.plugin(:Zpools) do
51
51
  pools = gather_pool_info
52
52
 
53
53
  # Grab individual health for devices in the zpools
54
- pools.keys.each do |pool|
54
+ pools.each_key do |pool|
55
55
  pools[pool][:devices] = Mash.new
56
56
 
57
57
  # Run "zpool status" as non-root user (adm) so that
@@ -70,7 +70,7 @@ Ohai.plugin(:Zpools) do
70
70
  # solaris: http://rubular.com/r/FqOBzUQQ4p
71
71
  # freebsd: http://rubular.com/r/RYkMNlytXl
72
72
  when /^\s+((sd|c|ad|da)[-_a-zA-Z0-9]+)\s+([-_a-zA-Z0-9]+)\s+(\d+)\s+(\d+)\s+(\d+)$/
73
- Ohai::Log.debug("Plugin Zpools: Parsing zpool status line: #{line.chomp}")
73
+ logger.trace("Plugin Zpools: Parsing zpool status line: #{line.chomp}")
74
74
  pools[pool][:devices][$1] = Mash.new
75
75
  pools[pool][:devices][$1][:state] = $3
76
76
  pools[pool][:devices][$1][:errors] = Mash.new
@@ -171,7 +171,7 @@ module Ohai
171
171
  # map, it will find all of the plugins that have at least one provided
172
172
  # attribute.
173
173
  def collect_plugins_in(provides_map, collected)
174
- provides_map.keys.each do |plugin|
174
+ provides_map.each_key do |plugin|
175
175
  if plugin.eql?("_plugins")
176
176
  collected.concat(provides_map[plugin])
177
177
  else
@@ -23,13 +23,15 @@ require "benchmark"
23
23
  module Ohai
24
24
  class Runner
25
25
 
26
- attr_reader :failed_plugins
26
+ attr_reader :failed_plugins, :logger
27
27
  # safe_run: set to true if this runner will run plugins in
28
28
  # safe-mode. default false.
29
29
  def initialize(controller, safe_run = false)
30
30
  @provides_map = controller.provides_map
31
31
  @safe_run = safe_run
32
32
  @failed_plugins = []
33
+ @logger = controller.logger.with_child
34
+ @logger.metadata = { subsystem: "runner" }
33
35
  end
34
36
 
35
37
  # Runs plugins and any un-run dependencies.
@@ -42,32 +44,27 @@ module Ohai
42
44
  end
43
45
 
44
46
  begin
45
- case plugin.version
46
- when :version7
47
+ if plugin.version == :version7
47
48
  run_v7_plugin(plugin)
48
- when :version6
49
- run_v6_plugin(plugin)
50
49
  else
51
50
  raise Ohai::Exceptions::InvalidPlugin, "Invalid plugin version #{plugin.version} for plugin #{plugin}"
52
51
  end
53
- rescue Ohai::Exceptions::Error
52
+ rescue Ohai::Exceptions::Error # rubocop: disable Lint/ShadowedException
54
53
  raise
55
54
  rescue SystemExit # abort or exit from plug-in should exit Ohai with failure code
56
55
  raise
57
56
  rescue Exception, Errno::ENOENT => e
58
- Ohai::Log.debug("Plugin #{plugin.name} threw exception #{e.inspect} #{e.backtrace.join("\n")}")
57
+ logger.trace("Plugin #{plugin.name} threw exception #{e.inspect} #{e.backtrace.join("\n")}")
59
58
  end
60
59
  end
61
- Ohai::Log.debug("Plugin #{plugin.name} took #{elapsed.total} seconds to run.")
62
- end
63
-
64
- def run_v6_plugin(plugin)
65
- return true if plugin.has_run?
66
-
67
- @safe_run ? plugin.safe_run : plugin.run
60
+ logger.trace("Plugin #{plugin.name} took #{elapsed.total} seconds to run.")
68
61
  end
69
62
 
70
63
  def run_v7_plugin(plugin)
64
+ return true if plugin.optional? &&
65
+ !Ohai.config[:run_all_plugins] &&
66
+ !Ohai.config[:optional_plugins].include?(plugin.name)
67
+
71
68
  visited = [ plugin ]
72
69
  until visited.empty?
73
70
  next_plugin = visited.pop
@@ -37,10 +37,10 @@ module Ohai
37
37
  attr_accessor :data
38
38
  attr_reader :config
39
39
  attr_reader :provides_map
40
- attr_reader :v6_dependency_solver
40
+ attr_reader :logger
41
41
 
42
42
  # the cli flag is used to determine if we're being constructed by
43
- # something like chef-client (which doesn't not set this flag) and
43
+ # something like chef-client (which doesn't set this flag) and
44
44
  # which sets up its own loggers, or if we're coming from Ohai::Application
45
45
  # and therefore need to configure Ohai's own logger.
46
46
  def initialize(config = {})
@@ -48,13 +48,14 @@ module Ohai
48
48
  @plugin_path = ""
49
49
  @config = config
50
50
  @failed_plugins = []
51
+ @logger = config[:logger] || Ohai::Log.with_child
52
+ @logger.metadata = { system: "ohai", version: Ohai::VERSION }
51
53
  reset_system
52
54
  end
53
55
 
54
56
  def reset_system
55
57
  @data = Mash.new
56
58
  @provides_map = ProvidesMap.new
57
- @v6_dependency_solver = Hash.new
58
59
 
59
60
  configure_ohai
60
61
  configure_logging if @cli
@@ -87,32 +88,19 @@ module Ohai
87
88
  end
88
89
 
89
90
  def run_plugins(safe = false, attribute_filter = nil)
90
- # First run all the version 6 plugins
91
- @v6_dependency_solver.values.each do |v6plugin|
92
- @runner.run_plugin(v6plugin)
93
- end
94
-
95
- # Users who are migrating from ohai 6 may give one or more Ohai 6 plugin
96
- # names as the +attribute_filter+. In this case we return early because
97
- # the v7 plugin provides map will not have an entry for this plugin.
98
- if attribute_filter && Array(attribute_filter).all? { |filter_item| have_v6_plugin?(filter_item) }
99
- return true
100
- end
101
-
102
- # Then run all the version 7 plugins
103
91
  begin
104
92
  @provides_map.all_plugins(attribute_filter).each do |plugin|
105
93
  @runner.run_plugin(plugin)
106
94
  end
107
95
  rescue Ohai::Exceptions::AttributeNotFound, Ohai::Exceptions::DependencyCycle => e
108
- Ohai::Log.error("Encountered error while running plugins: #{e.inspect}")
96
+ logger.error("Encountered error while running plugins: #{e.inspect}")
109
97
  raise
110
98
  end
111
99
  critical_failed = Ohai::Config.ohai[:critical_plugins] & @runner.failed_plugins
112
100
  unless critical_failed.empty?
113
101
  msg = "The following Ohai plugins marked as critical failed: #{critical_failed}"
114
102
  if @cli
115
- Ohai::Log.error(msg)
103
+ logger.error(msg)
116
104
  exit(true)
117
105
  else
118
106
  raise Ohai::Exceptions::CriticalPluginFailure, "#{msg}. Failing Chef run."
@@ -125,64 +113,13 @@ module Ohai
125
113
 
126
114
  def run_additional_plugins(plugin_path)
127
115
  @loader.load_additional(plugin_path).each do |plugin|
128
- Ohai::Log.debug "Running plugin #{plugin}"
116
+ logger.trace "Running plugin #{plugin}"
129
117
  @runner.run_plugin(plugin)
130
118
  end
131
119
 
132
120
  freeze_strings!
133
121
  end
134
122
 
135
- def have_v6_plugin?(name)
136
- @v6_dependency_solver.values.any? { |v6plugin| v6plugin.name == name }
137
- end
138
-
139
- def pathify_v6_plugin(plugin_name)
140
- path_components = plugin_name.split("::")
141
- File.join(path_components) + ".rb"
142
- end
143
-
144
- #
145
- # Below APIs are from V6.
146
- # Make sure that you are not breaking backwards compatibility
147
- # if you are changing any of the APIs below.
148
- #
149
- def require_plugin(plugin_ref, force = false)
150
- plugins = [ ]
151
- # This method is only callable by version 6 plugins.
152
- # First we check if there exists a v6 plugin that fulfills the dependency.
153
- if @v6_dependency_solver.has_key? pathify_v6_plugin(plugin_ref)
154
- # Note that: partial_path looks like Plugin::Name
155
- # keys for @v6_dependency_solver are in form 'plugin/name.rb'
156
- plugins << @v6_dependency_solver[pathify_v6_plugin(plugin_ref)]
157
- else
158
- # While looking up V7 plugins we need to convert the plugin_ref to an attribute.
159
- attribute = plugin_ref.gsub("::", "/")
160
- begin
161
- plugins = @provides_map.find_providers_for([attribute])
162
- rescue Ohai::Exceptions::AttributeNotFound
163
- Ohai::Log.debug("Can not find any v7 plugin that provides #{attribute}")
164
- plugins = [ ]
165
- end
166
- end
167
-
168
- if plugins.empty?
169
- raise Ohai::Exceptions::DependencyNotFound, "Can not find a plugin for dependency #{plugin_ref}"
170
- else
171
- plugins.each do |plugin|
172
- begin
173
- @runner.run_plugin(plugin)
174
- rescue SystemExit, Interrupt
175
- raise
176
- rescue Ohai::Exceptions::DependencyCycle, Ohai::Exceptions::AttributeNotFound => e
177
- Ohai::Log.error("Encountered error while running plugins: #{e.inspect}")
178
- raise
179
- rescue Exception, Errno::ENOENT => e
180
- Ohai::Log.debug("Plugin #{plugin.name} threw exception #{e.inspect} #{e.backtrace.join("\n")}")
181
- end
182
- end
183
- end
184
- end
185
-
186
123
  # Re-runs plugins that provide the attributes specified by
187
124
  # +attribute_filter+. If +attribute_filter+ is not given, re-runs all
188
125
  # plugins.
@@ -244,7 +181,7 @@ module Ohai
244
181
  Ohai.config[:plugin_path] << Ohai.config[:directory]
245
182
  end
246
183
 
247
- Ohai::Log.debug("Running Ohai with the following configuration: #{Ohai.config.configuration}")
184
+ logger.debug("Running Ohai with the following configuration: #{Ohai.config.configuration}")
248
185
  end
249
186
 
250
187
  def configure_logging
@@ -26,11 +26,11 @@ module Ohai
26
26
  paths.each do |path|
27
27
  filename = File.join(path, cmd)
28
28
  if File.executable?(filename)
29
- Ohai::Log.debug("Plugin #{name}: found #{cmd} at #{filename}")
29
+ logger.trace("Plugin #{name}: found #{cmd} at #{filename}")
30
30
  return filename
31
31
  end
32
32
  end
33
- Ohai::Log.debug("Plugin #{name}: did not find #{cmd}")
33
+ logger.trace("Plugin #{name}: did not find #{cmd}")
34
34
  false
35
35
  end
36
36
  end
@@ -29,8 +29,6 @@ module Ohai
29
29
  BUILTIN_ADMINISTRATORS_SID = "S-1-5-32-544"
30
30
 
31
31
  def self.windows_root_group_name
32
- administrators_group_name_result = nil
33
-
34
32
  administrators_sid_result = FFI::MemoryPointer.new(:pointer)
35
33
  convert_result = Win32.convert_string_sid_to_sid(BUILTIN_ADMINISTRATORS_SID, administrators_sid_result)
36
34
  last_win32_error = Win32.get_last_error
@@ -18,5 +18,5 @@
18
18
 
19
19
  module Ohai
20
20
  OHAI_ROOT = File.expand_path(File.dirname(__FILE__))
21
- VERSION = "13.12.6"
21
+ VERSION = "14.0.28"
22
22
  end
@@ -5,6 +5,7 @@ require "ohai/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "ohai"
7
7
  s.version = Ohai::VERSION
8
+ s.platform = Gem::Platform::RUBY
8
9
  s.summary = "Ohai profiles your system and emits JSON"
9
10
  s.description = s.summary
10
11
  s.license = "Apache-2.0"
@@ -12,19 +13,19 @@ Gem::Specification.new do |s|
12
13
  s.email = "adam@chef.io"
13
14
  s.homepage = "https://docs.chef.io/ohai.html"
14
15
 
15
- s.required_ruby_version = ">= 2.3"
16
+ s.required_ruby_version = ">= 2.4"
16
17
 
17
18
  s.add_dependency "systemu", "~> 2.6.4"
18
19
  s.add_dependency "ffi-yajl", "~> 2.2"
19
- s.add_dependency "mixlib-cli", "< 2.0" # 2.0 requires Ruby 2.5+
20
+ s.add_dependency "mixlib-cli"
20
21
  s.add_dependency "mixlib-config", "~> 2.0"
21
- s.add_dependency "mixlib-log", ">= 1.7.1", "< 2.0"
22
+ s.add_dependency "mixlib-log", "~> 2.0", ">= 2.0.1"
22
23
  s.add_dependency "mixlib-shellout", "~> 2.0"
23
24
  s.add_dependency "plist", "~> 3.1"
24
25
  s.add_dependency "ipaddress"
25
26
  s.add_dependency "wmi-lite", "~> 1.0"
26
27
  s.add_dependency "ffi", "~> 1.9"
27
- s.add_dependency "chef-config", ">= 12.5.0.alpha.1", "< 14"
28
+ s.add_dependency "chef-config", ">= 12.8", "< 15"
28
29
  # Note for ohai developers: If chef-config causes you grief, try:
29
30
  # bundle install --with development
30
31
  # this should work as long as chef is a development dependency in Gemfile.
@@ -34,5 +35,5 @@ Gem::Specification.new do |s|
34
35
  s.executables = %w{ohai}
35
36
 
36
37
  s.require_path = "lib"
37
- s.files = %w{LICENSE README.md Gemfile Rakefile} + Dir.glob("*.gemspec") + Dir.glob("{lib,spec}/**/*")
38
+ s.files = %w{LICENSE README.md Gemfile Rakefile} + Dir.glob("*.gemspec") + Dir.glob("{docs,lib,spec}/**/*")
38
39
  end
@@ -24,9 +24,9 @@ describe Ohai::System, "root_group plugin" do
24
24
  let(:plugin) { get_plugin("root_group") }
25
25
 
26
26
  describe "windows platform", :windows_only do
27
- let (:wmi) { wmi = WmiLite::Wmi.new }
27
+ let(:wmi) { WmiLite::Wmi.new }
28
28
 
29
- it 'should return the system\'s administrators (root) group' do
29
+ it "should return the system's administrators (root) group" do
30
30
  # Notethat the Win32_Group WMI provider can be slow if your
31
31
  # system is domain-joined and has hundreds of thousands of
32
32
  # groups in Active Directory -- not a typical test scenario, but
@@ -49,33 +49,4 @@ describe Ohai::System, "Windows plugin uptime" do
49
49
  expect(uptime_plugin[:uptime]).to eq("22 hours 18 minutes 51 seconds")
50
50
  end
51
51
  end
52
-
53
- context "for older version of Windows" do
54
- let(:uptime_plugin) do
55
- get_plugin("uptime").tap do |plugin|
56
- plugin[:platform_version] = "5.0.2195"
57
- end
58
- end
59
-
60
- let(:wmi) do
61
- double("wmi", { :first_of =>
62
- { "systemuptime" => "785345" },
63
- })
64
- end
65
-
66
- before(:each) do
67
- allow(uptime_plugin).to receive(:collect_os).and_return(:windows)
68
- allow(WmiLite::Wmi).to receive(:new).and_return(wmi)
69
- end
70
-
71
- it "should set uptime_seconds to uptime" do
72
- uptime_plugin.run
73
- expect(uptime_plugin[:uptime_seconds]).to be == 785345
74
- end
75
-
76
- it "should set uptime to a human readable value" do
77
- uptime_plugin.run
78
- expect(uptime_plugin[:uptime]).to eq("9 days 02 hours 09 minutes 05 seconds")
79
- end
80
- end
81
52
  end
@@ -62,8 +62,8 @@ shared_examples "Ohai::DSL::Plugin" do
62
62
  plugin.run
63
63
  end
64
64
 
65
- it "logs a message to debug" do
66
- expect(Ohai::Log).to receive(:debug).with(/Skipping disabled plugin TestPlugin/)
65
+ it "logs a message to trace" do
66
+ expect(plugin.logger).to receive(:trace).with(/Skipping disabled plugin TestPlugin/)
67
67
  plugin.run
68
68
  end
69
69
 
@@ -382,8 +382,9 @@ shared_examples "Ohai::DSL::Plugin" do
382
382
  end
383
383
 
384
384
  describe Ohai::DSL::Plugin::VersionVII do
385
+ let(:logger) { Ohai::Log }
385
386
  it "does not modify the plugin name when the plugin is named correctly" do
386
- plugin = Ohai.plugin(:FunkyVALIDpluginName) {}.new({})
387
+ plugin = Ohai.plugin(:FunkyVALIDpluginName) {}.new({}, logger)
387
388
  expect(plugin.name).to eql(:FunkyVALIDpluginName)
388
389
  end
389
390
 
@@ -435,13 +436,13 @@ describe Ohai::DSL::Plugin::VersionVII do
435
436
  end
436
437
 
437
438
  it "collects attributes across multiple plugin files" do
438
- plugin = Ohai.plugin(:Test) { provides("one") }
439
+ plugin = Ohai.plugin(:Test) { provides("one") } # rubocop: disable Lint/UselessAssignment
439
440
  plugin = Ohai.plugin(:Test) { provides("two", "three") }
440
441
  expect(plugin.provides_attrs).to eql(%w{one two three})
441
442
  end
442
443
 
443
444
  it "collects unique attributes" do
444
- plugin = Ohai.plugin(:Test) { provides("one") }
445
+ plugin = Ohai.plugin(:Test) { provides("one") } # rubocop: disable Lint/UselessAssignment
445
446
  plugin = Ohai.plugin(:Test) { provides("one", "two") }
446
447
  expect(plugin.provides_attrs).to eql(%w{one two})
447
448
  end
@@ -468,13 +469,13 @@ describe Ohai::DSL::Plugin::VersionVII do
468
469
  end
469
470
 
470
471
  it "collects dependencies across multiple plugin files" do
471
- plugin = Ohai.plugin(:Test) { depends("one") }
472
+ plugin = Ohai.plugin(:Test) { depends("one") } # rubocop: disable Lint/UselessAssignment
472
473
  plugin = Ohai.plugin(:Test) { depends("two", "three") }
473
474
  expect(plugin.depends_attrs).to eql(%w{one two three})
474
475
  end
475
476
 
476
477
  it "collects unique attributes" do
477
- plugin = Ohai.plugin(:Test) { depends("one") }
478
+ plugin = Ohai.plugin(:Test) { depends("one") } # rubocop: disable Lint/UselessAssignment
478
479
  plugin = Ohai.plugin(:Test) { depends("one", "two") }
479
480
  expect(plugin.depends_attrs).to eql(%w{one two})
480
481
  end
@@ -538,16 +539,16 @@ describe Ohai::DSL::Plugin::VersionVII do
538
539
 
539
540
  describe "#provides (deprecated)" do
540
541
  it "logs a warning" do
541
- plugin = Ohai::DSL::Plugin::VersionVII.new(Mash.new)
542
- expect(Ohai::Log).to receive(:warn).with(/\[UNSUPPORTED OPERATION\]/)
542
+ plugin = Ohai.plugin(:Test).new(Mash.new, logger)
543
+ expect_any_instance_of(Mixlib::Log::Child).to receive(:warn).with(/\[UNSUPPORTED OPERATION\]/)
543
544
  plugin.provides("attribute")
544
545
  end
545
546
  end
546
547
 
547
548
  describe "#require_plugin (deprecated)" do
548
549
  it "logs a warning" do
549
- plugin = Ohai::DSL::Plugin::VersionVII.new(Mash.new)
550
- expect(Ohai::Log).to receive(:warn).with(/\[UNSUPPORTED OPERATION\]/)
550
+ plugin = Ohai.plugin(:Test).new(Mash.new, logger)
551
+ expect_any_instance_of(Mixlib::Log::Child).to receive(:warn).with(/\[UNSUPPORTED OPERATION\]/)
551
552
  plugin.require_plugin("plugin")
552
553
  end
553
554
  end
@@ -555,7 +556,7 @@ describe Ohai::DSL::Plugin::VersionVII do
555
556
  describe "#configuration" do
556
557
  let(:plugin) do
557
558
  klass = Ohai.plugin(camel_name) {}
558
- klass.new({})
559
+ klass.new({}, logger)
559
560
  end
560
561
 
561
562
  shared_examples_for "plugin config lookup" do
@@ -627,40 +628,7 @@ describe Ohai::DSL::Plugin::VersionVII do
627
628
 
628
629
  it_behaves_like "Ohai::DSL::Plugin" do
629
630
  let(:ohai) { Ohai::System.new }
630
- let(:plugin) { Ohai::DSL::Plugin::VersionVII.new(ohai.data) }
631
+ let(:plugin) { Ohai.plugin(:Test).new(ohai.data, ohai.logger) }
631
632
  let(:version) { :version7 }
632
633
  end
633
634
  end
634
-
635
- describe Ohai::DSL::Plugin::VersionVI do
636
- describe "#version" do
637
- it "saves the plugin version as :version6" do
638
- plugin = Class.new(Ohai::DSL::Plugin::VersionVI) {}
639
- expect(plugin.version).to eql(:version6)
640
- end
641
- end
642
-
643
- describe "#provides" do
644
- let(:ohai) { Ohai::System.new }
645
-
646
- it "logs a debug message when provides is used" do
647
- allow(Ohai::Log).to receive(:debug)
648
- expect(Ohai::Log).to receive(:debug).with(/Skipping provides/)
649
- plugin = Ohai::DSL::Plugin::VersionVI.new(ohai, "/some/plugin/path.rb", "/some/plugin")
650
- plugin.provides("attribute")
651
- end
652
-
653
- it "does not update the provides map for version 6 plugins." do
654
- plugin = Ohai::DSL::Plugin::VersionVI.new(ohai, "/some/plugin/path.rb", "/some/plugin")
655
- plugin.provides("attribute")
656
- expect(ohai.provides_map.map).to be_empty
657
- end
658
-
659
- end
660
-
661
- it_behaves_like "Ohai::DSL::Plugin" do
662
- let(:ohai) { Ohai::System.new }
663
- let(:plugin) { Ohai::DSL::Plugin::VersionVI.new(ohai, "/some/plugin/path.rb", "/some/plugin") }
664
- let(:version) { :version6 }
665
- end
666
- end