From 482e75570d9bcf686fd4701d106a73144b0c45c5 Mon Sep 17 00:00:00 2001 From: Yang Chiu Date: Sun, 28 Apr 2024 21:10:18 +0800 Subject: [PATCH] test(robot): remove unused test pod functions Signed-off-by: Yang Chiu --- e2e/libs/keywords/volume_keywords.py | 85 +++++++++------------------- e2e/libs/node/node.py | 22 +++---- e2e/libs/node/utility.py | 2 +- e2e/tests/replica_rebuilding.robot | 11 ++-- 4 files changed, 41 insertions(+), 79 deletions(-) diff --git a/e2e/libs/keywords/volume_keywords.py b/e2e/libs/keywords/volume_keywords.py index 419626c40f..1a20098099 100644 --- a/e2e/libs/keywords/volume_keywords.py +++ b/e2e/libs/keywords/volume_keywords.py @@ -52,13 +52,6 @@ def wait_for_volume_expand_to_size(self, volume_name, size): logging(f'Waiting for volume {volume_name} expand to {size}') return self.volume.wait_for_volume_expand_to_size(volume_name, size) - def get_replica_node_ids(self, volume_name): - node_ids = [] - node_ids.extend(self.get_node_ids_by_replica_locality(volume_name, "volume node")) - node_ids.extend(self.get_node_ids_by_replica_locality(volume_name, "replica node")) - node_ids.extend(self.get_node_ids_by_replica_locality(volume_name, "test pod node")) - return node_ids - def get_replica_node(self, volume_name): return self.get_node_id_by_replica_locality(volume_name, "replica node") @@ -78,14 +71,9 @@ def get_node_ids_by_replica_locality(self, volume_name, replica_locality): worker_nodes = self.node.list_node_names_by_role("worker") volume_node = self.get_node_id_by_replica_locality(volume_name, "volume node") replica_nodes = [node for node in worker_nodes if node != volume_node] - test_pod_node = self.node.get_test_pod_running_node() - - if replica_locality == "test pod node": - if test_pod_node in replica_nodes: - return [test_pod_node] - elif replica_locality == "replica node": - return [node for node in replica_nodes if node != test_pod_node] + if replica_locality == "replica node": + return replica_nodes else: raise ValueError(f"Unknown replica locality {replica_locality}") @@ -108,64 +96,43 @@ def check_data_checksum(self, volume_name): logging(f"Checking volume {volume_name} data checksum is {checksum}") self.volume.check_data_checksum(volume_name, checksum) - def delete_replica(self, volume_name, replica_node): - if str(replica_node).isdigit(): - replica_node = self.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 delete_replica_on_node(self, volume_name, replica_locality): - check_replica_locality(replica_locality) - - node_id = self.get_node_id_by_replica_locality(volume_name, replica_locality) + node_name = None + if index := self.node.is_accessing_node_by_index(replica_locality): + node_name = self.node.get_node_by_index(index) + else: + node_name = self.get_node_id_by_replica_locality(volume_name, replica_locality) - logging(f"Deleting volume {volume_name}'s replica on node {node_id}") - self.volume.delete_replica(volume_name, node_id) + logging(f"Deleting volume {volume_name}'s replica on node {node_name}") + self.volume.delete_replica(volume_name, node_name) def set_annotation(self, volume_name, annotation_key, annotation_value): self.volume.set_annotation(volume_name, annotation_key, annotation_value) - async def wait_for_replica_rebuilding_start(self, volume_name, replica_node): - if str(replica_node).isdigit(): - replica_node = self.node.get_node_by_index(replica_node) - - logging(f"Waiting for volume {volume_name}'s replica on node {replica_node} rebuilding started") - await self.volume.wait_for_replica_rebuilding_start( - volume_name, - replica_node - ) - async def wait_for_replica_rebuilding_to_start_on_node(self, volume_name, replica_locality): - check_replica_locality(replica_locality) - - node_id = self.get_node_id_by_replica_locality(volume_name, replica_locality) - - logging(f"Waiting for volume {volume_name}'s replica on node {node_id} rebuilding started") - await self.volume.wait_for_replica_rebuilding_start(volume_name, node_id) - - def wait_for_replica_rebuilding_complete(self, volume_name, replica_node): - if str(replica_node).isdigit(): - replica_node = self.node.get_node_by_index(replica_node) + node_name = None + if index := self.node.is_accessing_node_by_index(replica_locality): + node_name = self.node.get_node_by_index(index) + else: + node_name = self.get_node_id_by_replica_locality(volume_name, replica_locality) - logging(f"Waiting for volume {volume_name}'s replica on node {replica_node} rebuilding completed") - self.volume.wait_for_replica_rebuilding_complete( - volume_name, - replica_node - ) + logging(f"Waiting for volume {volume_name}'s replica on node {node_name} rebuilding started") + await self.volume.wait_for_replica_rebuilding_start(volume_name, node_name) def wait_for_replica_rebuilding_to_complete_on_node(self, volume_name, replica_locality): - check_replica_locality(replica_locality) - - node_id = self.get_node_id_by_replica_locality(volume_name, replica_locality) + node_name = None + if index := self.node.is_accessing_node_by_index(replica_locality): + node_name = self.node.get_node_by_index(index) + else: + node_name = self.get_node_id_by_replica_locality(volume_name, replica_locality) - logging(f"Waiting for volume {volume_name}'s replica on node {node_id} rebuilding completed") - self.volume.wait_for_replica_rebuilding_complete(volume_name, node_id) + logging(f"Waiting for volume {volume_name}'s replica on node {node_name} rebuilding completed") + self.volume.wait_for_replica_rebuilding_complete(volume_name, node_name) def wait_for_replica_rebuilding_to_complete(self, volume_name): - for node_id in self.get_replica_node_ids(volume_name): - logging(f"Waiting for volume {volume_name}'s replica on node {node_id} rebuilding completed") - self.volume.wait_for_replica_rebuilding_complete(volume_name, node_id) + for node_name in self.node.list_node_names_by_role("worker"): + logging(f"Waiting for volume {volume_name}'s replica on node {node_name} rebuilding completed") + self.volume.wait_for_replica_rebuilding_complete(volume_name, node_name) async def only_one_replica_rebuilding_will_start_at_a_time_on_node(self, volume_name_0, volume_name_1, replica_locality): diff --git a/e2e/libs/node/node.py b/e2e/libs/node/node.py index 28cb407e38..fa50907644 100644 --- a/e2e/libs/node/node.py +++ b/e2e/libs/node/node.py @@ -1,6 +1,6 @@ import os import time - +import re from kubernetes import client from robot.libraries.BuiltIn import BuiltIn @@ -76,6 +76,13 @@ def wait_all_pods_evicted(self, node_name): assert evicted, 'failed to evict pods' + def is_accessing_node_by_index(self, node): + p = re.compile('node (\d)') + if m := p.match(node): + return m.group(1) + else: + return None + def get_node_by_index(self, index, role="worker"): nodes = self.list_node_names_by_role(role) return nodes[int(index)] @@ -84,19 +91,6 @@ def get_node_by_name(self, node_name): core_api = client.CoreV1Api() return core_api.read_node(node_name) - def get_test_pod_running_node(self): - if "NODE_NAME" in os.environ: - return os.environ["NODE_NAME"] - else: - return self.get_node_by_index(0) - - def get_test_pod_not_running_node(self): - worker_nodes = self.list_node_names_by_role("worker") - test_pod_running_node = self.get_test_pod_running_node() - for worker_node in worker_nodes: - if worker_node != test_pod_running_node: - return worker_node - def get_node_cpu_cores(self, node_name): node = self.get_node_by_name(node_name) return node.status.capacity['cpu'] diff --git a/e2e/libs/node/utility.py b/e2e/libs/node/utility.py index e625e81249..f285291aea 100644 --- a/e2e/libs/node/utility.py +++ b/e2e/libs/node/utility.py @@ -1,2 +1,2 @@ def check_replica_locality(replica_locality): - assert replica_locality in ["replica node", "test pod node", "volume node"], f"Unknown replica locality: {replica_locality}: " + assert replica_locality in ["replica node", "volume node"], f"Unknown replica locality: {replica_locality}: " diff --git a/e2e/tests/replica_rebuilding.robot b/e2e/tests/replica_rebuilding.robot index b0612e2174..5421928957 100644 --- a/e2e/tests/replica_rebuilding.robot +++ b/e2e/tests/replica_rebuilding.robot @@ -18,14 +18,15 @@ ${RETRY_INTERVAL} 1 Delete Replica While Replica Rebuilding Given Create volume 0 with 2 GB and 3 replicas And Attach volume 0 + And Wait for volume 0 healthy And Write data to volume 0 FOR ${i} IN RANGE ${LOOP_COUNT} - When Delete volume 0 replica on volume node - And Wait until volume 0 replica rebuilding started on volume node - And Delete volume 0 replica on replica node - And Wait until volume 0 replica rebuilding completed on volume node - And Delete volume 0 replica on test pod node + When Delete volume 0 replica on node 0 + And Wait until volume 0 replica rebuilding started on node 0 + And Delete volume 0 replica on node 1 + And Wait until volume 0 replica rebuilding completed on node 0 + And Delete volume 0 replica on node 2 Then Check volume 0 data is intact And Wait until volume 0 replicas rebuilding completed