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

Commit 3ba06cc

Browse files
committed
Avoid exceptions for zone facts on FreeBSD
FreeBSD currently loads all Solaris facts, but FreeBSD does not have "zones", and the zone related facts fail hardly when being processed. Improve error detection when building the zone facts, and do not emit these facts when an error occurred.
1 parent 106aebd commit 3ba06cc

3 files changed

Lines changed: 6 additions & 0 deletions

File tree

lib/facts/solaris/solaris_zones/zone.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def call_the_resolver
2121
zones = {}
2222

2323
results = Facter::Resolvers::SolarisZone.resolve(:zone)
24+
return unless results
25+
2426
results&.each do |result|
2527
zones.merge!(parse_result(result))
2628
resolved_facts << create_legacy_zone_facts(result)

lib/resolvers/solaris/solaris_zone_name.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ def post_resolve(fact_name)
1414
end
1515

1616
def build_current_zone_name_fact(fact_name)
17+
return unless File.executable?('/bin/zonename')
18+
1719
zone_name_output, status = Open3.capture2('/bin/zonename')
1820
unless status.to_s.include?('exit 0')
1921
@log.debug("Command #{command} returned status: #{status}")

lib/resolvers/solaris/zone_resolver.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ def post_resolve(fact_name)
1414
end
1515

1616
def build_zone_fact(fact_name)
17+
return unless File.executable?('/usr/sbin/zoneadm')
18+
1719
command = '/usr/sbin/zoneadm list -cp'
1820
zone_adm_output, status = Open3.capture2(command)
1921
unless status.to_s.include?('exit 0')

0 commit comments

Comments
 (0)