Skip to content

Commit a56ffed

Browse files
author
BogdanIrimie
committed
(FACT-2803) Detect hypervisors as amazon if virtwhat detects aws.
1 parent a8c5dc3 commit a56ffed

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

lib/facter/facts/linux/ec2_metadata.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ def call_the_resolver
1616
private
1717

1818
def aws_hypervisors?
19-
virtual = check_virt_what || check_xen || check_product_name || check_bios_vendor || check_lspci
19+
virtual =~ /kvm|xen|aws/
20+
end
2021

21-
virtual == 'kvm' || virtual =~ /xen/
22+
def virtual
23+
check_virt_what || check_xen || check_product_name || check_bios_vendor || check_lspci
2224
end
2325

2426
def check_virt_what

spec/facter/facts/linux/ec2_metadata_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,25 @@
6363
end
6464
end
6565
end
66+
67+
context 'when hypervisor is aws' do
68+
let(:hypervisor) { 'aws' }
69+
let(:value) { { 'info' => 'value' } }
70+
71+
it 'calls Facter::Resolvers::VirtWhat' do
72+
fact.call_the_resolver
73+
expect(Facter::Resolvers::VirtWhat).to have_received(:resolve).with(:vm)
74+
end
75+
76+
it 'calls Facter::Resolvers::Ec2' do
77+
fact.call_the_resolver
78+
expect(Facter::Resolvers::Ec2).to have_received(:resolve).with(:metadata)
79+
end
80+
81+
it 'returns ec2 userdata fact' do
82+
expect(fact.call_the_resolver).to be_an_instance_of(Facter::ResolvedFact).and \
83+
have_attributes(name: 'ec2_metadata', value: value)
84+
end
85+
end
6686
end
6787
end

0 commit comments

Comments
 (0)