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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 573fdb3e8bef180043ca49fa188ce03e9901ad3d
4
- data.tar.gz: c3dae0cc5e5b33668abdc8a12c250899dd6d5a11
3
+ metadata.gz: 09b47a615ee064d16781e8ce7a847d71035d535a
4
+ data.tar.gz: fd200214865bb27d7ebce651d06798ac8d1b401a
5
5
  SHA512:
6
- metadata.gz: 6b1b0e211f59a13907e7d573aa7cffee857568db53c7a36aadb3843fabbce25c3f652634258382f1b801296c9a7a1601dc93a0d93521c60b33b1237882e78b62
7
- data.tar.gz: 2191d554c332033d0a028f1add4a6c3ae0e304954a8ba470f1a336e7e8cef5e4a4393c0e45661e22438fe6e5ce598b6869ae819163b7e7c5f214d22f82fb0800
6
+ metadata.gz: 42971e6add7b1e917f52bd5d416d622555c03764ae6c7e8090cf945ab77e0fba561719c7e8c4210169f164b2967a68df5cda3d6c5ed8ce87522a618466bf22de
7
+ data.tar.gz: b34aa2275ff4f580d1c37de0234a92ff7a0e6b1a98161e38e8c0ebbe4f7c0fa9aef36c1dcccc21a42a7deb99d920e9830214932ef6720adf247a81b17752772e
data/Gemfile CHANGED
@@ -5,7 +5,7 @@ gemspec
5
5
  group :development do
6
6
  gem "sigar", :platform => "ruby"
7
7
 
8
- gem "chefstyle", "= 0.3.1"
8
+ gem "chefstyle", "= 0.4.0"
9
9
  gem "overcommit", ">= 0.34.1"
10
10
  gem "pry-byebug"
11
11
  gem "pry-stack_explorer"
@@ -24,7 +24,7 @@ module Ohai
24
24
  # all-lowercase, all non-alphanumeric converted to '_'
25
25
  # 128-255 are 'oem_data_[id]'
26
26
  # Everything else is 'unknown'
