summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Dibowitz <phil@ipom.com>2013-11-21 14:10:16 -0800
committerPhil Dibowitz <phil@ipom.com>2013-11-21 14:10:16 -0800
commit05aa115ac5e8accb20888cbd2c3d682284024c5c (patch)
tree2d563c33c3aaa70f98c46ffc3a05b4468babe15e
parent12258c744290c58fc72036a486b4df8adb2886d6 (diff)
downloadchef-05aa115ac5e8accb20888cbd2c3d682284024c5c.tar.gz
[CHEF-4110] Add whyrun_safe_ruby_block resource
-rw-r--r--lib/chef/platform/provider_mapping.rb1
-rw-r--r--lib/chef/provider/whyrun_safe_ruby_block.rb30
-rw-r--r--lib/chef/providers.rb1
-rw-r--r--lib/chef/resource/whyrun_safe_ruby_block.rb31
-rw-r--r--lib/chef/resources.rb1
-rw-r--r--spec/unit/provider/whyrun_safe_ruby_block_spec.rb47
6 files changed, 111 insertions, 0 deletions
diff --git a/lib/chef/platform/provider_mapping.rb b/lib/chef/platform/provider_mapping.rb
index a252bdc100..92a7278d2f 100644
--- a/lib/chef/platform/provider_mapping.rb
+++ b/lib/chef/platform/provider_mapping.rb
@@ -369,6 +369,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/lib/chef/provider/whyrun_safe_ruby_block.rb b/lib/chef/provider/whyrun_safe_ruby_block.rb
new file mode 100644
index 0000000000..4b491a4f60
--- /dev/null
+++ b/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/lib/chef/providers.rb b/lib/chef/providers.rb
index 50099e8afc..6cfd12827a 100644
--- a/lib/chef/providers.rb
+++ b/lib/chef/providers.rb
@@ -48,6 +48,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/lib/chef/resource/whyrun_safe_ruby_block.rb b/lib/chef/resource/whyrun_safe_ruby_block.rb
new file mode 100644
index 0000000000..ddb9d91dc3
--- /dev/null
+++ b/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/lib/chef/resources.rb b/lib/chef/resources.rb
index d0a27d8922..76adb6f1e1 100644
--- a/lib/chef/resources.rb
+++ b/lib/chef/resources.rb
@@ -68,6 +68,7 @@ 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'
require 'chef/resource/lwrp_base'
require 'chef/resource/bff_package'
diff --git a/spec/unit/provider/whyrun_safe_ruby_block_spec.rb b/spec/unit/provider/whyrun_safe_ruby_block_spec.rb
new file mode 100644
index 0000000000..5a17aacbd9
--- /dev/null
+++ b/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
+