From 49418bc0f6f598c97eae95437324e2b81006034d Mon Sep 17 00:00:00 2001 From: Chin-Ya Huang Date: Fri, 3 Nov 2023 09:11:17 +0800 Subject: [PATCH] refactor(negetive): reorganize list node function Signed-off-by: Chin-Ya Huang --- e2e/libs/keywords/node_keywords.py | 4 ++-- e2e/libs/keywords/volume_keywords.py | 8 ++++---- e2e/libs/node/utility.py | 5 +++++ e2e/libs/utility/utility.py | 7 ++----- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/e2e/libs/keywords/node_keywords.py b/e2e/libs/keywords/node_keywords.py index c41977bbeb..9e5dfdf7a7 100644 --- a/e2e/libs/keywords/node_keywords.py +++ b/e2e/libs/keywords/node_keywords.py @@ -2,8 +2,8 @@ from node import Node from node import Stress +from node.utility import get_node_by_index -from utility.utility import get_node from utility.utility import wait_for_all_instance_manager_running @@ -24,7 +24,7 @@ def reboot_replica_node(self, volume_name): self.node.reboot_node(replica_node) def reboot_node_by_index(self, idx, power_off_time_in_min=1): - node_name = get_node(idx) + node_name = get_node_by_index(idx) self.node.reboot_node(node_name, int(power_off_time_in_min) * 60) def reboot_all_worker_nodes(self, power_off_time_in_min=1): diff --git a/e2e/libs/keywords/volume_keywords.py b/e2e/libs/keywords/volume_keywords.py index d3e147b2f7..a0ed97ffb3 100644 --- a/e2e/libs/keywords/volume_keywords.py +++ b/e2e/libs/keywords/volume_keywords.py @@ -1,7 +1,7 @@ +from node.utility import get_node_by_index from node.utility import list_node_names_by_role from utility.utility import generate_volume_name -from utility.utility import get_node from utility.utility import get_test_pod_not_running_node from utility.utility import get_test_pod_running_node from utility.utility import logging @@ -57,14 +57,14 @@ def check_data_checksum(self, volume_name, checksum): def delete_replica(self, volume_name, replica_node): if str(replica_node).isdigit(): - replica_node = get_node(replica_node) + replica_node = get_node_by_index(replica_node) logging(f"Deleting volume {volume_name}'s replica on node {replica_node}") self.volume.delete_replica(volume_name, replica_node) def wait_for_replica_rebuilding_start(self, volume_name, replica_node): if str(replica_node).isdigit(): - replica_node = get_node(replica_node) + replica_node = get_node_by_index(replica_node) logging(f"Waiting for volume {volume_name}'s replica on node {replica_node} rebuilding started") self.volume.wait_for_replica_rebuilding_start( volume_name, @@ -74,7 +74,7 @@ def wait_for_replica_rebuilding_start(self, volume_name, replica_node): def wait_for_replica_rebuilding_complete(self, volume_name, replica_node): if str(replica_node).isdigit(): - replica_node = get_node(replica_node) + replica_node = get_node_by_index(replica_node) logging(f"Waiting for volume {volume_name}'s replica on node {replica_node} rebuilding completed") self.volume.wait_for_replica_rebuilding_complete( volume_name, diff --git a/e2e/libs/node/utility.py b/e2e/libs/node/utility.py index 3ac20ba74d..172482a6d8 100644 --- a/e2e/libs/node/utility.py +++ b/e2e/libs/node/utility.py @@ -1,5 +1,10 @@ from kubernetes import client + +def get_node_by_index(index, role="worker"): + nodes = list_node_names_by_role(role) + return nodes[int(index)] + def get_node_by_name(node_name): core_api = client.CoreV1Api() return core_api.read_node(node_name) diff --git a/e2e/libs/utility/utility.py b/e2e/libs/utility/utility.py index 1274b29cf4..f92542b2f0 100644 --- a/e2e/libs/utility/utility.py +++ b/e2e/libs/utility/utility.py @@ -15,6 +15,7 @@ from robot.api import logger from robot.libraries.BuiltIn import BuiltIn +from node.utility import get_node_by_index from node.utility import list_node_names_by_role @@ -87,10 +88,6 @@ def wait_for_all_instance_manager_running(): logging(f"Getting instance manager state error: {e}") assert len(instance_manager_map) == len(worker_nodes), f"expect all instance managers running, instance_managers = {instance_managers}, instance_manager_map = {instance_manager_map}" -def get_node(index): - worker_nodes = list_node_names_by_role("worker") - return worker_nodes[int(index)] - def apply_cr(manifest_dict): dynamic_client = dynamic.DynamicClient(client.api_client.ApiClient()) api_version = manifest_dict.get("apiVersion") @@ -191,7 +188,7 @@ def get_test_pod_running_node(): if "NODE_NAME" in os.environ: return os.environ["NODE_NAME"] else: - return get_node(0) + return get_node_by_index(0) def get_test_pod_not_running_node(): worker_nodes = list_node_names_by_role("worker")