From 9520d8b3e4fc8e5b44162a45fa2f1262b77e511f Mon Sep 17 00:00:00 2001 From: omercier Date: Tue, 12 Aug 2025 14:40:26 +0200 Subject: [PATCH] fix retrieving of results + factorize run & return --- tests/resources/connector.py | 8 ++--- tests/resources/resources.resource | 53 +++++++++++++++++++++++------- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/tests/resources/connector.py b/tests/resources/connector.py index a917121e6..5b1d02e43 100644 --- a/tests/resources/connector.py +++ b/tests/resources/connector.py @@ -142,9 +142,9 @@ def ctn_extract_result_from_log(tc, log_path="/tmp/connector.log", output_path=N with open(log_path, 'r') as f: for line in f: # Pattern: reporting check result # ... - m = re.search(r'reporting check result #(\d+).*output:(.*)', line) + m = re.search(r'reporting check result #(\d+) check:(\d+) .*output:(.*)', line) if m: - found_id, output = m.group(1), m.group(2).strip() + test_number, found_id, output = m.group(1), m.group(2), m.group(3).strip() if str(found_id) == str(tc): # Write the output to the file output_path = output_path or f"/tmp/connector.output.{tc}" @@ -167,9 +167,9 @@ def ctn_extract_result_from_log(tc, log_path="/tmp/connector.log", output_path=N import re with open(log_path, 'r') as f: for line in f: - m = re.search(r'reporting check result #(\d+).*output:(.*)', line) + m = re.search(r'reporting check result #(\d+) check:(\d+) .*output:(.*)', line) if m: - found_id, output = m.group(1), m.group(2).strip() + test_number, found_id, output = m.group(1), m.group(2), m.group(3).strip() if str(found_id) == str(tc): output_path = output_path or f"/tmp/connector.output.{tc}" with open(output_path, 'w') as out: diff --git a/tests/resources/resources.resource b/tests/resources/resources.resource index 031799db6..1c1721f40 100644 --- a/tests/resources/resources.resource +++ b/tests/resources/resources.resource @@ -107,18 +107,53 @@ Ctn Verify Command Without Connector Output ... values=False ... collapse_spaces=True -Ctn Run Command With Connector And Check Result As Strings - [Arguments] ${command} ${expected_result} ${tc}=0 ${timeout}=${TIMEOUT} - Log To Console c +Ctn Connector Log Contains Result + [Arguments] ${tc} + ${result}= Grep File /tmp/connector.log reporting check result + #\d+ check:${tc}${SPACE} + + IF "${result}" == '' + ${toto}= Grep File /tmp/connector.log . + Fail Result not available yet + ELSE + RETURN ${TRUE} + END + +Ctn Wait Until Connector Result Available + [Arguments] ${tc} ${timeout}=${TIMEOUT} + Wait Until Keyword Succeeds + ... ${timeout} + ... .2 + ... File Should Not Be Empty /tmp/connector.log + File Should Not Be Empty /tmp/connector.log + Wait Until Keyword Succeeds + ... ${timeout} + ... .2 + ... Ctn Connector Log Contains Result ${tc} + +Ctn Run Command With Connector And Return Result + [Arguments] ${tc} ${command} ${timeout}=${TIMEOUT} Remove File /tmp/connector.output Remove File /tmp/connector.command.log + Create File /tmp/connector.log + File Should Be Empty /tmp/connector.log + Ctn Send To Connector ${tc} ${command} ${timeout} + Ctn Wait Until Connector Result Available ${tc} ${timeout} + # 1. Extract the result from the log and write to /tmp/connector.output Ctn Extract Result From Log ${tc} # 2. Read the file ${output} Get File /tmp/connector.output ${output} Strip String ${output} - # 3. Compare with expected + RETURN ${output} + +Ctn Run Command With Connector And Check Result As Strings + [Arguments] ${command} ${expected_result} ${tc}=0 ${timeout}=${TIMEOUT} + Log To Console c + + ${output} Ctn Run Command With Connector And Return Result ${tc} ${command} ${timeout} + Should Be Equal As Strings ... ${expected_result} ... ${output} @@ -130,14 +165,8 @@ Ctn Run Command With Connector And Check Result As Strings Ctn Run Command With Connector And Check Result As Regexp [Arguments] ${command} ${expected_result} ${tc}=0 ${timeout}=${TIMEOUT} Log To Console c - Remove File /tmp/connector.output - Remove File /tmp/connector.command.log - Ctn Send To Connector ${tc} ${command} ${timeout} - # 1. Extract the result from the log and write to /tmp/connector.output - Ctn Extract Result From Log ${tc} - # 2. Read the file - ${output} Get File /tmp/connector.output - ${output} Strip String ${output} + ${output} Ctn Run Command With Connector And Return Result ${tc} ${command} ${timeout} + # 3. Compare with expected Should Match Regexp ... ${output}