Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

Commit

Permalink
(maint) Improve freebsd-version failure management
Browse files Browse the repository at this point in the history
This program is always supposed to be found and return the expected
output on FreeBSD but make sure it runs successfully, catpure stderr in
case it becomes used at some point, and do not raise exceptions if the
resolver fails.
  • Loading branch information
smortex committed Apr 30, 2020
1 parent 5723eec commit 5edea77
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/facts/freebsd/os/release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class Release
def call_the_resolver
installed_userland = Facter::Resolvers::Freebsd::FreebsdVersion.resolve(:installed_userland)

return [] if installed_userland.nil?

value = build_release_hash_from_version(installed_userland)

[Facter::ResolvedFact.new(FACT_NAME, value),
Expand Down
5 changes: 4 additions & 1 deletion lib/resolvers/freebsd/freebsd_version_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ def post_resolve(fact_name)
end

def freebsd_version_system_call(fact_name)
output, _status = Open3.capture2('/bin/freebsd-version -kru')
output, _stderr, status = Open3.capture3('/bin/freebsd-version -kru')
return nil unless status.success?

build_fact_list(output)

@fact_list[fact_name]
rescue Errno::ENOENT
nil
end

def build_fact_list(output)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

describe Facter::Resolvers::Freebsd::FreebsdVersion do
before do
allow(Open3).to receive(:capture2)
status = double('status')
allow(status).to receive(:success?).and_return(true)
allow(Open3).to receive(:capture3)
.with('/bin/freebsd-version -kru')
.and_return('13.0-CURRENT
.and_return(['13.0-CURRENT
12.1-RELEASE-p3
12.0-STABLE')
12.0-STABLE', nil, status])
end

it 'returns installed kernel' do
Expand Down

0 comments on commit 5edea77

Please sign in to comment.