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

Commit

Permalink
Avoid exceptions for zone facts on FreeBSD
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
smortex committed Mar 25, 2020
1 parent 6323e3b commit aa60dcc
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 4 deletions.
2 changes: 0 additions & 2 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ RSpec/ExpectInHook:
- 'spec/facter/facts/macosx/filesystems_spec.rb'
- 'spec/facter/resolvers/aix/ffi_helper_spec.rb'
- 'spec/facter/resolvers/lpar_resolver_spec.rb'
- 'spec/facter/resolvers/solaris/current_zone_resolver_spec.rb'
- 'spec/facter/resolvers/solaris/zfs_resolver_spec.rb'
- 'spec/facter/resolvers/solaris/zone_resolver_spec.rb'
- 'spec/facter/resolvers/solaris/zpool_resolver_spec.rb'
- 'spec/facter/resolvers/ssh_resolver_spec.rb'
- 'spec/facter/resolvers/wpar_resolver_spec.rb'
Expand Down
2 changes: 2 additions & 0 deletions lib/facts/solaris/solaris_zones/zone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def call_the_resolver
zones = {}

results = Facter::Resolvers::SolarisZone.resolve(:zone)
return Facter::ResolvedFact.new(FACT_NAME, nil) unless results

results&.each do |result|
zones.merge!(parse_result(result))
resolved_facts << create_legacy_zone_facts(result)
Expand Down
2 changes: 2 additions & 0 deletions lib/resolvers/solaris/solaris_zone_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def post_resolve(fact_name)
end

def build_current_zone_name_fact(fact_name)
return unless File.executable?('/bin/zonename')

zone_name_output, status = Open3.capture2('/bin/zonename')
unless status.to_s.include?('exit 0')
@log.debug("Command #{command} returned status: #{status}")
Expand Down
2 changes: 2 additions & 0 deletions lib/resolvers/solaris/zone_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def post_resolve(fact_name)
end

def build_zone_fact(fact_name)
return unless File.executable?('/usr/sbin/zoneadm')

command = '/usr/sbin/zoneadm list -cp'
zone_adm_output, status = Open3.capture2(command)
unless status.to_s.include?('exit 0')
Expand Down
5 changes: 4 additions & 1 deletion spec/facter/resolvers/solaris/current_zone_resolver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
describe Facter::Resolvers::SolarisZone do
before do
status = double(Process::Status, to_s: st)
expect(Open3).to receive(:capture2)
allow(File).to receive(:executable?)
.with('/bin/zonename')
.and_return(true)
allow(Open3).to receive(:capture2)
.with('/bin/zonename')
.ordered
.and_return([zone_name_output, status])
Expand Down
5 changes: 4 additions & 1 deletion spec/facter/resolvers/solaris/zone_resolver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
describe Facter::Resolvers::SolarisZone do
before do
status = double(Process::Status, to_s: st)
expect(Open3).to receive(:capture2)
allow(File).to receive(:executable?)
.with('/usr/sbin/zoneadm')
.and_return(true)
allow(Open3).to receive(:capture2)
.with('/usr/sbin/zoneadm list -cp')
.ordered
.and_return([output, status])
Expand Down

0 comments on commit aa60dcc

Please sign in to comment.