ohai 8.19.2 → 8.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/lib/ohai/common/dmi.rb +12 -12
  4. data/lib/ohai/config.rb +30 -28
  5. data/lib/ohai/loader.rb +1 -1
  6. data/lib/ohai/mixin/command.rb +2 -2
  7. data/lib/ohai/plugins/dmi.rb +1 -1
  8. data/lib/ohai/plugins/ip_scopes.rb +3 -3
  9. data/lib/ohai/plugins/kernel.rb +4 -0
  10. data/lib/ohai/plugins/linux/hostnamectl.rb +34 -0
  11. data/lib/ohai/plugins/linux/machineid.rb +35 -0
  12. data/lib/ohai/plugins/linux/network.rb +1 -1
  13. data/lib/ohai/plugins/linux/virtualization.rb +10 -0
  14. data/lib/ohai/plugins/rackspace.rb +4 -4
  15. data/lib/ohai/plugins/solaris2/dmi.rb +1 -1
  16. data/lib/ohai/plugins/solaris2/filesystem.rb +6 -6
  17. data/lib/ohai/plugins/solaris2/network.rb +8 -8
  18. data/lib/ohai/plugins/windows/cpu.rb +5 -3
  19. data/lib/ohai/plugins/windows/network.rb +59 -37
  20. data/lib/ohai/runner.rb +2 -2
  21. data/lib/ohai/system.rb +2 -2
  22. data/lib/ohai/version.rb +1 -1
  23. data/spec/functional/application_spec.rb +1 -1
  24. data/spec/support/integration_helper.rb +3 -3
  25. data/spec/unit/application_spec.rb +1 -1
  26. data/spec/unit/dsl/plugin_spec.rb +22 -22
  27. data/spec/unit/mixin/ec2_metadata_spec.rb +2 -2
  28. data/spec/unit/mixin/softlayer_metadata_spec.rb +2 -2
  29. data/spec/unit/plugin_config_spec.rb +6 -6
  30. data/spec/unit/plugins/aix/cpu_spec.rb +6 -6
  31. data/spec/unit/plugins/aix/filesystem_spec.rb +8 -8
  32. data/spec/unit/plugins/aix/virtualization_spec.rb +2 -2
  33. data/spec/unit/plugins/azure_spec.rb +2 -2
  34. data/spec/unit/plugins/darwin/hardware_spec.rb +3 -3
  35. data/spec/unit/plugins/darwin/hardware_system_profiler_output.rb +3 -3
  36. data/spec/unit/plugins/digital_ocean_spec.rb +2 -2
  37. data/spec/unit/plugins/init_package_spec.rb +2 -2
  38. data/spec/unit/plugins/ip_scopes_spec.rb +3 -2
  39. data/spec/unit/plugins/linux/hostnamectl_spec.rb +59 -0
  40. data/spec/unit/plugins/linux/machineid_spec.rb +46 -0
  41. data/spec/unit/plugins/linux/network_spec.rb +113 -77
  42. data/spec/unit/plugins/linux/platform_spec.rb +2 -2
  43. data/spec/unit/plugins/linux/virtualization_spec.rb +20 -0
  44. data/spec/unit/plugins/ruby_spec.rb +3 -2
  45. data/spec/unit/plugins/solaris2/kernel_spec.rb +23 -0
  46. data/spec/unit/runner_spec.rb +74 -74
  47. data/spec/unit/util/ip_helper_spec.rb +2 -2
  48. metadata +7 -3
@@ -25,6 +25,34 @@ Ohai.plugin(:Network) do
25
25
  encap
26
26
  end
27
27
 
