Skip to content

Commit

Permalink
Support 'xenhvm' for AWS instances
Browse files Browse the repository at this point in the history
  • Loading branch information
treydock committed Sep 19, 2024
1 parent 07037a3 commit 5de7808
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/facter/facts/linux/cloud/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def call_the_resolver
when 'hyperv'
metadata = Facter::Resolvers::Az.resolve(:metadata)
'azure' unless metadata.nil? || metadata.empty?
when 'kvm', 'xen'
when 'kvm', 'xen', 'xenhvm'
metadata = Facter::Resolvers::Ec2.resolve(:metadata)
'aws' unless metadata.nil? || metadata.empty?
when 'gce'
Expand Down
25 changes: 25 additions & 0 deletions spec/facter/facts/linux/cloud/provider_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,31 @@
end
end

describe 'when on xenhvm' do
before do
allow(Facter::Resolvers::Ec2).to receive(:resolve).with(:metadata).and_return(value)
allow(Facter::Util::Facts::Posix::VirtualDetector).to receive(:platform).and_return('xenhvm')
end

describe 'Ec2 data exists and aws fact is set' do
let(:value) { { 'some' => 'fact' } }

it 'Testing things' do
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \
have_attributes(name: 'cloud.provider', value: 'aws')
end
end

context 'when Ec2 data does not exist nil is returned' do
let(:value) { {} }

it 'returns nil' do
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \
have_attributes(name: 'cloud.provider', value: nil)
end
end
end

describe 'when on gce' do
before do
allow(Facter::Resolvers::Gce).to receive(:resolve).with(:metadata).and_return(value)
Expand Down

0 comments on commit 5de7808

Please sign in to comment.