Skip to content

Commit 7c21514

Browse files
committed
test(robot): move volume endpoint check logic to Python keyword
- Extracting the check into a new Python keyword `check_volume_endpoint_on_node`, which asserts the endpoint exists and raises a clear error if not. - simplify node-level directory check to always log as WARNING. longhorn/longhorn#13256 Signed-off-by: Roger Yao <roger.yao@suse.com>
1 parent 7eebdcb commit 7c21514

2 files changed

Lines changed: 13 additions & 32 deletions

File tree

e2e/keywords/host.resource

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -165,43 +165,16 @@ Get host log list on path ${log_path} on node ${node_id}
165165
Check volume endpoint on node of ${resource_kind} ${resource_id}
166166
[Documentation] Find which node ${resource_kind} ${resource_id}'s volume is attached to,
167167
... then run "ls -l /dev/longhorn/${volume_name}" on that node and log the output.
168-
... If the directory is empty or doesn't exist, log a WARNING.
168+
... Fails the test if the endpoint is empty or doesn't exist.
169169
${resource_name} = generate_name_with_suffix ${resource_kind} ${resource_id}
170170
${volume_name} = Run Keyword If '${resource_kind}' == 'volume'
171171
... Set Variable ${resource_name}
172172
... ELSE
173173
... get_workload_volume_name ${resource_name}
174174
${node_name} = get_volume_node ${volume_name}
175-
${result} = execute_command_on_node ls -l /dev/longhorn/${volume_name} ${node_name}
176-
177-
# Check if result is empty or contains error
178-
${result_stripped} = Strip String ${result}
179-
${is_empty} = Run Keyword And Return Status Should Be Empty ${result_stripped}
180-
${has_error} = Run Keyword And Return Status Should Contain ${result} No such file or directory
181-
182-
IF ${is_empty} or ${has_error}
183-
${warning_msg} = Set Variable /dev/longhorn/${volume_name} is empty or doesn't exist on node=${node_name}, ${resource_kind}=${resource_name}, volume=${volume_name}
184-
Log ${warning_msg} level=WARN console=True
185-
ELSE
186-
${message} = Set Variable node=${node_name}, volume=${volume_name}\n/dev/longhorn/${volume_name}:\n${result}
187-
Log ${message} console=True
188-
END
175+
check_volume_endpoint_on_node ${volume_name} ${node_name}
189176

190177
Check volume endpoint on node ${node_id}
191-
[Documentation] Run "ls -l /dev/longhorn/" on node ${node_id} and log the output.
192-
... If the directory is empty or doesn't exist, log a WARNING.
193-
${node_name} = get_node_by_index ${node_id}
194-
${result} = execute_command_on_node ls -l /dev/longhorn/ ${node_name}
195-
196-
# Check if result is empty or contains error
197-
${result_stripped} = Strip String ${result}
198-
${is_empty} = Run Keyword And Return Status Should Be Empty ${result_stripped}
199-
${has_error} = Run Keyword And Return Status Should Contain ${result} No such file or directory
200-
201-
IF ${is_empty} or ${has_error}
202-
${warning_msg} = Set Variable /dev/longhorn/ is empty or doesn't exist on node=${node_name}
203-
Log ${warning_msg} level=WARN console=True
204-
ELSE
205-
${message} = Set Variable node=${node_name}\n/dev/longhorn/:\n${result}
206-
Log ${message} console=True
207-
END
178+
[Documentation] Run "ls -l /dev/longhorn/" on node ${node_id} and log the output as a WARNING.
179+
${result} = Run command on node ${node_id} and get output string ls -l /dev/longhorn/
180+
Log /dev/longhorn/ on node ${node_id}:\n${result} level=WARN console=True

e2e/libs/keywords/host_keywords.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,11 @@ def execute_command_on_node_and_get_output_string(self, cmd, node_name):
140140

141141
def get_host_log_files(self, node_name, log_path):
142142
return self.host.get_host_log_files(node_name, log_path)
143+
144+
def check_volume_endpoint_on_node(self, volume_name, node_name):
145+
cmd = f"ls -l /dev/longhorn/{volume_name}"
146+
res = NodeExec(node_name).issue_cmd(cmd)
147+
assert res.strip() and "No such file or directory" not in res, \
148+
f"Volume endpoint /dev/longhorn/{volume_name} is empty or doesn't exist on node {node_name}"
149+
logging(f"node={node_name}, volume={volume_name}\n/dev/longhorn/{volume_name}:\n{res}")
150+

0 commit comments

Comments
 (0)