diff options
author | sersut <serdar@opscode.com> | 2014-01-15 16:14:44 -0800 |
---|---|---|
committer | sersut <serdar@opscode.com> | 2014-03-07 12:32:37 -0800 |
commit | 8466b2ba237e6d579c92b3e39084d0d2ad027f4b (patch) | |
tree | cde13fcc93bd5c43400838c4f5aef6cd0cf23ff7 | |
parent | bc609179d155b179d9bb24e7460b6e9c6575e6be (diff) | |
download | chef-8466b2ba237e6d579c92b3e39084d0d2ad027f4b.tar.gz |
Fix the Ohai resource for Ohai 7.
Conflicts:
spec/unit/provider/ohai_spec.rb
-rw-r--r-- | lib/chef/provider/ohai.rb | 11 | ||||
-rw-r--r-- | spec/functional/resource/ohai_spec.rb | 65 | ||||
-rw-r--r-- | spec/unit/provider/ohai_spec.rb | 5 |
3 files changed, 73 insertions, 8 deletions
diff --git a/lib/chef/provider/ohai.rb b/lib/chef/provider/ohai.rb index c686f67450..a6b5ab5daa 100644 --- a/lib/chef/provider/ohai.rb +++ b/lib/chef/provider/ohai.rb @@ -33,11 +33,12 @@ class Chef def action_reload converge_by("re-run ohai and merge results into node attributes") do ohai = ::Ohai::System.new - if @new_resource.plugin - ohai.require_plugin @new_resource.plugin - else - ohai.all_plugins - end + + # If @new_resource.plugin is nil, ohai will reload all the plugins + # Otherwise it will only reload the specified plugin + # Note that any changes to plugins, or new plugins placed on + # the path are picked up by ohai. + ohai.all_plugins @new_resource.plugin node.automatic_attrs.merge! ohai.data Chef::Log.info("#{@new_resource} reloaded") end diff --git a/spec/functional/resource/ohai_spec.rb b/spec/functional/resource/ohai_spec.rb new file mode 100644 index 0000000000..b1e4891293 --- /dev/null +++ b/spec/functional/resource/ohai_spec.rb @@ -0,0 +1,65 @@ +# +# Author:: Serdar Sutay (<serdar@opscode.com>) +# Copyright:: Copyright (c) 2014 Opscode, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'spec_helper' + +describe Chef::Resource::Ohai do + let(:ohai) { + o = Ohai::System.new + o.all_plugins + o + } + + let(:node) { Chef::Node.new } + + let(:run_context) { + node.default[:platform] = ohai[:platform] + node.default[:platform_version] = ohai[:platform_version] + events = Chef::EventDispatch::Dispatcher.new + Chef::RunContext.new(node, {}, events) + } + + shared_examples_for "reloaded :uptime" do + it "should reload :uptime" do + initial_uptime = ohai[:uptime] + + # Sleep for a second so the uptime gets updated. + sleep 1 + + ohai_resource.run_action(:reload) + node[:uptime].should_not == initial_uptime + end + end + + describe "when reloading all plugins" do + let(:ohai_resource) { Chef::Resource::Ohai.new("reload all", run_context)} + + it_behaves_like "reloaded :uptime" + end + + describe "when reloading only uptime" do + let(:ohai_resource) { + r = Chef::Resource::Ohai.new("reload all", run_context) + r.plugin("uptime") + r + } + + + it_behaves_like "reloaded :uptime" + end +end diff --git a/spec/unit/provider/ohai_spec.rb b/spec/unit/provider/ohai_spec.rb index 8b8a6b5939..2085f44309 100644 --- a/spec/unit/provider/ohai_spec.rb +++ b/spec/unit/provider/ohai_spec.rb @@ -41,9 +41,8 @@ describe Chef::Provider::Ohai do :newdata => "somevalue" } } - mock_ohai.stub(:all_plugins).and_return(true) - mock_ohai.stub(:require_plugin).and_return(true) - mock_ohai.stub(:data).and_return(mock_ohai[:data], + mock_ohai.stub!(:all_plugins).and_return(true) + mock_ohai.stub!(:data).and_return(mock_ohai[:data], mock_ohai[:data2]) Ohai::System.stub(:new).and_return(mock_ohai) Chef::Platform.stub(:find_platform_and_version).and_return({ "platform" => @platform, |