ohai 13.0.1 → 13.1.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.
- checksums.yaml +4 -4
- data/lib/ohai/loader.rb +2 -2
- data/lib/ohai/mixin/command.rb +5 -0
- data/lib/ohai/mixin/ec2_metadata.rb +37 -38
- data/lib/ohai/plugins/linux/mdadm.rb +10 -3
- data/lib/ohai/version.rb +1 -1
- data/spec/unit/mixin/command_spec.rb +13 -4
- data/spec/unit/plugins/ec2_spec.rb +1 -1
- data/spec/unit/plugins/eucalyptus_spec.rb +1 -1
- data/spec/unit/plugins/linux/mdadm_spec.rb +6 -0
- data/spec/unit/plugins/openstack_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a790e9dca44c313d60c13521eddb5f71fb17d95
|
4
|
+
data.tar.gz: b42fe376d2bc0ae29386b3d5e90607e65f47050a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9280f45b479f112e18e8118db63f9b091c94eab2a08756f3e306ee4fc23d4bba4246550c6c1e5d9fb2e2293eaeeac11da6946af12778258b3f96c5c236b13910
|
7
|
+
data.tar.gz: 94e260d4a12d569b9a8c3a0cef67359f05b82760b636f30f10658ebb73adcbcd9bd2af5a33681a715ce4c743d1ca3dc2292d83edcb8cb2fa5b0b0a023b01833a
|
data/lib/ohai/loader.rb
CHANGED
@@ -133,8 +133,8 @@ module Ohai
|
|
133
133
|
load_v7_plugin_class(contents, plugin_path)
|
134
134
|
else
|
135
135
|
Ohai::Log.warn("[DEPRECATION] Plugin at #{plugin_path} is a version 6 plugin. \
|
136
|
-
Version 6 plugins will not be supported in
|
137
|
-
Please upgrade your plugin to version 7 plugin
|
136
|
+
Version 6 plugins will not be supported in Chef/Ohai 14. \
|
137
|
+
Please upgrade your plugin to version 7 plugin format. \
|
138
138
|
For more information visit here: docs.chef.io/ohai_custom.html")
|
139
139
|
|
140
140
|
load_v6_plugin_class(contents, plugin_path, plugin_dir_path)
|
data/lib/ohai/mixin/command.rb
CHANGED
@@ -27,8 +27,13 @@ module Ohai
|
|
27
27
|
# DISCLAIMER: Logging only works in the context of a plugin!!
|
28
28
|
# accept a command and any of the mixlib-shellout options
|
29
29
|
def shell_out(cmd, **options)
|
30
|
+
options = options.dup
|
30
31
|
# unless specified by the caller timeout after 30 seconds
|
31
32
|
options[:timeout] ||= 30
|
33
|
+
unless RUBY_PLATFORM =~ /mswin|mingw32|windows/
|
34
|
+
options[:env] = options.key?(:env) ? options[:env].dup : {}
|
35
|
+
options[:env]["PATH"] ||= ((ENV["PATH"] || "").split(":") + %w{/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin}).join(":")
|
36
|
+
end
|
32
37
|
so = Mixlib::ShellOut.new(cmd, options)
|
33
38
|
begin
|
34
39
|
so.run_command
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# Author:: Tim Dysinger (<tim@dysinger.net>)
|
3
3
|
# Author:: Benjamin Black (<bb@chef.io>)
|
4
4
|
# Author:: Christopher Brown (<cb@chef.io>)
|
5
|
-
# Copyright::
|
5
|
+
# Copyright:: 2009-2017 Chef Software, Inc.
|
6
6
|
# License:: Apache License, Version 2.0
|
7
7
|
#
|
8
8
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -42,37 +42,41 @@ module Ohai
|
|
42
42
|
EC2_METADATA_ADDR = "169.254.169.254" unless defined?(EC2_METADATA_ADDR)
|
43
43
|
EC2_SUPPORTED_VERSIONS = %w{ 1.0 2007-01-19 2007-03-01 2007-08-29 2007-10-10 2007-12-15
|
44
44
|
2008-02-01 2008-09-01 2009-04-04 2011-01-01 2011-05-01 2012-01-12
|
45
|
-
2014-11-05
|
46
|
-
|
45
|
+
2014-02-25 2014-11-05 2015-10-20 2016-04-19 2016-06-30 2016-09-02 }
|
47
46
|
EC2_ARRAY_VALUES = %w{security-groups}
|
48
47
|
EC2_ARRAY_DIR = %w{network/interfaces/macs}
|
49
48
|
EC2_JSON_DIR = %w{iam}
|
50
49
|
|
51
50
|
def best_api_version
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
51
|
+
@api_version ||= begin
|
52
|
+
Ohai::Log.debug("ec2 metadata mixin: Fetching http://#{EC2_METADATA_ADDR}/ to determine the latest supported metadata release")
|
53
|
+
response = http_client.get("/")
|
54
|
+
if response.code == "404"
|
55
|
+
Ohai::Log.debug("ec2 metadata mixin: Received HTTP 404 from metadata server while determining API version, assuming 'latest'")
|
56
|
+
return "latest"
|
57
|
+
elsif response.code != "200"
|
58
|
+
raise "Unable to determine EC2 metadata version (returned #{response.code} response)"
|
59
|
+
end
|
60
|
+
# Note: Sorting the list of versions may have unintended consequences in
|
61
|
+
# non-EC2 environments. It appears to be safe in EC2 as of 2013-04-12.
|
62
|
+
versions = response.body.split("\n").sort
|
63
|
+
until versions.empty? || EC2_SUPPORTED_VERSIONS.include?(versions.last)
|
64
|
+
pv = versions.pop
|
65
|
+
Ohai::Log.debug("ec2 metadata mixin: EC2 lists metadata version: #{pv} not yet supported by Ohai") unless pv == "latest"
|
66
|
+
end
|
67
|
+
Ohai::Log.debug("ec2 metadata mixin: Latest supported EC2 metadata version: #{versions.last}")
|
68
|
+
if versions.empty?
|
69
|
+
raise "Unable to determine EC2 metadata version (no supported entries found)"
|
70
|
+
end
|
71
|
+
versions.last
|
70
72
|
end
|
71
|
-
versions.last
|
72
73
|
end
|
73
74
|
|
74
75
|
def http_client
|
75
|
-
Net::HTTP.start(EC2_METADATA_ADDR).tap
|
76
|
+
@conn ||= Net::HTTP.start(EC2_METADATA_ADDR).tap do |h|
|
77
|
+
h.read_timeout = 10
|
78
|
+
h.keep_alive_timeout = 10
|
79
|
+
end
|
76
80
|
end
|
77
81
|
|
78
82
|
# Get metadata for a given path and API version
|
@@ -84,6 +88,7 @@ module Ohai
|
|
84
88
|
# `nil` and continue the run instead of failing it.
|
85
89
|
def metadata_get(id, api_version)
|
86
90
|
path = "/#{api_version}/meta-data/#{id}"
|
91
|
+
Ohai::Log.debug("ec2 metadata mixin: Fetching http://#{EC2_METADATA_ADDR}#{path}")
|
87
92
|
response = http_client.get(path)
|
88
93
|
case response.code
|
89
94
|
when "200"
|
@@ -97,31 +102,28 @@ module Ohai
|
|
97
102
|
end
|
98
103
|
|
99
104
|
def fetch_metadata(id = "", api_version = nil)
|
100
|
-
api_version ||= best_api_version
|
101
|
-
return {} if api_version.nil?
|
102
|
-
|
103
105
|
metadata = {}
|
104
|
-
retrieved_metadata = metadata_get(id,
|
106
|
+
retrieved_metadata = metadata_get(id, best_api_version)
|
105
107
|
if retrieved_metadata
|
106
108
|
retrieved_metadata.split("\n").each do |o|
|
107
109
|
key = expand_path("#{id}#{o}")
|
108
110
|
if key[-1..-1] != "/"
|
109
111
|
metadata[metadata_key(key)] =
|
110
112
|
if EC2_ARRAY_VALUES.include? key
|
111
|
-
retr_meta = metadata_get(key,
|
113
|
+
retr_meta = metadata_get(key, best_api_version)
|
112
114
|
retr_meta ? retr_meta.split("\n") : retr_meta
|
113
115
|
else
|
114
|
-
metadata_get(key,
|
116
|
+
metadata_get(key, best_api_version)
|
115
117
|
end
|
116
118
|
elsif (not key.eql?(id)) && (not key.eql?("/"))
|
117
119
|
name = key[0..-2]
|
118
120
|
sym = metadata_key(name)
|
119
121
|
if EC2_ARRAY_DIR.include?(name)
|
120
|
-
metadata[sym] = fetch_dir_metadata(key,
|
122
|
+
metadata[sym] = fetch_dir_metadata(key, best_api_version)
|
121
123
|
elsif EC2_JSON_DIR.include?(name)
|
122
|
-
metadata[sym] = fetch_json_dir_metadata(key,
|
124
|
+
metadata[sym] = fetch_json_dir_metadata(key, best_api_version)
|
123
125
|
else
|
124
|
-
fetch_metadata(key,
|
126
|
+
fetch_metadata(key, best_api_version).each { |k, v| metadata[k] = v }
|
125
127
|
end
|
126
128
|
end
|
127
129
|
end
|
@@ -167,17 +169,14 @@ module Ohai
|
|
167
169
|
end
|
168
170
|
|
169
171
|
def fetch_userdata
|
170
|
-
|
171
|
-
|
172
|
-
response = http_client.get("/#{api_version}/user-data/")
|
172
|
+
Ohai::Log.debug("ec2 metadata mixin: Fetching http://#{EC2_METADATA_ADDR}/#{best_api_version}/user-data/")
|
173
|
+
response = http_client.get("/#{best_api_version}/user-data/")
|
173
174
|
response.code == "200" ? response.body : nil
|
174
175
|
end
|
175
176
|
|
176
177
|
def fetch_dynamic_data
|
177
178
|
@fetch_dynamic_data ||= begin
|
178
|
-
|
179
|
-
return {} if api_version.nil?
|
180
|
-
response = http_client.get("/#{api_version}/dynamic/instance-identity/document/")
|
179
|
+
response = http_client.get("/#{best_api_version}/dynamic/instance-identity/document/")
|
181
180
|
|
182
181
|
if json?(response.body) && response.code == "200"
|
183
182
|
FFI_Yajl::Parser.parse(response.body)
|
@@ -1,6 +1,8 @@
|
|
1
1
|
#
|
2
2
|
# Author:: Tim Smith <tsmith@limelight.com>
|
3
|
+
# Author:: Phil Dibowitz <phild@ipomc.com>
|
3
4
|
# Copyright:: Copyright (c) 2013-2014, Limelight Networks, Inc.
|
5
|
+
# Copyright:: Copyright (c) 2017 Facebook, Inc.
|
4
6
|
# Plugin:: mdadm
|
5
7
|
#
|
6
8
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -52,15 +54,19 @@ Ohai.plugin(:Mdadm) do
|
|
52
54
|
collect_data(:linux) do
|
53
55
|
# gather a list of all raid arrays
|
54
56
|
if File.exist?("/proc/mdstat")
|
55
|
-
devices =
|
57
|
+
devices = {}
|
56
58
|
File.open("/proc/mdstat").each do |line|
|
57
|
-
|
59
|
+
if line =~ /(md[0-9]+)/
|
60
|
+
device = Regexp.last_match[1]
|
61
|
+
pieces = line.split(/\s+/)
|
62
|
+
devices[device] = pieces[4..-1].map { |s| s.match(/(.+)\[\d\]/)[1] }
|
63
|
+
end
|
58
64
|
end
|
59
65
|
|
60
66
|
# create the mdadm mash and gather individual information if devices are present
|
61
67
|
unless devices.empty?
|
62
68
|
mdadm Mash.new
|
63
|
-
devices.sort.each do |device|
|
69
|
+
devices.keys.sort.each do |device|
|
64
70
|
mdadm[device] = Mash.new
|
65
71
|
|
66
72
|
# gather detailed information on the array
|
@@ -68,6 +74,7 @@ Ohai.plugin(:Mdadm) do
|
|
68
74
|
|
69
75
|
# if the mdadm command was sucessful pass so.stdout to create_raid_device_mash to grab the tidbits we want
|
70
76
|
mdadm[device] = create_raid_device_mash(so.stdout) if so.stdout
|
77
|
+
mdadm[device]["members"] = devices[device]
|
71
78
|
end
|
72
79
|
end
|
73
80
|
end
|
data/lib/ohai/version.rb
CHANGED
@@ -26,15 +26,24 @@ describe Ohai::Mixin::Command, "shell_out" do
|
|
26
26
|
|
27
27
|
let(:plugin_name) { :OSSparkleDream }
|
28
28
|
|
29
|
+
let(:options) { windows? ? { timeout: 30 } : { timeout: 30, env: { "PATH" => "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" } } }
|
30
|
+
|
29
31
|
before(:each) do
|
30
32
|
allow(Ohai::Mixin::Command).to receive(:name).and_return(plugin_name)
|
33
|
+
@original_env = ENV.to_hash
|
34
|
+
ENV.clear
|
35
|
+
end
|
36
|
+
|
37
|
+
after(:each) do
|
38
|
+
ENV.clear
|
39
|
+
ENV.update(@original_env)
|
31
40
|
end
|
32
41
|
|
33
42
|
describe "when the command runs" do
|
34
43
|
it "logs the command and exitstatus" do
|
35
44
|
expect(Mixlib::ShellOut).
|
36
45
|
to receive(:new).
|
37
|
-
with(cmd,
|
46
|
+
with(cmd, options).
|
38
47
|
and_return(shell_out)
|
39
48
|
|
40
49
|
expect(shell_out).
|
@@ -55,7 +64,7 @@ describe Ohai::Mixin::Command, "shell_out" do
|
|
55
64
|
it "logs the command and error message" do
|
56
65
|
expect(Mixlib::ShellOut).
|
57
66
|
to receive(:new).
|
58
|
-
with(cmd,
|
67
|
+
with(cmd, options).
|
59
68
|
and_return(shell_out)
|
60
69
|
|
61
70
|
expect(shell_out).
|
@@ -76,7 +85,7 @@ describe Ohai::Mixin::Command, "shell_out" do
|
|
76
85
|
it "logs the command an timeout error message" do
|
77
86
|
expect(Mixlib::ShellOut).
|
78
87
|
to receive(:new).
|
79
|
-
with(cmd,
|
88
|
+
with(cmd, options).
|
80
89
|
and_return(shell_out)
|
81
90
|
|
82
91
|
expect(shell_out).
|
@@ -94,7 +103,7 @@ describe Ohai::Mixin::Command, "shell_out" do
|
|
94
103
|
end
|
95
104
|
|
96
105
|
describe "when a timeout option is provided" do
|
97
|
-
let(:options) { { timeout: 10 } }
|
106
|
+
let(:options) { windows? ? { timeout: 10 } : { timeout: 10, env: { "PATH" => "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" } } }
|
98
107
|
|
99
108
|
it "runs the command with the provided timeout" do
|
100
109
|
expect(Mixlib::ShellOut).
|
@@ -49,7 +49,7 @@ describe Ohai::System, "plugin ec2" do
|
|
49
49
|
allow(t).to receive(:connect_nonblock).and_raise(Errno::EINPROGRESS)
|
50
50
|
allow(Socket).to receive(:new).and_return(t)
|
51
51
|
expect(@http_client).to receive(:get).
|
52
|
-
with("/").
|
52
|
+
with("/").
|
53
53
|
and_return(double("Net::HTTP Response", :body => "2012-01-12", :code => "200"))
|
54
54
|
end
|
55
55
|
|
@@ -36,7 +36,7 @@ describe Ohai::System, "plugin eucalyptus" do
|
|
36
36
|
allow(plugin).to receive(:http_client).and_return(@http_client)
|
37
37
|
|
38
38
|
expect(@http_client).to receive(:get).
|
39
|
-
with("/").
|
39
|
+
with("/").
|
40
40
|
and_return(double("Net::HTTP Response", :body => "2012-01-12", :code => "200"))
|
41
41
|
expect(@http_client).to receive(:get).
|
42
42
|
with("/2012-01-12/meta-data/").
|
@@ -160,7 +160,7 @@ EOM
|
|
160
160
|
}'
|
161
161
|
end
|
162
162
|
|
163
|
-
let(:http_client) { double("Net::HTTP", :read_timeout= => nil) }
|
163
|
+
let(:http_client) { double("Net::HTTP", { :read_timeout= => nil, :keep_alive_timeout= => nil } ) }
|
164
164
|
|
165
165
|
def allow_get(url, response_body)
|
166
166
|
allow(http_client).to receive(:get).
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ohai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 13.0
|
4
|
+
version: 13.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Jacob
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: systemu
|