Cover more NUMA CPU list types

In some cases cpulist doesn't contain '-' and lists all
cores one by one. For this kind of lists, splitting by
comma will break parse_cpu_list().

Change-Id: Icc5fcf6408d76fdef34ccb18657624cfe5593f10
Closes-Bug: #1771527
This commit is contained in:
Ante Karamatic 2018-05-16 10:45:52 +02:00
parent c26b6819a6
commit 54449e783d
2 changed files with 9 additions and 3 deletions

View File

@ -278,9 +278,12 @@ def parse_cpu_list(cpulist):
cores = [] cores = []
ranges = cpulist.split(',') ranges = cpulist.split(',')
for cpu_range in ranges: for cpu_range in ranges:
cpu_min_max = cpu_range.split('-') if "-" in cpu_range:
cores += range(int(cpu_min_max[0]), cpu_min_max = cpu_range.split('-')
int(cpu_min_max[1]) + 1) cores += range(int(cpu_min_max[0]),
int(cpu_min_max[1]) + 1)
else:
cores.append(int(cpu_range))
return cores return cores

View File

@ -495,6 +495,7 @@ class MockPCIDevice(object):
TEST_CPULIST_1 = "0-3" TEST_CPULIST_1 = "0-3"
TEST_CPULIST_2 = "0-7,16-23" TEST_CPULIST_2 = "0-7,16-23"
TEST_CPULIST_3 = "0,4,8,12,16,20,24"
DPDK_DATA_PORTS = ( DPDK_DATA_PORTS = (
"br-phynet3:fe:16:41:df:23:fe " "br-phynet3:fe:16:41:df:23:fe "
"br-phynet1:fe:16:41:df:23:fd " "br-phynet1:fe:16:41:df:23:fd "
@ -518,6 +519,8 @@ class TestDPDKUtils(CharmTestCase):
self.assertEqual(context.parse_cpu_list(TEST_CPULIST_2), self.assertEqual(context.parse_cpu_list(TEST_CPULIST_2),
[0, 1, 2, 3, 4, 5, 6, 7, [0, 1, 2, 3, 4, 5, 6, 7,
16, 17, 18, 19, 20, 21, 22, 23]) 16, 17, 18, 19, 20, 21, 22, 23])
self.assertEqual(context.parse_cpu_list(TEST_CPULIST_3),
[0, 4, 8, 12, 16, 20, 24])
@patch.object(context, 'parse_cpu_list', wraps=context.parse_cpu_list) @patch.object(context, 'parse_cpu_list', wraps=context.parse_cpu_list)
def test_numa_node_cores(self, _parse_cpu_list): def test_numa_node_cores(self, _parse_cpu_list):