From dfb2e784b31ee5c6935888bf407f56fe5867100a Mon Sep 17 00:00:00 2001 From: Qian Jianhua Date: Fri, 29 Mar 2024 17:14:00 +0800 Subject: [PATCH 1/4] libvirt_numa: Fix parsing of continuous numa nodes In PR#3804, a similar bug is fixed by replacing parse_numa_nodeset_to_str with the new convert_all_nodes_to_string function. However, parse_numa_nodeset_to_str is still called at several places. Therefore, in this PR, directly call convert_all_nodes_to_string in parse_numa_nodeset_to_str to fix the bug with minimal changes. Signed-off-by: Qian Jianhua --- virttest/utils_libvirt/libvirt_numa.py | 59 ++------------------------ 1 file changed, 3 insertions(+), 56 deletions(-) diff --git a/virttest/utils_libvirt/libvirt_numa.py b/virttest/utils_libvirt/libvirt_numa.py index bea473c987..4b620ef93d 100644 --- a/virttest/utils_libvirt/libvirt_numa.py +++ b/virttest/utils_libvirt/libvirt_numa.py @@ -122,67 +122,14 @@ def convert_all_nodes_to_string(node_list): def parse_numa_nodeset_to_str(numa_nodeset, node_list, ignore_error=False): """ - Parse numa nodeset to a string + Parse numa nodeset to a string. + The effect is the same as convert_all_nodes_to_string function. :param numa_nodeset: str, formats supported are 'x', 'x,y', 'x-y', 'x-y,^y' :param node_list: list, host numa nodes :param ignore_error: no exception raised if True :return: str, parsed numa nodeset - :raises exceptions.TestError if unsupported format of numa nodeset """ - def _get_first_continuous_numa_node_index(node_list): - """ - Get the first continues numa node index - For example: - If node list is [0, 1, 3, 4], return 0 - If node list is [0, 2, 3, 5], return 1 - If node list is [1, 4, 8], return -1 - - :param node_list: list, the host numa node list - :return: int, the first index of continuous numa node or -1 if not exists - """ - for index in range(0, len(node_list) - 1): - if node_list[index] + 1 == node_list[index + 1]: - return index - return -1 - - LOG.debug("numa_nodeset='%s', node_list=%s" % (numa_nodeset, node_list)) - if numa_nodeset == "x": - numa_nodeset = str(node_list[0]) - elif numa_nodeset == "x,y": - numa_nodeset = ",".join(map(str, node_list)) - elif numa_nodeset == "x-y": - candidate_index = _get_first_continuous_numa_node_index(node_list) - if candidate_index == -1: - LOG.debug( - "No continuous numa node, use 'x,y' format instead of 'x-y' format" - ) - numa_nodeset = ",".join(map(str, node_list)) - else: - numa_nodeset = "%s-%s" % ( - str(node_list[candidate_index]), - str(node_list[candidate_index + 1]), - ) - elif numa_nodeset == "x-y,^y": - candidate_index = _get_first_continuous_numa_node_index(node_list) - if candidate_index == -1: - LOG.debug( - "No continuous numa node, use 'x,y' format instead of 'x-y' format" - ) - numa_nodeset = ",".join(map(str, node_list)) - else: - numa_nodeset = "%s-%s,^%s" % ( - str(node_list[candidate_index]), - str(node_list[candidate_index + 1]), - str(node_list[candidate_index + 1]), - ) - elif ignore_error: - LOG.error("Supported formats are not found. No parsing happens.") - else: - raise exceptions.TestError( - "Unsupported format for numa_" "nodeset value '%s'" % numa_nodeset - ) - - LOG.debug("Parse output for numa nodeset: '%s'", numa_nodeset) + numa_nodeset = convert_all_nodes_to_string(node_list) return numa_nodeset From b62ef8cbc0e39eb37ab504bf719fbbc262db594e Mon Sep 17 00:00:00 2001 From: Qian Jianhua Date: Wed, 15 May 2024 16:16:28 +0800 Subject: [PATCH 2/4] libvirt_numa: remove parse_numa_nodeset_to_str() Signed-off-by: Qian Jianhua --- virttest/utils_libvirt/libvirt_numa.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/virttest/utils_libvirt/libvirt_numa.py b/virttest/utils_libvirt/libvirt_numa.py index 4b620ef93d..c4d67f714f 100644 --- a/virttest/utils_libvirt/libvirt_numa.py +++ b/virttest/utils_libvirt/libvirt_numa.py @@ -120,16 +120,3 @@ def convert_all_nodes_to_string(node_list): return converted_numa_nodes -def parse_numa_nodeset_to_str(numa_nodeset, node_list, ignore_error=False): - """ - Parse numa nodeset to a string. - The effect is the same as convert_all_nodes_to_string function. - - :param numa_nodeset: str, formats supported are 'x', 'x,y', 'x-y', 'x-y,^y' - :param node_list: list, host numa nodes - :param ignore_error: no exception raised if True - :return: str, parsed numa nodeset - """ - - numa_nodeset = convert_all_nodes_to_string(node_list) - return numa_nodeset From 8766f160a00d6dc92a0940f5753842c2851be12b Mon Sep 17 00:00:00 2001 From: Qian Jianhua Date: Wed, 15 May 2024 16:24:11 +0800 Subject: [PATCH 3/4] libvirt_numa: remove parse_numa_nodeset_to_str() Signed-off-by: Qian Jianhua --- virttest/utils_libvirt/libvirt_numa.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/virttest/utils_libvirt/libvirt_numa.py b/virttest/utils_libvirt/libvirt_numa.py index c4d67f714f..39bdc39665 100644 --- a/virttest/utils_libvirt/libvirt_numa.py +++ b/virttest/utils_libvirt/libvirt_numa.py @@ -118,5 +118,3 @@ def convert_all_nodes_to_string(node_list): converted_numa_nodes = ",".join(node_ranges) LOG.debug("Convert output for all online numa nodes: '%s'", converted_numa_nodes) return converted_numa_nodes - - From 1c07fdc9702c3537ee29534319b3c61584fb6153 Mon Sep 17 00:00:00 2001 From: Qian Jianhua Date: Wed, 15 May 2024 16:28:18 +0800 Subject: [PATCH 4/4] libvirt_numa: remove parse_numa_nodeset_to_str() Signed-off-by: Qian Jianhua --- virttest/utils_libvirt/libvirt_numa.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/virttest/utils_libvirt/libvirt_numa.py b/virttest/utils_libvirt/libvirt_numa.py index 39bdc39665..63f78e2a9d 100644 --- a/virttest/utils_libvirt/libvirt_numa.py +++ b/virttest/utils_libvirt/libvirt_numa.py @@ -7,8 +7,6 @@ import ast import logging -from avocado.core import exceptions - from virttest.libvirt_xml import vm_xml LOG = logging.getLogger("avocado." + __name__)