From b1a234c14a5e652436fc58cad4c952f65ed950c0 Mon Sep 17 00:00:00 2001 From: Trey Dockendorf Date: Thu, 19 Sep 2024 15:39:16 -0400 Subject: [PATCH] Support 'xenhvm' for AWS instances Currently this happens: ``` $ sudo facter -p cloud $ sudo facter -p virtual xenhvm $ sudo /opt/puppetlabs/puppet/bin/virt-what xen xen-hvm aws ``` --- lib/facter/facts/linux/cloud/provider.rb | 2 +- .../facter/facts/linux/cloud/provider_spec.rb | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/facter/facts/linux/cloud/provider.rb b/lib/facter/facts/linux/cloud/provider.rb index 38af049cde..1e16a19aef 100644 --- a/lib/facter/facts/linux/cloud/provider.rb +++ b/lib/facter/facts/linux/cloud/provider.rb @@ -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' diff --git a/spec/facter/facts/linux/cloud/provider_spec.rb b/spec/facter/facts/linux/cloud/provider_spec.rb index 694ec014e4..0e32fbb757 100644 --- a/spec/facter/facts/linux/cloud/provider_spec.rb +++ b/spec/facter/facts/linux/cloud/provider_spec.rb @@ -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)