mirror of
https://github.com/saltstack/salt.git
synced 2025-04-16 09:40:20 +00:00
Merge pull request #54682 from garethgreenaway/2019_2_1_port_49148
[master] Porting #49148 to master
This commit is contained in:
commit
784777c110
3 changed files with 30 additions and 1 deletions
1
changelog/54682.fixed
Normal file
1
changelog/54682.fixed
Normal file
|
@ -0,0 +1 @@
|
|||
Fixed grain num_cpus get wrong CPUs count in case of inconsistent CPU numbering.
|
|
@ -159,6 +159,7 @@ def _linux_cpudata():
|
|||
# Parse over the cpuinfo file
|
||||
if os.path.isfile(cpuinfo):
|
||||
with salt.utils.files.fopen(cpuinfo, "r") as _fp:
|
||||
grains["num_cpus"] = 0
|
||||
for line in _fp:
|
||||
comps = line.split(":")
|
||||
if not len(comps) > 1:
|
||||
|
@ -166,7 +167,7 @@ def _linux_cpudata():
|
|||
key = comps[0].strip()
|
||||
val = comps[1].strip()
|
||||
if key == "processor":
|
||||
grains["num_cpus"] = int(val) + 1
|
||||
grains["num_cpus"] += 1
|
||||
# head -2 /proc/cpuinfo
|
||||
# vendor_id : IBM/S390
|
||||
# # processors : 2
|
||||
|
|
|
@ -2603,6 +2603,33 @@ def test_osdata_virtual_key_win():
|
|||
assert osdata_grains["virtual"] != "physical"
|
||||
|
||||
|
||||
@pytest.mark.skip_unless_on_linux
|
||||
def test_linux_cpu_data_num_cpus():
|
||||
cpuinfo_list = []
|
||||
for i in range(0, 20):
|
||||
cpuinfo_dict = {
|
||||
"processor": i,
|
||||
"cpu_family": 6,
|
||||
"model_name": "Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz",
|
||||
"flags": "fpu vme de pse tsc msr pae mce cx8 apic sep mtrr",
|
||||
}
|
||||
cpuinfo_list.append(cpuinfo_dict)
|
||||
cpuinfo_content = ""
|
||||
for item in cpuinfo_list:
|
||||
cpuinfo_content += (
|
||||
"processor: {}\n" "cpu family: {}\n" "model name: {}\n" "flags: {}\n\n"
|
||||
).format(
|
||||
item["processor"], item["cpu_family"], item["model_name"], item["flags"]
|
||||
)
|
||||
|
||||
with patch.object(os.path, "isfile", MagicMock(return_value=True)), patch(
|
||||
"salt.utils.files.fopen", mock_open(read_data=cpuinfo_content)
|
||||
):
|
||||
ret = core._linux_cpudata()
|
||||
assert "num_cpus" in ret
|
||||
assert len(cpuinfo_list) == ret["num_cpus"]
|
||||
|
||||
|
||||
@pytest.mark.skip_on_windows
|
||||
def test_bsd_osfullname():
|
||||
"""
|
||||
|
|
Loading…
Add table
Reference in a new issue