summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhil Dibowitz <phil@ipom.com>2013-11-21 12:48:12 -0800
committerPhil Dibowitz <phil@ipom.com>2013-11-21 13:26:23 -0800
commit72ec233c262b1269002ef49a2d12797aa2734c8c (patch)
treec6f3513bed5ce050491e24f702be5e5ec2b0c3ce
parentf8de6a2c73efcae6b48517818284139693f35a7b (diff)
downloadchef-72ec233c262b1269002ef49a2d12797aa2734c8c.tar.gz
Move to making a seprate resource/provider
-rw-r--r--chef/lib/chef/platform.rb1
-rw-r--r--chef/lib/chef/provider/ruby_block.rb11
-rw-r--r--chef/lib/chef/provider/whyrun_safe_ruby_block.rb29
-rw-r--r--chef/lib/chef/providers.rb1
-rw-r--r--chef/lib/chef/resource/ruby_block.rb9
-rw-r--r--chef/lib/chef/resource/whyrun_safe_ruby_block.rb31
-rw-r--r--chef/lib/chef/resources.rb1
-rw-r--r--chef/spec/unit/provider/ruby_block_spec.rb18
-rw-r--r--chef/spec/unit/provider/whyrun_safe_ruby_block_spec.rb47
9 files changed, 112 insertions, 36 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 5b259a0215..d80b807267 100644
--- a/chef/lib/chef/provider/ruby_block.rb
+++ b/chef/lib/chef/provider/ruby_block.rb
@@ -29,16 +29,9 @@ class Chef
end
def action_create
- description = "execute the ruby block #{@new_resource.name}"
- if Chef::Config[:why_run] && @new_resource.whyrun_safe
+ converge_by("execute the ruby block #{@new_resource.name}") do
@new_resource.block.call
- new_resource.updated_by_last_action(true)
- Chef::Log.info("#{@new_resource} called - labelled as whyrun-safe")
- else
- converge_by(description) do
- @new_resource.block.call
- Chef::Log.info("#{@new_resource} called")
- end
+ Chef::Log.info("#{@new_resource} called")
end
end
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..2e24cf6967
--- /dev/null
+++ b/chef/lib/chef/provider/whyrun_safe_ruby_block.rb
@@ -0,0 +1,29 @@
+#
+# 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)
+ 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/ruby_block.rb b/chef/lib/chef/resource/ruby_block.rb
index babcb6a5e5..cb743819aa 100644
--- a/chef/lib/chef/resource/ruby_block.rb
+++ b/chef/lib/chef/resource/ruby_block.rb
@@ -29,7 +29,6 @@ class Chef
@action = "create"
@allowed_actions.push(:create)
@block_name = name
- @whyrun_safe = false
end
def block(&block)
@@ -47,14 +46,6 @@ class Chef
:kind_of => String
)
end
-
- def whyrun_safe(arg=nil)
- set_or_return(
- :whyrun_safe,
- arg,
- :kind_of => [ TrueClass, FalseClass ]
- )
- end
end
end
end
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/ruby_block_spec.rb b/chef/spec/unit/provider/ruby_block_spec.rb
index 9803f17253..7efb4c7fcd 100644
--- a/chef/spec/unit/provider/ruby_block_spec.rb
+++ b/chef/spec/unit/provider/ruby_block_spec.rb
@@ -34,23 +34,5 @@ describe Chef::Provider::RubyBlock, "initialize" do
$evil_global_evil_laugh.should == :mwahahaha
@new_resource.should be_updated
end
-
- it "should call why-run safe blocks in whyrun mode" do
- Chef::Config[:why_run] = true
- @new_resource.whyrun_safe(true)
- @provider.run_action(:create)
- $evil_global_evil_laugh.should == :mwahahaha
- @new_resource.should be_updated
- Chef::Config[:why_run] = false
- end
-
- it "should not call non-why-run safe blocks in whyrun mode" do
- Chef::Config[:why_run] = true
- @provider.run_action(:create)
- $evil_global_evil_laugh.should == :wahwah
- @new_resource.should be_updated
- Chef::Config[:why_run] = false
- end
-
end
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
+