From 54f41dbb255ea866fbc394fbdfebe1b00fc8faf3 Mon Sep 17 00:00:00 2001 From: Chin-Ya Huang Date: Wed, 1 Nov 2023 11:56:13 +0800 Subject: [PATCH] refactor(negative): stress node cpu/mem by volume list Signed-off-by: Chin-Ya Huang --- e2e/keywords/node.resource | 8 ++++---- e2e/libs/keywords/node_keywords.py | 13 +++++-------- e2e/libs/node/utility.py | 12 ++++++++++++ e2e/tests/stress_cpu.robot | 2 +- e2e/tests/stress_memory.robot | 2 +- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/e2e/keywords/node.resource b/e2e/keywords/node.resource index e64eca311b..38279e87e7 100644 --- a/e2e/keywords/node.resource +++ b/e2e/keywords/node.resource @@ -67,8 +67,8 @@ Restart cluster wait_for_workload_pod_stable ${statefulset} END -Stress volume node cpu - stress_node_cpu_by_volume ${volume_name} +Stress the CPU of all volume nodes + stress_node_cpu_by_volumes ${volume_list} -Stress volume node memory - stress_node_memory_by_volume ${volume_name} +Stress the memory of all volume nodes + stress_node_memory_by_volumes ${volume_list} diff --git a/e2e/libs/keywords/node_keywords.py b/e2e/libs/keywords/node_keywords.py index 9e5dfdf7a7..df2a0a0f4a 100644 --- a/e2e/libs/keywords/node_keywords.py +++ b/e2e/libs/keywords/node_keywords.py @@ -3,6 +3,7 @@ from node import Node from node import Stress from node.utility import get_node_by_index +from node.utility import list_node_names_by_volumes from utility.utility import wait_for_all_instance_manager_running @@ -42,12 +43,8 @@ def wait_for_all_instance_manager_running(self): def cleanup_stress_helper(self): self.stress.cleanup() - def stress_node_cpu_by_volume(self, volume_name): - volume_keywords = BuiltIn().get_library_instance('volume_keywords') - volume_node = volume_keywords.get_volume_node(volume_name) - self.stress.cpu([volume_node]) + def stress_node_cpu_by_volumes(self, volume_names): + self.stress.cpu(list_node_names_by_volumes(volume_names)) - def stress_node_memory_by_volume(self, volume_name): - volume_keywords = BuiltIn().get_library_instance('volume_keywords') - volume_node = volume_keywords.get_volume_node(volume_name) - self.stress.memory([volume_node]) + def stress_node_memory_by_volumes(self, volume_names): + self.stress.memory(list_node_names_by_volumes(volume_names)) diff --git a/e2e/libs/node/utility.py b/e2e/libs/node/utility.py index 172482a6d8..056b755e42 100644 --- a/e2e/libs/node/utility.py +++ b/e2e/libs/node/utility.py @@ -1,3 +1,5 @@ +from robot.libraries.BuiltIn import BuiltIn + from kubernetes import client @@ -35,3 +37,13 @@ def filter_nodes(nodes, condition): if role == "worker": condition = lambda node: not any(label in node.metadata.labels for label in control_plane_labels) return sorted(filter_nodes(nodes, condition)) + +def list_node_names_by_volumes(volume_names): + volume_nodes = {} + volume_keywords = BuiltIn().get_library_instance('volume_keywords') + + for volume_name in volume_names: + volume_node = volume_keywords.get_volume_node(volume_name) + if volume_node not in volume_nodes: + volume_nodes[volume_node] = True + return list(volume_nodes.keys()) diff --git a/e2e/tests/stress_cpu.robot b/e2e/tests/stress_cpu.robot index 3c9d376f20..11937f6301 100644 --- a/e2e/tests/stress_cpu.robot +++ b/e2e/tests/stress_cpu.robot @@ -20,7 +20,7 @@ Stress Volume Node CPU When Replica Is Rebuilding FOR ${i} IN RANGE ${LOOP_COUNT} When Delete replica on volume node to trigger replica rebuilding - And Stress volume node cpu + And Stress the CPU of all volume nodes Then Wait until replica on volume node rebuilt And Check data is intact diff --git a/e2e/tests/stress_memory.robot b/e2e/tests/stress_memory.robot index a96749d0c1..0568b6f872 100644 --- a/e2e/tests/stress_memory.robot +++ b/e2e/tests/stress_memory.robot @@ -20,7 +20,7 @@ Stress Volume Node Memory When Replica Is Rebuilding FOR ${i} IN RANGE ${LOOP_COUNT} When Delete replica on volume node to trigger replica rebuilding - And Stress volume node memory + And Stress the memory of all volume nodes Then Wait until replica on volume node rebuilt And Check data is intact