Skip to content

Commit

Permalink
(#9440) exec resource: set path param to path fact
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Sep 13, 2024
1 parent 7cc46f7 commit 62e7280
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 35 deletions.
4 changes: 3 additions & 1 deletion lib/puppet/type/exec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ def sync
newparam(:path) do
desc "The search path used for command execution.
Commands must be fully qualified if no path is specified. Paths
can be specified as an array or as a '#{File::PATH_SEPARATOR}' separated list."
can be specified as an array or as a '#{File::PATH_SEPARATOR}' separated list. Defaults to the `path` fact."

defaultto Puppet.runtime[:facter].value('path')

# Support both arrays and colon-separated fields.
def value=(*values)
Expand Down
12 changes: 6 additions & 6 deletions spec/integration/application/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -650,10 +650,10 @@ def with_another_agent_running(&block)
.and output(/No more routes to fileserver/).to_stderr
end

it 'preserves the old cached catalog if validation fails with the old one' do
it 'Updates the old cached catalog if a resource failed to apply' do
catalog_handler = -> (req, res) {
catalog = compile_to_catalog(<<-MANIFEST, node)
exec { 'unqualified_command': }
exec { 'unqualified_command': path => '' }
MANIFEST

res.body = formatter.render(catalog)
Expand All @@ -665,14 +665,14 @@ def with_another_agent_running(&block)
expect {
agent.command_line.args << '--test'
agent.run
}.to exit_with(1)
}.to exit_with(4)
.and output(%r{Retrieving plugin}).to_stdout
.and output(%r{Validation of Exec\[unqualified_command\] failed: 'unqualified_command' is not qualified and no path was specified}).to_stderr
.and output(%r{Error: Could not find command 'unqualified_command'}).to_stderr
end

# cached catalog should not be updated
# cached catalog should be updated
cached_catalog = "#{File.join(Puppet[:client_datadir], 'catalog', Puppet[:certname])}.json"
expect(File).to_not be_exist(cached_catalog)
expect(File).to be_exist(cached_catalog)
end
end

Expand Down
7 changes: 0 additions & 7 deletions spec/unit/provider/exec/posix_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ def make_exe
let(:provider) { described_class.new(resource) }

describe "#validatecmd" do
it "should fail if no path is specified and the command is not fully qualified" do
expect { provider.validatecmd("foo") }.to raise_error(
Puppet::Error,
"'foo' is not qualified and no path was specified. Please qualify the command or specify a path."
)
end

it "should pass if a path is given" do
provider.resource[:path] = ['/bogus/bin']
provider.validatecmd("../foo")
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/provider/exec/windows_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@
end

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

it "should not fail if the command is absolute and there is no path" do
Expand Down
14 changes: 0 additions & 14 deletions spec/unit/provider/exec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,6 @@ def echo_from_ruby_exit_1(message)
end

context "when validating the command" do
it "redacts the arguments if the command is relative" do
expect {
apply_compiled_manifest(<<-MANIFEST)
exec { 'echo':
command => Sensitive.new('echo #{supersecret}')
}
MANIFEST
}.to raise_error do |err|
expect(err).to be_a(Puppet::Error)
expect(err.message).to match(/'echo' is not qualified and no path was specified. Please qualify the command or specify a path./)
expect(err.message).to_not match(/#{supersecret}/)
end
end

it "redacts the arguments if the command is a directory" do
dir = tmpdir('exec')
apply_compiled_manifest(<<-MANIFEST)
Expand Down
5 changes: 0 additions & 5 deletions spec/unit/type/exec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -910,11 +910,6 @@ def instance(path)
let :abs do make_absolute('/bin/echo') end
let :path do make_absolute('/bin') end

it "should fail with relative command and no path" do
expect { type.new(:command => rel) }.
to raise_error Puppet::Error, /no path was specified/
end

it "should accept a relative command with a path" do
expect(type.new(:command => rel, :path => path)).to be
end
Expand Down

0 comments on commit 62e7280

Please sign in to comment.