From 54449e783db89a1ba83a1fa47b9a7ef34756de46 Mon Sep 17 00:00:00 2001 From: Ante Karamatic Date: Wed, 16 May 2018 10:45:52 +0200 Subject: [PATCH] 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 --- hooks/neutron_ovs_context.py | 9 ++++++--- unit_tests/test_neutron_ovs_context.py | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/hooks/neutron_ovs_context.py b/hooks/neutron_ovs_context.py index 74ff9355..bcefc5ff 100644 --- a/hooks/neutron_ovs_context.py +++ b/hooks/neutron_ovs_context.py @@ -278,9 +278,12 @@ def parse_cpu_list(cpulist): cores = [] ranges = cpulist.split(',') for cpu_range in ranges: - cpu_min_max = cpu_range.split('-') - cores += range(int(cpu_min_max[0]), - int(cpu_min_max[1]) + 1) + if "-" in cpu_range: + cpu_min_max = cpu_range.split('-') + cores += range(int(cpu_min_max[0]), + int(cpu_min_max[1]) + 1) + else: + cores.append(int(cpu_range)) return cores diff --git a/unit_tests/test_neutron_ovs_context.py b/unit_tests/test_neutron_ovs_context.py index 98ee1fd8..1fe1c93a 100644 --- a/unit_tests/test_neutron_ovs_context.py +++ b/unit_tests/test_neutron_ovs_context.py @@ -495,6 +495,7 @@ class MockPCIDevice(object): TEST_CPULIST_1 = "0-3" TEST_CPULIST_2 = "0-7,16-23" +TEST_CPULIST_3 = "0,4,8,12,16,20,24" DPDK_DATA_PORTS = ( "br-phynet3:fe:16:41:df:23:fe " "br-phynet1:fe:16:41:df:23:fd " @@ -518,6 +519,8 @@ class TestDPDKUtils(CharmTestCase): self.assertEqual(context.parse_cpu_list(TEST_CPULIST_2), [0, 1, 2, 3, 4, 5, 6, 7, 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) def test_numa_node_cores(self, _parse_cpu_list):