Skip to content

Commit

Permalink
Merge pull request #2095 from IrimieBogdan/FACT-2803
Browse files Browse the repository at this point in the history
(FACT-2803) Detect hypervisors as amazon if virtwhat detects aws.
  • Loading branch information
sebastian-miclea authored Sep 21, 2020
2 parents ec9ffb2 + a56ffed commit e73a6db
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/facter/facts/linux/ec2_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ def call_the_resolver
private

def aws_hypervisors?
virtual = check_virt_what || check_xen || check_product_name || check_bios_vendor || check_lspci
virtual =~ /kvm|xen|aws/
end

virtual == 'kvm' || virtual =~ /xen/
def virtual
check_virt_what || check_xen || check_product_name || check_bios_vendor || check_lspci
end

def check_virt_what
Expand Down
20 changes: 20 additions & 0 deletions spec/facter/facts/linux/ec2_metadata_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,25 @@
end
end
end

context 'when hypervisor is aws' do
let(:hypervisor) { 'aws' }
let(:value) { { 'info' => 'value' } }

it 'calls Facter::Resolvers::VirtWhat' do
fact.call_the_resolver
expect(Facter::Resolvers::VirtWhat).to have_received(:resolve).with(:vm)
end

it 'calls Facter::Resolvers::Ec2' do
fact.call_the_resolver
expect(Facter::Resolvers::Ec2).to have_received(:resolve).with(:metadata)
end

it 'returns ec2 userdata fact' do
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \
have_attributes(name: 'ec2_metadata', value: value)
end
end
end
end

0 comments on commit e73a6db

Please sign in to comment.