This repository has been archived by the owner on Jun 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d7ccf4
commit 67a5f04
Showing
4 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facter | ||
module Resolvers | ||
class Xen < BaseResolver | ||
@semaphore = Mutex.new | ||
@fact_list ||= {} | ||
|
||
class << self | ||
private | ||
|
||
def post_resolve(fact_name) | ||
@fact_list.fetch(fact_name) { chech_xen_dirs(fact_name) } | ||
end | ||
|
||
def chech_xen_dirs(fact_name) | ||
xen_type = 'xen0' if File.exist?('/dev/xen/evtchn') | ||
xen_type = 'xenu' if !xen_type && (File.exist?('/proc/xen') || File.exist?('/dev/xvda1')) | ||
|
||
@fact_list[:vm] = xen_type | ||
@fact_list[fact_name] | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
describe Facter::Resolvers::Xen do | ||
subject(:xen_resolver) { Facter::Resolvers::Xen } | ||
|
||
let(:proc_xen_file) { false } | ||
let(:xvda1_file) { false } | ||
|
||
before do | ||
allow(File).to receive(:exist?).with('/dev/xen/evtchn').and_return(evtchn_file) | ||
allow(File).to receive(:exist?).with('/proc/xen').and_return(proc_xen_file) | ||
allow(File).to receive(:exist?).with('/dev/xvda1').and_return(xvda1_file) | ||
xen_resolver.invalidate_cache | ||
end | ||
|
||
context 'when is priviledged xen' do | ||
let(:evtchn_file) { true } | ||
|
||
it 'returns xen0' do | ||
expect(xen_resolver.resolve(:vm)).to eq('xen0') | ||
end | ||
|
||
it 'does not check other files' do | ||
expect(File).not_to have_received(:exist?).with('/proc/xen') | ||
end | ||
end | ||
|
||
context 'when is unpriviledged xen' do | ||
let(:evtchn_file) { false } | ||
let(:xvda1_file) { true } | ||
|
||
it 'returns xenu' do | ||
expect(xen_resolver.resolve(:vm)).to eq('xenu') | ||
end | ||
end | ||
end |