【发布时间】:2020-05-21 15:26:35
【问题描述】:
我需要你的帮助来解决以下问题:
作为我的机器人框架测试的一部分,我还必须通过 Linux CLI 执行一些验证。我已经导入了 SSHLibrary,并且可以正确连接到我的 Linux 机器:
*** Keywords ***
Verify Service On All Nodes
Open Connection ${host} prompt=REGEXP:[$|#]
login ${user} ${user_pass}
SSHLibrary.Read Until Prompt
write su - \n
Read Until Password:
Write ${root_pass}\n
BuiltIn.sleep 10
SSHLibrary.Set Client Configuration prompt=~]
Read Until Prompt
Write verify #this stepp calls a shell script which does the required check
BuiltIn.sleep 90
SSHLibrary.Read Until Prompt
${output} SSHLibrary.Read Until Prompt
Log ${output}
上面的 sn-p 将我的验证脚本的输出正确记录到报告中,但我想更进一步。
我编写了一个 Python 函数来验证上述脚本的输出。
def verify_service_state(ab11, ab12, s):
import re
servers = [ab11, ab12]
for i in servers:
r1 = re.search(r"^Checking listening ports on " + (i) + " for roles: \(AB\)" + "\nThere were no errors reported.", s, re.MULTILINE)
if (r1):
print("Listening ports are open " + (i))
else:
print("Not all listening ports are open on " + (i))
r2 = re.search(r"^Checking process counts on " + (i) + " for roles: \(AB\)" + "\nThere were no errors reported.", s, re.MULTILINE)
if (r2):
print("There were no errors reported on " + (i))
else:
print("Not all services are working as expected on " + (i))
我已经根据这篇文章创建了一个 RF 库:Creating a robot framework library from existing python package 但是,我不清楚如何将属性传递给我的函数。
【问题讨论】:
标签: python robotframework