diff options
author | Tim Smith <tsmith@chef.io> | 2018-07-13 10:38:21 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-13 10:38:21 -0700 |
commit | 2cb5c8e97b449dc7b65397d5c81e07f5fb1d699f (patch) | |
tree | 55d3801c18a1ea2d0602c51775557db28ab3bd9a | |
parent | 5414c1aeed62dc2b7889fcdf21a11075c137cd88 (diff) | |
parent | cd544332419fc889f710481bf7551574f585765a (diff) | |
download | ohai-2cb5c8e97b449dc7b65397d5c81e07f5fb1d699f.tar.gz |
Merge pull request #1224 from chef/btm/fix-multiple-plugin-loading
Load collect_data() even if we've already seen it
-rw-r--r-- | lib/ohai/dsl/plugin/versionvii.rb | 7 | ||||
-rw-r--r-- | spec/unit/dsl/plugin_spec.rb | 21 | ||||
-rw-r--r-- | spec/unit/loader_spec.rb | 2 |
3 files changed, 13 insertions, 17 deletions
diff --git a/lib/ohai/dsl/plugin/versionvii.rb b/lib/ohai/dsl/plugin/versionvii.rb index c8f354d1..3a8c904e 100644 --- a/lib/ohai/dsl/plugin/versionvii.rb +++ b/lib/ohai/dsl/plugin/versionvii.rb @@ -108,11 +108,8 @@ module Ohai # @param block [block] the actual code to collect data for the specified platforms def self.collect_data(platform = :default, *other_platforms, &block) [platform, other_platforms].flatten.each do |plat| - if data_collector.key?(plat) - raise Ohai::Exceptions::IllegalPluginDefinition, "collect_data already defined on platform #{plat}" - else - data_collector[plat] = block - end + Ohai::Log.warn("collect_data already defined on platform '#{plat}' for #{self}, last plugin seen will be used") if data_collector.key?(plat) + data_collector[plat] = block end end diff --git a/spec/unit/dsl/plugin_spec.rb b/spec/unit/dsl/plugin_spec.rb index e93871d7..1ba70623 100644 --- a/spec/unit/dsl/plugin_spec.rb +++ b/spec/unit/dsl/plugin_spec.rb @@ -519,21 +519,20 @@ describe Ohai::DSL::Plugin::VersionVII do end it "fails a platform has already been defined in the same plugin" do - expect do - Ohai.plugin(:Test) do - collect_data {} - collect_data {} - end - end.to raise_error(Ohai::Exceptions::IllegalPluginDefinition, /collect_data already defined/) + Ohai.plugin(:Test) { collect_data {} } + expect(Ohai::Log).to receive(:warn).with(/collect_data already defined on platform/).twice + Ohai.plugin(:Test) do + collect_data {} + collect_data {} + end end it "fails if a platform has already been defined in another plugin file" do Ohai.plugin(:Test) { collect_data {} } - expect do - Ohai.plugin(:Test) do - collect_data {} - end - end.to raise_error(Ohai::Exceptions::IllegalPluginDefinition, /collect_data already defined/) + expect(Ohai::Log).to receive(:warn).with(/collect_data already defined on platform/) + Ohai.plugin(:Test) do + collect_data {} + end end end diff --git a/spec/unit/loader_spec.rb b/spec/unit/loader_spec.rb index 9a024c56..3f3c1778 100644 --- a/spec/unit/loader_spec.rb +++ b/spec/unit/loader_spec.rb @@ -130,7 +130,7 @@ EOF describe "when the plugin defines collect_data on the same platform more than once" do it "shoud log an illegal plugin definition warning" do - expect(loader.logger).to receive(:warn).with(/Plugin Definition Error: <#{path_to("illegal_def.rb")}>:/) + expect(Ohai::Log).to receive(:warn).with(/collect_data already defined on platform/) loader.load_plugin(path_to("illegal_def.rb")) end |