Skip to content

Commit 3864ff8

Browse files
committed
(#9440) exec resource: set path param to path fact
Signed-off-by: Tim Meusel <[email protected]>
1 parent 26ab7e1 commit 3864ff8

File tree

6 files changed

+7
-27
lines changed

6 files changed

+7
-27
lines changed

lib/puppet/provider/exec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,6 @@ def extractexe(command)
102102
def validatecmd(command)
103103
exe = extractexe(command)
104104
# if we're not fully qualified, require a path
105-
self.fail _("'%{exe}' is not qualified and no path was specified. Please qualify the command or specify a path.") % { exe: exe } if !absolute_path?(exe) and resource[:path].nil?
105+
self.fail _("'%{exe}' is not qualified and no path was specified. Please qualify the command or specify a path.") % { exe: exe } if !absolute_path?(exe) && (resource[:path].nil? || resource[:path].empty?)
106106
end
107107
end

lib/puppet/type/exec.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,9 @@ def sync
223223
newparam(:path) do
224224
desc "The search path used for command execution.
225225
Commands must be fully qualified if no path is specified. Paths
226-
can be specified as an array or as a '#{File::PATH_SEPARATOR}' separated list."
226+
can be specified as an array or as a '#{File::PATH_SEPARATOR}' separated list. Defaults to the `path` fact."
227+
228+
defaultto Puppet.runtime[:facter].value('path')
227229

228230
# Support both arrays and colon-separated fields.
229231
def value=(*values)

spec/unit/provider/exec/posix_spec.rb

+1-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ def make_exe
1616

1717
describe "#validatecmd" do
1818
it "should fail if no path is specified and the command is not fully qualified" do
19-
expect { provider.validatecmd("foo") }.to raise_error(
20-
Puppet::Error,
21-
"'foo' is not qualified and no path was specified. Please qualify the command or specify a path."
22-
)
19+
expect(provider.validatecmd('foo')).to eq(nil)
2320
end
2421

2522
it "should pass if a path is given" do

spec/unit/provider/exec/windows_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@
8888
end
8989

9090
describe "#validatecmd" do
91-
it "should fail if the command isn't absolute and there is no path" do
92-
expect { provider.validatecmd('foo') }.to raise_error(Puppet::Error, /'foo' is not qualified and no path was specified/)
91+
it "should not fail if the command isn't absolute and there is no path" do
92+
expect(provider.validatecmd('foo')).to eq(nil)
9393
end
9494

9595
it "should not fail if the command is absolute and there is no path" do

spec/unit/provider/exec_spec.rb

-14
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,6 @@ def echo_from_ruby_exit_1(message)
7373
end
7474

7575
context "when validating the command" do
76-
it "redacts the arguments if the command is relative" do
77-
expect {
78-
apply_compiled_manifest(<<-MANIFEST)
79-
exec { 'echo':
80-
command => Sensitive.new('echo #{supersecret}')
81-
}
82-
MANIFEST
83-
}.to raise_error do |err|
84-
expect(err).to be_a(Puppet::Error)
85-
expect(err.message).to match(/'echo' is not qualified and no path was specified. Please qualify the command or specify a path./)
86-
expect(err.message).to_not match(/#{supersecret}/)
87-
end
88-
end
89-
9076
it "redacts the arguments if the command is a directory" do
9177
dir = tmpdir('exec')
9278
apply_compiled_manifest(<<-MANIFEST)

spec/unit/type/exec_spec.rb

-5
Original file line numberDiff line numberDiff line change
@@ -910,11 +910,6 @@ def instance(path)
910910
let :abs do make_absolute('/bin/echo') end
911911
let :path do make_absolute('/bin') end
912912

913-
it "should fail with relative command and no path" do
914-
expect { type.new(:command => rel) }.
915-
to raise_error Puppet::Error, /no path was specified/
916-
end
917-
918913
it "should accept a relative command with a path" do
919914
expect(type.new(:command => rel, :path => path)).to be
920915
end

0 commit comments

Comments
 (0)