diff options
author | Phil Dibowitz <phil@ipom.com> | 2013-11-21 14:01:17 -0800 |
---|---|---|
committer | Phil Dibowitz <phil@ipom.com> | 2013-11-21 14:01:17 -0800 |
commit | 5cae63bf8b9de07dd8c08d7e2b0876e2ed5b86e2 (patch) | |
tree | a1447b63def6a065848f895332087feaf275fe0a | |
parent | 06c0b8b13b326871710d4233b0cbc36744c57f79 (diff) | |
parent | d12a4affa441922255965598ca8b37230fb60712 (diff) | |
download | chef-5cae63bf8b9de07dd8c08d7e2b0876e2ed5b86e2.tar.gz |
Merge pull request #1116 from jaymzh/CHEF-4110-10stable
[CHEF-4110-10stable] Add a "whyrun_safe" attribute to ruby_block
-rw-r--r-- | chef/lib/chef/platform.rb | 1 | ||||
-rw-r--r-- | chef/lib/chef/provider/ruby_block.rb | 2 | ||||
-rw-r--r-- | chef/lib/chef/provider/whyrun_safe_ruby_block.rb | 30 | ||||
-rw-r--r-- | chef/lib/chef/providers.rb | 1 | ||||
-rw-r--r-- | chef/lib/chef/resource/whyrun_safe_ruby_block.rb | 31 | ||||
-rw-r--r-- | chef/lib/chef/resources.rb | 1 | ||||
-rw-r--r-- | chef/spec/unit/provider/whyrun_safe_ruby_block_spec.rb | 47 |
7 files changed, 112 insertions, 1 deletions
diff --git a/chef/lib/chef/platform.rb b/chef/lib/chef/platform.rb index 1eafb1149b..17d6b189a8 100644 --- a/chef/lib/chef/platform.rb +++ b/chef/lib/chef/platform.rb @@ -331,6 +331,7 @@ class Chef :route => Chef::Provider::Route, :ifconfig => Chef::Provider::Ifconfig, :ruby_block => Chef::Provider::RubyBlock, + :whyrun_safe_ruby_block => Chef::Provider::WhyrunSafeRubyBlock, :erl_call => Chef::Provider::ErlCall, :log => Chef::Provider::Log::ChefLog } diff --git a/chef/lib/chef/provider/ruby_block.rb b/chef/lib/chef/provider/ruby_block.rb index e5e5d01152..d80b807267 100644 --- a/chef/lib/chef/provider/ruby_block.rb +++ b/chef/lib/chef/provider/ruby_block.rb @@ -29,7 +29,7 @@ class Chef end def action_create - converge_by("execute the ruby block #{@new_resource.name}") do + converge_by("execute the ruby block #{@new_resource.name}") do @new_resource.block.call Chef::Log.info("#{@new_resource} called") end diff --git a/chef/lib/chef/provider/whyrun_safe_ruby_block.rb b/chef/lib/chef/provider/whyrun_safe_ruby_block.rb new file mode 100644 index 0000000000..4b491a4f60 --- /dev/null +++ b/chef/lib/chef/provider/whyrun_safe_ruby_block.rb @@ -0,0 +1,30 @@ +# +# Author:: Phil Dibowitz (<phild@fb.com>) +# Copyright:: Copyright (c) 2013 Facebook +# 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. +# + +class Chef + class Provider + class WhyrunSafeRubyBlock < Chef::Provider::RubyBlock + def action_create + @new_resource.block.call + @new_resource.updated_by_last_action(true) + @run_context.events.resource_update_applied(@new_resource, :create, "execute the whyrun_safe_ruby_block #{@new_resource.name}") + Chef::Log.info("#{@new_resource} called") + end + end + end +end diff --git a/chef/lib/chef/providers.rb b/chef/lib/chef/providers.rb index d6ffd7e47b..8ebb9ca21b 100644 --- a/chef/lib/chef/providers.rb +++ b/chef/lib/chef/providers.rb @@ -45,6 +45,7 @@ require 'chef/provider/service' require 'chef/provider/subversion' require 'chef/provider/template' require 'chef/provider/user' +require 'chef/provider/whyrun_safe_ruby_block' require 'chef/provider/env/windows' diff --git a/chef/lib/chef/resource/whyrun_safe_ruby_block.rb b/chef/lib/chef/resource/whyrun_safe_ruby_block.rb new file mode 100644 index 0000000000..ddb9d91dc3 --- /dev/null +++ b/chef/lib/chef/resource/whyrun_safe_ruby_block.rb @@ -0,0 +1,31 @@ +# +# Author:: Phil Dibowitz (<phild@fb.com>) +# Copyright:: Copyright (c) 2013 Facebook +# 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. +# + +class Chef + class Resource + class WhyrunSafeRubyBlock < Chef::Resource::RubyBlock + + def initialize(name, run_context=nil) + super + @resource_name = :whyrun_safe_ruby_block + @provider = Chef::Provider::WhyrunSafeRubyBlock + end + + end + end +end diff --git a/chef/lib/chef/resources.rb b/chef/lib/chef/resources.rb index 7fadb17444..207cef57ea 100644 --- a/chef/lib/chef/resources.rb +++ b/chef/lib/chef/resources.rb @@ -64,4 +64,5 @@ require 'chef/resource/smartos_package' require 'chef/resource/template' require 'chef/resource/timestamped_deploy' require 'chef/resource/user' +require 'chef/resource/whyrun_safe_ruby_block' require 'chef/resource/yum_package' diff --git a/chef/spec/unit/provider/whyrun_safe_ruby_block_spec.rb b/chef/spec/unit/provider/whyrun_safe_ruby_block_spec.rb new file mode 100644 index 0000000000..5a17aacbd9 --- /dev/null +++ b/chef/spec/unit/provider/whyrun_safe_ruby_block_spec.rb @@ -0,0 +1,47 @@ +# +# Author:: Phil Dibowitz (<phild@fb.com>) +# Copyright:: Copyright (c) 2013 Facebook +# 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::Provider::WhyrunSafeRubyBlock, "initialize" do + before(:each) do + $evil_global_evil_laugh = :wahwah + @node = Chef::Node.new + @events = Chef::EventDispatch::Dispatcher.new + @run_context = Chef::RunContext.new(@node, {}, @events) + @new_resource = Chef::Resource::WhyrunSafeRubyBlock.new("bloc party") + @new_resource.block { $evil_global_evil_laugh = :mwahahaha} + @provider = Chef::Provider::WhyrunSafeRubyBlock.new(@new_resource, @run_context) + end + + it "should call the block and flag the resource as updated" do + @provider.run_action(:create) + $evil_global_evil_laugh.should == :mwahahaha + @new_resource.should be_updated + end + + it "should call the block and flat the resource as updated - even in whyrun" do + Chef::Config[:why_run] = true + @provider.run_action(:create) + $evil_global_evil_laugh.should == :mwahahaha + @new_resource.should be_updated + Chef::Config[:why_run] = false + end + +end + |