Skip to content

Commit

Permalink
Merge pull request #2636 from mhashizume/FACT-3436/main/revert-debian…
Browse files Browse the repository at this point in the history
…-architecture

(FACT-3436) Revert Debian ARM architecture change
  • Loading branch information
joshcooper authored Nov 10, 2023
2 parents 83ef039 + 7e34fe2 commit 44c49f6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 9 deletions.
4 changes: 2 additions & 2 deletions acceptance/lib/facter/acceptance/base_fact_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lib/facter/facts/debian/architecture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 51 additions & 6 deletions spec/facter/facts/debian/os/architecture_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 44c49f6

Please sign in to comment.