ohai 15.3.1 → 15.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -6
  3. data/lib/ohai/mixin/{network_constants.rb → network_helper.rb} +8 -1
  4. data/lib/ohai/plugins/aix/network.rb +3 -8
  5. data/lib/ohai/plugins/darwin/network.rb +6 -4
  6. data/lib/ohai/plugins/filesystem.rb +166 -0
  7. data/lib/ohai/plugins/network.rb +5 -5
  8. data/lib/ohai/plugins/openstack.rb +2 -1
  9. data/lib/ohai/plugins/solaris2/network.rb +6 -4
  10. data/lib/ohai/version.rb +1 -1
  11. data/ohai.gemspec +1 -1
  12. metadata +3 -162
  13. data/Rakefile +0 -42
  14. data/lib/ohai/plugins/windows/filesystem.rb +0 -147
  15. data/spec/data/plugins/dpkg-query.output +0 -4
  16. data/spec/data/plugins/lslpp.output +0 -50
  17. data/spec/data/plugins/pacman.output +0 -51
  18. data/spec/data/plugins/pkg-query.output +0 -58
  19. data/spec/data/plugins/pkginfo.output +0 -50
  20. data/spec/data/plugins/pkglist.output +0 -24
  21. data/spec/data/plugins/rpmquery.output +0 -7
  22. data/spec/functional/application_spec.rb +0 -107
  23. data/spec/functional/loader_spec.rb +0 -53
  24. data/spec/functional/plugins/powershell_spec.rb +0 -88
  25. data/spec/functional/plugins/root_group_spec.rb +0 -41
  26. data/spec/functional/plugins/windows/uptime_spec.rb +0 -51
  27. data/spec/ohai_spec.rb +0 -27
  28. data/spec/rcov.opts +0 -2
  29. data/spec/spec.opts +0 -2
  30. data/spec/spec_helper.rb +0 -124
  31. data/spec/support/integration_helper.rb +0 -61
  32. data/spec/support/platform_helpers.rb +0 -38
  33. data/spec/unit/application_spec.rb +0 -96
  34. data/spec/unit/config_spec.rb +0 -57
  35. data/spec/unit/dsl/plugin_spec.rb +0 -634
  36. data/spec/unit/hints_spec.rb +0 -65
  37. data/spec/unit/loader_spec.rb +0 -195
  38. data/spec/unit/mixin/azure_metadata_spec.rb +0 -72
  39. data/spec/unit/mixin/command_spec.rb +0 -151
  40. data/spec/unit/mixin/dmi_decode.rb +0 -75
  41. data/spec/unit/mixin/ec2_metadata_spec.rb +0 -88
  42. data/spec/unit/mixin/softlayer_metadata_spec.rb +0 -72
  43. data/spec/unit/plugin_config_spec.rb +0 -117
  44. data/spec/unit/plugins/abort_spec.rb +0 -69
  45. data/spec/unit/plugins/aix/cpu_spec.rb +0 -127
  46. data/spec/unit/plugins/aix/filesystem_spec.rb +0 -238
  47. data/spec/unit/plugins/aix/hostname_spec.rb +0 -33
  48. data/spec/unit/plugins/aix/kernel_spec.rb +0 -61
  49. data/spec/unit/plugins/aix/memory_spec.rb +0 -49
  50. data/spec/unit/plugins/aix/network_spec.rb +0 -313
  51. data/spec/unit/plugins/aix/platform_spec.rb +0 -44
  52. data/spec/unit/plugins/aix/uptime_spec.rb +0 -42
  53. data/spec/unit/plugins/aix/virtualization_spec.rb +0 -319
  54. data/spec/unit/plugins/azure_spec.rb +0 -243
  55. data/spec/unit/plugins/bsd/filesystem_spec.rb +0 -138
  56. data/spec/unit/plugins/bsd/virtualization_spec.rb +0 -145
  57. data/spec/unit/plugins/c_spec.rb +0 -341
  58. data/spec/unit/plugins/chef_spec.rb +0 -44
  59. data/spec/unit/plugins/cloud_spec.rb +0 -484
  60. data/spec/unit/plugins/darwin/cpu_spec.rb +0 -124
  61. data/spec/unit/plugins/darwin/filesystem_spec.rb +0 -140
  62. data/spec/unit/plugins/darwin/hardware_spec.rb +0 -105
  63. data/spec/unit/plugins/darwin/hardware_system_profiler_output.rb +0 -1110
  64. data/spec/unit/plugins/darwin/hostname_spec.rb +0 -43
  65. data/spec/unit/plugins/darwin/kernel_spec.rb +0 -65
  66. data/spec/unit/plugins/darwin/memory_spec.rb +0 -64
  67. data/spec/unit/plugins/darwin/network_spec.rb +0 -849
  68. data/spec/unit/plugins/darwin/platform_spec.rb +0 -71
  69. data/spec/unit/plugins/darwin/virtualization_spec.rb +0 -156
  70. data/spec/unit/plugins/digital_ocean_spec.rb +0 -106
  71. data/spec/unit/plugins/dmi_spec.rb +0 -156
  72. data/spec/unit/plugins/docker_spec.rb +0 -100
  73. data/spec/unit/plugins/ec2_spec.rb +0 -452
  74. data/spec/unit/plugins/elixir_spec.rb +0 -55
  75. data/spec/unit/plugins/erlang_spec.rb +0 -71
  76. data/spec/unit/plugins/eucalyptus_spec.rb +0 -109
  77. data/spec/unit/plugins/fail_spec.rb +0 -260
  78. data/spec/unit/plugins/freebsd/cpu_spec.rb +0 -129
  79. data/spec/unit/plugins/freebsd/hostname_spec.rb +0 -35
  80. data/spec/unit/plugins/freebsd/kernel_spec.rb +0 -36
  81. data/spec/unit/plugins/freebsd/platform_spec.rb +0 -38
  82. data/spec/unit/plugins/gce_spec.rb +0 -81
  83. data/spec/unit/plugins/go_spec.rb +0 -48
  84. data/spec/unit/plugins/groovy_spec.rb +0 -66
  85. data/spec/unit/plugins/haskell_spec.rb +0 -231
  86. data/spec/unit/plugins/hostname_spec.rb +0 -162
  87. data/spec/unit/plugins/init_package_spec.rb +0 -60
  88. data/spec/unit/plugins/java_spec.rb +0 -230
  89. data/spec/unit/plugins/joyent_spec.rb +0 -100
  90. data/spec/unit/plugins/kernel_spec.rb +0 -38
  91. data/spec/unit/plugins/linode_spec.rb +0 -135
  92. data/spec/unit/plugins/linux/block_device_spec.rb +0 -75
  93. data/spec/unit/plugins/linux/cpu_spec.rb +0 -441
  94. data/spec/unit/plugins/linux/filesystem_spec.rb +0 -550
  95. data/spec/unit/plugins/linux/fips_spec.rb +0 -60
  96. data/spec/unit/plugins/linux/hostname_spec.rb +0 -52
  97. data/spec/unit/plugins/linux/hostnamectl_spec.rb +0 -59
  98. data/spec/unit/plugins/linux/kernel_spec.rb +0 -71
  99. data/spec/unit/plugins/linux/lsb_spec.rb +0 -147
  100. data/spec/unit/plugins/linux/lspci_spec.rb +0 -133
  101. data/spec/unit/plugins/linux/machineid_spec.rb +0 -46
  102. data/spec/unit/plugins/linux/mdadm_spec.rb +0 -170
  103. data/spec/unit/plugins/linux/memory_spec.rb +0 -256
  104. data/spec/unit/plugins/linux/network_spec.rb +0 -1392
  105. data/spec/unit/plugins/linux/platform_spec.rb +0 -812
  106. data/spec/unit/plugins/linux/sessions_spec.rb +0 -98
  107. data/spec/unit/plugins/linux/sysctl_spec.rb +0 -53
  108. data/spec/unit/plugins/linux/systemd_paths_spec.rb +0 -122
  109. data/spec/unit/plugins/linux/uptime_spec.rb +0 -48
  110. data/spec/unit/plugins/linux/virtualization_spec.rb +0 -650
  111. data/spec/unit/plugins/lua_spec.rb +0 -60
  112. data/spec/unit/plugins/mono_spec.rb +0 -67
  113. data/spec/unit/plugins/netbsd/hostname_spec.rb +0 -43
  114. data/spec/unit/plugins/netbsd/kernel_spec.rb +0 -35
  115. data/spec/unit/plugins/netbsd/platform_spec.rb +0 -38
  116. data/spec/unit/plugins/network_spec.rb +0 -1078
  117. data/spec/unit/plugins/nodejs_spec.rb +0 -55
  118. data/spec/unit/plugins/ohai_spec.rb +0 -32
  119. data/spec/unit/plugins/ohai_time_spec.rb +0 -44
  120. data/spec/unit/plugins/openbsd/hostname_spec.rb +0 -43
  121. data/spec/unit/plugins/openbsd/kernel_spec.rb +0 -36
  122. data/spec/unit/plugins/openbsd/platform_spec.rb +0 -33
  123. data/spec/unit/plugins/openstack_spec.rb +0 -311
  124. data/spec/unit/plugins/os_spec.rb +0 -115
  125. data/spec/unit/plugins/packages_spec.rb +0 -353
  126. data/spec/unit/plugins/passwd_spec.rb +0 -65
  127. data/spec/unit/plugins/perl_spec.rb +0 -62
  128. data/spec/unit/plugins/php_spec.rb +0 -97
  129. data/spec/unit/plugins/platform_spec.rb +0 -65
  130. data/spec/unit/plugins/powershell_spec.rb +0 -71
  131. data/spec/unit/plugins/python_spec.rb +0 -51
  132. data/spec/unit/plugins/rackspace_spec.rb +0 -350
  133. data/spec/unit/plugins/root_group_spec.rb +0 -90
  134. data/spec/unit/plugins/ruby_spec.rb +0 -60
  135. data/spec/unit/plugins/rust_spec.rb +0 -43
  136. data/spec/unit/plugins/scala_spec.rb +0 -58
  137. data/spec/unit/plugins/scaleway_spec.rb +0 -93
  138. data/spec/unit/plugins/scsi_spec.rb +0 -69
  139. data/spec/unit/plugins/shard_spec.rb +0 -121
  140. data/spec/unit/plugins/shells_spec.rb +0 -56
  141. data/spec/unit/plugins/softlayer_spec.rb +0 -60
  142. data/spec/unit/plugins/solaris2/cpu_spec.rb +0 -2926
  143. data/spec/unit/plugins/solaris2/dmi_spec.rb +0 -153
  144. data/spec/unit/plugins/solaris2/filesystem.rb +0 -407
  145. data/spec/unit/plugins/solaris2/hostname_spec.rb +0 -37
  146. data/spec/unit/plugins/solaris2/kernel_spec.rb +0 -183
  147. data/spec/unit/plugins/solaris2/memory_spec.rb +0 -43
  148. data/spec/unit/plugins/solaris2/network_spec.rb +0 -201
  149. data/spec/unit/plugins/solaris2/platform_spec.rb +0 -108
  150. data/spec/unit/plugins/solaris2/virtualization_spec.rb +0 -97
  151. data/spec/unit/plugins/ssh_host_keys_spec.rb +0 -116
  152. data/spec/unit/plugins/sysconf_spec.rb +0 -680
  153. data/spec/unit/plugins/timezone_spec.rb +0 -30
  154. data/spec/unit/plugins/vbox_host_spec.rb +0 -14
  155. data/spec/unit/plugins/virtualbox_spec.rb +0 -375
  156. data/spec/unit/plugins/vmware_spec.rb +0 -81
  157. data/spec/unit/plugins/windows/cpu_spec.rb +0 -118
  158. data/spec/unit/plugins/windows/filesystem_spec.rb +0 -226
  159. data/spec/unit/plugins/windows/fips_spec.rb +0 -60
  160. data/spec/unit/plugins/windows/kernel_spec.rb +0 -79
  161. data/spec/unit/plugins/windows/memory_spec.rb +0 -52
  162. data/spec/unit/plugins/windows/network_spec.rb +0 -137
  163. data/spec/unit/plugins/windows/system_enclosure_spec.rb +0 -45
  164. data/spec/unit/plugins/windows/uptime_spec.rb +0 -38
  165. data/spec/unit/plugins/windows/virtualization_spec.rb +0 -63
  166. data/spec/unit/plugins/zpools_spec.rb +0 -244
  167. data/spec/unit/provides_map_spec.rb +0 -208
  168. data/spec/unit/runner_spec.rb +0 -422
  169. data/spec/unit/system_spec.rb +0 -416
  170. data/spec/unit/util/file_helper_spec.rb +0 -47
  171. data/spec/unit/util/ip_helper_spec.rb +0 -128
