Skip to content

Commit

Permalink
test(robot): remove unused test pod functions
Browse files Browse the repository at this point in the history
Signed-off-by: Yang Chiu <yang.chiu@suse.com>
  • Loading branch information
yangchiu committed May 3, 2024
1 parent d1a36a4 commit 482e755
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 79 deletions.
85 changes: 26 additions & 59 deletions e2e/libs/keywords/volume_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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}")
Expand All @@ -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):

Expand Down
22 changes: 8 additions & 14 deletions e2e/libs/node/node.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import time

import re
from kubernetes import client

from robot.libraries.BuiltIn import BuiltIn
Expand Down Expand Up @@ -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)]
Expand All @@ -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']
Expand Down
2 changes: 1 addition & 1 deletion e2e/libs/node/utility.py
Original file line number Diff line number Diff line change
@@ -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}: "
11 changes: 6 additions & 5 deletions e2e/tests/replica_rebuilding.robot
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 482e755

Please sign in to comment.