Define all processor facts on s390x (#19755) (#79806)

Signed-off-by: Yaakov Selkowitz <yselkowi@redhat.com>
pull/80088/head
Yaakov Selkowitz 2 years ago committed by GitHub
parent f587856beb
commit c028006aaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
bugfixes:
- ansible_facts.hardware - Define all processor facts on s390x (https://github.com/ansible/ansible/issues/19755)

@ -170,6 +170,8 @@ class LinuxHardware(Hardware):
coreid = 0
sockets = {}
cores = {}
zp = 0
zmt = 0
xen = False
xen_paravirt = False
@ -209,7 +211,6 @@ class LinuxHardware(Hardware):
# model name is for Intel arch, Processor (mind the uppercase P)
# works for some ARM devices, like the Sheevaplug.
# 'ncpus active' is SPARC attribute
if key in ['model name', 'Processor', 'vendor_id', 'cpu', 'Vendor', 'processor']:
if 'processor' not in cpu_facts:
cpu_facts['processor'] = []
@ -233,8 +234,12 @@ class LinuxHardware(Hardware):
sockets[physid] = int(val)
elif key == 'siblings':
cores[coreid] = int(val)
# S390x classic cpuinfo
elif key == '# processors':
cpu_facts['processor_cores'] = int(val)
zp = int(val)
elif key == 'max thread id':
zmt = int(val) + 1
# SPARC
elif key == 'ncpus active':
i = int(val)
@ -250,13 +255,20 @@ class LinuxHardware(Hardware):
if collected_facts.get('ansible_architecture', '').startswith(('armv', 'aarch', 'ppc')):
i = processor_occurrence
# FIXME
if collected_facts.get('ansible_architecture') != 's390x':
if collected_facts.get('ansible_architecture') == 's390x':
# getting sockets would require 5.7+ with CONFIG_SCHED_TOPOLOGY
cpu_facts['processor_count'] = 1
cpu_facts['processor_cores'] = zp // zmt
cpu_facts['processor_threads_per_core'] = zmt
cpu_facts['processor_vcpus'] = zp
cpu_facts['processor_nproc'] = zp
else:
if xen_paravirt:
cpu_facts['processor_count'] = i
cpu_facts['processor_cores'] = i
cpu_facts['processor_threads_per_core'] = 1
cpu_facts['processor_vcpus'] = i
cpu_facts['processor_nproc'] = i
else:
if sockets:
cpu_facts['processor_count'] = len(sockets)
@ -278,25 +290,25 @@ class LinuxHardware(Hardware):
cpu_facts['processor_vcpus'] = (cpu_facts['processor_threads_per_core'] *
cpu_facts['processor_count'] * cpu_facts['processor_cores'])
# if the number of processors available to the module's
# thread cannot be determined, the processor count
# reported by /proc will be the default:
cpu_facts['processor_nproc'] = processor_occurrence
try:
cpu_facts['processor_nproc'] = len(
os.sched_getaffinity(0)
)
except AttributeError:
# In Python < 3.3, os.sched_getaffinity() is not available
try:
cmd = get_bin_path('nproc')
except ValueError:
pass
else:
rc, out, _err = self.module.run_command(cmd)
if rc == 0:
cpu_facts['processor_nproc'] = int(out)
# if the number of processors available to the module's
# thread cannot be determined, the processor count
# reported by /proc will be the default (as previously defined)
try:
cpu_facts['processor_nproc'] = len(
os.sched_getaffinity(0)
)
except AttributeError:
# In Python < 3.3, os.sched_getaffinity() is not available
try:
cmd = get_bin_path('nproc')
except ValueError:
pass
else:
rc, out, _err = self.module.run_command(cmd)
if rc == 0:
cpu_facts['processor_nproc'] = int(out)
return cpu_facts

@ -0,0 +1,14 @@
vendor_id : IBM/S390
# processors : 2
bogomips per cpu: 3033.00
max thread id : 0
features : esan3 zarch stfle msa ldisp eimm dfp edat etf3eh highgprs te vx sie
facilities : 0 1 2 3 4 6 7 8 9 10 12 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 30 31 32 33 34 35 36 37 40 41 42 43 44 45 46 47 48 49 50 51 52 53 55 57 73 74 75 76 77 80 81 82 128 129 131
cache0 : level=1 type=Data scope=Private size=128K line_size=256 associativity=8
cache1 : level=1 type=Instruction scope=Private size=96K line_size=256 associativity=6
cache2 : level=2 type=Data scope=Private size=2048K line_size=256 associativity=8
cache3 : level=2 type=Instruction scope=Private size=2048K line_size=256 associativity=8
cache4 : level=3 type=Unified scope=Shared size=65536K line_size=256 associativity=16
cache5 : level=4 type=Unified scope=Shared size=491520K line_size=256 associativity=30
processor 0: version = FF, identification = FFFFFF, machine = 2964
processor 1: version = FF, identification = FFFFFF, machine = 2964

@ -566,6 +566,40 @@ CPU_INFO_TEST_SCENARIOS = [
'processor_vcpus': 24
},
},
{
'cpuinfo': open(os.path.join(os.path.dirname(__file__), '../fixtures/cpuinfo/s390x-z13-2cpu-cpuinfo')).readlines(),
'architecture': 's390x',
'nproc_out': 2,
'sched_getaffinity': set([0, 1]),
'expected_result': {
'processor': [
'IBM/S390',
],
'processor_cores': 2,
'processor_count': 1,
'processor_nproc': 2,
'processor_threads_per_core': 1,
'processor_vcpus': 2
},
},
{
'cpuinfo': open(os.path.join(os.path.dirname(__file__), '../fixtures/cpuinfo/s390x-z14-64cpu-cpuinfo')).readlines(),
'architecture': 's390x',
'nproc_out': 64,
'sched_getaffinity': set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]),
'expected_result': {
'processor': [
'IBM/S390',
],
'processor_cores': 32,
'processor_count': 1,
'processor_nproc': 64,
'processor_threads_per_core': 2,
'processor_vcpus': 64
},
},
{
'cpuinfo': open(os.path.join(os.path.dirname(__file__), '../fixtures/cpuinfo/sparc-t5-debian-ldom-24vcpu')).readlines(),
'architecture': 'sparc64',

@ -45,7 +45,7 @@ def test_get_cpu_info_missing_arch(mocker):
module = mocker.Mock()
inst = linux.LinuxHardware(module)
# ARM and Power will report incorrect processor count if architecture is not available
# ARM, Power, and zSystems 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:
@ -56,7 +56,7 @@ def test_get_cpu_info_missing_arch(mocker):
test_result = inst.get_cpu_facts()
if test['architecture'].startswith(('armv', 'aarch', 'ppc')):
if test['architecture'].startswith(('armv', 'aarch', 'ppc', 's390')):
assert test['expected_result'] != test_result
else:
assert test['expected_result'] == test_result

Loading…
Cancel
Save