diff --git a/acceptance/lib/facter/acceptance/base_fact_utils.rb b/acceptance/lib/facter/acceptance/base_fact_utils.rb index bc916b8795..eb328a84a8 100644 --- a/acceptance/lib/facter/acceptance/base_fact_utils.rb +++ b/acceptance/lib/facter/acceptance/base_fact_utils.rb @@ -81,7 +81,7 @@ def debian_expected_facts(agent) os_hardware = 'x86_64' processor_model_pattern = /(Intel\(R\).*)|(AMD.*)/ elsif agent['platform'] =~ /aarch64/ - os_arch = 'arm64' + os_arch = 'aarch64' os_hardware = 'aarch64' processor_model_pattern = // # FACT-3439 - facter doesn't figure out the processor type on these machines else @@ -391,7 +391,7 @@ def ubuntu_expected_facts(agent) os_hardware = 'x86_64' processor_model_pattern = /(Intel\(R\).*)|(AMD.*)/ elsif agent['platform'] =~ /aarch64/ - os_arch = 'arm64' + os_arch = 'aarch64' os_hardware = 'aarch64' processor_model_pattern = // # facter doesn't figure out the processor type on these machines else diff --git a/lib/facter/facts/debian/architecture.rb b/lib/facter/facts/debian/architecture.rb index 73e56b2c28..96779d5161 100644 --- a/lib/facter/facts/debian/architecture.rb +++ b/lib/facter/facts/debian/architecture.rb @@ -8,7 +8,9 @@ class Architecture ALIASES = 'architecture' def call_the_resolver - fact_value = Facter::Core::Execution.execute('dpkg --print-architecture') + fact_value = Facter::Resolvers::Uname.resolve(:machine) + fact_value = 'amd64' if fact_value == 'x86_64' + fact_value = 'i386' if /i[3456]86|pentium/.match?(fact_value) [Facter::ResolvedFact.new(FACT_NAME, fact_value), Facter::ResolvedFact.new(ALIASES, fact_value, :legacy)] end diff --git a/spec/facter/facts/debian/os/architecture_spec.rb b/spec/facter/facts/debian/os/architecture_spec.rb index fbd8dbf835..059c4940f1 100644 --- a/spec/facter/facts/debian/os/architecture_spec.rb +++ b/spec/facter/facts/debian/os/architecture_spec.rb @@ -4,16 +4,61 @@ describe '#call_the_resolver' do subject(:fact) { Facts::Debian::Os::Architecture.new } - %w[amd64 arm64 i386].each do |arch| - it 'calls Facter::Core::Execution and returns architecture fact' do - allow(Facter::Core::Execution).to receive(:execute).and_return(arch) + context 'when resolver does not return x86_64' do + let(:value) { 'i86pc' } + before do + allow(Facter::Resolvers::Uname).to receive(:resolve).with(:machine).and_return(value) + end + + it 'calls Facter::Resolvers::Uname' do + fact.call_the_resolver + expect(Facter::Resolvers::Uname).to have_received(:resolve).with(:machine) + end + + it 'returns architecture fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'os.architecture', value: value), + an_object_having_attributes(name: 'architecture', value: value, type: :legacy)) + end + end + + context 'when os is 32-bit' do + let(:value) { 'i586' } + let(:fact_value) { 'i386' } + + before do + allow(Facter::Resolvers::Uname).to receive(:resolve).with(:machine).and_return(value) + end + + it 'calls Facter::Resolvers::Uname' do fact.call_the_resolver - expect(Facter::Core::Execution).to have_received(:execute).with('dpkg --print-architecture') + expect(Facter::Resolvers::Uname).to have_received(:resolve).with(:machine) + end + + it 'returns architecture fact' do + expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ + contain_exactly(an_object_having_attributes(name: 'os.architecture', value: fact_value), + an_object_having_attributes(name: 'architecture', value: fact_value, type: :legacy)) + end + end + + context 'when resolver returns x86_64' do + let(:value) { 'x86_64' } + + before do + allow(Facter::Resolvers::Uname).to receive(:resolve).with(:machine).and_return(value) + end + + it 'calls Facter::Resolvers::Uname' do + fact.call_the_resolver + expect(Facter::Resolvers::Uname).to have_received(:resolve).with(:machine) + end + it 'returns architecture fact' do expect(fact.call_the_resolver).to be_an_instance_of(Array).and \ - contain_exactly(an_object_having_attributes(name: 'os.architecture', value: arch), - an_object_having_attributes(name: 'architecture', value: arch, type: :legacy)) + contain_exactly(an_object_having_attributes(name: 'os.architecture', value: 'amd64'), + an_object_having_attributes(name: 'architecture', value: 'amd64', type: :legacy)) end end end