ohai 6.24.2 → 7.0.0.rc.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ohai.rb +1 -1
- data/lib/ohai/application.rb +5 -12
- data/lib/ohai/common/dmi.rb +126 -0
- data/lib/ohai/config.rb +9 -9
- data/lib/ohai/{plugins/darwin/hostname.rb → dsl.rb} +7 -7
- data/lib/ohai/dsl/plugin.rb +186 -0
- data/lib/ohai/dsl/plugin/versionvi.rb +62 -0
- data/lib/ohai/dsl/plugin/versionvii.rb +106 -0
- data/lib/ohai/exception.rb +11 -2
- data/lib/ohai/hints.rb +48 -0
- data/lib/ohai/loader.rb +205 -0
- data/lib/ohai/mixin/command.rb +14 -18
- data/lib/ohai/mixin/constant_helper.rb +53 -0
- data/lib/ohai/mixin/gce_metadata.rb +0 -2
- data/lib/ohai/{plugins/freebsd/uptime.rb → mixin/network_constants.rb} +15 -13
- data/lib/ohai/mixin/os.rb +59 -0
- data/lib/ohai/mixin/seconds_to_human.rb +48 -0
- data/lib/ohai/plugins/aix/cpu.rb +26 -22
- data/lib/ohai/plugins/aix/filesystem.rb +47 -48
- data/lib/ohai/plugins/aix/kernel.rb +11 -7
- data/lib/ohai/plugins/aix/memory.rb +8 -4
- data/lib/ohai/plugins/aix/network.rb +73 -82
- data/lib/ohai/plugins/aix/platform.rb +9 -6
- data/lib/ohai/plugins/aix/uptime.rb +14 -12
- data/lib/ohai/plugins/azure.rb +33 -11
- data/lib/ohai/plugins/c.rb +103 -78
- data/lib/ohai/plugins/chef.rb +20 -8
- data/lib/ohai/plugins/cloud.rb +234 -230
- data/lib/ohai/plugins/command.rb +6 -2
- data/lib/ohai/plugins/darwin/cpu.rb +10 -4
- data/lib/ohai/plugins/darwin/filesystem.rb +32 -32
- data/lib/ohai/plugins/darwin/network.rb +157 -154
- data/lib/ohai/plugins/darwin/platform.rb +18 -16
- data/lib/ohai/plugins/darwin/system_profiler.rb +49 -46
- data/lib/ohai/plugins/dmi.rb +102 -102
- data/lib/ohai/plugins/ec2.rb +30 -28
- data/lib/ohai/plugins/erlang.rb +19 -16
- data/lib/ohai/plugins/eucalyptus.rb +37 -36
- data/lib/ohai/plugins/freebsd/cpu.rb +34 -29
- data/lib/ohai/plugins/freebsd/filesystem.rb +32 -32
- data/lib/ohai/plugins/freebsd/memory.rb +35 -25
- data/lib/ohai/plugins/freebsd/network.rb +94 -89
- data/lib/ohai/plugins/freebsd/platform.rb +10 -4
- data/lib/ohai/plugins/freebsd/virtualization.rb +62 -61
- data/lib/ohai/plugins/gce.rb +30 -36
- data/lib/ohai/plugins/groovy.rb +14 -11
- data/lib/ohai/plugins/hostname.rb +132 -10
- data/lib/ohai/plugins/ip_scopes.rb +31 -16
- data/lib/ohai/plugins/java.rb +45 -21
- data/lib/ohai/plugins/kernel.rb +186 -19
- data/lib/ohai/plugins/keys.rb +6 -2
- data/lib/ohai/plugins/languages.rb +6 -2
- data/lib/ohai/plugins/linode.rb +38 -30
- data/lib/ohai/plugins/linux/block_device.rb +19 -15
- data/lib/ohai/plugins/linux/cpu.rb +42 -38
- data/lib/ohai/plugins/linux/filesystem.rb +70 -130
- data/lib/ohai/plugins/linux/lsb.rb +35 -35
- data/lib/ohai/plugins/linux/memory.rb +65 -61
- data/lib/ohai/plugins/linux/network.rb +343 -362
- data/lib/ohai/plugins/linux/platform.rb +90 -88
- data/lib/ohai/plugins/linux/virtualization.rb +95 -90
- data/lib/ohai/plugins/lua.rb +14 -10
- data/lib/ohai/plugins/mono.rb +17 -13
- data/lib/ohai/plugins/netbsd/cpu.rb +25 -23
- data/lib/ohai/plugins/netbsd/filesystem.rb +32 -32
- data/lib/ohai/plugins/netbsd/memory.rb +59 -59
- data/lib/ohai/plugins/netbsd/network.rb +92 -88
- data/lib/ohai/plugins/netbsd/platform.rb +10 -3
- data/lib/ohai/plugins/netbsd/virtualization.rb +41 -38
- data/lib/ohai/plugins/network.rb +131 -130
- data/lib/ohai/plugins/network_listeners.rb +26 -22
- data/lib/ohai/plugins/nodejs.rb +14 -10
- data/lib/ohai/plugins/ohai.rb +11 -6
- data/lib/ohai/plugins/ohai_time.rb +6 -2
- data/lib/ohai/plugins/openbsd/cpu.rb +20 -15
- data/lib/ohai/plugins/openbsd/filesystem.rb +32 -32
- data/lib/ohai/plugins/openbsd/memory.rb +59 -59
- data/lib/ohai/plugins/openbsd/network.rb +92 -88
- data/lib/ohai/plugins/openbsd/platform.rb +10 -4
- data/lib/ohai/plugins/openbsd/virtualization.rb +41 -39
- data/lib/ohai/plugins/openstack.rb +23 -21
- data/lib/ohai/plugins/os.rb +8 -32
- data/lib/ohai/plugins/passwd.rb +27 -22
- data/lib/ohai/plugins/perl.rb +21 -16
- data/lib/ohai/plugins/php.rb +15 -12
- data/lib/ohai/plugins/platform.rb +9 -9
- data/lib/ohai/plugins/{linux/kernel.rb → ps.rb} +13 -12
- data/lib/ohai/plugins/python.rb +16 -12
- data/lib/ohai/plugins/rackspace.rb +82 -77
- data/lib/ohai/plugins/root_group.rb +13 -9
- data/lib/ohai/plugins/ruby.rb +50 -48
- data/lib/ohai/plugins/sigar/cpu.rb +21 -17
- data/lib/ohai/plugins/sigar/filesystem.rb +26 -23
- data/lib/ohai/plugins/sigar/memory.rb +17 -14
- data/lib/ohai/plugins/sigar/network.rb +133 -67
- data/lib/ohai/plugins/sigar/network_route.rb +33 -28
- data/lib/ohai/plugins/sigar/platform.rb +10 -6
- data/lib/ohai/plugins/solaris2/cpu.rb +41 -33
- data/lib/ohai/plugins/solaris2/dmi.rb +146 -146
- data/lib/ohai/plugins/solaris2/filesystem.rb +74 -77
- data/lib/ohai/plugins/{aix/hostname.rb → solaris2/memory.rb} +7 -4
- data/lib/ohai/plugins/solaris2/network.rb +91 -86
- data/lib/ohai/plugins/solaris2/platform.rb +40 -36
- data/lib/ohai/plugins/solaris2/virtualization.rb +54 -59
- data/lib/ohai/plugins/solaris2/zpools.rb +38 -38
- data/lib/ohai/plugins/ssh_host_key.rb +49 -45
- data/lib/ohai/plugins/uptime.rb +87 -25
- data/lib/ohai/plugins/virtualization.rb +59 -55
- data/lib/ohai/plugins/windows/cpu.rb +44 -40
- data/lib/ohai/plugins/windows/filesystem.rb +28 -22
- data/lib/ohai/plugins/windows/network.rb +88 -79
- data/lib/ohai/plugins/windows/platform.rb +10 -3
- data/lib/ohai/provides_map.rb +184 -0
- data/lib/ohai/runner.rb +109 -0
- data/lib/ohai/system.rb +103 -184
- data/lib/ohai/version.rb +4 -3
- data/spec/data/plugins/___lib64___libc.so.6.output +135 -0
- data/spec/data/plugins/___lib___libc.so.6.output +135 -0
- data/spec/data/plugins/cc.output +135 -0
- data/spec/data/plugins/cl.output +135 -0
- data/spec/data/plugins/devenv.com.output +135 -0
- data/spec/data/plugins/env.output +71 -0
- data/spec/data/plugins/erl.output +144 -0
- data/spec/data/plugins/gcc.output +135 -0
- data/spec/data/plugins/groovy.output +159 -0
- data/spec/data/plugins/java.output +143 -0
- data/spec/data/plugins/lua.output +143 -0
- data/spec/data/plugins/messages.rb +8 -0
- data/spec/data/plugins/node.output +143 -0
- data/spec/data/plugins/perl.output +143 -0
- data/spec/data/plugins/php.output +143 -0
- data/spec/data/plugins/python.output +143 -0
- data/spec/data/plugins/uname.output +71 -0
- data/spec/data/plugins/v6message.rb +2 -0
- data/spec/data/plugins/v7message.rb +7 -0
- data/spec/data/plugins/what.output +135 -0
- data/spec/data/plugins/xlc.output +135 -0
- data/spec/spec_helper.rb +52 -18
- data/spec/support/integration_helper.rb +44 -0
- data/spec/unit/dsl/plugin_spec.rb +298 -0
- data/spec/unit/hints_spec.rb +65 -0
- data/spec/unit/loader_spec.rb +226 -0
- data/spec/unit/mixin/ec2_metadata_spec.rb +9 -9
- data/spec/unit/plugins/aix/cpu_spec.rb +17 -18
- data/spec/unit/plugins/aix/filesystem_spec.rb +20 -18
- data/spec/unit/plugins/aix/hostname_spec.rb +8 -4
- data/spec/unit/plugins/aix/kernel_spec.rb +13 -12
- data/spec/unit/plugins/aix/network_spec.rb +66 -45
- data/spec/unit/plugins/aix/platform_spec.rb +11 -10
- data/spec/unit/plugins/aix/uptime_spec.rb +7 -8
- data/spec/unit/plugins/azure_spec.rb +20 -21
- data/spec/unit/plugins/c_spec.rb +88 -87
- data/spec/unit/plugins/chef_spec.rb +5 -6
- data/spec/unit/plugins/cloud_spec.rb +81 -82
- data/spec/unit/plugins/darwin/cpu_spec.rb +8 -9
- data/spec/unit/plugins/darwin/hostname_spec.rb +23 -11
- data/spec/unit/plugins/darwin/kernel_spec.rb +39 -16
- data/spec/unit/plugins/darwin/network_spec.rb +375 -378
- data/spec/unit/plugins/darwin/platform_spec.rb +23 -50
- data/spec/unit/plugins/darwin/system_profiler_spec.rb +7 -8
- data/spec/unit/plugins/dmi_spec.rb +7 -12
- data/spec/unit/plugins/ec2_spec.rb +70 -59
- data/spec/unit/plugins/erlang_spec.rb +18 -20
- data/spec/unit/plugins/eucalyptus_spec.rb +37 -33
- data/spec/unit/plugins/fail_spec.rb +276 -23
- data/spec/unit/plugins/freebsd/hostname_spec.rb +11 -9
- data/spec/unit/plugins/freebsd/kernel_spec.rb +8 -8
- data/spec/unit/plugins/freebsd/platform_spec.rb +9 -10
- data/spec/unit/plugins/freebsd/virtualization_spec.rb +32 -32
- data/spec/unit/plugins/gce_spec.rb +19 -25
- data/spec/unit/plugins/groovy_spec.rb +10 -16
- data/spec/unit/plugins/hostname_spec.rb +45 -20
- data/spec/unit/plugins/ip_scopes_spec.rb +97 -0
- data/spec/unit/plugins/java_spec.rb +145 -99
- data/spec/unit/plugins/kernel_spec.rb +51 -15
- data/spec/unit/plugins/linode_spec.rb +31 -29
- data/spec/unit/plugins/linux/cpu_spec.rb +42 -43
- data/spec/unit/plugins/linux/filesystem_spec.rb +143 -324
- data/spec/unit/plugins/linux/hostname_spec.rb +16 -23
- data/spec/unit/plugins/linux/kernel_spec.rb +22 -8
- data/spec/unit/plugins/linux/lsb_spec.rb +54 -56
- data/spec/unit/plugins/linux/network_spec.rb +196 -238
- data/spec/unit/plugins/linux/platform_spec.rb +186 -205
- data/spec/unit/plugins/linux/uptime_spec.rb +13 -25
- data/spec/unit/plugins/linux/virtualization_spec.rb +149 -129
- data/spec/unit/plugins/lua_spec.rb +12 -15
- data/spec/unit/plugins/mono_spec.rb +10 -15
- data/spec/unit/plugins/netbsd/hostname_spec.rb +17 -7
- data/spec/unit/plugins/netbsd/kernel_spec.rb +8 -8
- data/spec/unit/plugins/netbsd/platform_spec.rb +8 -10
- data/spec/unit/plugins/network_spec.rb +358 -235
- data/spec/unit/plugins/nodejs_spec.rb +13 -15
- data/spec/unit/plugins/ohai_spec.rb +3 -4
- data/spec/unit/plugins/ohai_time_spec.rb +8 -9
- data/spec/unit/plugins/openbsd/hostname_spec.rb +21 -11
- data/spec/unit/plugins/openbsd/kernel_spec.rb +8 -8
- data/spec/unit/plugins/openbsd/platform_spec.rb +6 -12
- data/spec/unit/plugins/openstack_spec.rb +214 -0
- data/spec/unit/plugins/os_spec.rb +13 -16
- data/spec/unit/plugins/passwd_spec.rb +12 -13
- data/spec/unit/plugins/perl_spec.rb +20 -44
- data/spec/unit/plugins/php_spec.rb +20 -15
- data/spec/unit/plugins/platform_spec.rb +24 -29
- data/spec/unit/plugins/python_spec.rb +13 -17
- data/spec/unit/plugins/rackspace_spec.rb +90 -57
- data/spec/unit/plugins/root_group_spec.rb +17 -19
- data/spec/unit/plugins/ruby_spec.rb +15 -16
- data/spec/unit/plugins/sigar/network_route_spec.rb +12 -13
- data/spec/unit/plugins/solaris2/cpu_spec.rb +82 -0
- data/spec/unit/plugins/solaris2/hostname_spec.rb +12 -13
- data/spec/unit/plugins/solaris2/kernel_spec.rb +11 -15
- data/{lib/ohai/plugins/openbsd/uptime.rb → spec/unit/plugins/solaris2/memory_spec.rb} +10 -12
- data/spec/unit/plugins/solaris2/network_spec.rb +44 -20
- data/spec/unit/plugins/solaris2/platform_spec.rb +13 -22
- data/spec/unit/plugins/solaris2/virtualization_spec.rb +37 -45
- data/spec/unit/plugins/ssh_host_keys_spec.rb +11 -15
- data/spec/unit/provides_map_spec.rb +208 -0
- data/spec/unit/runner_spec.rb +488 -0
- data/spec/unit/system_spec.rb +639 -104
- metadata +151 -87
- checksums.yaml +0 -7
- data/lib/ohai/mixin/from_file.rb +0 -36
- data/lib/ohai/plugins/aix/ps.rb +0 -23
- data/lib/ohai/plugins/darwin/kernel.rb +0 -37
- data/lib/ohai/plugins/darwin/ps.rb +0 -23
- data/lib/ohai/plugins/darwin/uptime.rb +0 -32
- data/lib/ohai/plugins/dmi_common.rb +0 -121
- data/lib/ohai/plugins/freebsd/hostname.rb +0 -22
- data/lib/ohai/plugins/freebsd/kernel.rb +0 -37
- data/lib/ohai/plugins/freebsd/ps.rb +0 -24
- data/lib/ohai/plugins/hpux/cpu.rb +0 -19
- data/lib/ohai/plugins/hpux/filesystem.rb +0 -19
- data/lib/ohai/plugins/hpux/hostname.rb +0 -19
- data/lib/ohai/plugins/hpux/memory.rb +0 -19
- data/lib/ohai/plugins/hpux/network.rb +0 -19
- data/lib/ohai/plugins/hpux/platform.rb +0 -19
- data/lib/ohai/plugins/hpux/ps.rb +0 -23
- data/lib/ohai/plugins/hpux/uptime.rb +0 -19
- data/lib/ohai/plugins/linux/hostname.rb +0 -40
- data/lib/ohai/plugins/linux/ps.rb +0 -23
- data/lib/ohai/plugins/linux/uptime.rb +0 -28
- data/lib/ohai/plugins/netbsd/hostname.rb +0 -22
- data/lib/ohai/plugins/netbsd/kernel.rb +0 -35
- data/lib/ohai/plugins/netbsd/ps.rb +0 -24
- data/lib/ohai/plugins/netbsd/uptime.rb +0 -31
- data/lib/ohai/plugins/openbsd/hostname.rb +0 -22
- data/lib/ohai/plugins/openbsd/kernel.rb +0 -35
- data/lib/ohai/plugins/openbsd/ps.rb +0 -24
- data/lib/ohai/plugins/sigar/hostname.rb +0 -28
- data/lib/ohai/plugins/sigar/uptime.rb +0 -27
- data/lib/ohai/plugins/solaris2/hostname.rb +0 -34
- data/lib/ohai/plugins/solaris2/kernel.rb +0 -40
- data/lib/ohai/plugins/solaris2/ps.rb +0 -23
- data/lib/ohai/plugins/solaris2/uptime.rb +0 -36
- data/lib/ohai/plugins/windows/hostname.rb +0 -33
- data/lib/ohai/plugins/windows/kernel.rb +0 -58
- data/lib/ohai/plugins/windows/kernel_devices.rb +0 -39
- data/lib/ohai/plugins/windows/uptime.rb +0 -23
- data/spec/unit/mixin/from_file_spec.rb +0 -53
@@ -0,0 +1,488 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Claire McQuin (<claire@opscode.com>)
|
3
|
+
# Copyright:: Copyright (c) 2013 Opscode, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you
|
7
|
+
# may not use this file except in compliance with the License. You may
|
8
|
+
# 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 expressed or
|
15
|
+
# implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License
|
18
|
+
#
|
19
|
+
|
20
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
|
21
|
+
|
22
|
+
describe Ohai::Runner, "run_plugin" do
|
23
|
+
let(:safe_run) { true }
|
24
|
+
|
25
|
+
before(:each) do
|
26
|
+
@ohai = Ohai::System.new
|
27
|
+
@runner = Ohai::Runner.new(@ohai, safe_run)
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "when running an invalid plugin" do
|
31
|
+
it "should raise error" do
|
32
|
+
lambda { @runner.run_plugin(double("Ohai::NotPlugin")) }.should raise_error(Ohai::Exceptions::InvalidPlugin)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "when running a plugin" do
|
37
|
+
let(:plugin) { double("Ohai::DSL::Plugin", :kind_of? => true, :version => version, :name => "Test", :has_run? => has_run, :dependencies => [ ]) }
|
38
|
+
let(:version) { :version7 }
|
39
|
+
let(:has_run) { false }
|
40
|
+
|
41
|
+
describe "version 7" do
|
42
|
+
it "should call run_v7_plugin" do
|
43
|
+
@runner.should_receive(:run_v7_plugin)
|
44
|
+
@runner.run_plugin(plugin)
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "if the plugin has run before" do
|
48
|
+
let(:has_run) { true }
|
49
|
+
|
50
|
+
it "should not run the plugin" do
|
51
|
+
plugin.should_not_receive(:safe_run)
|
52
|
+
@runner.run_plugin(plugin)
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "if the plugin is disabled" do
|
56
|
+
it "should not run the plugin" do
|
57
|
+
Ohai::Config.should_receive(:[]).with(:disabled_plugins).and_return(["Test"])
|
58
|
+
@runner.should_not_receive(:run_v7_plugin)
|
59
|
+
@runner.run_plugin(plugin)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "version 6" do
|
66
|
+
let(:version) { :version6 }
|
67
|
+
|
68
|
+
it "should call run_v6_plugin" do
|
69
|
+
@runner.should_receive(:run_v6_plugin)
|
70
|
+
@runner.run_plugin(plugin)
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "if the plugin has not run before" do
|
74
|
+
describe "if safe_run is not set" do
|
75
|
+
it "safe_run should be called" do
|
76
|
+
plugin.should_receive(:safe_run)
|
77
|
+
@runner.run_plugin(plugin)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "if safe_run is set" do
|
82
|
+
let(:safe_run) { false }
|
83
|
+
|
84
|
+
it "run should be called" do
|
85
|
+
plugin.should_receive(:run)
|
86
|
+
@runner.run_plugin(plugin)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "if the plugin has run before" do
|
92
|
+
let(:has_run) { true }
|
93
|
+
|
94
|
+
it "should not run" do
|
95
|
+
plugin.should_not_receive(:safe_run)
|
96
|
+
@runner.run_plugin(plugin)
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "if the plugin is disabled" do
|
102
|
+
it "should not run the plugin" do
|
103
|
+
Ohai::Config.should_receive(:[]).with(:disabled_plugins).and_return(["Test"])
|
104
|
+
@runner.should_not_receive(:run_v7_plugin)
|
105
|
+
@runner.run_plugin(plugin)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "invalid version" do
|
111
|
+
let(:version) { :versionBla }
|
112
|
+
|
113
|
+
it "should raise error" do
|
114
|
+
lambda { @runner.run_plugin(plugin) }.should raise_error(Ohai::Exceptions::InvalidPlugin)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "when plugin is disabled" do
|
119
|
+
before do
|
120
|
+
Ohai::Config.should_receive(:[]).with(:disabled_plugins).and_return(["Test"])
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should not run the plugin" do
|
124
|
+
@runner.should_not_receive(:run_v7_plugin)
|
125
|
+
@runner.run_plugin(plugin)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe "when running a plugin with no dependencies, Ohai::Runner" do
|
131
|
+
let(:plugin) {
|
132
|
+
klass = Ohai.plugin(:Test) {
|
133
|
+
provides("thing")
|
134
|
+
collect_data {
|
135
|
+
thing(Mash.new)
|
136
|
+
}
|
137
|
+
}
|
138
|
+
klass.new(@ohai.data)
|
139
|
+
}
|
140
|
+
|
141
|
+
it "should run the plugin" do
|
142
|
+
@runner.run_plugin(plugin)
|
143
|
+
plugin.has_run?.should be_true
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should add plugin data to Ohai::System.data" do
|
147
|
+
@runner.run_plugin(plugin)
|
148
|
+
@ohai.data.should have_key(:thing)
|
149
|
+
@ohai.data[:thing].should eql({})
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe "when running a plugin with one dependency" do
|
154
|
+
describe "when the dependency does not exist" do
|
155
|
+
before(:each) do
|
156
|
+
klass = Ohai.plugin(:Test) {
|
157
|
+
provides("thing")
|
158
|
+
depends("other_thing")
|
159
|
+
collect_data {
|
160
|
+
thing(other_thing)
|
161
|
+
}
|
162
|
+
}
|
163
|
+
@plugin = klass.new(@ohai.data)
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should raise Ohai::Excpetions::AttributeNotFound" do
|
167
|
+
expect{ @runner.run_plugin(@plugin) }.to raise_error(Ohai::Exceptions::AttributeNotFound)
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should not run the plugin" do
|
171
|
+
expect{ @runner.run_plugin(@plugin) }.to raise_error
|
172
|
+
@plugin.has_run?.should be_false
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
describe "when the dependency has a single provider" do
|
177
|
+
before(:each) do
|
178
|
+
klass1 = Ohai.plugin(:Thing) {
|
179
|
+
provides("thing")
|
180
|
+
collect_data {
|
181
|
+
thing("thang")
|
182
|
+
}
|
183
|
+
}
|
184
|
+
klass2 = Ohai.plugin(:Other) {
|
185
|
+
provides("other")
|
186
|
+
depends("thing")
|
187
|
+
collect_data {
|
188
|
+
other(thing)
|
189
|
+
}
|
190
|
+
}
|
191
|
+
|
192
|
+
@plugins = []
|
193
|
+
[klass1, klass2].each do |klass|
|
194
|
+
@plugins << klass.new(@ohai.data)
|
195
|
+
end
|
196
|
+
@plugin1, @plugin2 = @plugins
|
197
|
+
|
198
|
+
@ohai.provides_map.set_providers_for(@plugin1, ["thing"])
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should run the plugins" do
|
202
|
+
@runner.run_plugin(@plugin2)
|
203
|
+
@plugins.each do |plugin|
|
204
|
+
plugin.has_run?.should be_true
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe "when the dependency has multiple providers" do
|
210
|
+
before(:each) do
|
211
|
+
klass1 = Ohai.plugin(:Thing) {
|
212
|
+
provides("thing")
|
213
|
+
collect_data {
|
214
|
+
thing(Mash.new)
|
215
|
+
}
|
216
|
+
}
|
217
|
+
klass2 = Ohai.plugin(:Other) {
|
218
|
+
provides("other")
|
219
|
+
depends("thing")
|
220
|
+
collect_data {
|
221
|
+
other(thing)
|
222
|
+
}
|
223
|
+
}
|
224
|
+
|
225
|
+
@plugins = []
|
226
|
+
[klass1, klass1, klass2].each do |klass|
|
227
|
+
@plugins << klass.new(@ohai.data)
|
228
|
+
end
|
229
|
+
@plugin1, @plugin2, @plugin3 = @plugins
|
230
|
+
|
231
|
+
@ohai.provides_map.set_providers_for(@plugin1, ["thing"])
|
232
|
+
@ohai.provides_map.set_providers_for(@plugin2, ["thing"])
|
233
|
+
end
|
234
|
+
|
235
|
+
it "should run the plugins" do
|
236
|
+
@runner.run_plugin(@plugin3)
|
237
|
+
@plugins.each do |plugin|
|
238
|
+
plugin.has_run?.should be_true
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
describe "when running a plugin with many dependencies" do
|
245
|
+
before(:each) do
|
246
|
+
@ohai = Ohai::System.new
|
247
|
+
@runner = Ohai::Runner.new(@ohai, true)
|
248
|
+
|
249
|
+
klass1 = Ohai.plugin(:One) {
|
250
|
+
provides("one")
|
251
|
+
collect_data {
|
252
|
+
one(1)
|
253
|
+
}
|
254
|
+
}
|
255
|
+
klass2 = Ohai.plugin(:Two) {
|
256
|
+
provides("two")
|
257
|
+
collect_data {
|
258
|
+
two(2)
|
259
|
+
}
|
260
|
+
}
|
261
|
+
klass3 = Ohai.plugin(:Three) {
|
262
|
+
provides("three")
|
263
|
+
depends("one", "two")
|
264
|
+
collect_data {
|
265
|
+
three(3)
|
266
|
+
}
|
267
|
+
}
|
268
|
+
|
269
|
+
@plugins = []
|
270
|
+
[klass1, klass2, klass3].each do |klass|
|
271
|
+
@plugins << klass.new(@ohai.data)
|
272
|
+
end
|
273
|
+
@plugin1, @plugin2, @plugin3 = @plugins
|
274
|
+
@ohai.provides_map.set_providers_for(@plugin1, ["one", "two"])
|
275
|
+
@ohai.provides_map.set_providers_for(@plugin2, ["one", "two"])
|
276
|
+
end
|
277
|
+
|
278
|
+
it "should run the plugins" do
|
279
|
+
@runner.run_plugin(@plugin3)
|
280
|
+
@plugins.each do |plugin|
|
281
|
+
plugin.has_run?.should be_true
|
282
|
+
end
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
describe "when a cycle is detected" do
|
287
|
+
let(:runner) { Ohai::Runner.new(@ohai, true) }
|
288
|
+
|
289
|
+
context "when there are no edges in the cycle (A->A)" do
|
290
|
+
let(:plugin_class) do
|
291
|
+
klass1 = Ohai.plugin(:Thing) do
|
292
|
+
provides("thing")
|
293
|
+
depends("thing")
|
294
|
+
collect_data do
|
295
|
+
thing(other)
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
299
|
+
let(:plugin) { plugin_class.new(@ohai.data) }
|
300
|
+
|
301
|
+
it "ignores the cycle" do
|
302
|
+
@ohai.provides_map.set_providers_for(plugin, ["thing"])
|
303
|
+
|
304
|
+
expected_error_string = "Dependency cycle detected. Please refer to the following plugins: Thing, Other"
|
305
|
+
runner.run_plugin(plugin) # should not raise
|
306
|
+
end
|
307
|
+
|
308
|
+
end
|
309
|
+
|
310
|
+
context "when there is one edge in the cycle (A->B and B->A)" do
|
311
|
+
before(:each) do
|
312
|
+
klass1 = Ohai.plugin(:Thing) {
|
313
|
+
provides("thing")
|
314
|
+
depends("other")
|
315
|
+
collect_data {
|
316
|
+
thing(other)
|
317
|
+
}
|
318
|
+
}
|
319
|
+
klass2 = Ohai.plugin(:Other) {
|
320
|
+
provides("other")
|
321
|
+
depends("thing")
|
322
|
+
collect_data {
|
323
|
+
other(thing)
|
324
|
+
}
|
325
|
+
}
|
326
|
+
|
327
|
+
@plugins = []
|
328
|
+
[klass1, klass2].each_with_index do |klass, idx|
|
329
|
+
@plugins << klass.new(@ohai.data)
|
330
|
+
end
|
331
|
+
|
332
|
+
@plugin1, @plugin2 = @plugins
|
333
|
+
end
|
334
|
+
|
335
|
+
it "should raise Ohai::Exceptions::DependencyCycle" do
|
336
|
+
runner.stub(:fetch_plugins).with(["thing"]).and_return([@plugin1])
|
337
|
+
runner.stub(:fetch_plugins).with(["other"]).and_return([@plugin2])
|
338
|
+
expected_error_string = "Dependency cycle detected. Please refer to the following plugins: Thing, Other"
|
339
|
+
expect { runner.run_plugin(@plugin1) }.to raise_error(Ohai::Exceptions::DependencyCycle, expected_error_string)
|
340
|
+
end
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
describe "when A depends on B and C, and B depends on C" do
|
345
|
+
before(:each) do
|
346
|
+
@ohai = Ohai::System.new
|
347
|
+
@runner = Ohai::Runner.new(@ohai, true)
|
348
|
+
|
349
|
+
klassA = Ohai.plugin(:A) {
|
350
|
+
provides("A")
|
351
|
+
depends("B", "C")
|
352
|
+
collect_data { }
|
353
|
+
}
|
354
|
+
klassB = Ohai.plugin(:B) {
|
355
|
+
provides("B")
|
356
|
+
depends("C")
|
357
|
+
collect_data { }
|
358
|
+
}
|
359
|
+
klassC = Ohai.plugin(:C) {
|
360
|
+
provides("C")
|
361
|
+
collect_data { }
|
362
|
+
}
|
363
|
+
|
364
|
+
@plugins = []
|
365
|
+
[klassA, klassB, klassC].each do |klass|
|
366
|
+
@plugins << klass.new(@ohai.data)
|
367
|
+
end
|
368
|
+
@pluginA, @pluginB, @pluginC = @plugins
|
369
|
+
end
|
370
|
+
|
371
|
+
it "should not detect a cycle when B is the first provider returned" do
|
372
|
+
@ohai.provides_map.set_providers_for(@pluginA, ["A"])
|
373
|
+
@ohai.provides_map.set_providers_for(@pluginB, ["B"])
|
374
|
+
@ohai.provides_map.set_providers_for(@pluginC, ["C"])
|
375
|
+
|
376
|
+
Ohai::Log.should_not_receive(:error).with(/DependencyCycleError/)
|
377
|
+
@runner.run_plugin(@pluginA)
|
378
|
+
|
379
|
+
@plugins.each do |plugin|
|
380
|
+
plugin.has_run?.should be_true
|
381
|
+
end
|
382
|
+
end
|
383
|
+
|
384
|
+
it "should not detect a cycle when C is the first provider returned" do
|
385
|
+
@ohai.provides_map.set_providers_for(@pluginA, ["A"])
|
386
|
+
@ohai.provides_map.set_providers_for(@pluginC, ["C"])
|
387
|
+
@ohai.provides_map.set_providers_for(@pluginB, ["B"])
|
388
|
+
|
389
|
+
Ohai::Log.should_not_receive(:error).with(/DependencyCycleError/)
|
390
|
+
@runner.run_plugin(@pluginA)
|
391
|
+
|
392
|
+
@plugins.each do |plugin|
|
393
|
+
plugin.has_run?.should be_true
|
394
|
+
end
|
395
|
+
end
|
396
|
+
end
|
397
|
+
end
|
398
|
+
|
399
|
+
describe Ohai::Runner, "fetch_plugins" do
|
400
|
+
before(:each) do
|
401
|
+
@provides_map = Ohai::ProvidesMap.new
|
402
|
+
@data = Mash.new
|
403
|
+
@ohai = double('Ohai::System', :data => @data, :provides_map => @provides_map)
|
404
|
+
@runner = Ohai::Runner.new(@ohai, true)
|
405
|
+
end
|
406
|
+
|
407
|
+
it "should collect the provider" do
|
408
|
+
plugin = Ohai::DSL::Plugin.new(@ohai.data)
|
409
|
+
@ohai.provides_map.set_providers_for(plugin, ["top/middle/bottom"])
|
410
|
+
|
411
|
+
dependency_providers = @runner.fetch_plugins(["top/middle/bottom"])
|
412
|
+
dependency_providers.should eql([plugin])
|
413
|
+
end
|
414
|
+
|
415
|
+
describe "when the attribute is not provided by any plugin" do
|
416
|
+
describe "and some parent attribute has providers" do
|
417
|
+
it "should return the providers for the parent" do
|
418
|
+
plugin = Ohai::DSL::Plugin.new(@ohai.data)
|
419
|
+
@provides_map.set_providers_for(plugin, ["test/attribute"])
|
420
|
+
@runner.fetch_plugins(["test/attribute/too_far"]).should eql([plugin])
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
424
|
+
describe "and no parent attribute has providers" do
|
425
|
+
it "should raise Ohai::Exceptions::AttributeNotFound exception" do
|
426
|
+
# provides map is empty
|
427
|
+
expect{ @runner.fetch_plugins(["false/attribute"]) }.to raise_error(Ohai::Exceptions::AttributeNotFound, "No such attribute: 'false/attribute'")
|
428
|
+
end
|
429
|
+
end
|
430
|
+
end
|
431
|
+
|
432
|
+
it "should return unique providers" do
|
433
|
+
plugin = Ohai::DSL::Plugin.new(@ohai.data)
|
434
|
+
@provides_map.set_providers_for(plugin, ["test", "test/too_far/way_too_far"])
|
435
|
+
@runner.fetch_plugins(["test", "test/too_far/way_too_far"]).should eql([plugin])
|
436
|
+
end
|
437
|
+
end
|
438
|
+
|
439
|
+
describe Ohai::Runner, "#get_cycle" do
|
440
|
+
before(:each) do
|
441
|
+
@ohai = Ohai::System.new
|
442
|
+
@runner = Ohai::Runner.new(@ohai, true)
|
443
|
+
|
444
|
+
klass1 = Ohai.plugin(:One) {
|
445
|
+
provides("one")
|
446
|
+
depends("two")
|
447
|
+
collect_data {
|
448
|
+
one(two)
|
449
|
+
}
|
450
|
+
}
|
451
|
+
klass2 = Ohai.plugin(:Two) {
|
452
|
+
provides("two")
|
453
|
+
depends("one")
|
454
|
+
collect_data {
|
455
|
+
two(one)
|
456
|
+
}
|
457
|
+
}
|
458
|
+
klass3 = Ohai.plugin(:Three) {
|
459
|
+
provides("three")
|
460
|
+
depends("two")
|
461
|
+
collect_data {
|
462
|
+
three(two)
|
463
|
+
}
|
464
|
+
}
|
465
|
+
|
466
|
+
plugins = []
|
467
|
+
[klass1, klass2, klass3].each_with_index do |klass, idx|
|
468
|
+
plugins << klass.new(@ohai.data)
|
469
|
+
end
|
470
|
+
@plugin1, @plugin2, @plugin3 = plugins
|
471
|
+
end
|
472
|
+
|
473
|
+
it "should return the sources for the plugins in the cycle, when given an exact cycle" do
|
474
|
+
cycle = [@plugin1, @plugin2]
|
475
|
+
cycle_start = @plugin1
|
476
|
+
|
477
|
+
cycle_names = @runner.get_cycle(cycle, cycle_start)
|
478
|
+
cycle_names.should eql([@plugin1.name, @plugin2.name])
|
479
|
+
end
|
480
|
+
|
481
|
+
it "should return the sources for only the plugins in the cycle, when there are plugins before the cycle begins" do
|
482
|
+
cycle = [@plugin3, @plugin1, @plugin2]
|
483
|
+
cycle_start = @plugin1
|
484
|
+
|
485
|
+
cycle_names = @runner.get_cycle(cycle, cycle_start)
|
486
|
+
cycle_names.should eql([@plugin1.name, @plugin2.name])
|
487
|
+
end
|
488
|
+
end
|