ohai 15.3.1 → 15.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -6
- data/lib/ohai/mixin/{network_constants.rb → network_helper.rb} +8 -1
- data/lib/ohai/plugins/aix/network.rb +3 -8
- data/lib/ohai/plugins/darwin/network.rb +6 -4
- data/lib/ohai/plugins/filesystem.rb +166 -0
- data/lib/ohai/plugins/network.rb +5 -5
- data/lib/ohai/plugins/openstack.rb +2 -1
- data/lib/ohai/plugins/solaris2/network.rb +6 -4
- data/lib/ohai/version.rb +1 -1
- data/ohai.gemspec +1 -1
- metadata +3 -162
- data/Rakefile +0 -42
- data/lib/ohai/plugins/windows/filesystem.rb +0 -147
- data/spec/data/plugins/dpkg-query.output +0 -4
- data/spec/data/plugins/lslpp.output +0 -50
- data/spec/data/plugins/pacman.output +0 -51
- data/spec/data/plugins/pkg-query.output +0 -58
- data/spec/data/plugins/pkginfo.output +0 -50
- data/spec/data/plugins/pkglist.output +0 -24
- data/spec/data/plugins/rpmquery.output +0 -7
- data/spec/functional/application_spec.rb +0 -107
- data/spec/functional/loader_spec.rb +0 -53
- data/spec/functional/plugins/powershell_spec.rb +0 -88
- data/spec/functional/plugins/root_group_spec.rb +0 -41
- data/spec/functional/plugins/windows/uptime_spec.rb +0 -51
- data/spec/ohai_spec.rb +0 -27
- data/spec/rcov.opts +0 -2
- data/spec/spec.opts +0 -2
- data/spec/spec_helper.rb +0 -124
- data/spec/support/integration_helper.rb +0 -61
- data/spec/support/platform_helpers.rb +0 -38
- data/spec/unit/application_spec.rb +0 -96
- data/spec/unit/config_spec.rb +0 -57
- data/spec/unit/dsl/plugin_spec.rb +0 -634
- data/spec/unit/hints_spec.rb +0 -65
- data/spec/unit/loader_spec.rb +0 -195
- data/spec/unit/mixin/azure_metadata_spec.rb +0 -72
- data/spec/unit/mixin/command_spec.rb +0 -151
- data/spec/unit/mixin/dmi_decode.rb +0 -75
- data/spec/unit/mixin/ec2_metadata_spec.rb +0 -88
- data/spec/unit/mixin/softlayer_metadata_spec.rb +0 -72
- data/spec/unit/plugin_config_spec.rb +0 -117
- data/spec/unit/plugins/abort_spec.rb +0 -69
- data/spec/unit/plugins/aix/cpu_spec.rb +0 -127
- data/spec/unit/plugins/aix/filesystem_spec.rb +0 -238
- data/spec/unit/plugins/aix/hostname_spec.rb +0 -33
- data/spec/unit/plugins/aix/kernel_spec.rb +0 -61
- data/spec/unit/plugins/aix/memory_spec.rb +0 -49
- data/spec/unit/plugins/aix/network_spec.rb +0 -313
- data/spec/unit/plugins/aix/platform_spec.rb +0 -44
- data/spec/unit/plugins/aix/uptime_spec.rb +0 -42
- data/spec/unit/plugins/aix/virtualization_spec.rb +0 -319
- data/spec/unit/plugins/azure_spec.rb +0 -243
- data/spec/unit/plugins/bsd/filesystem_spec.rb +0 -138
- data/spec/unit/plugins/bsd/virtualization_spec.rb +0 -145
- data/spec/unit/plugins/c_spec.rb +0 -341
- data/spec/unit/plugins/chef_spec.rb +0 -44
- data/spec/unit/plugins/cloud_spec.rb +0 -484
- data/spec/unit/plugins/darwin/cpu_spec.rb +0 -124
- data/spec/unit/plugins/darwin/filesystem_spec.rb +0 -140
- data/spec/unit/plugins/darwin/hardware_spec.rb +0 -105
- data/spec/unit/plugins/darwin/hardware_system_profiler_output.rb +0 -1110
- data/spec/unit/plugins/darwin/hostname_spec.rb +0 -43
- data/spec/unit/plugins/darwin/kernel_spec.rb +0 -65
- data/spec/unit/plugins/darwin/memory_spec.rb +0 -64
- data/spec/unit/plugins/darwin/network_spec.rb +0 -849
- data/spec/unit/plugins/darwin/platform_spec.rb +0 -71
- data/spec/unit/plugins/darwin/virtualization_spec.rb +0 -156
- data/spec/unit/plugins/digital_ocean_spec.rb +0 -106
- data/spec/unit/plugins/dmi_spec.rb +0 -156
- data/spec/unit/plugins/docker_spec.rb +0 -100
- data/spec/unit/plugins/ec2_spec.rb +0 -452
- data/spec/unit/plugins/elixir_spec.rb +0 -55
- data/spec/unit/plugins/erlang_spec.rb +0 -71
- data/spec/unit/plugins/eucalyptus_spec.rb +0 -109
- data/spec/unit/plugins/fail_spec.rb +0 -260
- data/spec/unit/plugins/freebsd/cpu_spec.rb +0 -129
- data/spec/unit/plugins/freebsd/hostname_spec.rb +0 -35
- data/spec/unit/plugins/freebsd/kernel_spec.rb +0 -36
- data/spec/unit/plugins/freebsd/platform_spec.rb +0 -38
- data/spec/unit/plugins/gce_spec.rb +0 -81
- data/spec/unit/plugins/go_spec.rb +0 -48
- data/spec/unit/plugins/groovy_spec.rb +0 -66
- data/spec/unit/plugins/haskell_spec.rb +0 -231
- data/spec/unit/plugins/hostname_spec.rb +0 -162
- data/spec/unit/plugins/init_package_spec.rb +0 -60
- data/spec/unit/plugins/java_spec.rb +0 -230
- data/spec/unit/plugins/joyent_spec.rb +0 -100
- data/spec/unit/plugins/kernel_spec.rb +0 -38
- data/spec/unit/plugins/linode_spec.rb +0 -135
- data/spec/unit/plugins/linux/block_device_spec.rb +0 -75
- data/spec/unit/plugins/linux/cpu_spec.rb +0 -441
- data/spec/unit/plugins/linux/filesystem_spec.rb +0 -550
- data/spec/unit/plugins/linux/fips_spec.rb +0 -60
- data/spec/unit/plugins/linux/hostname_spec.rb +0 -52
- data/spec/unit/plugins/linux/hostnamectl_spec.rb +0 -59
- data/spec/unit/plugins/linux/kernel_spec.rb +0 -71
- data/spec/unit/plugins/linux/lsb_spec.rb +0 -147
- data/spec/unit/plugins/linux/lspci_spec.rb +0 -133
- data/spec/unit/plugins/linux/machineid_spec.rb +0 -46
- data/spec/unit/plugins/linux/mdadm_spec.rb +0 -170
- data/spec/unit/plugins/linux/memory_spec.rb +0 -256
- data/spec/unit/plugins/linux/network_spec.rb +0 -1392
- data/spec/unit/plugins/linux/platform_spec.rb +0 -812
- data/spec/unit/plugins/linux/sessions_spec.rb +0 -98
- data/spec/unit/plugins/linux/sysctl_spec.rb +0 -53
- data/spec/unit/plugins/linux/systemd_paths_spec.rb +0 -122
- data/spec/unit/plugins/linux/uptime_spec.rb +0 -48
- data/spec/unit/plugins/linux/virtualization_spec.rb +0 -650
- data/spec/unit/plugins/lua_spec.rb +0 -60
- data/spec/unit/plugins/mono_spec.rb +0 -67
- data/spec/unit/plugins/netbsd/hostname_spec.rb +0 -43
- data/spec/unit/plugins/netbsd/kernel_spec.rb +0 -35
- data/spec/unit/plugins/netbsd/platform_spec.rb +0 -38
- data/spec/unit/plugins/network_spec.rb +0 -1078
- data/spec/unit/plugins/nodejs_spec.rb +0 -55
- data/spec/unit/plugins/ohai_spec.rb +0 -32
- data/spec/unit/plugins/ohai_time_spec.rb +0 -44
- data/spec/unit/plugins/openbsd/hostname_spec.rb +0 -43
- data/spec/unit/plugins/openbsd/kernel_spec.rb +0 -36
- data/spec/unit/plugins/openbsd/platform_spec.rb +0 -33
- data/spec/unit/plugins/openstack_spec.rb +0 -311
- data/spec/unit/plugins/os_spec.rb +0 -115
- data/spec/unit/plugins/packages_spec.rb +0 -353
- data/spec/unit/plugins/passwd_spec.rb +0 -65
- data/spec/unit/plugins/perl_spec.rb +0 -62
- data/spec/unit/plugins/php_spec.rb +0 -97
- data/spec/unit/plugins/platform_spec.rb +0 -65
- data/spec/unit/plugins/powershell_spec.rb +0 -71
- data/spec/unit/plugins/python_spec.rb +0 -51
- data/spec/unit/plugins/rackspace_spec.rb +0 -350
- data/spec/unit/plugins/root_group_spec.rb +0 -90
- data/spec/unit/plugins/ruby_spec.rb +0 -60
- data/spec/unit/plugins/rust_spec.rb +0 -43
- data/spec/unit/plugins/scala_spec.rb +0 -58
- data/spec/unit/plugins/scaleway_spec.rb +0 -93
- data/spec/unit/plugins/scsi_spec.rb +0 -69
- data/spec/unit/plugins/shard_spec.rb +0 -121
- data/spec/unit/plugins/shells_spec.rb +0 -56
- data/spec/unit/plugins/softlayer_spec.rb +0 -60
- data/spec/unit/plugins/solaris2/cpu_spec.rb +0 -2926
- data/spec/unit/plugins/solaris2/dmi_spec.rb +0 -153
- data/spec/unit/plugins/solaris2/filesystem.rb +0 -407
- data/spec/unit/plugins/solaris2/hostname_spec.rb +0 -37
- data/spec/unit/plugins/solaris2/kernel_spec.rb +0 -183
- data/spec/unit/plugins/solaris2/memory_spec.rb +0 -43
- data/spec/unit/plugins/solaris2/network_spec.rb +0 -201
- data/spec/unit/plugins/solaris2/platform_spec.rb +0 -108
- data/spec/unit/plugins/solaris2/virtualization_spec.rb +0 -97
- data/spec/unit/plugins/ssh_host_keys_spec.rb +0 -116
- data/spec/unit/plugins/sysconf_spec.rb +0 -680
- data/spec/unit/plugins/timezone_spec.rb +0 -30
- data/spec/unit/plugins/vbox_host_spec.rb +0 -14
- data/spec/unit/plugins/virtualbox_spec.rb +0 -375
- data/spec/unit/plugins/vmware_spec.rb +0 -81
- data/spec/unit/plugins/windows/cpu_spec.rb +0 -118
- data/spec/unit/plugins/windows/filesystem_spec.rb +0 -226
- data/spec/unit/plugins/windows/fips_spec.rb +0 -60
- data/spec/unit/plugins/windows/kernel_spec.rb +0 -79
- data/spec/unit/plugins/windows/memory_spec.rb +0 -52
- data/spec/unit/plugins/windows/network_spec.rb +0 -137
- data/spec/unit/plugins/windows/system_enclosure_spec.rb +0 -45
- data/spec/unit/plugins/windows/uptime_spec.rb +0 -38
- data/spec/unit/plugins/windows/virtualization_spec.rb +0 -63
- data/spec/unit/plugins/zpools_spec.rb +0 -244
- data/spec/unit/provides_map_spec.rb +0 -208
- data/spec/unit/runner_spec.rb +0 -422
- data/spec/unit/system_spec.rb +0 -416
- data/spec/unit/util/file_helper_spec.rb +0 -47
- data/spec/unit/util/ip_helper_spec.rb +0 -128
data/spec/unit/system_spec.rb
DELETED
@@ -1,416 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Adam Jacob (<adam@chef.io>)
|
3
|
-
# Author:: Claire McQuin (<claire@chef.io>)
|
4
|
-
# Copyright:: Copyright (c) 2008-2017, Chef Software Inc.
|
5
|
-
# License:: Apache License, Version 2.0
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
#
|
19
|
-
|
20
|
-
require "spec_helper"
|
21
|
-
require "ohai/mixin/os"
|
22
|
-
|
23
|
-
describe "Ohai::System" do
|
24
|
-
extend IntegrationSupport
|
25
|
-
|
26
|
-
let(:ohai_external) {}
|
27
|
-
let(:ohai) { Ohai::System.new({ invoked_from_cli: true }) }
|
28
|
-
|
29
|
-
describe "#initialize" do
|
30
|
-
it "returns an Ohai::System object" do
|
31
|
-
expect(ohai).to be_a_kind_of(Ohai::System)
|
32
|
-
end
|
33
|
-
|
34
|
-
it "sets @attributes to a ProvidesMap" do
|
35
|
-
expect(ohai.provides_map).to be_a_kind_of(Ohai::ProvidesMap)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "merges provided configuration options into the ohai config context" do
|
39
|
-
config = {
|
40
|
-
disabled_plugins: %i{Foo Baz},
|
41
|
-
directory: ["/some/extra/plugins"],
|
42
|
-
critical_plugins: %i{Foo Bar},
|
43
|
-
}
|
44
|
-
Ohai::System.new(config)
|
45
|
-
config.each do |option, value|
|
46
|
-
expect(Ohai.config[option]).to eq(value)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
context "when a single directory is configured as a string" do
|
51
|
-
let(:directory) { "/some/fantastic/plugins" }
|
52
|
-
|
53
|
-
it "adds directory to plugin_path" do
|
54
|
-
Ohai.config[:directory] = directory
|
55
|
-
Ohai::System.new({ invoked_from_cli: true })
|
56
|
-
expect(Ohai.config[:plugin_path]).to include("/some/fantastic/plugins")
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context "when multiple directories are configured" do
|
61
|
-
let(:directory) { ["/some/fantastic/plugins", "/some/other/plugins"] }
|
62
|
-
|
63
|
-
it "adds directories to plugin_path" do
|
64
|
-
Ohai.config[:directory] = directory
|
65
|
-
Ohai::System.new({ invoked_from_cli: true })
|
66
|
-
expect(Ohai.config[:plugin_path]).to include("/some/fantastic/plugins")
|
67
|
-
expect(Ohai.config[:plugin_path]).to include("/some/other/plugins")
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context "when testing the intializer that does way too much" do
|
72
|
-
it "configures logging" do
|
73
|
-
log_level = :debug
|
74
|
-
Ohai.config[:log_level] = log_level
|
75
|
-
expect(Ohai::Log).to receive(:level=).with(log_level)
|
76
|
-
Ohai::System.new({ invoked_from_cli: true })
|
77
|
-
end
|
78
|
-
|
79
|
-
it "resolves log_level when set to :auto" do
|
80
|
-
expect(Ohai::Log).to receive(:level=).with(:info)
|
81
|
-
Ohai::System.new({ invoked_from_cli: true })
|
82
|
-
end
|
83
|
-
|
84
|
-
context "when called externally" do
|
85
|
-
it "does not configure logging" do
|
86
|
-
log_level = :debug
|
87
|
-
Ohai.config[:log_level] = log_level
|
88
|
-
expect(Ohai::Log).not_to receive(:level=).with(log_level)
|
89
|
-
Ohai::System.new
|
90
|
-
end
|
91
|
-
|
92
|
-
it "does not resolve log_level when set to :auto" do
|
93
|
-
expect(Ohai::Log).not_to receive(:level=).with(:info)
|
94
|
-
Ohai::System.new
|
95
|
-
end
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
when_plugins_directory "contains directories inside" do
|
101
|
-
with_plugin("repo1/zoo.rb", <<~EOF)
|
102
|
-
Ohai.plugin(:Zoo) do
|
103
|
-
provides 'seals'
|
104
|
-
end
|
105
|
-
EOF
|
106
|
-
|
107
|
-
with_plugin("repo1/lake.rb", <<~EOF)
|
108
|
-
Ohai.plugin(:Nature) do
|
109
|
-
provides 'fish'
|
110
|
-
end
|
111
|
-
EOF
|
112
|
-
|
113
|
-
with_plugin("repo2/nature.rb", <<~EOF)
|
114
|
-
Ohai.plugin(:Nature) do
|
115
|
-
provides 'crabs'
|
116
|
-
end
|
117
|
-
EOF
|
118
|
-
|
119
|
-
with_plugin("repo2/mountain.rb", <<~EOF)
|
120
|
-
Ohai.plugin(:Nature) do
|
121
|
-
provides 'bear'
|
122
|
-
end
|
123
|
-
EOF
|
124
|
-
|
125
|
-
before do
|
126
|
-
Ohai.config[:plugin_path] = [ path_to("repo1"), path_to("repo2") ]
|
127
|
-
end
|
128
|
-
|
129
|
-
it "load_plugins() should load all the plugins" do
|
130
|
-
ohai.load_plugins
|
131
|
-
expect(ohai.provides_map.map.keys).to include("seals")
|
132
|
-
expect(ohai.provides_map.map.keys).to include("crabs")
|
133
|
-
expect(Ohai::NamedPlugin.const_get(:Zoo)).to eq(Ohai::NamedPlugin::Zoo)
|
134
|
-
expect(Ohai::NamedPlugin.const_get(:Nature)).to eq(Ohai::NamedPlugin::Nature)
|
135
|
-
end
|
136
|
-
|
137
|
-
end
|
138
|
-
|
139
|
-
describe "when running plugins" do
|
140
|
-
when_plugins_directory "contains a v7 plugins with :default and platform specific blocks" do
|
141
|
-
with_plugin("message.rb", <<~EOF)
|
142
|
-
Ohai.plugin(:Message) do
|
143
|
-
provides 'message'
|
144
|
-
|
145
|
-
collect_data(:default) do
|
146
|
-
message("default")
|
147
|
-
end
|
148
|
-
|
149
|
-
collect_data(:#{Ohai::Mixin::OS.collect_os}) do
|
150
|
-
message("platform_specific_message")
|
151
|
-
end
|
152
|
-
end
|
153
|
-
EOF
|
154
|
-
|
155
|
-
it "collects platform specific" do
|
156
|
-
Ohai.config[:plugin_path] = [ path_to(".") ]
|
157
|
-
ohai.all_plugins
|
158
|
-
expect(ohai.data[:message]).to eq("platform_specific_message")
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
|
-
when_plugins_directory "contains v7 plugins only" do
|
163
|
-
with_plugin("zoo.rb", <<~EOF)
|
164
|
-
Ohai.plugin(:Zoo) do
|
165
|
-
provides 'zoo'
|
166
|
-
|
167
|
-
collect_data(:default) do
|
168
|
-
zoo("animals")
|
169
|
-
end
|
170
|
-
end
|
171
|
-
EOF
|
172
|
-
|
173
|
-
with_plugin("park.rb", <<~EOF)
|
174
|
-
Ohai.plugin(:Park) do
|
175
|
-
provides 'park'
|
176
|
-
collect_data(:default) do
|
177
|
-
park("plants")
|
178
|
-
end
|
179
|
-
end
|
180
|
-
EOF
|
181
|
-
|
182
|
-
with_plugin("fails.rb", <<~EOF)
|
183
|
-
Ohai.plugin(:Fails) do
|
184
|
-
provides 'fails'
|
185
|
-
collect_data(:default) do
|
186
|
-
fail 'thing'
|
187
|
-
end
|
188
|
-
end
|
189
|
-
EOF
|
190
|
-
|
191
|
-
with_plugin("optional.rb", <<~EOF)
|
192
|
-
Ohai.plugin(:Optional) do
|
193
|
-
provides 'optional'
|
194
|
-
optional true
|
195
|
-
|
196
|
-
collect_data(:default) do
|
197
|
-
optional("canteloupe")
|
198
|
-
end
|
199
|
-
end
|
200
|
-
EOF
|
201
|
-
|
202
|
-
it "collects data from all the plugins" do
|
203
|
-
Ohai.config[:plugin_path] = [ path_to(".") ]
|
204
|
-
ohai.all_plugins
|
205
|
-
expect(ohai.data[:zoo]).to eq("animals")
|
206
|
-
expect(ohai.data[:park]).to eq("plants")
|
207
|
-
expect(ohai.data[:zoo]).to be_frozen
|
208
|
-
expect(ohai.data[:park]).to be_frozen
|
209
|
-
end
|
210
|
-
|
211
|
-
it "writes an error to Ohai::Log" do
|
212
|
-
Ohai.config[:plugin_path] = [ path_to(".") ]
|
213
|
-
# Make sure the stubbing of runner is not overriden with reset_system during test
|
214
|
-
allow(ohai).to receive(:reset_system)
|
215
|
-
allow(ohai.instance_variable_get("@runner")).to receive(:run_plugin).and_raise(Ohai::Exceptions::AttributeNotFound)
|
216
|
-
expect(ohai.logger).to receive(:error).with(/Encountered error while running plugins/)
|
217
|
-
expect { ohai.all_plugins }.to raise_error(Ohai::Exceptions::AttributeNotFound)
|
218
|
-
end
|
219
|
-
|
220
|
-
describe "when using :disabled_plugins" do
|
221
|
-
before do
|
222
|
-
Ohai.config[:disabled_plugins] = [ :Zoo ]
|
223
|
-
end
|
224
|
-
|
225
|
-
after do
|
226
|
-
Ohai.config[:disabled_plugins] = [ ]
|
227
|
-
end
|
228
|
-
|
229
|
-
it "does not run disabled plugins" do
|
230
|
-
Ohai.config[:plugin_path] = [ path_to(".") ]
|
231
|
-
ohai.all_plugins
|
232
|
-
expect(ohai.data[:zoo]).to be_nil
|
233
|
-
expect(ohai.data[:park]).to eq("plants")
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
describe "when using :critical_plugins" do
|
238
|
-
# if called from cli is true, we'll exit these tests
|
239
|
-
let(:ohai) { Ohai::System.new }
|
240
|
-
|
241
|
-
before do
|
242
|
-
Ohai.config[:critical_plugins] = [ :Fails ]
|
243
|
-
end
|
244
|
-
|
245
|
-
after do
|
246
|
-
Ohai.config[:critical_plugins] = []
|
247
|
-
end
|
248
|
-
|
249
|
-
it "fails when critical plugins fail" do
|
250
|
-
Ohai.config[:plugin_path] = [ path_to(".") ]
|
251
|
-
expect { ohai.all_plugins }.to raise_error(Ohai::Exceptions::CriticalPluginFailure,
|
252
|
-
"The following Ohai plugins marked as critical failed: [:Fails]. Failing Chef run.")
|
253
|
-
end
|
254
|
-
end
|
255
|
-
|
256
|
-
describe "when using :optional_plugins" do
|
257
|
-
it "does not run optional plugins by default" do
|
258
|
-
Ohai.config[:plugin_path] = [ path_to(".") ]
|
259
|
-
ohai.all_plugins
|
260
|
-
expect(ohai.data[:optional]).to be_nil
|
261
|
-
end
|
262
|
-
|
263
|
-
it "runs optional plugins when specifically enabled" do
|
264
|
-
Ohai.config[:optional_plugins] = [ :Optional ]
|
265
|
-
Ohai.config[:plugin_path] = [ path_to(".") ]
|
266
|
-
ohai.all_plugins
|
267
|
-
expect(ohai.data[:optional]).to eq("canteloupe")
|
268
|
-
end
|
269
|
-
|
270
|
-
it "runs optional plugins when all plugins are enabled" do
|
271
|
-
Ohai.config[:run_all_plugins] = true
|
272
|
-
Ohai.config[:plugin_path] = [ path_to(".") ]
|
273
|
-
ohai.all_plugins
|
274
|
-
expect(ohai.data[:optional]).to eq("canteloupe")
|
275
|
-
end
|
276
|
-
end
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
describe "when Chef OHAI resource executes :reload action" do
|
281
|
-
|
282
|
-
when_plugins_directory "contains a random plugin" do
|
283
|
-
with_plugin("random.rb", <<-E)
|
284
|
-
Ohai.plugin(:Random) do
|
285
|
-
provides 'random'
|
286
|
-
|
287
|
-
collect_data do
|
288
|
-
random rand(1 << 32)
|
289
|
-
end
|
290
|
-
end
|
291
|
-
E
|
292
|
-
|
293
|
-
before do
|
294
|
-
Ohai.config[:plugin_path] = [ path_to(".") ]
|
295
|
-
end
|
296
|
-
|
297
|
-
it "reruns the plugin providing the desired attributes" do
|
298
|
-
ohai.all_plugins
|
299
|
-
initial_value = ohai.data["random"]
|
300
|
-
ohai.all_plugins
|
301
|
-
updated_value = ohai.data["random"]
|
302
|
-
expect(initial_value).not_to eq(updated_value)
|
303
|
-
end
|
304
|
-
|
305
|
-
end
|
306
|
-
end
|
307
|
-
|
308
|
-
describe "when running ohai for specific attributes" do
|
309
|
-
when_plugins_directory "contains v7 plugins" do
|
310
|
-
with_plugin("languages.rb", <<-E)
|
311
|
-
Ohai.plugin(:Languages) do
|
312
|
-
provides 'languages'
|
313
|
-
|
314
|
-
collect_data do
|
315
|
-
languages Mash.new
|
316
|
-
end
|
317
|
-
end
|
318
|
-
E
|
319
|
-
|
320
|
-
with_plugin("english.rb", <<-E)
|
321
|
-
Ohai.plugin(:English) do
|
322
|
-
provides 'languages/english'
|
323
|
-
|
324
|
-
depends 'languages'
|
325
|
-
|
326
|
-
collect_data do
|
327
|
-
languages[:english] = Mash.new
|
328
|
-
languages[:english][:version] = 2014
|
329
|
-
end
|
330
|
-
end
|
331
|
-
E
|
332
|
-
|
333
|
-
with_plugin("french.rb", <<-E)
|
334
|
-
Ohai.plugin(:French) do
|
335
|
-
provides 'languages/french'
|
336
|
-
|
337
|
-
depends 'languages'
|
338
|
-
|
339
|
-
collect_data do
|
340
|
-
languages[:french] = Mash.new
|
341
|
-
languages[:french][:version] = 2012
|
342
|
-
end
|
343
|
-
end
|
344
|
-
E
|
345
|
-
|
346
|
-
before do
|
347
|
-
Ohai.config[:plugin_path] = [ path_to(".") ]
|
348
|
-
end
|
349
|
-
|
350
|
-
it "runs all the plugins when a top level attribute is specified" do
|
351
|
-
ohai.all_plugins("languages")
|
352
|
-
expect(ohai.data[:languages][:english][:version]).to eq(2014)
|
353
|
-
expect(ohai.data[:languages][:french][:version]).to eq(2012)
|
354
|
-
end
|
355
|
-
|
356
|
-
it "runs the first parent when a non-existent child is specified" do
|
357
|
-
ohai.all_plugins("languages/english/version")
|
358
|
-
expect(ohai.data[:languages][:english][:version]).to eq(2014)
|
359
|
-
expect(ohai.data[:languages][:french]).to be_nil
|
360
|
-
end
|
361
|
-
|
362
|
-
it "is able to run multiple plugins" do
|
363
|
-
ohai.all_plugins(["languages/english", "languages/french"])
|
364
|
-
expect(ohai.data[:languages][:english][:version]).to eq(2014)
|
365
|
-
expect(ohai.data[:languages][:french][:version]).to eq(2012)
|
366
|
-
end
|
367
|
-
|
368
|
-
end
|
369
|
-
end
|
370
|
-
|
371
|
-
describe "when loading a specific plugin path" do
|
372
|
-
when_plugins_directory "contains v7 plugins" do
|
373
|
-
with_plugin("my_cookbook/canteloupe.rb", <<-E)
|
374
|
-
Ohai.plugin(:Canteloupe) do
|
375
|
-
provides 'canteloupe'
|
376
|
-
|
377
|
-
collect_data do
|
378
|
-
canteloupe Mash.new
|
379
|
-
end
|
380
|
-
end
|
381
|
-
E
|
382
|
-
|
383
|
-
with_plugin("english/english.rb", <<-E)
|
384
|
-
Ohai.plugin(:English) do
|
385
|
-
provides 'canteloupe/english'
|
386
|
-
|
387
|
-
depends 'canteloupe'
|
388
|
-
|
389
|
-
collect_data do
|
390
|
-
canteloupe[:english] = Mash.new
|
391
|
-
canteloupe[:english][:version] = 2014
|
392
|
-
end
|
393
|
-
end
|
394
|
-
E
|
395
|
-
|
396
|
-
with_plugin("french/french.rb", <<-E)
|
397
|
-
Ohai.plugin(:French) do
|
398
|
-
provides 'canteloupe/french'
|
399
|
-
|
400
|
-
depends 'canteloupe'
|
401
|
-
|
402
|
-
collect_data do
|
403
|
-
canteloupe[:french] = Mash.new
|
404
|
-
canteloupe[:french][:version] = 2012
|
405
|
-
end
|
406
|
-
end
|
407
|
-
E
|
408
|
-
|
409
|
-
it "runs all the plugins" do
|
410
|
-
ohai.run_additional_plugins(@plugins_directory)
|
411
|
-
expect(ohai.data[:canteloupe][:english][:version]).to eq(2014)
|
412
|
-
expect(ohai.data[:canteloupe][:french][:version]).to eq(2012)
|
413
|
-
end
|
414
|
-
end
|
415
|
-
end
|
416
|
-
end
|
@@ -1,47 +0,0 @@
|
|
1
|
-
# Author:: Bryan McLellan <btm@loftninjas.org>
|
2
|
-
#
|
3
|
-
# Copyright:: Copyright (c) 2014-2016 Chef Software, Inc.
|
4
|
-
#
|
5
|
-
# License:: Apache License, Version 2.0
|
6
|
-
#
|
7
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
-
# you may not use this file except in compliance with the License.
|
9
|
-
# You may obtain a copy of the License at
|
10
|
-
#
|
11
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
-
#
|
13
|
-
# Unless required by applicable law or agreed to in writing, software
|
14
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
-
# See the License for the specific language governing permissions and
|
17
|
-
# limitations under the License.
|
18
|
-
|
19
|
-
require "spec_helper"
|
20
|
-
require "ohai/util/file_helper"
|
21
|
-
|
22
|
-
class FileHelperMock
|
23
|
-
include Ohai::Util::FileHelper
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "Ohai::Util::FileHelper" do
|
27
|
-
let(:file_helper) { FileHelperMock.new }
|
28
|
-
|
29
|
-
before do
|
30
|
-
allow(file_helper).to receive(:name).and_return("Fakeclass")
|
31
|
-
logger = instance_double("Mixlib::Log::Child", trace: nil, debug: nil, warn: nil)
|
32
|
-
allow(file_helper).to receive(:logger).and_return(logger)
|
33
|
-
allow(File).to receive(:executable?).and_return(false)
|
34
|
-
end
|
35
|
-
|
36
|
-
describe "which" do
|
37
|
-
it "returns the path to an executable that is in the path" do
|
38
|
-
allow(File).to receive(:executable?).with("/usr/bin/skyhawk").and_return(true)
|
39
|
-
|
40
|
-
expect(file_helper.which("skyhawk")).to eql "/usr/bin/skyhawk"
|
41
|
-
end
|
42
|
-
|
43
|
-
it "returns false if the executable is not in the path" do
|
44
|
-
expect(file_helper.which("the_cake")).to be false
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|