From 3d0a7329733ae76cd59d1a818c62acd77208d2d2 Mon Sep 17 00:00:00 2001 From: Chin-Ya Huang Date: Thu, 14 Nov 2024 14:01:20 +0800 Subject: [PATCH] test(robot): detached volume should not reattach after node eviction longhorn/longhorn-9781 Signed-off-by: Chin-Ya Huang --- e2e/keywords/node.resource | 5 +++++ e2e/keywords/volume.resource | 7 +++++++ e2e/libs/keywords/node_keywords.py | 4 ++++ e2e/libs/node/node.py | 23 +++++++++++++++++++++++ e2e/tests/regression/test_volume.robot | 18 ++++++++++++++++++ 5 files changed, 57 insertions(+) diff --git a/e2e/keywords/node.resource b/e2e/keywords/node.resource index a83ce98df9..60cdcde8ae 100644 --- a/e2e/keywords/node.resource +++ b/e2e/keywords/node.resource @@ -11,6 +11,11 @@ Add ${disk_type} type disk ${disk_path} for all worker nodes add_disk ${worker_node} ${disk_type} ${disk_path} END +Set node ${node_id} with + [Arguments] &{config} + ${node_name} = get_node_by_index ${node_id} + set_node ${node_name} &{config} + Disable node ${node_id} scheduling ${node_name} = get_node_by_index ${node_id} disable_node_scheduling ${node_name} diff --git a/e2e/keywords/volume.resource b/e2e/keywords/volume.resource index b322b369e0..c9bc00ec11 100644 --- a/e2e/keywords/volume.resource +++ b/e2e/keywords/volume.resource @@ -119,6 +119,13 @@ Wait for volume ${volume_id} detached ${volume_name} = generate_name_with_suffix volume ${volume_id} wait_for_volume_detached ${volume_name} +Assert volume ${volume_id} remains detached for at least ${period} seconds + ${volume_name} = generate_name_with_suffix volume ${volume_id} + FOR ${i} IN RANGE ${period} + wait_for_volume_detached ${volume_name} + Sleep 1 + END + Wait for volume ${volume_id} faulted ${volume_name} = generate_name_with_suffix volume ${volume_id} wait_for_volume_faulted ${volume_name} diff --git a/e2e/libs/keywords/node_keywords.py b/e2e/libs/keywords/node_keywords.py index cb9a8dbaab..832834f6c6 100644 --- a/e2e/libs/keywords/node_keywords.py +++ b/e2e/libs/keywords/node_keywords.py @@ -34,6 +34,10 @@ def disable_default_disk(self, node_name): def enable_default_disk(self, node_name): self.node.set_default_disk_scheduling(node_name, allowScheduling=True) + def set_node(self, node_name, allowScheduling=True, evictionRequested=False): + logging(f"Setting node {node_name}; scheduling={allowScheduling}; evictionRequested={evictionRequested}") + self.node.set_node(node_name, allowScheduling, evictionRequested) + def disable_node_scheduling(self, node_name): self.node.set_node_scheduling(node_name, allowScheduling=False) diff --git a/e2e/libs/node/node.py b/e2e/libs/node/node.py index cd5a48c3bf..7cd94606cf 100644 --- a/e2e/libs/node/node.py +++ b/e2e/libs/node/node.py @@ -128,6 +128,29 @@ def filter_nodes(nodes, condition): elif role == "worker": return worker_nodes + def set_node(self, node_name: str, allowScheduling: bool, evictionRequested: bool) -> object: + node = get_longhorn_client().by_id_node(node_name) + + for _ in range(self.retry_count): + try: + node = get_longhorn_client().by_id_node(node_name) + + get_longhorn_client().update(node, + allowScheduling=allowScheduling, + evictionRequested=evictionRequested) + + node = get_longhorn_client().by_id_node(node_name) + assert node.allowScheduling == allowScheduling + assert node.evictionRequested == evictionRequested + + return node + except Exception as e: + logging(f"Updating node {node_name} error: {e}") + + time.sleep(self.retry_interval) + + raise AssertionError(f"Updating node {node_name} failed") + def set_node_scheduling(self, node_name, allowScheduling=True, retry=False): node = get_longhorn_client().by_id_node(node_name) diff --git a/e2e/tests/regression/test_volume.robot b/e2e/tests/regression/test_volume.robot index bca2ad2266..f6954594d9 100644 --- a/e2e/tests/regression/test_volume.robot +++ b/e2e/tests/regression/test_volume.robot @@ -9,6 +9,8 @@ Resource ../keywords/longhorn.resource Resource ../keywords/persistentvolumeclaim.resource Resource ../keywords/setting.resource Resource ../keywords/workload.resource +Resource ../keywords/node.resource +Resource ../keywords/volume.resource Test Setup Set test environment Test Teardown Cleanup test resources @@ -42,3 +44,19 @@ Test RWX volume data integrity after CSI plugin pod restart ... longhorn-csi-plugin Then Check deployment 0 data in file data.txt is intact + +Test detached volume should not reattach after node eviction + [Tags] volume node-eviction + [Documentation] Test detached volume should not reattach after node eviction. + ... + ... Issue: https://github.com/longhorn/longhorn/issues/9781 + + Given Create volume 0 with dataEngine=${DATA_ENGINE} + And Attach volume 0 + And Wait for volume 0 healthy + + When Detach volume 0 + And Set node 1 with allowScheduling=false evictionRequested=true + + Then Wait for volume 0 detached + And Assert volume 0 remains detached for at least 60 seconds