28
+ def mac_addresses(iface)
29
+ prop = iface[:configuration][:mac_address] || iface[:instance][:network_addresses]
30
+ [prop].flatten.map { |addr| addr.include?(":") ? addr : addr.scan(/.{1,2}/).join(":") }
31
+ end
32
+
33
+ def network_data
34
+ @network_data ||= begin
35
+ data = {}
36
+ wmi = WmiLite::Wmi.new
37
+ data[:addresses] = wmi.instances_of("Win32_NetworkAdapterConfiguration")
38
+
39
+ # If we are running on windows nano or anothe roperating system from the future
40
+ # that does not populate the deprecated win32_* WMI classes, then we should
41
+ # grab data from the newer MSFT_* classes
42
+ return msft_adapter_data if data[:addresses].count.zero?
43
+ data[:adapters] = wmi.instances_of("Win32_NetworkAdapter")
44
+ data
45
+ end
46
+ end
47
+
48
+ def msft_adapter_data
49
+ data = {}
50
+ wmi = WmiLite::Wmi.new("ROOT/StandardCimv2")
51
+ data[:addresses] = wmi.instances_of("MSFT_NetIPAddress")
52
+ data[:adapters] = wmi.instances_of("MSFT_NetAdapter")
53
+ data
54
+ end
55
+
28
56
  collect_data(:windows) do
29
57
 
30
58
  require "wmi-lite/wmi"
@@ -37,26 +65,20 @@ Ohai.plugin(:Network) do
37
65
  counters Mash.new unless counters
38
66
  counters[:network] = Mash.new unless counters[:network]
39
67
 
40
- # http://msdn.microsoft.com/en-us/library/windows/desktop/aa394217%28v=vs.85%29.aspx
41
- wmi = WmiLite::Wmi.new
42
-
43
- adapters = wmi.instances_of("Win32_NetworkAdapterConfiguration")
44
-
45
- adapters.each do |adapter|
46
-
47
- i = adapter["index"]
48
- iface_config[i] = Mash.new
68
+ network_data[:addresses].each do |adapter|
69
+ i = adapter["index"] || adapter["InterfaceIndex"]
70
+ iface_config[i] = Mash.new unless iface_config[i]
71
+ iface_config[i][:ip_address] ||= []
72
+ iface_config[i][:ip_address] << adapter["IPAddress"]
49
73
  adapter.wmi_ole_object.properties_.each do |p|
50
- iface_config[i][p.name.wmi_underscore.to_sym] = adapter[p.name.downcase]
74
+ if iface_config[i][p.name.wmi_underscore.to_sym].nil?
75
+ iface_config[i][p.name.wmi_underscore.to_sym] = adapter[p.name.downcase]
76
+ end
51
77
  end
52
78
  end
53
79
 
54
- # http://msdn.microsoft.com/en-us/library/windows/desktop/aa394216(v=vs.85).aspx
55
-
56
- adapters = wmi.instances_of("Win32_NetworkAdapter")
57
-
58
- adapters.each do |adapter|
59
- i = adapter["index"]
80
+ network_data[:adapters].each do |adapter|
81
+ i = adapter["index"] || adapter["InterfaceIndex"]
60
82
  iface_instance[i] = Mash.new
61
83
  adapter.wmi_ole_object.properties_.each do |p|
62
84
  iface_instance[i][p.name.wmi_underscore.to_sym] = adapter[p.name.downcase]
@@ -64,45 +86,45 @@ Ohai.plugin(:Network) do
64
86
  end
65
87
 
66
88
  iface_instance.keys.each do |i|
67
- if iface_config[i][:ip_enabled] && iface_instance[i][:net_connection_id]
68
- cint = sprintf("0x%x", iface_instance[i][:interface_index] ? iface_instance[i][:interface_index] : iface_instance[i][:index] ).downcase
89
+ if iface_instance[i][:name] && iface_config[i] && iface_config[i][:ip_address][0]
90
+ cint = sprintf("0x%x", (iface_instance[i][:interface_index] || iface_instance[i][:index]) ).downcase
69
91
  iface[cint] = Mash.new
70
92
  iface[cint][:configuration] = iface_config[i]
71
93
  iface[cint][:instance] = iface_instance[i]
72
94
 
73
95
  iface[cint][:counters] = Mash.new
74
96
  iface[cint][:addresses] = Mash.new