@@ -1,208 +0,0 @@
1
- #
2
- # Author:: Daniel DeLeo (<dan@chef.io>)
3
- # Copyright:: Copyright (c) 2013-2016 Chef Software, 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 "spec_helper"
21
-
22
- describe Ohai::ProvidesMap do
23
-
24
- let(:ohai_system) { Ohai::System.new }
25
- let(:provides_map) { Ohai::ProvidesMap.new }
26
- let(:plugin_1) { Ohai::DSL::Plugin.new(ohai_system.data, ohai_system.logger) }
27
- let(:plugin_2) { Ohai::DSL::Plugin.new(ohai_system.data, ohai_system.logger) }
28
- let(:plugin_3) { Ohai::DSL::Plugin.new(ohai_system.data, ohai_system.logger) }
29
- let(:plugin_4) { Ohai::DSL::Plugin.new(ohai_system.data, ohai_system.logger) }
30
-
31
- describe "when looking up providing plugins for a single attribute" do
32
- describe "when the attribute does not exist" do
33
- it "raises Ohai::Exceptions::AttributeNotFound error" do
34
- expect { provides_map.find_providers_for(["single"]) }.to raise_error(Ohai::Exceptions::AttributeNotFound, "No such attribute: 'single'")
35
- end
36
- end
37
-
38
- describe "when the attribute does not have a provider" do
39
- it "raises Ohai::Exceptions::ProviderNotFound error" do
40
- provides_map.set_providers_for(plugin_1, ["first/second"])
41
- expect { provides_map.find_providers_for(["first"]) }.to raise_error(Ohai::Exceptions::ProviderNotFound, "Cannot find plugin providing attribute: 'first'")
42
- end
43
- end
44
-
45
- describe "when only one plugin provides the attribute" do
46
- before do
47
- provides_map.set_providers_for(plugin_1, ["single"])
48
- end
49
-
50
- it "returns the provider" do
51
- expect(provides_map.find_providers_for(["single"])).to eq([plugin_1])
52
- end
53
- end
54
-
55
- describe "when multiple plugins provide the attribute" do
56
- before do
57
- provides_map.set_providers_for(plugin_1, ["single"])
58
- provides_map.set_providers_for(plugin_2, ["single"])
59
- end
60
-
61
- it "returns all providers" do
62
- expect(provides_map.find_providers_for(["single"])).to eq([plugin_1, plugin_2])
63
- end
64
- end
65
- end
66
-
67
- describe "when looking up providing plugins for multiple attributes" do
68
- describe "when a different plugin provides each attribute" do
69
-
70
- before do
71
- provides_map.set_providers_for(plugin_1, ["one"])
72
- provides_map.set_providers_for(plugin_2, ["two"])
73
- end
74
-
75
- it "returns each provider" do
76
- expect(provides_map.find_providers_for(%w{one two})).to eq([plugin_1, plugin_2])
77
- end
78
- end
79
-
80
- describe "when one plugin provides both requested attributes" do
81
-
82
- before do
83
- provides_map.set_providers_for(plugin_1, ["one"])
84
- provides_map.set_providers_for(plugin_1, ["one_again"])
85
- end
86
-
87
- it "returns unique providers" do
88
- expect(provides_map.find_providers_for(%w{one one_again})).to eq([plugin_1])
89
- end
90
- end
91
- end
92
-
93
- describe "when looking up providers for multi-level attributes" do
94
- describe "when the full attribute exists in the map" do
95
- before do
96
- provides_map.set_providers_for(plugin_1, ["top/middle/bottom"])
97
- end
98
-
99
- it "collects the provider" do
100
- expect(provides_map.find_providers_for(["top/middle/bottom"])).to eq([plugin_1])
101
- end
102
- end
103
- end
104
-
105
- describe "when setting multi-level attributes" do
106
- describe "when the attribute contains //" do
107
- it "raises an Ohai::Exceptions::AttributeSyntaxError" do
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
- end
110
- end
111
-
112
- describe "when the attribute has a trailing slash" do
113
- it "raises an Ohai::Exceptions::AttributeSyntaxError" do
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
- end
116
- end
117
- end
118
-
119
- describe "when looking for providers of attributes specified in CLI" do
120
- before do
121
- provides_map.set_providers_for(plugin_1, ["cat/whiskers"])
122
- provides_map.set_providers_for(plugin_2, ["cat/paws", "cat/paws/toes"])
123
- provides_map.set_providers_for(plugin_3, ["cat/mouth/teeth"])
124
- end
125
-
126
- it "finds providers for subattributes if any exists when the attribute doesn't have a provider" do
127
- providers = provides_map.deep_find_providers_for(["cat"])
128
- expect(providers).to have(3).plugins
129
- expect(providers).to include(plugin_1)
130
- expect(providers).to include(plugin_2)
131
- expect(providers).to include(plugin_3)
132
- end
133
-
134
- it "finds providers for the first parent attribute when the attribute or any subattributes doesn't have a provider" do
135
- providers = provides_map.deep_find_providers_for(["cat/paws/front"])
136
- expect(providers).to eq([plugin_2])
137
- end
138
- end
139
-
140
- describe "when looking for the closest providers" do
141
- describe "and the full attribute is provided" do
142
- before do
143
- provides_map.set_providers_for(plugin_1, ["do/not/eat/metal"])
144
- end
145
-
146
- it "returns the provider of the full attribute" do
147
- expect(provides_map.find_closest_providers_for(["do/not/eat/metal"])).to eql([plugin_1])
148
- end
149
- end
150
-
151
- describe "and the full attribute is not provided" do
152
- before do
153
- provides_map.set_providers_for(plugin_1, ["do/not/eat"])
154
- end
155
-
156
- it "does not raise error if a parent attribute is provided" do
157
- expect { provides_map.find_closest_providers_for(["do/not/eat/plastic"]) }.not_to raise_error
158
- end
159
-
160
- it "returns the providers of the closest parent attribute" do
161
- provides_map.set_providers_for(plugin_2, ["do/not"]) # set a less-specific parent
162
- expect(provides_map.find_closest_providers_for(["do/not/eat/glass"])).to eql([plugin_1])
163
- end
164
-
165
- it "raises error if the least-specific parent is not an attribute" do
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
- end
168
-
169
- it "raises error if no parent attribute has a provider" do
170
- expect { provides_map.find_closest_providers_for(["do/not"]) }.to raise_error(Ohai::Exceptions::ProviderNotFound, "Cannot find plugin providing attribute: 'do/not'")
171
- end
172
- end
173
- end
174
-
175
- describe "when listing all plugins" do
176
- before do
177
- provides_map.set_providers_for(plugin_1, ["one"])
178
- provides_map.set_providers_for(plugin_2, ["two"])
179
- provides_map.set_providers_for(plugin_3, ["stub/three"])
180
- provides_map.set_providers_for(plugin_4, ["foo/bar/four", "also/this/four"])
181
- end
182
-
183
- it "finds all the plugins providing attributes" do
184
- all_plugins = provides_map.all_plugins
185
- expect(all_plugins).to have(4).plugins
186
- expect(all_plugins).to include(plugin_1)
187
- expect(all_plugins).to include(plugin_2)
188
- expect(all_plugins).to include(plugin_3)
189
- expect(all_plugins).to include(plugin_4)
190
- end
191
-
192
- describe "with an attribute filter" do
193
- it "finds plugins with a single level of attribute" do
194
- expect(provides_map.all_plugins("one")).to eq([plugin_1])
195
- end
196
-
197
- it "finds plugins with an exact match for multiple levels of attribute" do
198
- expect(provides_map.all_plugins("stub/three")).to eq([plugin_3])
199
- end
200
-
201
- it "finds plugins that provide subattributes of the requested path" do
202
- expect(provides_map.all_plugins("stub")).to eq([plugin_3])
203
- expect(provides_map.all_plugins("foo/bar")).to eq([plugin_4])
204
- end
205
- end
206
- end
207
-
208
- end
@@ -1,422 +0,0 @@
1
- #
2
- # Author:: Claire McQuin (<claire@chef.io>)
3
- # Copyright:: Copyright (c) 2013-2019, Chef Software 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 "spec_helper"
21
-
22
- describe Ohai::Runner, "run_plugin" do
23
- let(:safe_run) { true }
24
-
25
- before 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 "raises error" do
32
- expect { @runner.run_plugin(double("Ohai::NotPlugin")) }.to raise_error(Ohai::Exceptions::InvalidPlugin)
33
- end
34
- end
35
-
36
- describe "when running a plugin" do
37
- let(:plugin) { double("Ohai::DSL::Plugin", is_a?: 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 "calls run_v7_plugin" do
43
- expect(@runner).to 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 "does not run the plugin" do
51
- expect(plugin).not_to receive(:safe_run)
52
- @runner.run_plugin(plugin)
53
- end
54
- end
55
- end
56
-
57
- describe "invalid version" do
58
- let(:version) { :versionBla }
59
-
60
- it "raises error" do
61
- expect { @runner.run_plugin(plugin) }.to raise_error(Ohai::Exceptions::InvalidPlugin)
62
- end
63
- end
64
- end
65
-
66
- describe "when running a plugin with no dependencies, Ohai::Runner" do
67
- let(:plugin) do
68
- klass = Ohai.plugin(:Test) do
69
- provides("thing")
70
- collect_data do
71
- thing(Mash.new)
72
- end
73
- end
74
- klass.new(@ohai.data, @ohai.logger)
75
- end
76
-
77
- it "runs the plugin" do
78
- @runner.run_plugin(plugin)
79
- expect(plugin.has_run?).to be true
80
- end
81
-
82
- it "adds plugin data to Ohai::System.data" do
83
- @runner.run_plugin(plugin)
84
- expect(@ohai.data).to have_key(:thing)
85
- expect(@ohai.data[:thing]).to eql({})
86
- end
87
- end
88
-
89
- describe "when running a plugin with one dependency" do
90
- describe "when the dependency does not exist" do
91
- before do
92
- klass = Ohai.plugin(:Test) do
93
- provides("thing")
94
- depends("other_thing")
95
- collect_data do
96
- thing(other_thing)
97
- end
98
- end
99
- @plugin = klass.new(@ohai.data, @ohai.logger)
100
- end
101
-
102
- it "raises Ohai::Excpetions::AttributeNotFound" do
103
- expect { @runner.run_plugin(@plugin) }.to raise_error(Ohai::Exceptions::AttributeNotFound)
104
- end
105
-
106
- it "does not run the plugin" do
107
- expect { @runner.run_plugin(@plugin) }.to raise_error(Ohai::Exceptions::AttributeNotFound)
108
- expect(@plugin.has_run?).to be false
109
- end
110
- end
111
-
112
- describe "when the dependency has a single provider" do
113
- before do
114
- klass1 = Ohai.plugin(:Thing) do
115
- provides("thing")
116
- collect_data do
117
- thing("thang")
118
- end
119
- end
120
- klass2 = Ohai.plugin(:Other) do
121
- provides("other")
122
- depends("thing")
123
- collect_data do
124
- other(thing)
125
- end
126
- end
127
-
128
- @plugins = []
129
- [klass1, klass2].each do |klass|
130
- @plugins << klass.new(@ohai.data, @ohai.logger)
131
- end
132
- @plugin1, @plugin2 = @plugins
133
-
134
- @ohai.provides_map.set_providers_for(@plugin1, ["thing"])
135
- end
136
-
137
- it "runs the plugins" do
138
- @runner.run_plugin(@plugin2)
139
- @plugins.each do |plugin|
140
- expect(plugin.has_run?).to be true
141
- end
142
- end
143
- end
144
-
145
- describe "when the dependency has multiple providers" do
146
- before do
147
- klass1 = Ohai.plugin(:Thing) do
148
- provides("thing")
149
- collect_data do
150
- thing(Mash.new)
151
- end
152
- end
153
- klass2 = Ohai.plugin(:Other) do
154
- provides("other")
155
- depends("thing")
156
- collect_data do
157
- other(thing)
158
- end
159
- end
160
-
161
- @plugins = []
162
- [klass1, klass1, klass2].each do |klass|
163
- @plugins << klass.new(@ohai.data, @ohai.logger)
164
- end
165
- @plugin1, @plugin2, @plugin3 = @plugins
166
-
167
- @ohai.provides_map.set_providers_for(@plugin1, ["thing"])
168
- @ohai.provides_map.set_providers_for(@plugin2, ["thing"])
169
- end
170
-
171
- it "runs the plugins" do
172
- @runner.run_plugin(@plugin3)
173
- @plugins.each do |plugin|
174
- expect(plugin.has_run?).to be true
175
- end
176
- end
177
- end
178
- end
179
-
180
- describe "when running a plugin with many dependencies" do
181
- before do
182
- @ohai = Ohai::System.new
183
- @runner = Ohai::Runner.new(@ohai, true)
184
-
185
- klass1 = Ohai.plugin(:One) do
186
- provides("one")
187
- collect_data do
188
- one(1)
189
- end
190
- end
191
- klass2 = Ohai.plugin(:Two) do
192
- provides("two")
193
- collect_data do
194
- two(2)
195
- end
196
- end
197
- klass3 = Ohai.plugin(:Three) do
198
- provides("three")
199
- depends("one", "two")
200
- collect_data do
201
- three(3)
202
- end
203
- end
204
-
205
- @plugins = []
206
- [klass1, klass2, klass3].each do |klass|
207
- @plugins << klass.new(@ohai.data, @ohai.logger)
208
- end
209
- @plugin1, @plugin2, @plugin3 = @plugins
210
- @ohai.provides_map.set_providers_for(@plugin1, %w{one two})
211
- @ohai.provides_map.set_providers_for(@plugin2, %w{one two})
212
- end
213
-
214
- it "runs the plugins" do
215
- @runner.run_plugin(@plugin3)
216
- @plugins.each do |plugin|
217
- expect(plugin.has_run?).to be true
218
- end
219
- end
220
- end
221
-
222
- describe "when a cycle is detected" do
223
- let(:runner) { Ohai::Runner.new(@ohai, true) }
224
-
225
- context "when there are no edges in the cycle (A->A)" do
226
- let(:plugin_class) do
227
- Ohai.plugin(:Thing) do
228
- provides("thing")
229
- depends("thing")
230
- collect_data do
231
- thing(other)
232
- end
233
- end
234
- end
235
- let(:plugin) { plugin_class.new(@ohai.data, @ohai.logger) }
236
-
237
- it "ignores the cycle" do
238
- @ohai.provides_map.set_providers_for(plugin, ["thing"])
239
- runner.run_plugin(plugin) # should not raise
240
- end
241
-
242
- end
243
-
244
- context "when there is one edge in the cycle (A->B and B->A)" do
245
- before do
246
- klass1 = Ohai.plugin(:Thing) do # rubocop disable Lint/UselessAssignment
247
- provides("thing")
248
- depends("other")
249
- collect_data do
250
- thing(other)
251
- end
252
- end
253
- klass2 = Ohai.plugin(:Other) do
254
- provides("other")
255
- depends("thing")
256
- collect_data do
257
- other(thing)
258
- end
259
- end
260
-
261
- @plugins = []
262
- [klass1, klass2].each_with_index do |klass, idx|
263
- @plugins << klass.new(@ohai.data, @ohai.logger)
264
- end
265
-
266
- @plugin1, @plugin2 = @plugins
267
- end
268
-
269
- it "raises Ohai::Exceptions::DependencyCycle" do
270
- allow(runner).to receive(:fetch_plugins).with(["thing"]).and_return([@plugin1])
271
- allow(runner).to receive(:fetch_plugins).with(["other"]).and_return([@plugin2])
272
- expected_error_string = "Dependency cycle detected. Please refer to the following plugins: Thing, Other"
273
- expect { runner.run_plugin(@plugin1) }.to raise_error(Ohai::Exceptions::DependencyCycle, expected_error_string)
274
- end
275
- end
276
- end
277
-
278
- describe "when A depends on B and C, and B depends on C" do
279
- before do
280
- @ohai = Ohai::System.new
281
- @runner = Ohai::Runner.new(@ohai, true)
282
-
283
- klass_a = Ohai.plugin(:A) do
284
- provides("A")
285
- depends("B", "C")
286
- collect_data {}
287
- end
288
- klass_b = Ohai.plugin(:B) do
289
- provides("B")
290
- depends("C")
291
- collect_data {}
292
- end
293
- klass_c = Ohai.plugin(:C) do
294
- provides("C")
295
- collect_data {}
296
- end
297
-
298
- @plugins = []
299
- [klass_a, klass_b, klass_c].each do |klass|
300
- @plugins << klass.new(@ohai.data, @ohai.logger)
301
- end
302
- @plugin_a, @plugin_b, @plugin_c = @plugins
303
- end
304
-
305
- it "does not detect a cycle when B is the first provider returned" do
306
- @ohai.provides_map.set_providers_for(@plugin_a, ["A"])
307
- @ohai.provides_map.set_providers_for(@plugin_b, ["B"])
308
- @ohai.provides_map.set_providers_for(@plugin_c, ["C"])
309
-
310
- expect(Ohai::Log).not_to receive(:error).with(/DependencyCycleError/)
311
- @runner.run_plugin(@plugin_a)
312
-
313
- @plugins.each do |plugin|
314
- expect(plugin.has_run?).to be true
315
- end
316
- end
317
-
318
- it "does not detect a cycle when C is the first provider returned" do
319
- @ohai.provides_map.set_providers_for(@plugin_a, ["A"])
320
- @ohai.provides_map.set_providers_for(@plugin_c, ["C"])
321
- @ohai.provides_map.set_providers_for(@plugin_b, ["B"])
322
-
323
- expect(Ohai::Log).not_to receive(:error).with(/DependencyCycleError/)
324
- @runner.run_plugin(@plugin_a)
325
-
326
- @plugins.each do |plugin|
327
- expect(plugin.has_run?).to be true
328
- end
329
- end
330
- end
331
- end
332
-
333
- describe Ohai::Runner, "fetch_plugins" do
334
- before do
335
- @provides_map = Ohai::ProvidesMap.new
336
- @data = Mash.new
337
- @ohai = double("Ohai::System", data: @data, provides_map: @provides_map, logger: Ohai::Log.with_child)
338
- @runner = Ohai::Runner.new(@ohai, true)
339
- end
340
-
341
- it "collects the provider" do
342
- plugin = Ohai::DSL::Plugin.new(@ohai.data, @ohai.logger)
343
- @ohai.provides_map.set_providers_for(plugin, ["top/middle/bottom"])
344
-
345
- dependency_providers = @runner.fetch_plugins(["top/middle/bottom"])
346
- expect(dependency_providers).to eql([plugin])
347
- end
348
-
349
- describe "when the attribute is not provided by any plugin" do
350
- describe "and some parent attribute has providers" do
351
- it "returns the providers for the parent" do
352
- plugin = Ohai::DSL::Plugin.new(@ohai.data, @ohai.logger)
353
- @provides_map.set_providers_for(plugin, ["test/attribute"])
354
- expect(@runner.fetch_plugins(["test/attribute/too_far"])).to eql([plugin])
355
- end
356
- end
357
-
358
- describe "and no parent attribute has providers" do
359
- it "raises Ohai::Exceptions::AttributeNotFound exception" do
360
- # provides map is empty
361
- expect { @runner.fetch_plugins(["false/attribute"]) }.to raise_error(Ohai::Exceptions::AttributeNotFound, "No such attribute: 'false/attribute'")
362
- end
363
- end
364
- end
365
-
366
- it "returns unique providers" do
367
- plugin = Ohai::DSL::Plugin.new(@ohai.data, @ohai.logger)
368
- @provides_map.set_providers_for(plugin, ["test", "test/too_far/way_too_far"])
369
- expect(@runner.fetch_plugins(["test", "test/too_far/way_too_far"])).to eql([plugin])
370
- end
371
- end
372
-
373
- describe Ohai::Runner, "#get_cycle" do
374
- before do
375
- @ohai = Ohai::System.new
376
- @runner = Ohai::Runner.new(@ohai, true)
377
-
378
- klass1 = Ohai.plugin(:One) do
379
- provides("one")
380
- depends("two")
381
- collect_data do
382
- one(two)
383
- end
384
- end
385
- klass2 = Ohai.plugin(:Two) do
386
- provides("two")
387
- depends("one")
388
- collect_data do
389
- two(one)
390
- end
391
- end
392
- klass3 = Ohai.plugin(:Three) do
393
- provides("three")
394
- depends("two")
395
- collect_data do
396
- three(two)
397
- end
398
- end
399
-
400
- plugins = []
401
- [klass1, klass2, klass3].each_with_index do |klass, idx|
402
- plugins << klass.new(@ohai.data, @ohai.logger)
403
- end
404
- @plugin1, @plugin2, @plugin3 = plugins
405
- end
406
-
407
- it "returns the sources for the plugins in the cycle, when given an exact cycle" do
408
- cycle = [@plugin1, @plugin2]
409
- cycle_start = @plugin1
410
-
411
- cycle_names = @runner.get_cycle(cycle, cycle_start)
412
- expect(cycle_names).to eql([@plugin1.name, @plugin2.name])
413
- end
414
-
415
- it "returns the sources for only the plugins in the cycle, when there are plugins before the cycle begins" do
416
- cycle = [@plugin3, @plugin1, @plugin2]
417
- cycle_start = @plugin1
418
-
419
- cycle_names = @runner.get_cycle(cycle, cycle_start)
420
- expect(cycle_names).to eql([@plugin1.name, @plugin2.name])
421
- end
422
- end