Skip to content

Commit

Permalink
Merge pull request #2135 from oanatmaria/FACT-2832
Browse files Browse the repository at this point in the history
(FACT-2832) Use full path for augparse command
  • Loading branch information
mihaibuzgau authored Oct 14, 2020
2 parents 380f268 + bf6827e commit ae9d38e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/facter/resolvers/augeas_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ def read_augeas_version(fact_name)
end

def read_augeas_from_cli
output = Facter::Core::Execution.execute('augparse --version 2>&1', logger: log)
command = if File.readable?('/opt/puppetlabs/puppet/bin/augparse')
'/opt/puppetlabs/puppet/bin/augparse'
else
'augparse'
end

output = Facter::Core::Execution.execute("#{command} --version 2>&1", logger: log)
Regexp.last_match(1) if output =~ /^augparse (\d+\.\d+\.\d+)/
end

Expand Down
16 changes: 16 additions & 0 deletions spec/facter/resolvers/augeas_resolver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
subject(:augeas) { Facter::Resolvers::Augeas }

let(:log_spy) { instance_spy(Facter::Log) }
let(:readable) { false }

before do
augeas.instance_variable_set(:@log, log_spy)
allow(File).to receive(:readable?).with('/opt/puppetlabs/puppet/bin/augparse').and_return(readable)
end

after do
Expand All @@ -25,6 +27,20 @@
end
end

context 'when augparse is installed with puppet-agent package on unix based systems' do
let(:readable) { true }

before do
allow(Facter::Core::Execution).to receive(:execute)
.with('/opt/puppetlabs/puppet/bin/augparse --version 2>&1', logger: log_spy)
.and_return('augparse 1.12.0 <http://augeas.net/>')
end

it 'returns build' do
expect(augeas.resolve(:augeas_version)).to eq('1.12.0')
end
end

context 'when augparse is not installed' do
before do
allow(Facter::Core::Execution).to receive(:execute)
Expand Down

0 comments on commit ae9d38e

Please sign in to comment.