75
- iface[cint][:configuration][:ip_address].each_index do |i|
76
- ip = iface[cint][:configuration][:ip_address][i]
77
- _ip = IPAddress("#{ip}/#{iface[cint][:configuration][:ip_subnet][i]}")
78
- iface[cint][:addresses][ip] = Mash.new(
79
- :prefixlen => _ip.prefix
80
- )
81
- if _ip.ipv6?
82
- # inet6 address
97
+ iface[cint][:configuration][:ip_address] = iface[cint][:configuration][:ip_address].flatten
98
+ iface[cint][:configuration][:ip_address].each_index do |ip_index|
99
+ ip = iface[cint][:configuration][:ip_address][ip_index]
100
+ ip_and_subnet = ip.dup
101
+ ip_and_subnet << "/#{iface[cint][:configuration][:ip_subnet][ip_index]}" if iface[cint][:configuration][:ip_subnet]
102
+ ip2 = IPAddress(ip_and_subnet)
103
+ iface[cint][:addresses][ip] = Mash.new(:prefixlen => ip2.prefix)
104
+ if ip2.ipv6?
83
105
  iface[cint][:addresses][ip][:family] = "inet6"
84
106
  iface[cint][:addresses][ip][:scope] = "Link" if ip =~ /^fe80/i
85
107
  else
86
- # should be an inet4 address
87
- iface[cint][:addresses][ip][:netmask] = _ip.netmask.to_s
88
- if iface[cint][:configuration][:ip_use_zero_broadcast]
89
- iface[cint][:addresses][ip][:broadcast] = _ip.network.to_s
90
- else
91
- iface[cint][:addresses][ip][:broadcast] = _ip.broadcast.to_s
108
+ if iface[cint][:configuration][:ip_subnet]
109
+ iface[cint][:addresses][ip][:netmask] = ip2.netmask.to_s
110
+ if iface[cint][:configuration][:ip_use_zero_broadcast]
111
+ iface[cint][:addresses][ip][:broadcast] = ip2.network.to_s
112
+ else
113
+ iface[cint][:addresses][ip][:broadcast] = ip2.broadcast.to_s
114
+ end
92
115
  end
93
116
  iface[cint][:addresses][ip][:family] = "inet"
94
117
  end
95
118
  end
96
- # Apparently you can have more than one mac_address? Odd.
97
- [iface[cint][:configuration][:mac_address]].flatten.each do |mac_addr|
119
+ mac_addresses(iface[cint]).each do |mac_addr|
98
120
  iface[cint][:addresses][mac_addr] = {
99
121
  "family" => "lladdr",
100
122
  }
101
123
  end
102
- iface[cint][:mtu] = iface[cint][:configuration][:mtu]
103
- iface[cint][:type] = iface[cint][:instance][:adapter_type]
124
+ iface[cint][:mtu] = iface[cint][:configuration][:mtu] if iface[cint][:configuration].has_key?(:mtu)
125
+ iface[cint][:type] = iface[cint][:instance][:adapter_type] if iface[cint][:instance][:adapter_type]
104
126
  iface[cint][:arp] = {}
105
- iface[cint][:encapsulation] = windows_encaps_lookup(iface[cint][:instance][:adapter_type])
127
+ iface[cint][:encapsulation] = windows_encaps_lookup(iface[cint][:instance][:adapter_type]) if iface[cint][:instance][:adapter_type]
106
128
  if iface[cint][:configuration][:default_ip_gateway] != nil && iface[cint][:configuration][:default_ip_gateway].size > 0
107
129
  network[:default_gateway] = iface[cint][:configuration][:default_ip_gateway].first
108
130
  network[:default_interface] = cint
@@ -76,9 +76,9 @@ module Ohai
76
76
 
77
77
  # Remove the already ran plugins from dependencies if force is not set
78
78
  # Also remove the plugin that we are about to run from dependencies as well.
79
- dependency_providers.delete_if { |dep_plugin|
79
+ dependency_providers.delete_if do |dep_plugin|
80
80
  dep_plugin.has_run? || dep_plugin.eql?(next_plugin)
81
- }
81
+ end
82
82
 
83
83
  if dependency_providers.empty?
84
84
  @safe_run ? next_plugin.safe_run : next_plugin.run
@@ -94,9 +94,9 @@ module Ohai
94
94
 
95
95
  # Then run all the version 7 plugins
96
96
  begin
97
- @provides_map.all_plugins(attribute_filter).each { |plugin|
97
+ @provides_map.all_plugins(attribute_filter).each do |plugin|
98
98
  @runner.run_plugin(plugin)
99
- }
99
+ end
100
100
  rescue Ohai::Exceptions::AttributeNotFound, Ohai::Exceptions::DependencyCycle => e
