Handle situation where ansible_architecure may not be defined when gathering facts (#55466)

This commit is contained in:
Sam Doran 2019-07-19 11:33:05 -04:00 committed by GitHub
parent bb006db7c8
commit f231f21669
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 1 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- facts - handle situation where ``ansible_architecture`` may not be defined (https://github.com/ansible/ansible/issues/55400)

View file

@ -240,7 +240,7 @@ class LinuxHardware(Hardware):
# The fields for ARM CPUs do not always include 'vendor_id' or 'model name', # The fields for ARM CPUs do not always include 'vendor_id' or 'model name',
# and sometimes includes both 'processor' and 'Processor'. # and sometimes includes both 'processor' and 'Processor'.
# Always use 'processor' count for ARM systems # 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 i = processor_occurence
# FIXME # FIXME

View file

@ -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']]) mocker.patch('ansible.module_utils.facts.hardware.linux.get_file_lines', side_effect=[[], test['cpuinfo']])
collected_facts = {'ansible_architecture': test['architecture']} collected_facts = {'ansible_architecture': test['architecture']}
assert test['expected_result'] == inst.get_cpu_facts(collected_facts=collected_facts) 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