27
- IdToDescription = {
27
+ ID_TO_DESCRIPTION = {
28
28
  0 => "bios",
29
29
  1 => "system",
30
30
  2 => "base_board",
@@ -71,7 +71,7 @@ module Ohai
71
71
 
72
72
  # list of IDs to collect, otherwise we generate pages of hashes about cache chip size and whatnot
73
73
  # See OHAI-260. When we can give the user a choice, this will be a default.
74
- IdToCapture = [ 0, 1, 2, 3, 4, 6, 11 ]
74
+ ID_TO_CAPTURE = [ 0, 1, 2, 3, 4, 6, 11 ]
75
75
 
76
76
  # look up DMI ID
77
77
  def id_lookup(id)
@@ -79,8 +79,8 @@ module Ohai
79
79
  id = id.to_i
80
80
  if (id >= 128) && (id <= 255)
81
81
  id = "oem_data_#{id}"
82
- elsif DMI::IdToDescription.has_key?(id)
83
- id = DMI::IdToDescription[id]
82
+ elsif DMI::ID_TO_DESCRIPTION.has_key?(id)
83
+ id = DMI::ID_TO_DESCRIPTION[id]
84
84
  else
85
85
  Ohai::Log.debug("unrecognized header id; falling back to 'unknown'")
86
86
  id = "unknown"
@@ -95,12 +95,12 @@ module Ohai
95
95
  # for single occurrences of one type, copy to top level all fields and values
96
96
  # for multiple occurrences of same type, copy to top level all fields and values that are common to all records
97
97
  def convenience_keys(dmi)
98
- dmi.each { |type, records|
98
+ dmi.each do |type, records|
99
99
  in_common = Mash.new
100
100
  next unless records.class.to_s == "Mash"
101
101
  next unless records.has_key?("all_records")
102
- records[:all_records].each { |record|
103
- record.each { |field, value|
102
+ records[:all_records].each do |record|
103
+ record.each do |field, value|
104
104
  next if value.class.to_s == "Mash"
105
105
  next if field.to_s == "application_identifier"
106
106
  next if field.to_s == "size"
@@ -112,13 +112,13 @@ module Ohai
112
112
  else
113
113
  in_common[translated] = value
114
114
  end
115
- }
116
- }
117
- in_common.each { |field, value|
115
+ end
116
+ end
117
+ in_common.each do |field, value|
118
118
  next if value == nil
119
119
  dmi[type][field] = value.strip
120
- }
121
- }
120
+ end
121
+ end
122
122
  end
123
123
 
124
124
  module_function :id_lookup, :convenience_keys
@@ -31,29 +31,28 @@ module Ohai
31
31
  # These methods need to be defined before they are used as config defaults,
32
32
  # otherwise they will get method_missing'd to nil.
33
33
 
34
- private
35
-
36
- def self.default_hints_path
37
- [ ChefConfig::Config.platform_specific_path("/etc/chef/ohai/hints") ]
38
- end
39
-
40
- def self.default_plugin_path
41
- [ File.expand_path(File.join(File.dirname(__FILE__), "plugins")) ]
42
- end
34
+ class << self
35
+ def merge_deprecated_config
36
+ [ :hints_path, :plugin_path ].each do |option|
37
+ if has_key?(option) && send(option) != send("default_#{option}".to_sym)
38
+ Ohai::Log.warn(option_deprecated(option))
39
+ end
40
+ end
43
41
 
44
- public
42
+ ohai.merge!(configuration)
43
+ end
45
44
 
46
- # Copy deprecated configuration options into the ohai config context.
47
- def self.merge_deprecated_config
48
- [ :hints_path, :plugin_path ].each do |option|
49
- if has_key?(option) && send(option) != send("default_#{option}".to_sym)
50
- Ohai::Log.warn(option_deprecated(option))
51
- end
45
+ def default_hints_path
46
+ [ ChefConfig::Config.platform_specific_path("/etc/chef/ohai/hints") ]
52
47
  end
53
48
 
54
- ohai.merge!(configuration)
49
+ def default_plugin_path
50
+ [ File.expand_path(File.join(File.dirname(__FILE__), "plugins")) ]
51
+ end
55
52
  end
56
53
 
54
+ # Copy deprecated configuration options into the ohai config context.
55
+
57
56
  # Keep "old" config defaults around so anyone calling Ohai::Config[:key]
58
57
  # won't be broken. Also allows users to append to configuration options
59
58
  # (e.g., Ohai::Config[:plugin_path] << some_path) in their config files.
@@ -86,8 +85,11 @@ module Ohai
86
85
  # Furthermore, when the top-level config settings are removed we will
87
86
  # need to ensure that Ohai.config[:log_level] can be set by writing
88
87
  # log_level in a configuration file for consistent behavior with chef.
89
- deprecation_warning = [ :log_level, :log_location ].include?(value) ?
90
- option_might_be_deprecated(option) : option_deprecated(option)
88
+ deprecation_warning = if [ :log_level, :log_location ].include?(value)
89
+ option_might_be_deprecated(option)
90
+ else
91
+ option_deprecated(option)
92
+ end
91
93
  Ohai::Log.warn(deprecation_warning)
92
94
  value
93
95
  end
@@ -102,22 +104,22 @@ module Ohai
102
104
  default :plugin_path, Ohai::Config.default_plugin_path
103
105
  end
104
106
 
105
- private
106
-
107
- def self.option_deprecated(option)
108
- <<-EOM.chomp!.tr("\n", " ")
107
+ class << self
108
+ def option_deprecated(option)
109
+ <<-EOM.chomp!.tr("\n", " ")
109
110
  Ohai::Config[:#{option}] is set. Ohai::Config[:#{option}] is deprecated and will
110
111
  be removed in future releases of ohai. Use ohai.#{option} in your configuration
111
112
  file to configure :#{option} for ohai.
112
- EOM
113
- end
113
+ EOM
114
+ end
114
115
 
115
- def self.option_might_be_deprecated(option)
116
- option_deprecated(option) + <<-EOM.chomp!.tr("\n", " ")
116
+ def option_might_be_deprecated(option)
117
+ option_deprecated(option) + <<-EOM.chomp!.tr("\n", " ")
117
118
  If your configuration file is used with other applications which configure
118
119
  :#{option}, and you have not configured Ohai::Config[:#{option}], you may
119
120
  disregard this warning.
120
- EOM
121
+ EOM
122
+ end
121
123
  end
122
124
  end
123
125
 
@@ -35,7 +35,7 @@ module Ohai
35
35
  # specified by calling `require_plugin` with a relative path. To manage
36
36
  # this, we track the path and root of each file as we discover them so we
37
37
  # can feed this into the v6 "dependency solver" as we load them.
38
- class PluginFile < Struct.new(:path, :plugin_root)
38
+ PluginFile = Struct.new(:path, :plugin_root) do
39
39
 
40
40
  # Finds all the *.rb files under the configured paths in :plugin_path
41
41
  def self.find_all_in(plugin_dir)
@@ -177,7 +177,7 @@ module Ohai
177
177
  $VERBOSE = nil
178
178
  ps.last.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
179
179
 
180
- cid = fork {
180
+ cid = fork do
181
181
  Process.setsid
182
182
 
183
183
  pw.last.close
@@ -226,7 +226,7 @@ module Ohai
226
226
  end
227
227
  ps.last.close unless ps.last.closed?
228
228
  exit!
229
- }
229
+ end
230
230
  ensure
231
231
  $VERBOSE = verbose
232
232
  end
@@ -75,7 +75,7 @@ Ohai.plugin(:DMI) do
75
75
 
76
76
  elsif handle = handle_line.match(line)
77
77
  # Don't overcapture for now (OHAI-260)
78
- unless Ohai::Common::DMI::IdToCapture.include?(handle[2].to_i)
78
+ unless Ohai::Common::DMI::ID_TO_CAPTURE.include?(handle[2].to_i)
79
79
  dmi_record = nil
80
80
  next
81
81
  end
@@ -24,10 +24,10 @@ Ohai.plugin(:IpScopes) do
24
24
  begin
25
25
  require "ipaddr_extensions"
26
26
 
27
- network["interfaces"].keys.sort.each do |ifName|
28
- next if network["interfaces"][ifName]["addresses"].nil?
27
+ network["interfaces"].keys.sort.each do |if_name|
28
+ next if network["interfaces"][if_name]["addresses"].nil?
29
29
 
30
- interface = network["interfaces"][ifName]
30
+ interface = network["interfaces"][if_name]
31
31
  interface["addresses"].each do |address, attrs|
32
32
  begin
33
33
  attrs["ip_scope"] = address.to_ip.scope
@@ -156,6 +156,10 @@ Ohai.plugin(:Kernel) do
156
156
  so = shell_out("uname -s")
157
157
  kernel[:os] = so.stdout.split($/)[0]
158
158
 
159
+ so = File.open("/etc/release") { |file| file.gets }
160
+ md = /(?<update>\d.*\d)/.match(so)
161
+ kernel[:update] = md[:update] if md
162
+
159
163
  modules = Mash.new
160
164
 
161
165
  so = shell_out("modinfo")
@@ -0,0 +1,34 @@
1
+ #
2
+ # Author:: Davide Cavalca (<dcavalca@fb.com>)
3
+ # Copyright:: Copyright (c) 2016 Facebook
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ Ohai.plugin(:Hostnamectl) do
20
+ provides "hostnamectl"
21
+
22
+ collect_data(:linux) do
23
+ hostnamectl Mash.new unless hostnamectl
24
+
25
+ hostnamectl_path = which("hostnamectl")
26
+ if hostnamectl_path
27
+ hostnamectl_cmd = shell_out(hostnamectl_path)
28
+ hostnamectl_cmd.stdout.split("\n").each do |line|
29
+ key, val = line.split(":")
30
+ hostnamectl[key.chomp.lstrip.tr(" ", "_").downcase] = val.chomp.lstrip
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,35 @@
1
+ #
2
+ # Author:: Davide Cavalca (<dcavalca@fb.com>)
3
+ # Copyright:: Copyright (c) 2016 Facebook
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ Ohai.plugin(:Machineid) do
20
+ provides "machine_id"
21
+
22
+ collect_data(:linux) do
23
+ mid = nil
24
+
25
+ if File.exists?("/etc/machine-id")
26
+ mid = File.read("/etc/machine-id").chomp
27
+ elsif File.exists?("/var/lib/dbus/machine-id")
28
+ mid = File.read("/var/lib/dbus/machine-id").chomp
29
+ end
30
+
31
+ if mid
32
+ machine_id mid
33
+ end
34
+ end
35
+ end
@@ -380,7 +380,7 @@ Ohai.plugin(:Network) do
380
380
  end
381
381
 
382
382
  def interface_address_not_link_level?(iface, address)
383
- iface[:addresses][address][:scope].downcase != "link"
383
+ !iface[:addresses][address][:scope].casecmp("link").zero?
384
384
  end
385
385
 
386
386
  def interface_valid_for_route?(iface, address, family)
@@ -194,5 +194,15 @@ Ohai.plugin(:Virtualization) do
194
194
  virtualization[:role] = "guest"
195
195
  virtualization[:systems][:docker] = "guest"
196
196
  end
197
+
198
+ # Detect LXD
199
+ # See https://github.com/lxc/lxd/blob/master/doc/dev-lxd.md
200
+ if File.exist?("/dev/lxd/sock")
201
+ virtualization[:system] = "lxd"
202
+ virtualization[:role] = "guest"
203
+ elsif File.exist?("/var/lib/lxd/devlxd")
204
+ virtualization[:system] = "lxd"
205
+ virtualization[:role] = "host"
206
+ end
197
207
  end
198
208
  end
@@ -38,7 +38,7 @@ Ohai.plugin(:Rackspace) do
38
38
  def has_rackspace_metadata?
39
39
  so = shell_out("xenstore-read vm-data/provider_data/provider")
40
40
  if so.exitstatus == 0
41
- so.stdout.strip.downcase == "rackspace"
41
+ so.stdout.strip.casecmp("rackspace").zero?
42
42
  end
43
43
  rescue Ohai::Exceptions::Exec
44
44
  false
@@ -115,9 +115,9 @@ Ohai.plugin(:Rackspace) do
115
115
  if so.exitstatus == 0
116
116
  networks = []
117
117
  so.stdout.split("\n").map { |l| l.split("=").first.strip }.map do |item|
118
- _so = shell_out("xenstore-read vm-data/networking/#{item}")
119
- if _so.exitstatus == 0
120
- networks.push(FFI_Yajl::Parser.new.parse(_so.stdout))
118
+ so = shell_out("xenstore-read vm-data/networking/#{item}")
119
+ if so.exitstatus == 0
120
+ networks.push(FFI_Yajl::Parser.new.parse(so.stdout))
121
121
  else
122
122
  Ohai::Log.debug("rackspace plugin: Unable to capture custom private networking information for Rackspace cloud")
123
123
  return false
@@ -129,7 +129,7 @@ Ohai.plugin(:DMI) do
129
129
  id = smb_to_id[header_information[3]]
130
130
 
131
131
  # Don't overcapture for now (OHAI-260)
132
- unless Ohai::Common::DMI::IdToCapture.include?(id)
132
+ unless Ohai::Common::DMI::ID_TO_CAPTURE.include?(id)
133
133
  dmi_record = nil
134
134
  next
135
135
  end
@@ -44,10 +44,10 @@ Ohai.plugin(:Filesystem) do
44
44
  so.stdout.lines do |line|
45
45
  next unless line =~ /^(.+?)\s*: (\S+)\s*$/
46
46
  mount = $1
47
- fs.each { |filesystem, fs_attributes|
47
+ fs.each do |filesystem, fs_attributes|
48
48
  next unless fs_attributes[:mount] == mount
49
49
  fs[filesystem][:fs_type] = $2
50
- }
50
+ end
51
51
  end
52
52
 
53
53
  # Grab mount information from /bin/mount
@@ -82,7 +82,7 @@ Ohai.plugin(:Filesystem) do
82
82
  zfs[filesystem][:sources][$2] = $4.chomp
83
83
  end
84
84
 
85
- zfs.each { |filesystem, attributes|
85
+ zfs.each do |filesystem, attributes|
86
86
  fs[filesystem] = Mash.new unless fs.has_key?(filesystem)
87
87
  fs[filesystem][:fs_type] = "zfs"
88
88
  fs[filesystem][:mount] = attributes[:values][:mountpoint] if attributes[:values].has_key?("mountpoint")
@@ -91,14 +91,14 @@ Ohai.plugin(:Filesystem) do
91
91
  # find all zfs parents
92
92
  parents = filesystem.split("/")
93
93
  zfs_parents = []
94
- (0..parents.length - 1).to_a.each { |parent_indexes|
94
+ (0..parents.length - 1).to_a.each do |parent_indexes|
95
95
  next_parent = parents[0..parent_indexes].join("/")
96
96
  zfs_parents.push(next_parent)
97
- }
97
+ end
98
98
  zfs_parents.pop
99
99
  fs[filesystem][:zfs_parents] = zfs_parents
100
100
  fs[filesystem][:zfs_zpool] = (zfs_parents.length == 0)
101
- }
101
+ end
102
102
 
103
103
  # Set the filesystem data
104
104
  filesystem fs
@@ -170,14 +170,14 @@ Ohai.plugin(:Network) do
170
170
  matches = /interface: (?<name>\S+)\s+index\s+(?<index>\d+)/.match(line)
171
171
  if matches
172
172
  network[:default_interface] =
173
- case
174
- when iface[matches[:name]]
175
- matches[:name]
176
- when int_name = full_interface_name(iface, matches[:name], matches[:index])
177
- int_name
178
- else
179
- matches[:name]
180
- end
173
+ case
174
+ when iface[matches[:name]]
175
+ matches[:name]
176
+ when int_name = full_interface_name(iface, matches[:name], matches[:index])
177
+ int_name
178
+ else
179
+ matches[:name]
180
+ end
181
181
  Ohai::Log.debug("found interface device: #{network[:default_interface]} #{matches[:name]}")
182
182
  end
183
183
  matches = /gateway: (\S+)/.match(line)
@@ -54,9 +54,11 @@ Ohai.plugin(:CPU) do
54
54
  cpu[current_cpu]["vendor_id"] = processor["manufacturer"]
55
55
  cpu[current_cpu]["family"] = processor["family"].to_s
56
56
  cpu[current_cpu]["model"] = processor["revision"].to_s
57
- cpu[current_cpu]["stepping"] = processor["stepping"].nil? \
58
- ? processor["description"].match(/Stepping\s+(\d+)/)[1] \
59
- : processor["stepping"]
57
+ cpu[current_cpu]["stepping"] = if processor["stepping"].nil?
58
+ processor["description"].match(/Stepping\s+(\d+)/)[1]
59
+ else
60
+ processor["stepping"]
61
+ end
60
62
  cpu[current_cpu]["physical_id"] = processor["deviceid"]
61
63
  cpu[current_cpu]["model_name"] = processor["description"]
62
64
  cpu[current_cpu]["mhz"] = processor["maxclockspeed"].to_s