[stable-2.8] Handle situation where ansible_architecure may not be defined when gathering facts (#55466)
(cherry picked from commit f231f21669
)
Co-authored-by: Sam Doran <sdoran@redhat.com>
This commit is contained in:
parent
c40949df8a
commit
2f5c3b3cb4
3 changed files with 19 additions and 1 deletions
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- facts - handle situation where ``ansible_architecture`` may not be defined (https://github.com/ansible/ansible/issues/55400)
|
|
@ -240,7 +240,7 @@ class LinuxHardware(Hardware):
|
|||
# The fields for ARM CPUs do not always include 'vendor_id' or 'model name',
|
||||
# and sometimes includes both 'processor' and 'Processor'.
|
||||
# Always use 'processor' count for ARM systems
|
||||
if collected_facts.get('ansible_architecture').startswith(('armv', 'aarch')):
|
||||
if collected_facts.get('ansible_architecture', '').startswith(('armv', 'aarch')):
|
||||
i = processor_occurence
|
||||
|
||||
# FIXME
|
||||
|
|
|
@ -20,3 +20,19 @@ def test_get_cpu_info(mocker):
|
|||
mocker.patch('ansible.module_utils.facts.hardware.linux.get_file_lines', side_effect=[[], test['cpuinfo']])
|
||||
collected_facts = {'ansible_architecture': test['architecture']}
|
||||
assert test['expected_result'] == inst.get_cpu_facts(collected_facts=collected_facts)
|
||||
|
||||
|
||||
def test_get_cpu_info_missing_arch(mocker):
|
||||
module = mocker.Mock()
|
||||
inst = linux.LinuxHardware(module)
|
||||
|
||||
# ARM will report incorrect processor count if architecture is not available
|
||||
mocker.patch('os.path.exists', return_value=False)
|
||||
mocker.patch('os.access', return_value=True)
|
||||
for test in CPU_INFO_TEST_SCENARIOS:
|
||||
mocker.patch('ansible.module_utils.facts.hardware.linux.get_file_lines', side_effect=[[], test['cpuinfo']])
|
||||
test_result = inst.get_cpu_facts()
|
||||
if test['architecture'].startswith(('armv', 'aarch')):
|
||||
assert test['expected_result'] != test_result
|
||||
else:
|
||||
assert test['expected_result'] == test_result
|
||||
|
|
Loading…
Reference in a new issue