ohai 13.5.0 → 13.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ohai/config.rb +1 -0
- data/lib/ohai/dsl/plugin.rb +4 -0
- data/lib/ohai/exception.rb +1 -0
- data/lib/ohai/plugins/aix/uptime.rb +2 -1
- data/lib/ohai/plugins/linux/filesystem.rb +7 -1
- data/lib/ohai/plugins/linux/virtualization.rb +1 -1
- data/lib/ohai/plugins/packages.rb +1 -1
- data/lib/ohai/plugins/rackspace.rb +17 -3
- data/lib/ohai/runner.rb +5 -0
- data/lib/ohai/system.rb +11 -0
- data/lib/ohai/version.rb +1 -1
- data/spec/unit/plugins/aix/uptime_spec.rb +1 -2
- data/spec/unit/plugins/linux/filesystem_spec.rb +10 -1
- data/spec/unit/plugins/linux/virtualization_spec.rb +13 -5
- data/spec/unit/plugins/rackspace_spec.rb +12 -0
- data/spec/unit/system_spec.rb +26 -0
- 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: f877e6723a132a880743b84ab9a9d6a0ede623eb
|
4
|
+
data.tar.gz: 7bb2833e7c7d12bc8207608bf14f93b266e48371
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7b5ff8c56d7f071ac3278e345c91bd8df4f9a5e4e07fd4aec0a714833f1debaabc02a588d6ca2b5c43595d8799662410d6ec95cca4b9fb84a641358ccfb4c06
|
7
|
+
data.tar.gz: d062c3f9b9595a699be681be9d3b1a8bb6513e61fefc7662fbc3e88f0f5063dbe2b640997e4957e0ff4667b79023e4016e114ba68c34d288b6c2e27479b22e40
|
data/lib/ohai/config.rb
CHANGED
@@ -35,6 +35,7 @@ module Ohai
|
|
35
35
|
default :log_location, STDERR
|
36
36
|
default :plugin, Ohai::PluginConfig.new { |h, k| h[k] = Ohai::PluginConfig.new }
|
37
37
|
default :plugin_path, [ File.expand_path(File.join(File.dirname(__FILE__), "plugins")), ChefConfig::Config.platform_specific_path("/etc/chef/ohai/plugins") ]
|
38
|
+
default :critical_plugins, []
|
38
39
|
end
|
39
40
|
end
|
40
41
|
|
data/lib/ohai/dsl/plugin.rb
CHANGED
@@ -85,10 +85,12 @@ module Ohai
|
|
85
85
|
include Ohai::Util::FileHelper
|
86
86
|
|
87
87
|
attr_reader :data
|
88
|
+
attr_reader :failed
|
88
89
|
|
89
90
|
def initialize(data)
|
90
91
|
@data = data
|
91
92
|
@has_run = false
|
93
|
+
@failed = false
|
92
94
|
end
|
93
95
|
|
94
96
|
def run
|
@@ -182,8 +184,10 @@ module Ohai
|
|
182
184
|
def safe_run
|
183
185
|
run
|
184
186
|
rescue Ohai::Exceptions::Error => e
|
187
|
+
@failed = true
|
185
188
|
raise e
|
186
189
|
rescue => e
|
190
|
+
@failed = true
|
187
191
|
Ohai::Log.debug("Plugin #{name} threw #{e.inspect}")
|
188
192
|
e.backtrace.each { |line| Ohai::Log.debug( line ) }
|
189
193
|
end
|
data/lib/ohai/exception.rb
CHANGED
@@ -46,7 +46,8 @@ Ohai.plugin(:Uptime) do
|
|
46
46
|
end
|
47
47
|
elapsed_seconds = ((d.to_i * 86400) + (h.to_i * 3600) + (m.to_i * 60) + s.to_i)
|
48
48
|
|
49
|
-
|
49
|
+
# uptime seconds below will return the elapsed time since boot
|
50
|
+
uptime_seconds elapsed_seconds
|
50
51
|
uptime seconds_to_human(elapsed_seconds)
|
51
52
|
end
|
52
53
|
end
|
@@ -130,7 +130,10 @@ Ohai.plugin(:Filesystem) do
|
|
130
130
|
fs[key][:mount] = $6
|
131
131
|
end
|
132
132
|
end
|
133
|
-
rescue Ohai::Exceptions::Exec
|
133
|
+
rescue Ohai::Exceptions::Exec => e
|
134
|
+
unless Ohai.config[:plugin][:filesystem][:allow_partial_data]
|
135
|
+
raise e
|
136
|
+
end
|
134
137
|
Ohai::Log.warn("Plugin Filesystem: df binary is not available. Some data will not be available.")
|
135
138
|
end
|
136
139
|
|
@@ -148,6 +151,9 @@ Ohai.plugin(:Filesystem) do
|
|
148
151
|
end
|
149
152
|
end
|
150
153
|
rescue Ohai::Exceptions::Exec
|
154
|
+
unless Ohai.config[:plugin][:filesystem][:allow_partial_data]
|
155
|
+
raise e
|
156
|
+
end
|
151
157
|
Ohai::Log.warn("Plugin Filesystem: mount binary is not available. Some data will not be available.")
|
152
158
|
end
|
153
159
|
|
@@ -43,7 +43,7 @@ Ohai.plugin(:Packages) do
|
|
43
43
|
packages[name] = { "version" => version, "arch" => arch }
|
44
44
|
end
|
45
45
|
|
46
|
-
when "rhel", "fedora", "suse", "pld"
|
46
|
+
when "rhel", "fedora", "suse", "pld", "amazon"
|
47
47
|
format = '%{NAME}\t%|EPOCH?{%{EPOCH}}:{0}|\t%{VERSION}\t%{RELEASE}\t%{INSTALLTIME}\t%{ARCH}\n'
|
48
48
|
so = shell_out("rpm -qa --qf '#{format}'")
|
49
49
|
pkgs = so.stdout.lines
|
@@ -43,13 +43,27 @@ Ohai.plugin(:Rackspace) do
|
|
43
43
|
false
|
44
44
|
end
|
45
45
|
|
46
|
+
# Checks for the rackspace manufacturer on Windows
|
47
|
+
# === Return
|
48
|
+
# true:: If the rackspace cloud can be identified
|
49
|
+
# false:: Otherwise
|
50
|
+
def has_rackspace_manufacturer?
|
51
|
+
return false unless RUBY_PLATFORM =~ /mswin|mingw32|windows/
|
52
|
+
require "wmi-lite/wmi"
|
53
|
+
wmi = WmiLite::Wmi.new
|
54
|
+
if wmi.first_of("Win32_ComputerSystem")["PrimaryOwnerName"] == "Rackspace"
|
55
|
+
Ohai::Log.debug("Plugin Rackspace: has_rackspace_manufacturer? == true")
|
56
|
+
return true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
46
60
|
# Identifies the rackspace cloud
|
47
61
|
#
|
48
62
|
# === Return
|
49
63
|
# true:: If the rackspace cloud can be identified
|
50
64
|
# false:: Otherwise
|
51
65
|
def looks_like_rackspace?
|
52
|
-
hint?("rackspace") || has_rackspace_metadata? || has_rackspace_kernel?
|
66
|
+
hint?("rackspace") || has_rackspace_metadata? || has_rackspace_kernel? || has_rackspace_manufacturer?
|
53
67
|
end
|
54
68
|
|
55
69
|
# Names rackspace ip address
|
@@ -137,8 +151,8 @@ Ohai.plugin(:Rackspace) do
|
|
137
151
|
rackspace Mash.new
|
138
152
|
get_ip_address(:public_ip, :eth0)
|
139
153
|
get_ip_address(:private_ip, :eth1)
|
140
|
-
get_region
|
141
|
-
get_instance_id
|
154
|
+
get_region
|
155
|
+
get_instance_id
|
142
156
|
# public_ip + private_ip are deprecated in favor of public_ipv4 and local_ipv4 to standardize.
|
143
157
|
rackspace[:public_ipv4] = rackspace[:public_ip]
|
144
158
|
get_global_ipv6_address(:public_ipv6, :eth0)
|
data/lib/ohai/runner.rb
CHANGED
@@ -23,11 +23,13 @@ require "benchmark"
|
|
23
23
|
module Ohai
|
24
24
|
class Runner
|
25
25
|
|
26
|
+
attr_reader :failed_plugins
|
26
27
|
# safe_run: set to true if this runner will run plugins in
|
27
28
|
# safe-mode. default false.
|
28
29
|
def initialize(controller, safe_run = false)
|
29
30
|
@provides_map = controller.provides_map
|
30
31
|
@safe_run = safe_run
|
32
|
+
@failed_plugins = []
|
31
33
|
end
|
32
34
|
|
33
35
|
# Runs plugins and any un-run dependencies.
|
@@ -86,6 +88,9 @@ module Ohai
|
|
86
88
|
|
87
89
|
if dependency_providers.empty?
|
88
90
|
@safe_run ? next_plugin.safe_run : next_plugin.run
|
91
|
+
if next_plugin.failed
|
92
|
+
@failed_plugins << next_plugin.name
|
93
|
+
end
|
89
94
|
else
|
90
95
|
visited << next_plugin << dependency_providers.first
|
91
96
|
end
|
data/lib/ohai/system.rb
CHANGED
@@ -47,6 +47,7 @@ module Ohai
|
|
47
47
|
@cli = config[:invoked_from_cli]
|
48
48
|
@plugin_path = ""
|
49
49
|
@config = config
|
50
|
+
@failed_plugins = []
|
50
51
|
reset_system
|
51
52
|
end
|
52
53
|
|
@@ -107,6 +108,16 @@ module Ohai
|
|
107
108
|
Ohai::Log.error("Encountered error while running plugins: #{e.inspect}")
|
108
109
|
raise
|
109
110
|
end
|
111
|
+
critical_failed = Ohai::Config.ohai[:critical_plugins] & @runner.failed_plugins
|
112
|
+
unless critical_failed.empty?
|
113
|
+
msg = "The following Ohai plugins marked as critical failed: #{critical_failed}"
|
114
|
+
if @cli
|
115
|
+
Ohai::Log.error(msg)
|
116
|
+
exit(true)
|
117
|
+
else
|
118
|
+
raise Ohai::Exceptions::CriticalPluginFailure, "#{msg}. Failing Chef run."
|
119
|
+
end
|
120
|
+
end
|
110
121
|
|
111
122
|
# Freeze all strings.
|
112
123
|
freeze_strings!
|
data/lib/ohai/version.rb
CHANGED
@@ -24,13 +24,12 @@ describe Ohai::System, "Aix plugin uptime" do
|
|
24
24
|
@plugin = get_plugin("aix/uptime")
|
25
25
|
allow(@plugin).to receive(:collect_os).and_return(:aix)
|
26
26
|
allow(@plugin).to receive(:shell_out).and_call_original
|
27
|
-
allow(Time).to receive_message_chain(:now, :to_i).and_return(1504287957)
|
28
27
|
allow(@plugin).to receive(:shell_out).with("LC_ALL=POSIX ps -o etime= -p 1").and_return(mock_shell_out(0, "1148-20:54:50", nil))
|
29
28
|
@plugin.run
|
30
29
|
end
|
31
30
|
|
32
31
|
it "should set uptime_seconds to uptime with days" do
|
33
|
-
expect(@plugin[:uptime_seconds]).to eq(
|
32
|
+
expect(@plugin[:uptime_seconds]).to eq(99262490)
|
34
33
|
end
|
35
34
|
|
36
35
|
it "should set uptime to a human readable date with days" do
|
@@ -533,8 +533,17 @@ BLKID_TYPE
|
|
533
533
|
end
|
534
534
|
|
535
535
|
%w{df mount}.each do |command|
|
536
|
-
describe "when #{command} does not exist" do
|
536
|
+
describe "when :allow_partial_data set, #{command} does not exist" do
|
537
|
+
before do
|
538
|
+
Ohai.config[:plugin][:filesystem][:allow_partial_data] = true
|
539
|
+
end
|
540
|
+
|
541
|
+
after do
|
542
|
+
Ohai.config[:plugin][:filesystem][:allow_partial_data] = false
|
543
|
+
end
|
544
|
+
|
537
545
|
it "logs warning about #{command} missing" do
|
546
|
+
Ohai.config[:plugin][:filesystem][:allow_partial_data] = true
|
538
547
|
allow(plugin).to receive(:shell_out).with(/#{command}/).and_raise(Ohai::Exceptions::Exec)
|
539
548
|
expect(Ohai::Log).to receive(:warn).with("Plugin Filesystem: #{command} binary is not available. Some data will not be available.")
|
540
549
|
plugin.run
|
@@ -42,7 +42,8 @@ describe Ohai::System, "Linux virtualization platform" do
|
|
42
42
|
allow(File).to receive(:exist?).with("/var/lib/lxd/devlxd").and_return(false)
|
43
43
|
|
44
44
|
# default the which wrappers to nil
|
45
|
-
allow(plugin).to receive(:
|
45
|
+
allow(plugin).to receive(:which).with("lxc-version").and_return(nil)
|
46
|
+
allow(plugin).to receive(:which).with("lxc-start").and_return(nil)
|
46
47
|
allow(plugin).to receive(:nova_exists?).and_return(false)
|
47
48
|
end
|
48
49
|
|
@@ -577,7 +578,15 @@ CGROUP
|
|
577
578
|
end
|
578
579
|
|
579
580
|
it "sets lxc host if lxc-version exists" do
|
580
|
-
allow(plugin).to receive(:
|
581
|
+
allow(plugin).to receive(:which).with("lxc-start").and_return("/usr/bin/lxc-version")
|
582
|
+
plugin.run
|
583
|
+
expect(plugin[:virtualization][:system]).to eq("lxc")
|
584
|
+
expect(plugin[:virtualization][:role]).to eq("host")
|
585
|
+
expect(plugin[:virtualization][:systems][:lxc]).to eq("host")
|
586
|
+
end
|
587
|
+
|
588
|
+
it "sets lxc host if lxc-start exists" do
|
589
|
+
allow(plugin).to receive(:which).with("lxc-start").and_return("/usr/bin/lxc-start")
|
581
590
|
plugin.run
|
582
591
|
expect(plugin[:virtualization][:system]).to eq("lxc")
|
583
592
|
expect(plugin[:virtualization][:role]).to eq("host")
|
@@ -585,7 +594,7 @@ CGROUP
|
|
585
594
|
end
|
586
595
|
|
587
596
|
it "does not set the old virtualization attributes if they are already set" do
|
588
|
-
allow(plugin).to receive(:
|
597
|
+
allow(plugin).to receive(:which).with("lxc-version").and_return("/usr/bin/lxc-version")
|
589
598
|
plugin[:virtualization] = Mash.new
|
590
599
|
plugin[:virtualization][:system] = "the cloud"
|
591
600
|
plugin[:virtualization][:role] = "cumulonimbus"
|
@@ -594,8 +603,7 @@ CGROUP
|
|
594
603
|
expect(plugin[:virtualization][:role]).not_to eq("host")
|
595
604
|
end
|
596
605
|
|
597
|
-
it "does not set lxc host if lxc-version
|
598
|
-
allow(plugin).to receive(:lxc_version_exists?).and_return(false)
|
606
|
+
it "does not set lxc host if neither lxc-version nor lxc-start exists" do
|
599
607
|
plugin.run
|
600
608
|
expect(plugin[:virtualization][:system]).to be_nil
|
601
609
|
expect(plugin[:virtualization][:role]).to be_nil
|
@@ -223,6 +223,18 @@ OUT
|
|
223
223
|
end
|
224
224
|
end
|
225
225
|
|
226
|
+
describe "with Rackspace windows manufacturer data" do
|
227
|
+
it "has rackspace attribute" do
|
228
|
+
plugin.run
|
229
|
+
expect(plugin[:rackspace]).not_to be_nil
|
230
|
+
end
|
231
|
+
|
232
|
+
before(:each) do
|
233
|
+
allow(plugin).to receive(:hint?).with("rackspace").and_return(false)
|
234
|
+
allow(plugin).to receive(:has_rackspace_manufacturer?).and_return(true)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
226
238
|
describe "xenstore provider returns rackspace" do
|
227
239
|
it_behaves_like "rackspace"
|
228
240
|
|
data/spec/unit/system_spec.rb
CHANGED
@@ -43,6 +43,7 @@ describe "Ohai::System" do
|
|
43
43
|
config = {
|
44
44
|
disabled_plugins: [ :Foo, :Baz ],
|
45
45
|
directory: "/some/extra/plugins",
|
46
|
+
critical_plugins: [ :Foo, :Bar ],
|
46
47
|
}
|
47
48
|
Ohai::System.new(config)
|
48
49
|
config.each do |option, value|
|
@@ -307,6 +308,15 @@ Ohai.plugin(:Park) do
|
|
307
308
|
park("plants")
|
308
309
|
end
|
309
310
|
end
|
311
|
+
EOF
|
312
|
+
|
313
|
+
with_plugin("fails.rb", <<EOF)
|
314
|
+
Ohai.plugin(:Fails) do
|
315
|
+
provides 'fails'
|
316
|
+
collect_data(:default) do
|
317
|
+
fail 'thing'
|
318
|
+
end
|
319
|
+
end
|
310
320
|
EOF
|
311
321
|
|
312
322
|
it "should collect data from all the plugins" do
|
@@ -343,6 +353,22 @@ EOF
|
|
343
353
|
expect(ohai.data[:park]).to eq("plants")
|
344
354
|
end
|
345
355
|
end
|
356
|
+
|
357
|
+
describe "when using :critical_plugins" do
|
358
|
+
before do
|
359
|
+
Ohai.config[:critical_plugins] = [ :Fails ]
|
360
|
+
end
|
361
|
+
after do
|
362
|
+
Ohai.config[:critical_plugins] = []
|
363
|
+
end
|
364
|
+
|
365
|
+
it "should fail when critical plugins fail" do
|
366
|
+
Ohai.config[:plugin_path] = [ path_to(".") ]
|
367
|
+
expect(Ohai::Log).to receive(:error).with(/marked as critical/)
|
368
|
+
ohai.all_plugins
|
369
|
+
end
|
370
|
+
|
371
|
+
end
|
346
372
|
end
|
347
373
|
|
348
374
|
when_plugins_directory "contains v6 & v7 plugins in different directories" do
|
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.
|
4
|
+
version: 13.6.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-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: systemu
|