Skip to content

Commit

Permalink
(FACT-2832) Use puppet path for augeas fact
Browse files Browse the repository at this point in the history
  • Loading branch information
Oana Tanasoiu committed Oct 14, 2020
1 parent cc69ac6 commit fc38501
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(:executable?) { false }

before do
augeas.instance_variable_set(:@log, log_spy)
allow(File).to receive(:readable?).with('/opt/puppetlabs/puppet/bin/augparse').and_return(executable?)
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(:executable?) { 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 fc38501

Please sign in to comment.