diff options
author | Serdar Sutay <serdar@opscode.com> | 2014-01-17 11:11:16 -0800 |
---|---|---|
committer | Serdar Sutay <serdar@opscode.com> | 2014-01-17 11:11:16 -0800 |
commit | 3c98f761f924ff459529e5bf096f817dbd61e0e3 (patch) | |
tree | 2438016ac0619e8074c7e58ada8d1afa49057011 | |
parent | f0439992a4e12dc7a6ee163ce8cb61e51d1485e2 (diff) | |
parent | b19b49866f584d1da4af1eaee2ebb6a3e659358b (diff) | |
download | chef-3c98f761f924ff459529e5bf096f817dbd61e0e3.tar.gz |
Merge pull request #1214 from opscode/ohai-resource-fix
Ohai 7 Compatibility for Chef
-rw-r--r-- | Gemfile | 3 | ||||
-rw-r--r-- | chef.gemspec | 2 | ||||
-rw-r--r-- | lib/chef/provider/ohai.rb | 11 | ||||
-rw-r--r-- | lib/chef/version.rb | 2 | ||||
-rw-r--r-- | spec/functional/resource/base.rb | 4 | ||||
-rw-r--r-- | spec/functional/resource/deploy_revision_spec.rb | 2 | ||||
-rw-r--r-- | spec/functional/resource/git_spec.rb | 2 | ||||
-rw-r--r-- | spec/functional/resource/ohai_spec.rb | 65 | ||||
-rw-r--r-- | spec/spec_helper.rb | 3 | ||||
-rw-r--r-- | spec/support/shared/functional/windows_script.rb | 3 | ||||
-rw-r--r-- | spec/unit/provider/ohai_spec.rb | 1 |
11 files changed, 81 insertions, 17 deletions
@@ -3,6 +3,9 @@ gemspec :name => "chef" gem "activesupport", "< 4.0.0", :group => :compat_testing, :platform => "ruby" +# Remove this line before shipping Chef version for Ohai 7.0 Release Candidate. +gem "ohai", :git => "https://github.com/opscode/ohai.git" + group(:docgen) do gem "ronn" gem "yard" diff --git a/chef.gemspec b/chef.gemspec index fb30266a01..ed0ae15ac5 100644 --- a/chef.gemspec +++ b/chef.gemspec @@ -17,7 +17,7 @@ Gem::Specification.new do |s| s.add_dependency "mixlib-log", "~> 1.3" s.add_dependency "mixlib-authentication", "~> 1.3" s.add_dependency "mixlib-shellout", "~> 1.2" - s.add_dependency "ohai", "~> 6.0" + s.add_dependency "ohai", "= 7.0.0.alpha.0" s.add_dependency "rest-client", ">= 1.0.4", "< 1.7.0" # rest-client has an unbounded dependency on mime-types. 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/lib/chef/version.rb b/lib/chef/version.rb index 173b0cc944..da713e261b 100644 --- a/lib/chef/version.rb +++ b/lib/chef/version.rb @@ -17,7 +17,7 @@ class Chef CHEF_ROOT = File.dirname(File.expand_path(File.dirname(__FILE__))) - VERSION = '11.8.2' + VERSION = '11.8.4.ohai7.0' end # NOTE: the Chef::Version class is defined in version_class.rb diff --git a/spec/functional/resource/base.rb b/spec/functional/resource/base.rb index 13438c1759..056db39877 100644 --- a/spec/functional/resource/base.rb +++ b/spec/functional/resource/base.rb @@ -22,9 +22,7 @@ def ohai # provider is platform-dependent, we need platform ohai data: @OHAI_SYSTEM ||= begin ohai = Ohai::System.new - ohai.require_plugin("os") - ohai.require_plugin("platform") - ohai.require_plugin("passwd") + ohai.all_plugins("platform") ohai end end diff --git a/spec/functional/resource/deploy_revision_spec.rb b/spec/functional/resource/deploy_revision_spec.rb index 14e6e69d6d..1cd26309c4 100644 --- a/spec/functional/resource/deploy_revision_spec.rb +++ b/spec/functional/resource/deploy_revision_spec.rb @@ -45,7 +45,7 @@ describe Chef::Resource::DeployRevision, :unix_only => true do before(:all) do @ohai = Ohai::System.new - @ohai.require_plugin("os") + @ohai.all_plugins("os") end let(:node) do diff --git a/spec/functional/resource/git_spec.rb b/spec/functional/resource/git_spec.rb index 7ade6eea21..f0bd94b0c0 100644 --- a/spec/functional/resource/git_spec.rb +++ b/spec/functional/resource/git_spec.rb @@ -92,7 +92,7 @@ E before(:all) do @ohai = Ohai::System.new - @ohai.require_plugin("os") + @ohai.all_plugins("os") end context "working with pathes with special characters" do 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/spec_helper.rb b/spec/spec_helper.rb index 618f782c7c..2f883d0093 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -87,8 +87,7 @@ Dir["spec/support/**/*.rb"]. OHAI_SYSTEM = Ohai::System.new -OHAI_SYSTEM.require_plugin("os") -OHAI_SYSTEM.require_plugin("platform") +OHAI_SYSTEM.all_plugins("platform") TEST_PLATFORM = OHAI_SYSTEM["platform"].dup.freeze TEST_PLATFORM_VERSION = OHAI_SYSTEM["platform_version"].dup.freeze diff --git a/spec/support/shared/functional/windows_script.rb b/spec/support/shared/functional/windows_script.rb index afeb4c029c..db2882e1a1 100644 --- a/spec/support/shared/functional/windows_script.rb +++ b/spec/support/shared/functional/windows_script.rb @@ -23,8 +23,7 @@ shared_context Chef::Resource::WindowsScript do before(:all) do ohai_reader = Ohai::System.new - ohai_reader.require_plugin("os") - ohai_reader.require_plugin("windows::platform") + ohai_reader.all_plugins("platform") new_node = Chef::Node.new new_node.consume_external_attrs(ohai_reader.data,{}) diff --git a/spec/unit/provider/ohai_spec.rb b/spec/unit/provider/ohai_spec.rb index 8402c92e97..18c12b8ae4 100644 --- a/spec/unit/provider/ohai_spec.rb +++ b/spec/unit/provider/ohai_spec.rb @@ -42,7 +42,6 @@ describe Chef::Provider::Ohai do } } 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[:data2]) Ohai::System.stub!(:new).and_return(mock_ohai) |