101
101
  Ohai::Log.error("Encountered error while running plugins: #{e.inspect}")
102
102
  raise
@@ -18,5 +18,5 @@
18
18
 
19
19
  module Ohai
20
20
  OHAI_ROOT = File.expand_path(File.dirname(__FILE__))
21
- VERSION = "8.19.2"
21
+ VERSION = "8.20.0"
22
22
  end
@@ -35,7 +35,7 @@ RSpec.describe "Ohai::Application" do
35
35
  ARGV.replace(@original_argv)
36
36
  end
37
37
 
38
- describe '#configure_ohai' do
38
+ describe "#configure_ohai" do
39
39
 
40
40
  let(:config_content) { "" }
41
41
  let(:config_dir) { Dir.mktmpdir(".chef") }
@@ -18,7 +18,7 @@ module IntegrationSupport
18
18
  end
19
19
  end
20
20
 
21
- def with_plugin(plugin_path, contents)
21
+ def with_plugin(plugin_path, contents) # rubocop:disable Lint/NestedMethodDefinition
22
22
  filename = path_to(plugin_path)
23
23
  dir = File.dirname(filename)
24
24
  FileUtils.mkdir_p(dir) unless dir == "."
@@ -27,11 +27,11 @@ module IntegrationSupport
27
27
  end
28
28
  end
29
29
 
30
- def path_to(plugin_path)
30
+ def path_to(plugin_path) # rubocop:disable Lint/NestedMethodDefinition
31
31
  File.expand_path(plugin_path, @plugins_directory)
32
32
  end
33
33
 
34
- def self.with_plugin(plugin_path, contents)
34
+ def self.with_plugin(plugin_path, contents) # rubocop:disable Lint/NestedMethodDefinition
35
35
  before :each do
36
36
  with_plugin(plugin_path, contents)
37
37
  end
@@ -34,7 +34,7 @@ RSpec.describe "Ohai::Application" do
34
34
  ARGV.replace(@original_argv)
35
35
  end
36
36
 
37
- describe '#configure_ohai' do
37
+ describe "#configure_ohai" do
38
38
  describe "loading configuration from a file" do
39
39
  let(:config_file) { "/local/workstation/config" }
40
40
  let(:config_loader) { instance_double("ChefConfig::WorkstationConfigLoader") }
@@ -170,10 +170,10 @@ shared_examples "Ohai::DSL::Plugin" do
170
170
 
171
171
  describe "and an intermediate key is not a hash" do
172
172
  it "raises a TypeError" do
