From ebdecf9390b15d85ff168686cebbf8cb5f8e6af0 Mon Sep 17 00:00:00 2001 From: Chin-Ya Huang Date: Thu, 26 Oct 2023 14:41:53 +0800 Subject: [PATCH] test(negative): stress volume node cpu/memory while detach/attaching ref: 6951 Signed-off-by: Chin-Ya Huang --- e2e/keywords/volume.resource | 6 +++++ e2e/libs/keywords/volume_keywords.py | 5 ++++ e2e/libs/volume/crd.py | 35 ++++++++++++++++++++++++++++ e2e/libs/volume/volume.py | 3 +++ e2e/libs/workload/pod.py | 9 +++++-- e2e/tests/stress_cpu.robot | 14 +++++++++++ e2e/tests/stress_memory.robot | 13 +++++++++++ 7 files changed, 83 insertions(+), 2 deletions(-) diff --git a/e2e/keywords/volume.resource b/e2e/keywords/volume.resource index 076db9a8d9..0e0bf9d5c0 100644 --- a/e2e/keywords/volume.resource +++ b/e2e/keywords/volume.resource @@ -18,6 +18,12 @@ Create volume ${idx} with ${size} GB and ${replica_count} replicas attach_volume ${volume_name} Insert Into List ${volume_list} ${idx} ${volume_name} +Attach volume to node + attach_volume ${volume_name} + +Detach volume from node + detach_volume ${volume_name} + Write data to the volume ${volume_data_checksum} = write_volume_random_data ${volume_name} 2048 Set Test Variable ${volume_data_checksum} diff --git a/e2e/libs/keywords/volume_keywords.py b/e2e/libs/keywords/volume_keywords.py index a0ed97ffb3..a94bf875fb 100644 --- a/e2e/libs/keywords/volume_keywords.py +++ b/e2e/libs/keywords/volume_keywords.py @@ -28,6 +28,11 @@ def attach_volume(self, volume_name): self.volume.attach(volume_name, attach_node) + def detach_volume(self, volume_name): + logging(f'Detaching volume {volume_name}') + self.volume.detach(volume_name) + + def get_volume_node(self, volume_name): volume = self.volume.get(volume_name) return volume['spec']['nodeID'] diff --git a/e2e/libs/volume/crd.py b/e2e/libs/volume/crd.py index d12cc48b1d..3eacac9d7d 100644 --- a/e2e/libs/volume/crd.py +++ b/e2e/libs/volume/crd.py @@ -93,6 +93,41 @@ def attach(self, volume_name, node_name): Exception(f'exception for creating volumeattachments:', e) self.wait_for_volume_state(volume_name, "attached") + def detach(self, volume_name): + try: + self.obj_api.patch_namespaced_custom_object( + group="longhorn.io", + version="v1beta2", + namespace="longhorn-system", + plural="volumeattachments", + name=volume_name, + body={ + "spec": { + "attachmentTickets": None, + } + } + ) + except Exception as e: + # new CRD: volumeattachments was added since from 1.5.0 + # https://github.com/longhorn/longhorn/issues/3715 + if e.reason != "Not Found": + Exception(f'exception for patching volumeattachments:', e) + + self.obj_api.patch_namespaced_custom_object( + group="longhorn.io", + version="v1beta2", + namespace="longhorn-system", + plural="volumes", + name=volume_name, + body={ + "spec": { + "nodeID": "" + } + } + ) + + self.wait_for_volume_state(volume_name, "detached") + def delete(self, volume_name): try: self.obj_api.delete_namespaced_custom_object( diff --git a/e2e/libs/volume/volume.py b/e2e/libs/volume/volume.py index fda2ecefcf..8c7e12a4d2 100644 --- a/e2e/libs/volume/volume.py +++ b/e2e/libs/volume/volume.py @@ -27,6 +27,9 @@ def create(self, volume_name, size, replica_count): def attach(self, volume_name, node_name): return self.volume.attach(volume_name, node_name) + def detach(self, volume_name): + return self.volume.detach(volume_name) + def delete(self, volume_name): return self.volume.delete(volume_name) diff --git a/e2e/libs/workload/pod.py b/e2e/libs/workload/pod.py index e2c71c0dbd..879d2934a1 100644 --- a/e2e/libs/workload/pod.py +++ b/e2e/libs/workload/pod.py @@ -116,8 +116,13 @@ def wait_delete_pod(name, namespace='default'): assert not found def get_pod(name, namespace='default'): - core_api = client.CoreV1Api() - return core_api.read_namespaced_pod(name=name, namespace=namespace) + try: + core_api = client.CoreV1Api() + return core_api.read_namespaced_pod(name=name, namespace=namespace) + except Exception as e: + if e.reason == 'Not Found': + return None + raise e def wait_for_pod_status(name, status, namespace='default'): retry_count, retry_interval = get_retry_count_and_interval() diff --git a/e2e/tests/stress_cpu.robot b/e2e/tests/stress_cpu.robot index a89b7085a1..3c9d376f20 100644 --- a/e2e/tests/stress_cpu.robot +++ b/e2e/tests/stress_cpu.robot @@ -25,3 +25,17 @@ Stress Volume Node CPU When Replica Is Rebuilding Then Wait until replica on volume node rebuilt And Check data is intact END + + +Stress Volume Node CPU When Volume Is Detaching and Attaching + Given Create a volume with 5 GB and 3 replicas + And Write data to the volume + + FOR ${i} IN RANGE ${LOOP_COUNT} + When Stress volume node cpu + + And Detach volume from node + And Attach volume to node + + And Check data is intact + END diff --git a/e2e/tests/stress_memory.robot b/e2e/tests/stress_memory.robot index 7414bba490..a96749d0c1 100644 --- a/e2e/tests/stress_memory.robot +++ b/e2e/tests/stress_memory.robot @@ -25,3 +25,16 @@ Stress Volume Node Memory When Replica Is Rebuilding Then Wait until replica on volume node rebuilt And Check data is intact END + +Stress Volume Node Memory When Volume Is Detaching and Attaching + Given Create a volume with 5 GB and 3 replicas + And Write data to the volume + + FOR ${i} IN RANGE ${LOOP_COUNT} + When Stress volume node memory + + And Detach volume from node + And Attach volume to node + + And Check data is intact + END