ohai 15.2.5 → 15.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ohai/application.rb +2 -2
- data/lib/ohai/mixin/dmi_decode.rb +4 -1
- data/lib/ohai/plugins/linux/sysctl.rb +38 -0
- data/lib/ohai/plugins/linux/virtualization.rb +11 -10
- data/lib/ohai/plugins/openstack.rb +8 -3
- data/lib/ohai/plugins/passwd.rb +4 -0
- data/lib/ohai/version.rb +1 -1
- data/spec/functional/application_spec.rb +5 -5
- data/spec/functional/loader_spec.rb +2 -2
- data/spec/functional/plugins/powershell_spec.rb +11 -5
- data/spec/functional/plugins/root_group_spec.rb +1 -1
- data/spec/functional/plugins/windows/uptime_spec.rb +3 -3
- data/spec/ohai_spec.rb +1 -1
- data/spec/spec_helper.rb +8 -8
- data/spec/support/integration_helper.rb +3 -3
- data/spec/unit/application_spec.rb +5 -5
- data/spec/unit/dsl/plugin_spec.rb +8 -7
- data/spec/unit/mixin/command_spec.rb +2 -2
- data/spec/unit/mixin/dmi_decode.rb +8 -1
- data/spec/unit/plugins/abort_spec.rb +4 -4
- data/spec/unit/plugins/aix/cpu_spec.rb +1 -1
- data/spec/unit/plugins/aix/filesystem_spec.rb +1 -1
- data/spec/unit/plugins/aix/hostname_spec.rb +2 -2
- data/spec/unit/plugins/aix/kernel_spec.rb +1 -1
- data/spec/unit/plugins/aix/memory_spec.rb +5 -5
- data/spec/unit/plugins/aix/network_spec.rb +4 -1
- data/spec/unit/plugins/aix/platform_spec.rb +4 -4
- data/spec/unit/plugins/aix/uptime_spec.rb +3 -3
- data/spec/unit/plugins/aix/virtualization_spec.rb +1 -1
- data/spec/unit/plugins/azure_spec.rb +8 -8
- data/spec/unit/plugins/bsd/filesystem_spec.rb +17 -16
- data/spec/unit/plugins/bsd/virtualization_spec.rb +1 -1
- data/spec/unit/plugins/c_spec.rb +6 -5
- data/spec/unit/plugins/chef_spec.rb +2 -2
- data/spec/unit/plugins/cloud_spec.rb +4 -4
- data/spec/unit/plugins/darwin/cpu_spec.rb +11 -11
- data/spec/unit/plugins/darwin/filesystem_spec.rb +14 -13
- data/spec/unit/plugins/darwin/hardware_spec.rb +2 -1
- data/spec/unit/plugins/darwin/hostname_spec.rb +3 -3
- data/spec/unit/plugins/darwin/kernel_spec.rb +5 -5
- data/spec/unit/plugins/darwin/memory_spec.rb +5 -5
- data/spec/unit/plugins/darwin/network_spec.rb +3 -3
- data/spec/unit/plugins/darwin/platform_spec.rb +9 -9
- data/spec/unit/plugins/darwin/virtualization_spec.rb +10 -10
- data/spec/unit/plugins/digital_ocean_spec.rb +14 -12
- data/spec/unit/plugins/dmi_spec.rb +1 -1
- data/spec/unit/plugins/docker_spec.rb +2 -2
- data/spec/unit/plugins/ec2_spec.rb +41 -30
- data/spec/unit/plugins/elixir_spec.rb +2 -2
- data/spec/unit/plugins/erlang_spec.rb +1 -1
- data/spec/unit/plugins/eucalyptus_spec.rb +17 -13
- data/spec/unit/plugins/fail_spec.rb +15 -15
- data/spec/unit/plugins/freebsd/cpu_spec.rb +2 -2
- data/spec/unit/plugins/freebsd/hostname_spec.rb +1 -1
- data/spec/unit/plugins/freebsd/kernel_spec.rb +2 -2
- data/spec/unit/plugins/freebsd/platform_spec.rb +3 -3
- data/spec/unit/plugins/gce_spec.rb +9 -7
- data/spec/unit/plugins/go_spec.rb +2 -2
- data/spec/unit/plugins/groovy_spec.rb +1 -1
- data/spec/unit/plugins/haskell_spec.rb +10 -10
- data/spec/unit/plugins/hostname_spec.rb +15 -14
- data/spec/unit/plugins/init_package_spec.rb +4 -4
- data/spec/unit/plugins/java_spec.rb +7 -3
- data/spec/unit/plugins/joyent_spec.rb +4 -4
- data/spec/unit/plugins/kernel_spec.rb +1 -1
- data/spec/unit/plugins/linux/block_device_spec.rb +2 -2
- data/spec/unit/plugins/linux/cpu_spec.rb +9 -8
- data/spec/unit/plugins/linux/filesystem_spec.rb +36 -35
- data/spec/unit/plugins/linux/fips_spec.rb +7 -5
- data/spec/unit/plugins/linux/hostname_spec.rb +4 -4
- data/spec/unit/plugins/linux/hostnamectl_spec.rb +3 -3
- data/spec/unit/plugins/linux/kernel_spec.rb +1 -1
- data/spec/unit/plugins/linux/lsb_spec.rb +18 -18
- data/spec/unit/plugins/linux/lspci_spec.rb +2 -1
- data/spec/unit/plugins/linux/machineid_spec.rb +3 -3
- data/spec/unit/plugins/linux/mdadm_spec.rb +13 -13
- data/spec/unit/plugins/linux/memory_spec.rb +39 -39
- data/spec/unit/plugins/linux/network_spec.rb +20 -19
- data/spec/unit/plugins/linux/platform_spec.rb +60 -57
- data/spec/unit/plugins/linux/sessions_spec.rb +3 -3
- data/spec/unit/plugins/linux/sysctl_spec.rb +53 -0
- data/spec/unit/plugins/linux/systemd_paths_spec.rb +3 -3
- data/spec/unit/plugins/linux/uptime_spec.rb +5 -5
- data/spec/unit/plugins/linux/virtualization_spec.rb +4 -4
- data/spec/unit/plugins/lua_spec.rb +1 -1
- data/spec/unit/plugins/mono_spec.rb +1 -1
- data/spec/unit/plugins/netbsd/hostname_spec.rb +3 -3
- data/spec/unit/plugins/netbsd/kernel_spec.rb +2 -2
- data/spec/unit/plugins/netbsd/platform_spec.rb +3 -3
- data/spec/unit/plugins/network_spec.rb +3 -3
- data/spec/unit/plugins/nodejs_spec.rb +1 -1
- data/spec/unit/plugins/ohai_spec.rb +2 -2
- data/spec/unit/plugins/ohai_time_spec.rb +4 -4
- data/spec/unit/plugins/openbsd/hostname_spec.rb +3 -3
- data/spec/unit/plugins/openbsd/kernel_spec.rb +2 -2
- data/spec/unit/plugins/openbsd/platform_spec.rb +2 -2
- data/spec/unit/plugins/openstack_spec.rb +13 -8
- data/spec/unit/plugins/os_spec.rb +12 -12
- data/spec/unit/plugins/packages_spec.rb +10 -7
- data/spec/unit/plugins/passwd_spec.rb +18 -19
- data/spec/unit/plugins/perl_spec.rb +1 -1
- data/spec/unit/plugins/php_spec.rb +1 -1
- data/spec/unit/plugins/platform_spec.rb +7 -7
- data/spec/unit/plugins/powershell_spec.rb +1 -1
- data/spec/unit/plugins/rackspace_spec.rb +25 -20
- data/spec/unit/plugins/root_group_spec.rb +14 -10
- data/spec/unit/plugins/ruby_spec.rb +2 -2
- data/spec/unit/plugins/rust_spec.rb +3 -3
- data/spec/unit/plugins/scala_spec.rb +2 -2
- data/spec/unit/plugins/scaleway_spec.rb +14 -12
- data/spec/unit/plugins/scsi_spec.rb +2 -1
- data/spec/unit/plugins/shard_spec.rb +18 -16
- data/spec/unit/plugins/solaris2/cpu_spec.rb +29 -29
- data/spec/unit/plugins/solaris2/dmi_spec.rb +4 -4
- data/spec/unit/plugins/solaris2/filesystem.rb +3 -3
- data/spec/unit/plugins/solaris2/hostname_spec.rb +2 -2
- data/spec/unit/plugins/solaris2/kernel_spec.rb +4 -4
- data/spec/unit/plugins/solaris2/memory_spec.rb +4 -4
- data/spec/unit/plugins/solaris2/platform_spec.rb +9 -9
- data/spec/unit/plugins/solaris2/virtualization_spec.rb +6 -6
- data/spec/unit/plugins/ssh_host_keys_spec.rb +4 -1
- data/spec/unit/plugins/sysconf_spec.rb +2 -2
- data/spec/unit/plugins/timezone_spec.rb +2 -2
- data/spec/unit/plugins/virtualbox_spec.rb +10 -10
- data/spec/unit/plugins/vmware_spec.rb +4 -4
- data/spec/unit/plugins/windows/cpu_spec.rb +13 -13
- data/spec/unit/plugins/windows/filesystem_spec.rb +1 -1
- data/spec/unit/plugins/windows/fips_spec.rb +7 -5
- data/spec/unit/plugins/windows/kernel_spec.rb +1 -1
- data/spec/unit/plugins/windows/memory_spec.rb +4 -4
- data/spec/unit/plugins/windows/network_spec.rb +1 -1
- data/spec/unit/plugins/windows/system_enclosure_spec.rb +2 -2
- data/spec/unit/plugins/windows/uptime_spec.rb +1 -1
- data/spec/unit/plugins/windows/virtualization_spec.rb +1 -1
- data/spec/unit/plugins/zpools_spec.rb +2 -0
- data/spec/unit/provides_map_spec.rb +18 -18
- data/spec/unit/runner_spec.rb +29 -29
- data/spec/unit/system_spec.rb +13 -13
- data/spec/unit/util/file_helper_spec.rb +1 -1
- data/spec/unit/util/ip_helper_spec.rb +6 -6
- metadata +4 -2
@@ -20,16 +20,16 @@ require "spec_helper"
|
|
20
20
|
require "openssl"
|
21
21
|
|
22
22
|
describe Ohai::System, "plugin fips" do
|
23
|
-
let(:enabled) { 0 }
|
24
|
-
let(:plugin) { get_plugin("windows/fips") }
|
25
|
-
let(:openssl_test_mode) { false }
|
26
|
-
|
27
23
|
subject do
|
28
24
|
plugin.run
|
29
25
|
plugin["fips"]["kernel"]["enabled"]
|
30
26
|
end
|
31
27
|
|
32
|
-
|
28
|
+
let(:enabled) { 0 }
|
29
|
+
let(:plugin) { get_plugin("windows/fips") }
|
30
|
+
let(:openssl_test_mode) { false }
|
31
|
+
|
32
|
+
before do
|
33
33
|
allow(plugin).to receive(:collect_os).and_return(:windows)
|
34
34
|
end
|
35
35
|
|
@@ -44,6 +44,7 @@ describe Ohai::System, "plugin fips" do
|
|
44
44
|
|
45
45
|
context "with OpenSSL.fips_mode == false" do
|
46
46
|
before { allow(OpenSSL).to receive(:fips_mode).and_return(false) }
|
47
|
+
|
47
48
|
it "does not set fips plugin" do
|
48
49
|
expect(subject).to be(false)
|
49
50
|
end
|
@@ -51,6 +52,7 @@ describe Ohai::System, "plugin fips" do
|
|
51
52
|
|
52
53
|
context "with OpenSSL.fips_mode == true" do
|
53
54
|
before { allow(OpenSSL).to receive(:fips_mode).and_return(true) }
|
55
|
+
|
54
56
|
it "sets fips plugin" do
|
55
57
|
expect(subject).to be(true)
|
56
58
|
end
|
@@ -65,7 +65,7 @@ describe Ohai::System, "Windows kernel plugin", :windows_only do
|
|
65
65
|
plugin.run
|
66
66
|
end
|
67
67
|
|
68
|
-
it "
|
68
|
+
it "sets the correct system information" do
|
69
69
|
expect(plugin[:kernel][:name]).to eq("Microsoft Windows 7 Ultimate")
|
70
70
|
expect(plugin[:kernel][:release]).to eq("6.1.7601")
|
71
71
|
expect(plugin[:kernel][:version]).to eq("6.1.7601 Service Pack 1 Build 7601")
|
@@ -29,22 +29,22 @@ describe Ohai::System, "Windows memory plugin", :windows_only do
|
|
29
29
|
expect_any_instance_of(WmiLite::Wmi).to receive(:first_of).with("Win32_OperatingSystem").and_return(mock_os)
|
30
30
|
end
|
31
31
|
|
32
|
-
it "
|
32
|
+
it "gets total memory" do
|
33
33
|
@plugin.run
|
34
34
|
expect(@plugin["memory"]["total"]).to eql("10485760kB")
|
35
35
|
end
|
36
36
|
|
37
|
-
it "
|
37
|
+
it "gets free memory" do
|
38
38
|
@plugin.run
|
39
39
|
expect(@plugin["memory"]["free"]).to eql("5242880kB")
|
40
40
|
end
|
41
41
|
|
42
|
-
it "
|
42
|
+
it "gets total swap" do
|
43
43
|
@plugin.run
|
44
44
|
expect(@plugin["memory"]["swap"]["total"]).to eql("20971520kB")
|
45
45
|
end
|
46
46
|
|
47
|
-
it "
|
47
|
+
it "gets free memory" do
|
48
48
|
@plugin.run
|
49
49
|
expect(@plugin["memory"]["swap"]["free"]).to eql("15728640kB")
|
50
50
|
end
|
@@ -33,12 +33,12 @@ describe Ohai::System, "System Enclosure", :windows_only do
|
|
33
33
|
expect_any_instance_of(WmiLite::Wmi).to receive(:first_of).with(("Win32_SystemEnclosure")).and_return(wmi_object)
|
34
34
|
end
|
35
35
|
|
36
|
-
it "
|
36
|
+
it "returns the manufacturer" do
|
37
37
|
@plugin.run
|
38
38
|
expect(@plugin["system_enclosure"]["manufacturer"]).to eql("My Fake Manufacturer")
|
39
39
|
end
|
40
40
|
|
41
|
-
it "
|
41
|
+
it "returns a serial number" do
|
42
42
|
@plugin.run
|
43
43
|
expect(@plugin["system_enclosure"]["serialnumber"]).to eql("1234123412341234")
|
44
44
|
end
|
@@ -23,7 +23,7 @@ describe Ohai::System, "Windows plugin uptime" do
|
|
23
23
|
let(:plugin) { get_plugin("uptime") }
|
24
24
|
let(:wmi) { double("wmi", { first_of: "" }) }
|
25
25
|
|
26
|
-
before
|
26
|
+
before do
|
27
27
|
allow(WmiLite::Wmi).to receive(:new).and_return(wmi)
|
28
28
|
allow(plugin).to receive(:collect_os).and_return(:windows)
|
29
29
|
end
|
@@ -24,7 +24,7 @@ describe Ohai::System, "Windows virtualization platform" do
|
|
24
24
|
let(:plugin) { get_plugin("windows/virtualization") }
|
25
25
|
let(:wmi) { double("WmiLite::Wmi") }
|
26
26
|
|
27
|
-
before
|
27
|
+
before do
|
28
28
|
allow(WmiLite::Wmi).to receive(:new).and_return(wmi)
|
29
29
|
allow(plugin).to receive(:collect_os).and_return(:windows)
|
30
30
|
end
|
@@ -66,6 +66,7 @@ describe Ohai::System, "zpools plugin" do
|
|
66
66
|
errors: No known data errors
|
67
67
|
EOSR
|
68
68
|
end
|
69
|
+
|
69
70
|
before do
|
70
71
|
allow(plugin).to receive(:platform_family).and_return("rhel")
|
71
72
|
allow(plugin).to receive(:collect_os).and_return(:linux)
|
@@ -177,6 +178,7 @@ describe Ohai::System, "zpools plugin" do
|
|
177
178
|
errors: No known data errors
|
178
179
|
EOSR
|
179
180
|
end
|
181
|
+
|
180
182
|
before do
|
181
183
|
allow(plugin).to receive(:platform_family).and_return("solaris2")
|
182
184
|
allow(plugin).to receive(:collect_os).and_return(:solaris2)
|
@@ -30,13 +30,13 @@ describe Ohai::ProvidesMap do
|
|
30
30
|
|
31
31
|
describe "when looking up providing plugins for a single attribute" do
|
32
32
|
describe "when the attribute does not exist" do
|
33
|
-
it "
|
33
|
+
it "raises Ohai::Exceptions::AttributeNotFound error" do
|
34
34
|
expect { provides_map.find_providers_for(["single"]) }.to raise_error(Ohai::Exceptions::AttributeNotFound, "No such attribute: 'single'")
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
describe "when the attribute does not have a provider" do
|
39
|
-
it "
|
39
|
+
it "raises Ohai::Exceptions::ProviderNotFound error" do
|
40
40
|
provides_map.set_providers_for(plugin_1, ["first/second"])
|
41
41
|
expect { provides_map.find_providers_for(["first"]) }.to raise_error(Ohai::Exceptions::ProviderNotFound, "Cannot find plugin providing attribute: 'first'")
|
42
42
|
end
|
@@ -47,7 +47,7 @@ describe Ohai::ProvidesMap do
|
|
47
47
|
provides_map.set_providers_for(plugin_1, ["single"])
|
48
48
|
end
|
49
49
|
|
50
|
-
it "
|
50
|
+
it "returns the provider" do
|
51
51
|
expect(provides_map.find_providers_for(["single"])).to eq([plugin_1])
|
52
52
|
end
|
53
53
|
end
|
@@ -58,7 +58,7 @@ describe Ohai::ProvidesMap do
|
|
58
58
|
provides_map.set_providers_for(plugin_2, ["single"])
|
59
59
|
end
|
60
60
|
|
61
|
-
it "
|
61
|
+
it "returns all providers" do
|
62
62
|
expect(provides_map.find_providers_for(["single"])).to eq([plugin_1, plugin_2])
|
63
63
|
end
|
64
64
|
end
|
@@ -72,7 +72,7 @@ describe Ohai::ProvidesMap do
|
|
72
72
|
provides_map.set_providers_for(plugin_2, ["two"])
|
73
73
|
end
|
74
74
|
|
75
|
-
it "
|
75
|
+
it "returns each provider" do
|
76
76
|
expect(provides_map.find_providers_for(%w{one two})).to eq([plugin_1, plugin_2])
|
77
77
|
end
|
78
78
|
end
|
@@ -84,7 +84,7 @@ describe Ohai::ProvidesMap do
|
|
84
84
|
provides_map.set_providers_for(plugin_1, ["one_again"])
|
85
85
|
end
|
86
86
|
|
87
|
-
it "
|
87
|
+
it "returns unique providers" do
|
88
88
|
expect(provides_map.find_providers_for(%w{one one_again})).to eq([plugin_1])
|
89
89
|
end
|
90
90
|
end
|
@@ -96,7 +96,7 @@ describe Ohai::ProvidesMap do
|
|
96
96
|
provides_map.set_providers_for(plugin_1, ["top/middle/bottom"])
|
97
97
|
end
|
98
98
|
|
99
|
-
it "
|
99
|
+
it "collects the provider" do
|
100
100
|
expect(provides_map.find_providers_for(["top/middle/bottom"])).to eq([plugin_1])
|
101
101
|
end
|
102
102
|
end
|
@@ -104,13 +104,13 @@ describe Ohai::ProvidesMap do
|
|
104
104
|
|
105
105
|
describe "when setting multi-level attributes" do
|
106
106
|
describe "when the attribute contains //" do
|
107
|
-
it "
|
107
|
+
it "raises an Ohai::Exceptions::AttributeSyntaxError" do
|
108
108
|
expect { provides_map.set_providers_for(plugin_1, ["this/plugin//is/bad"]) }.to raise_error(Ohai::Exceptions::AttributeSyntaxError, "Attribute contains duplicate '/' characters: this/plugin//is/bad")
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
112
|
describe "when the attribute has a trailing slash" do
|
113
|
-
it "
|
113
|
+
it "raises an Ohai::Exceptions::AttributeSyntaxError" do
|
114
114
|
expect { provides_map.set_providers_for(plugin_1, ["this/plugin/is/bad/"]) }.to raise_error(Ohai::Exceptions::AttributeSyntaxError, "Attribute contains a trailing '/': this/plugin/is/bad/")
|
115
115
|
end
|
116
116
|
end
|
@@ -123,7 +123,7 @@ describe Ohai::ProvidesMap do
|
|
123
123
|
provides_map.set_providers_for(plugin_3, ["cat/mouth/teeth"])
|
124
124
|
end
|
125
125
|
|
126
|
-
it "
|
126
|
+
it "finds providers for subattributes if any exists when the attribute doesn't have a provider" do
|
127
127
|
providers = provides_map.deep_find_providers_for(["cat"])
|
128
128
|
expect(providers).to have(3).plugins
|
129
129
|
expect(providers).to include(plugin_1)
|
@@ -131,7 +131,7 @@ describe Ohai::ProvidesMap do
|
|
131
131
|
expect(providers).to include(plugin_3)
|
132
132
|
end
|
133
133
|
|
134
|
-
it "
|
134
|
+
it "finds providers for the first parent attribute when the attribute or any subattributes doesn't have a provider" do
|
135
135
|
providers = provides_map.deep_find_providers_for(["cat/paws/front"])
|
136
136
|
expect(providers).to eq([plugin_2])
|
137
137
|
end
|
@@ -143,7 +143,7 @@ describe Ohai::ProvidesMap do
|
|
143
143
|
provides_map.set_providers_for(plugin_1, ["do/not/eat/metal"])
|
144
144
|
end
|
145
145
|
|
146
|
-
it "
|
146
|
+
it "returns the provider of the full attribute" do
|
147
147
|
expect(provides_map.find_closest_providers_for(["do/not/eat/metal"])).to eql([plugin_1])
|
148
148
|
end
|
149
149
|
end
|
@@ -153,34 +153,34 @@ describe Ohai::ProvidesMap do
|
|
153
153
|
provides_map.set_providers_for(plugin_1, ["do/not/eat"])
|
154
154
|
end
|
155
155
|
|
156
|
-
it "
|
156
|
+
it "does not raise error if a parent attribute is provided" do
|
157
157
|
expect { provides_map.find_closest_providers_for(["do/not/eat/plastic"]) }.not_to raise_error
|
158
158
|
end
|
159
159
|
|
160
|
-
it "
|
160
|
+
it "returns the providers of the closest parent attribute" do
|
161
161
|
provides_map.set_providers_for(plugin_2, ["do/not"]) # set a less-specific parent
|
162
162
|
expect(provides_map.find_closest_providers_for(["do/not/eat/glass"])).to eql([plugin_1])
|
163
163
|
end
|
164
164
|
|
165
|
-
it "
|
165
|
+
it "raises error if the least-specific parent is not an attribute" do
|
166
166
|
expect { provides_map.find_closest_providers_for(["please/eat/your/vegetables"]) }.to raise_error(Ohai::Exceptions::AttributeNotFound, "No such attribute: 'please/eat/your/vegetables'")
|
167
167
|
end
|
168
168
|
|
169
|
-
it "
|
169
|
+
it "raises error if no parent attribute has a provider" do
|
170
170
|
expect { provides_map.find_closest_providers_for(["do/not"]) }.to raise_error(Ohai::Exceptions::ProviderNotFound, "Cannot find plugin providing attribute: 'do/not'")
|
171
171
|
end
|
172
172
|
end
|
173
173
|
end
|
174
174
|
|
175
175
|
describe "when listing all plugins" do
|
176
|
-
before
|
176
|
+
before do
|
177
177
|
provides_map.set_providers_for(plugin_1, ["one"])
|
178
178
|
provides_map.set_providers_for(plugin_2, ["two"])
|
179
179
|
provides_map.set_providers_for(plugin_3, ["stub/three"])
|
180
180
|
provides_map.set_providers_for(plugin_4, ["foo/bar/four", "also/this/four"])
|
181
181
|
end
|
182
182
|
|
183
|
-
it "
|
183
|
+
it "finds all the plugins providing attributes" do
|
184
184
|
all_plugins = provides_map.all_plugins
|
185
185
|
expect(all_plugins).to have(4).plugins
|
186
186
|
expect(all_plugins).to include(plugin_1)
|
data/spec/unit/runner_spec.rb
CHANGED
@@ -22,13 +22,13 @@ require "spec_helper"
|
|
22
22
|
describe Ohai::Runner, "run_plugin" do
|
23
23
|
let(:safe_run) { true }
|
24
24
|
|
25
|
-
before
|
25
|
+
before do
|
26
26
|
@ohai = Ohai::System.new
|
27
27
|
@runner = Ohai::Runner.new(@ohai, safe_run)
|
28
28
|
end
|
29
29
|
|
30
30
|
describe "when running an invalid plugin" do
|
31
|
-
it "
|
31
|
+
it "raises error" do
|
32
32
|
expect { @runner.run_plugin(double("Ohai::NotPlugin")) }.to raise_error(Ohai::Exceptions::InvalidPlugin)
|
33
33
|
end
|
34
34
|
end
|
@@ -39,7 +39,7 @@ describe Ohai::Runner, "run_plugin" do
|
|
39
39
|
let(:has_run) { false }
|
40
40
|
|
41
41
|
describe "version 7" do
|
42
|
-
it "
|
42
|
+
it "calls run_v7_plugin" do
|
43
43
|
expect(@runner).to receive(:run_v7_plugin)
|
44
44
|
@runner.run_plugin(plugin)
|
45
45
|
end
|
@@ -47,7 +47,7 @@ describe Ohai::Runner, "run_plugin" do
|
|
47
47
|
describe "if the plugin has run before" do
|
48
48
|
let(:has_run) { true }
|
49
49
|
|
50
|
-
it "
|
50
|
+
it "does not run the plugin" do
|
51
51
|
expect(plugin).not_to receive(:safe_run)
|
52
52
|
@runner.run_plugin(plugin)
|
53
53
|
end
|
@@ -57,7 +57,7 @@ describe Ohai::Runner, "run_plugin" do
|
|
57
57
|
describe "invalid version" do
|
58
58
|
let(:version) { :versionBla }
|
59
59
|
|
60
|
-
it "
|
60
|
+
it "raises error" do
|
61
61
|
expect { @runner.run_plugin(plugin) }.to raise_error(Ohai::Exceptions::InvalidPlugin)
|
62
62
|
end
|
63
63
|
end
|
@@ -74,12 +74,12 @@ describe Ohai::Runner, "run_plugin" do
|
|
74
74
|
klass.new(@ohai.data, @ohai.logger)
|
75
75
|
end
|
76
76
|
|
77
|
-
it "
|
77
|
+
it "runs the plugin" do
|
78
78
|
@runner.run_plugin(plugin)
|
79
79
|
expect(plugin.has_run?).to be true
|
80
80
|
end
|
81
81
|
|
82
|
-
it "
|
82
|
+
it "adds plugin data to Ohai::System.data" do
|
83
83
|
@runner.run_plugin(plugin)
|
84
84
|
expect(@ohai.data).to have_key(:thing)
|
85
85
|
expect(@ohai.data[:thing]).to eql({})
|
@@ -88,7 +88,7 @@ describe Ohai::Runner, "run_plugin" do
|
|
88
88
|
|
89
89
|
describe "when running a plugin with one dependency" do
|
90
90
|
describe "when the dependency does not exist" do
|
91
|
-
before
|
91
|
+
before do
|
92
92
|
klass = Ohai.plugin(:Test) do
|
93
93
|
provides("thing")
|
94
94
|
depends("other_thing")
|
@@ -99,18 +99,18 @@ describe Ohai::Runner, "run_plugin" do
|
|
99
99
|
@plugin = klass.new(@ohai.data, @ohai.logger)
|
100
100
|
end
|
101
101
|
|
102
|
-
it "
|
102
|
+
it "raises Ohai::Excpetions::AttributeNotFound" do
|
103
103
|
expect { @runner.run_plugin(@plugin) }.to raise_error(Ohai::Exceptions::AttributeNotFound)
|
104
104
|
end
|
105
105
|
|
106
|
-
it "
|
106
|
+
it "does not run the plugin" do
|
107
107
|
expect { @runner.run_plugin(@plugin) }.to raise_error(Ohai::Exceptions::AttributeNotFound)
|
108
108
|
expect(@plugin.has_run?).to be false
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
112
|
describe "when the dependency has a single provider" do
|
113
|
-
before
|
113
|
+
before do
|
114
114
|
klass1 = Ohai.plugin(:Thing) do
|
115
115
|
provides("thing")
|
116
116
|
collect_data do
|
@@ -134,7 +134,7 @@ describe Ohai::Runner, "run_plugin" do
|
|
134
134
|
@ohai.provides_map.set_providers_for(@plugin1, ["thing"])
|
135
135
|
end
|
136
136
|
|
137
|
-
it "
|
137
|
+
it "runs the plugins" do
|
138
138
|
@runner.run_plugin(@plugin2)
|
139
139
|
@plugins.each do |plugin|
|
140
140
|
expect(plugin.has_run?).to be true
|
@@ -143,7 +143,7 @@ describe Ohai::Runner, "run_plugin" do
|
|
143
143
|
end
|
144
144
|
|
145
145
|
describe "when the dependency has multiple providers" do
|
146
|
-
before
|
146
|
+
before do
|
147
147
|
klass1 = Ohai.plugin(:Thing) do
|
148
148
|
provides("thing")
|
149
149
|
collect_data do
|
@@ -168,7 +168,7 @@ describe Ohai::Runner, "run_plugin" do
|
|
168
168
|
@ohai.provides_map.set_providers_for(@plugin2, ["thing"])
|
169
169
|
end
|
170
170
|
|
171
|
-
it "
|
171
|
+
it "runs the plugins" do
|
172
172
|
@runner.run_plugin(@plugin3)
|
173
173
|
@plugins.each do |plugin|
|
174
174
|
expect(plugin.has_run?).to be true
|
@@ -178,7 +178,7 @@ describe Ohai::Runner, "run_plugin" do
|
|
178
178
|
end
|
179
179
|
|
180
180
|
describe "when running a plugin with many dependencies" do
|
181
|
-
before
|
181
|
+
before do
|
182
182
|
@ohai = Ohai::System.new
|
183
183
|
@runner = Ohai::Runner.new(@ohai, true)
|
184
184
|
|
@@ -211,7 +211,7 @@ describe Ohai::Runner, "run_plugin" do
|
|
211
211
|
@ohai.provides_map.set_providers_for(@plugin2, %w{one two})
|
212
212
|
end
|
213
213
|
|
214
|
-
it "
|
214
|
+
it "runs the plugins" do
|
215
215
|
@runner.run_plugin(@plugin3)
|
216
216
|
@plugins.each do |plugin|
|
217
217
|
expect(plugin.has_run?).to be true
|
@@ -242,7 +242,7 @@ describe Ohai::Runner, "run_plugin" do
|
|
242
242
|
end
|
243
243
|
|
244
244
|
context "when there is one edge in the cycle (A->B and B->A)" do
|
245
|
-
before
|
245
|
+
before do
|
246
246
|
klass1 = Ohai.plugin(:Thing) do # rubocop disable Lint/UselessAssignment
|
247
247
|
provides("thing")
|
248
248
|
depends("other")
|
@@ -266,7 +266,7 @@ describe Ohai::Runner, "run_plugin" do
|
|
266
266
|
@plugin1, @plugin2 = @plugins
|
267
267
|
end
|
268
268
|
|
269
|
-
it "
|
269
|
+
it "raises Ohai::Exceptions::DependencyCycle" do
|
270
270
|
allow(runner).to receive(:fetch_plugins).with(["thing"]).and_return([@plugin1])
|
271
271
|
allow(runner).to receive(:fetch_plugins).with(["other"]).and_return([@plugin2])
|
272
272
|
expected_error_string = "Dependency cycle detected. Please refer to the following plugins: Thing, Other"
|
@@ -276,7 +276,7 @@ describe Ohai::Runner, "run_plugin" do
|
|
276
276
|
end
|
277
277
|
|
278
278
|
describe "when A depends on B and C, and B depends on C" do
|
279
|
-
before
|
279
|
+
before do
|
280
280
|
@ohai = Ohai::System.new
|
281
281
|
@runner = Ohai::Runner.new(@ohai, true)
|
282
282
|
|
@@ -302,7 +302,7 @@ describe Ohai::Runner, "run_plugin" do
|
|
302
302
|
@plugin_a, @plugin_b, @plugin_c = @plugins
|
303
303
|
end
|
304
304
|
|
305
|
-
it "
|
305
|
+
it "does not detect a cycle when B is the first provider returned" do
|
306
306
|
@ohai.provides_map.set_providers_for(@plugin_a, ["A"])
|
307
307
|
@ohai.provides_map.set_providers_for(@plugin_b, ["B"])
|
308
308
|
@ohai.provides_map.set_providers_for(@plugin_c, ["C"])
|
@@ -315,7 +315,7 @@ describe Ohai::Runner, "run_plugin" do
|
|
315
315
|
end
|
316
316
|
end
|
317
317
|
|
318
|
-
it "
|
318
|
+
it "does not detect a cycle when C is the first provider returned" do
|
319
319
|
@ohai.provides_map.set_providers_for(@plugin_a, ["A"])
|
320
320
|
@ohai.provides_map.set_providers_for(@plugin_c, ["C"])
|
321
321
|
@ohai.provides_map.set_providers_for(@plugin_b, ["B"])
|
@@ -331,14 +331,14 @@ describe Ohai::Runner, "run_plugin" do
|
|
331
331
|
end
|
332
332
|
|
333
333
|
describe Ohai::Runner, "fetch_plugins" do
|
334
|
-
before
|
334
|
+
before do
|
335
335
|
@provides_map = Ohai::ProvidesMap.new
|
336
336
|
@data = Mash.new
|
337
337
|
@ohai = double("Ohai::System", data: @data, provides_map: @provides_map, logger: Ohai::Log.with_child)
|
338
338
|
@runner = Ohai::Runner.new(@ohai, true)
|
339
339
|
end
|
340
340
|
|
341
|
-
it "
|
341
|
+
it "collects the provider" do
|
342
342
|
plugin = Ohai::DSL::Plugin.new(@ohai.data, @ohai.logger)
|
343
343
|
@ohai.provides_map.set_providers_for(plugin, ["top/middle/bottom"])
|
344
344
|
|
@@ -348,7 +348,7 @@ describe Ohai::Runner, "fetch_plugins" do
|
|
348
348
|
|
349
349
|
describe "when the attribute is not provided by any plugin" do
|
350
350
|
describe "and some parent attribute has providers" do
|
351
|
-
it "
|
351
|
+
it "returns the providers for the parent" do
|
352
352
|
plugin = Ohai::DSL::Plugin.new(@ohai.data, @ohai.logger)
|
353
353
|
@provides_map.set_providers_for(plugin, ["test/attribute"])
|
354
354
|
expect(@runner.fetch_plugins(["test/attribute/too_far"])).to eql([plugin])
|
@@ -356,14 +356,14 @@ describe Ohai::Runner, "fetch_plugins" do
|
|
356
356
|
end
|
357
357
|
|
358
358
|
describe "and no parent attribute has providers" do
|
359
|
-
it "
|
359
|
+
it "raises Ohai::Exceptions::AttributeNotFound exception" do
|
360
360
|
# provides map is empty
|
361
361
|
expect { @runner.fetch_plugins(["false/attribute"]) }.to raise_error(Ohai::Exceptions::AttributeNotFound, "No such attribute: 'false/attribute'")
|
362
362
|
end
|
363
363
|
end
|
364
364
|
end
|
365
365
|
|
366
|
-
it "
|
366
|
+
it "returns unique providers" do
|
367
367
|
plugin = Ohai::DSL::Plugin.new(@ohai.data, @ohai.logger)
|
368
368
|
@provides_map.set_providers_for(plugin, ["test", "test/too_far/way_too_far"])
|
369
369
|
expect(@runner.fetch_plugins(["test", "test/too_far/way_too_far"])).to eql([plugin])
|
@@ -371,7 +371,7 @@ describe Ohai::Runner, "fetch_plugins" do
|
|
371
371
|
end
|
372
372
|
|
373
373
|
describe Ohai::Runner, "#get_cycle" do
|
374
|
-
before
|
374
|
+
before do
|
375
375
|
@ohai = Ohai::System.new
|
376
376
|
@runner = Ohai::Runner.new(@ohai, true)
|
377
377
|
|
@@ -404,7 +404,7 @@ describe Ohai::Runner, "#get_cycle" do
|
|
404
404
|
@plugin1, @plugin2, @plugin3 = plugins
|
405
405
|
end
|
406
406
|
|
407
|
-
it "
|
407
|
+
it "returns the sources for the plugins in the cycle, when given an exact cycle" do
|
408
408
|
cycle = [@plugin1, @plugin2]
|
409
409
|
cycle_start = @plugin1
|
410
410
|
|
@@ -412,7 +412,7 @@ describe Ohai::Runner, "#get_cycle" do
|
|
412
412
|
expect(cycle_names).to eql([@plugin1.name, @plugin2.name])
|
413
413
|
end
|
414
414
|
|
415
|
-
it "
|
415
|
+
it "returns the sources for only the plugins in the cycle, when there are plugins before the cycle begins" do
|
416
416
|
cycle = [@plugin3, @plugin1, @plugin2]
|
417
417
|
cycle_start = @plugin1
|
418
418
|
|