Skip to content

Commit

Permalink
Handle case where we're not xen
Browse files Browse the repository at this point in the history
Previously if neither /sur/sbin/xl nor xm existed, then the `find_command`
method returned the array of XEN_COMMANDS. Since that wasn't nil, the resolver
tried to execute the Array of commands and failed (for the wrong reason).

Now explicitly return nil in the case neither file exists.
  • Loading branch information
joshcooper committed May 17, 2024
1 parent 04dd296 commit b880f0d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/facter/resolvers/xen.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def find_command
return XEN_TOOLSTACK if num_stacks > 1 && File.exist?(XEN_TOOLSTACK)

XEN_COMMANDS.each { |command| return command if File.exist?(command) }

nil
end
end
end
Expand Down
12 changes: 12 additions & 0 deletions spec/facter/resolvers/xen_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@
xen_resolver.invalidate_cache
end

context 'when not xen' do
let(:evtchn_file) { false }
let(:proc_xen_file) { false }
let(:xvda1_file) { false }

it 'returns' do
allow(File).to receive(:exist?).with('/usr/sbin/xm').and_return(false)

expect(xen_resolver.resolve(:vm)).to be_nil
end
end

context 'when xen is privileged' do
context 'when /dev/xen/evtchn exists' do
let(:domains) { load_fixture('xen_domains').read }
Expand Down

0 comments on commit b880f0d

Please sign in to comment.