ohai 13.0.1 → 13.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc03fe6ff6ba0d982a2aa2f46478ef5a9591aedb
4
- data.tar.gz: 060eee8013d65b8225ae6d430c694b6356d9584f
3
+ metadata.gz: 5a790e9dca44c313d60c13521eddb5f71fb17d95
4
+ data.tar.gz: b42fe376d2bc0ae29386b3d5e90607e65f47050a
5
5
  SHA512:
6
- metadata.gz: 50cb72595109dd4e3a7d2b0bd573dfe7eca8624a9d6ec398ec14e60b0085050f6ca9cf0438123d53b928d5f86a9696610d4931be2b1f6450d0b0f25d3a41ee65
7
- data.tar.gz: 1d0ad0f6f97869c6875e5b71d83c2bb64f5dcf5db5e41d99c18da40e9667fe0cc3654338623ff885b76be270513775aee51ed7289e82410c0c15dfe9fe3e8d32
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 future releases of Ohai. \
137
- Please upgrade your plugin to version 7 plugin syntax. \
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)
@@ -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:: Copyright (c) 2009-2016 Chef Software, Inc.
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 2014-02-25 }
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
- response = http_client.get("/")
53
- if response.code == "404"
54
- Ohai::Log.debug("ec2 metadata mixin: Received HTTP 404 from metadata server while determining API version, assuming 'latest'")
55
- return "latest"
56
- elsif response.code != "200"
57
- raise "Unable to determine EC2 metadata version (returned #{response.code} response)"
58
- end
59
- # Note: Sorting the list of versions may have unintended consequences in
60
- # non-EC2 environments. It appears to be safe in EC2 as of 2013-04-12.
61
- versions = response.body.split("\n")
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 shows unsupported metadata version: #{pv}") unless pv == "latest"
66
- end
67
- Ohai::Log.debug("ec2 metadata mixin: EC2 metadata version: #{versions.last}")
68
- if versions.empty?
69
- raise "Unable to determine EC2 metadata version (no supported entries found)"
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 { |h| h.read_timeout = 30 }
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, api_version)
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, api_version)
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, api_version)
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, api_version)
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, api_version)
124
+ metadata[sym] = fetch_json_dir_metadata(key, best_api_version)
123
125
  else
124
- fetch_metadata(key, api_version).each { |k, v| metadata[k] = v }
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
- api_version = best_api_version
171
- return nil if api_version.nil?
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
- api_version = best_api_version
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
- devices << Regexp.last_match[1] if line =~ /(md[0-9]+)/
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
@@ -18,5 +18,5 @@
18
18
 
19
19
  module Ohai
20
20
  OHAI_ROOT = File.expand_path(File.dirname(__FILE__))
21
- VERSION = "13.0.1"
21
+ VERSION = "13.1.0"
22
22
  end
@@ -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, { timeout: 30 }).
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, { timeout: 30 }).
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, { timeout: 30 }).
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("/").exactly(3).times.
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("/").twice.
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/").
@@ -99,6 +99,12 @@ MD
99
99
  end
100
100
  end
101
101
 
102
+ it "should detect member devies" do
103
+ @plugin.run
104
+ expect(@plugin[:mdadm][:md0][:members].sort).to eq(
105
+ %w{sdc sdd sde sdf sdg sdh}
106
+ )
107
+ end
102
108
  end
103
109
 
104
110
  end
@@ -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.1
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-04-12 00:00:00.000000000 Z
11
+ date: 2017-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: systemu