summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@opscode.com>2013-04-12 11:38:41 -0700
committerBryan McLellan <btm@opscode.com>2013-04-12 11:38:41 -0700
commite58ed68e8886f0f250d5f6ebd9f44a9425da66e6 (patch)
tree7490bc0b2378beb818309d7a03f8c3f770d0ce80
parent084cec650a242c261c7987a45baa475cd67b8edf (diff)
parent7bc64aacd0acbcde66077515d54c101ca8e61310 (diff)
downloadchef-e58ed68e8886f0f250d5f6ebd9f44a9425da66e6.tar.gz
Merge branch 'CHEF-3819'
-rw-r--r--lib/chef/provider/execute.rb27
-rw-r--r--spec/unit/provider/execute_spec.rb28
2 files changed, 49 insertions, 6 deletions
diff --git a/lib/chef/provider/execute.rb b/lib/chef/provider/execute.rb
index d6b2f91bab..8d2a7d997d 100644
--- a/lib/chef/provider/execute.rb
+++ b/lib/chef/provider/execute.rb
@@ -37,11 +37,9 @@ class Chef
def action_run
opts = {}
- if sentinel_file = @new_resource.creates
- if ::File.exists?(sentinel_file)
- Chef::Log.debug("#{@new_resource} sentinel file #{sentinel_file} exists - nothing to do")
- return false
- end
+ if sentinel_file = sentinel_file_if_exists
+ Chef::Log.debug("#{@new_resource} sentinel file #{sentinel_file} exists - nothing to do")
+ return false
end
# original implementation did not specify a timeout, but ShellOut
@@ -63,6 +61,25 @@ class Chef
Chef::Log.info("#{@new_resource} ran successfully")
end
end
+
+ private
+
+ def sentinel_file_if_exists
+ if sentinel_file = @new_resource.creates
+ relative = Pathname(sentinel_file).relative?
+ cwd = @new_resource.cwd
+ if relative && !cwd
+ Chef::Log.warn "You have provided relative path for execute#creates (#{sentinel_file}) without execute#cwd (see CHEF-3819)"
+ end
+
+ if ::File.exists?(sentinel_file)
+ sentinel_file
+ elsif cwd && relative
+ sentinel_file = ::File.join(cwd, sentinel_file)
+ sentinel_file if ::File.exists?(sentinel_file)
+ end
+ end
+ end
end
end
end
diff --git a/spec/unit/provider/execute_spec.rb b/spec/unit/provider/execute_spec.rb
index a944793a89..bf913cca12 100644
--- a/spec/unit/provider/execute_spec.rb
+++ b/spec/unit/provider/execute_spec.rb
@@ -27,7 +27,7 @@ describe Chef::Provider::Execute do
@new_resource = Chef::Resource::Execute.new("foo_resource", @run_context)
@new_resource.timeout 3600
@new_resource.returns 0
- @new_resource.creates "foo_resource"
+ @new_resource.creates "/foo_resource"
@provider = Chef::Provider::Execute.new(@new_resource, @run_context)
@current_resource = Chef::Resource::Ifconfig.new("foo_resource", @run_context)
@provider.current_resource = @current_resource
@@ -46,6 +46,7 @@ describe Chef::Provider::Execute do
opts[:log_tag] = @new_resource.to_s
opts[:live_stream] = STDOUT
@provider.should_receive(:shell_out!).with(@new_resource.command, opts)
+ Chef::Log.should_not_receive(:warn)
@provider.run_action(:run)
@new_resource.should be_updated
@@ -55,6 +56,31 @@ describe Chef::Provider::Execute do
@provider.stub!(:load_current_resource)
File.should_receive(:exists?).with(@new_resource.creates).and_return(true)
@provider.should_not_receive(:shell_out!)
+ Chef::Log.should_not_receive(:warn)
+
+ @provider.run_action(:run)
+ @new_resource.should_not be_updated
+ end
+
+ it "should respect cwd options for 'creates'" do
+ @new_resource.cwd "/tmp"
+ @new_resource.creates "foo_resource"
+ @provider.stub!(:load_current_resource)
+ File.should_receive(:exists?).with(@new_resource.creates).and_return(false)
+ File.should_receive(:exists?).with(File.join("/tmp", @new_resource.creates)).and_return(true)
+ Chef::Log.should_not_receive(:warn)
+ @provider.should_not_receive(:shell_out!)
+
+ @provider.run_action(:run)
+ @new_resource.should_not be_updated
+ end
+
+ it "should warn if user specified relative path without cwd" do
+ @new_resource.creates "foo_resource"
+ @provider.stub!(:load_current_resource)
+ Chef::Log.should_receive(:warn).with(/relative path/)
+ File.should_receive(:exists?).with(@new_resource.creates).and_return(true)
+ @provider.should_not_receive(:shell_out!)
@provider.run_action(:run)
@new_resource.should_not be_updated