173
- expect {
173
+ expect do
174
174
  plugin.get_attribute("the_monarch", "arch_rival",
175
175
  "dr_venture", "since")
176
- }.to raise_error(TypeError,
176
+ end.to raise_error(TypeError,
177
177
  "Expected Hash but got String.")
178
178
  end
179
179
  end
@@ -204,10 +204,10 @@ shared_examples "Ohai::DSL::Plugin" do
204
204
 
205
205
  describe "and an intermediate key is not a hash" do
206
206
  it "raises a TypeError" do
207
- expect {
207
+ expect do
208
208
  plugin.get_attribute(:the_monarch, :arch_rival,
209
209
  :dr_venture, :since)
210
- }.to raise_error(TypeError,
210
+ end.to raise_error(TypeError,
211
211
  "Expected Hash but got String.")
212
212
  end
213
213
  end
@@ -277,10 +277,10 @@ shared_examples "Ohai::DSL::Plugin" do
277
277
 
278
278
  describe "and an intermediate key is not a hash" do
279
279
  it "raises a TypeError" do
280
- expect {
280
+ expect do
281
281
  plugin.attribute?("the_monarch", "arch_rival",
282
282
  "dr_venture", "since")
283
- }.to raise_error(TypeError,
283
+ end.to raise_error(TypeError,
284
284
  "Expected Hash but got String.")
285
285
  end
286
286
  end
@@ -310,10 +310,10 @@ shared_examples "Ohai::DSL::Plugin" do
310
310
 
311
311
  describe "and an intermediate key is not a hash" do
312
312
  it "raises a TypeError" do
313
- expect {
313
+ expect do
314
314
  plugin.attribute?(:the_monarch, :arch_rival,
315
315
  :dr_venture, :since)
316
- }.to raise_error(TypeError,
316
+ end.to raise_error(TypeError,
317
317
  "Expected Hash but got String.")
318
318
  end
319
319
  end
@@ -369,11 +369,11 @@ describe Ohai::DSL::Plugin::VersionVII do
369
369
  end
370
370
 
371
371
  it "collects from multiple provides statements" do
372
- plugin = Ohai.plugin(:Test) {
372
+ plugin = Ohai.plugin(:Test) do
373
373
  provides("one")
374
374
  provides("two", "three")
375
375
  provides("four")
376
- }
376
+ end
377
377
  expect(plugin.provides_attrs).to eql(%w{one two three four})
378
378
  end
379
379
 
@@ -402,11 +402,11 @@ describe Ohai::DSL::Plugin::VersionVII do
402
402
  end
403
403
 
404
404
  it "collects from multiple depends statements" do
405
- plugin = Ohai.plugin(:Test) {
405
+ plugin = Ohai.plugin(:Test) do
406
406
  depends("one")
407
407
  depends("two", "three")
408
408
  depends("four")
409
- }
409
+ end
410
410
  expect(plugin.depends_attrs).to eql(%w{one two three four})
411
411
  end
412
412
 
@@ -442,11 +442,11 @@ describe Ohai::DSL::Plugin::VersionVII do
442
442
  end
443
443
 
444
444
  it "saves multiple collect_data blocks" do
445
- plugin = Ohai.plugin(:Test) {
445
+ plugin = Ohai.plugin(:Test) do
446
446
  collect_data {}
447
447
  collect_data(:windows) {}
448
448
  collect_data(:darwin) {}
449
- }
449
+ end
450
450
  [:darwin, :default, :windows].each do |platform|
451
451
  expect(plugin.data_collector).to have_key(platform)
452
452
  end
@@ -461,21 +461,21 @@ describe Ohai::DSL::Plugin::VersionVII do
461
461
  end
462
462
 
463
463
  it "fails a platform has already been defined in the same plugin" do
464
- expect {
465
- Ohai.plugin(:Test) {
464
+ expect do
465
+ Ohai.plugin(:Test) do
466
466
  collect_data {}
467
467
  collect_data {}
468
- }
469
- }.to raise_error(Ohai::Exceptions::IllegalPluginDefinition, /collect_data already defined/)
468
+ end
469
+ end.to raise_error(Ohai::Exceptions::IllegalPluginDefinition, /collect_data already defined/)
470
470
  end
471
471
 
472
472
  it "fails if a platform has already been defined in another plugin file" do
473
473
  Ohai.plugin(:Test) { collect_data {} }
474
- expect {
475
- Ohai.plugin(:Test) {
474
+ expect do
475
+ Ohai.plugin(:Test) do
476
476
  collect_data {}
477
- }
478
- }.to raise_error(Ohai::Exceptions::IllegalPluginDefinition, /collect_data already defined/)
477
+ end
478
+ end.to raise_error(Ohai::Exceptions::IllegalPluginDefinition, /collect_data already defined/)
479
479
  end
480
480
  end
481
481
 
@@ -20,13 +20,13 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper.rb")
20
20
  require "ohai/mixin/ec2_metadata"
21
21
 
22
22
  describe Ohai::Mixin::Ec2Metadata do
23
- let(:mixin) {
23
+ let(:mixin) do
24
24
  metadata_object = Object.new.extend(Ohai::Mixin::Ec2Metadata)
25
25
  http_client = double("Net::HTTP client")
26
26
  allow(http_client).to receive(:get).and_return(response)
27
27
  allow(metadata_object).to receive(:http_client).and_return(http_client)
28
28
  metadata_object
29
- }
29
+ end
30
30
 
31
31
  context "#best_api_version" do
32
32
  context "with a sorted list of metadata versions" do
@@ -22,10 +22,10 @@ require "ohai/mixin/softlayer_metadata"
22
22
 
23
23
  describe ::Ohai::Mixin::SoftlayerMetadata do
24
24
 
25
- let(:mixin) {
25
+ let(:mixin) do
26
26
  mixin = Object.new.extend(::Ohai::Mixin::SoftlayerMetadata)
27
27
  mixin
28
- }
28
+ end
29
29
 
30
30
  def make_request(item)
31
31
  "/rest/v3.1/SoftLayer_Resource_Metadata/#{item}"
@@ -52,13 +52,13 @@ describe "Ohai::PluginConfig" do
52
52
 
53
53
  describe "when all Hash keys are symbols" do
54
54
 
55
- let(:value) {
55
+ let(:value) do
56
56
  {
57
57
  :bar0 => true,
58
58
  :bar1 => [ :baz0, :baz1, :baz2 ],
59
59
  :bar2 => { :qux0 => true, :qux1 => false },
60
60
  }
61
- }
61
+ end
62
62
 
63
63
  include_examples "success"
64
64
 
@@ -66,13 +66,13 @@ describe "Ohai::PluginConfig" do
66
66
 
67
67
  describe "when some top-level Hash key is not a symbol" do
68
68
 
69
- let(:value) {
69
+ let(:value) do
70
70
  {
71
71
  :bar0 => true,
72
72
  "bar1" => [ :baz0, :baz1, :baz2 ],
73
73
  :bar2 => { :qux0 => true, :qux1 => false },
74
74
  }
75
- }
75
+ end
76
76
 
77
77
  include_examples "failure"
78
78
 
@@ -80,13 +80,13 @@ describe "Ohai::PluginConfig" do
80
80
 
81
81
  describe "when some nested Hash key is not a symbol" do
82
82
 
83
- let(:value) {
83
+ let(:value) do
84
84
  {
85
85
  :bar0 => true,
86
86
  :bar1 => [ :baz0, :baz1, :baz2 ],
87
87
  :bar2 => { :qux0 => true, "qux1" => false },
88
88
  }
89
- }
89
+ end
90
90
 
91
91
  include_examples "failure"
92
92
 
@@ -20,12 +20,12 @@ require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper.rb")
20
20
 
21
21
  describe Ohai::System, "AIX cpu plugin" do
22
22
  before(:each) do
23
- @lsdev_Cc_processor = <<-LSDEV_CC_PROCESSOR
23
+ @lsdev_cc_processor = <<-LSDEV_CC_PROCESSOR
24
24
  proc0 Available 00-00 Processor
25
25
  proc4 Defined 00-04 Processor
26
26
  LSDEV_CC_PROCESSOR
27
27
 
28
- @lsattr_El_proc0 = <<-LSATTR_EL
28
+ @lsattr_el_proc0 = <<-LSATTR_EL
29
29
  frequency 1654344000 Processor Speed False
30
30
  smt_enabled true Processor SMT enabled False
31
31
  smt_threads 2 Processor SMT threads False
@@ -43,8 +43,8 @@ PMCYCLES_M
43
43
  @plugin = get_plugin("aix/cpu")
44
44
  allow(@plugin).to receive(:collect_os).and_return(:aix)
45
45
 
46
- allow(@plugin).to receive(:shell_out).with("lsdev -Cc processor").and_return(mock_shell_out(0, @lsdev_Cc_processor, nil))
47
- allow(@plugin).to receive(:shell_out).with("lsattr -El proc0").and_return(mock_shell_out(0, @lsattr_El_proc0, nil))
46
+ allow(@plugin).to receive(:shell_out).with("lsdev -Cc processor").and_return(mock_shell_out(0, @lsdev_cc_processor, nil))
47
+ allow(@plugin).to receive(:shell_out).with("lsattr -El proc0").and_return(mock_shell_out(0, @lsattr_el_proc0, nil))
48
48
  allow(@plugin).to receive(:shell_out).with("pmcycles -m").and_return(mock_shell_out(0, @pmcycles_m, nil))
49
49
  end
50
50
 
@@ -119,9 +119,9 @@ PMCYCLES_M
119
119
 
120
120
  it "doesn't set mhz of a processor it can't see" do
121
121
  # I'm so sorry
122
- expect {
122
+ expect do
123
123
  expect(@plugin[:cpu]["0"][:mhz]).to eq(1654)
124
- }.to raise_error(NoMethodError)
124
+ end.to raise_error(NoMethodError)
125
125
  end
126
126
  end
127
127
  end