Skip to content

Commit dfbf93e

Browse files
authored
Fix network.py crash on unexpected NUMA node data (BugFix) (#2035)
1 parent 6e12e45 commit dfbf93e

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

providers/base/bin/network.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ def extract_core_list(self, line):
213213
cpu_list = line[colon + 1 :]
214214
core_list = []
215215
for core_range in cpu_list.split(","):
216+
# Skip it if the CPU list for the NUMA node is empty....
217+
core_range = core_range.strip()
218+
if not core_range:
219+
logging.error("Empty core range in line: %s", line)
220+
continue
216221
# core_range should be of the form "a-b" or "a"
217222
range_list = core_range.split("-")
218223
if len(range_list) > 1:

providers/base/tests/test_network.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@
2525

2626

2727
class IPerfPerfomanceTestTests(unittest.TestCase):
28+
def test_extract_core_list_single(self):
29+
"""Tests parsing a NUMA node CPUs list with a single CPU."""
30+
line = "NUMA node0 CPU(s): 0"
31+
core_list = network.IPerfPerformanceTest.extract_core_list(None, line)
32+
self.assertListEqual(core_list, [0])
33+
34+
def test_extract_core_list_range(self):
35+
"""Tests parsing a NUMA node CPUs list."""
36+
line = "NUMA node0 CPU(s): 0-2"
37+
core_list = network.IPerfPerformanceTest.extract_core_list(None, line)
38+
self.assertListEqual(core_list, [0, 1, 2])
39+
40+
def test_extract_core_list_empty(self):
41+
"""Tests that parsing an empty NUMA node CPUs does not crash."""
42+
line = "NUMA node0 CPU(s):"
43+
core_list = network.IPerfPerformanceTest.extract_core_list(None, line)
44+
self.assertListEqual(core_list, [])
2845

2946
def test_find_numa_reports_node(self):
3047
with patch("builtins.open", mock_open(read_data="1")) as mo:

0 commit comments

Comments
 (0)