Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to have this fact only in a puppet-agent context? What if i want to use the augeas fact with standalone facter and i install augeas to have augparse command?

For example installing augeas-tools and cfacter 3.11.0 on ubuntu-20.04 i can have the augeas fact.

Copy link
Copy Markdown
Contributor Author

@oanatmaria oanatmaria Oct 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the behaviour as follows:
1st: check if the path from puppet-agent's augparse exists and is readable; If not
2st: call 'augparse' without path and hope it is in path; If this command returns empty string
3rd: try requiring augeas gem and calling Augeas cli method to determine it's version.

So if augeas is present on the system, facter will determine it's version, even if it isn't in path or if it was installed manually and not shipped in puppet-agent context.

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