Robotframework 如何使用robot框架检查unix进程是否正在运行
我正在尝试检查进程是否正在unix系统中运行。它可以是一个进程,也可以是多个进程。下面是我正在尝试的示例。有人能指导我如何做到这一点吗Robotframework 如何使用robot框架检查unix进程是否正在运行,robotframework,Robotframework,我正在尝试检查进程是否正在unix系统中运行。它可以是一个进程,也可以是多个进程。下面是我正在尝试的示例。有人能指导我如何做到这一点吗 *** Settings *** Library Process Library OperatingSystem *** Test cases *** Example ${output} = Run process /etc/init.d/bluetooth ${op}= Is Process
*** Settings ***
Library Process
Library OperatingSystem
*** Test cases ***
Example
${output} = Run process /etc/init.d/bluetooth
${op}= Is Process Running ${output}
Should be equal ${op} True
[root@test ssh-scripts]# pybot test-process.robot
==============================================================================
Test-Process
==============================================================================
Example | FAIL |
Non-existing index or alias '<result object with rc 3>'.
------------------------------------------------------------------------------
Test-Process | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
***设置***
图书馆流程
图书馆操作系统
***测试用例***
例子
${output}=运行进程/etc/init.d/bluetooth
${op}=进程正在运行${output}
应等于${op}True
[root@testssh脚本]#pybot test-process.robot
==============================================================================
测试过程
==============================================================================
例子|失败|
不存在索引或别名“”。
------------------------------------------------------------------------------
测试过程|失败|
1个关键测试,0个通过,1个失败
共1个测试,0个通过,1个失败
==============================================================================
/etc/init.d/bluetooth
是启动脚本,您不需要检查启动脚本,而是检查它启动的进程运行进程
等待进程终止。您可能不会等待终止,而是希望在后台运行该进程Test Processes
${handle} Start Process echo foo stdout=/tmp/bar
${output} Is Process Running handle=${handle}
Should Not Be True ${output}
${handle} Start Process yes stdout=/dev/null
${output} Is Process Running handle=${handle}
Should Be True ${output}
[Teardown] Terminate All Processes
即,echo
在第一个进程运行之前终止
执行检查。但是yes
在进程运行的第二瞬间启动并保持运行
/etc/init.d/bluetooth
是启动脚本,您不需要检查启动脚本,而是检查它启动的进程运行进程
等待进程终止。您可能不会等待终止,而是希望在后台运行该进程Test Processes
${handle} Start Process echo foo stdout=/tmp/bar
${output} Is Process Running handle=${handle}
Should Not Be True ${output}
${handle} Start Process yes stdout=/dev/null
${output} Is Process Running handle=${handle}
Should Be True ${output}
[Teardown] Terminate All Processes
即,
echo
在第一个进程运行之前终止
执行检查。但是yes
启动并在第二秒保持运行进程正在运行
以下脚本对我有效。在执行命令后,我放置了一个正则表达式模式来匹配字符串。这可以通过另一种方式实现,但这符合我的目的
*** Settings ***
Library Process
Library SSHLibrary
Suite Setup Open Connection And Log In
Suite Teardown Close All Connections
Library OperatingSystem
*** Variables ***
${HOST} 16.10.90.24
${USERNAME} root
${PASSWORD} admin123
${postgres_cmd} /etc/init.d/DB_Platform_TaskManager status
${PATTERN} (?m).*is\ running
*** Test Cases ***
Check whether postgres is running
Open Connection And Log In
Start Command ${postgres_cmd}
${rc}= Read Command Output return_stdout=True return_rc=False
Log ${rc}
Should Match Regexp ${rc} ${PATTERN}
*** Keywords ***
Open Connection And Log In
Open Connection ${HOST}
Login ${USERNAME} ${PASSWORD}
下面的脚本适合我。在执行命令后,我放置了一个正则表达式模式来匹配字符串。这可以通过另一种方式实现,但这符合我的目的
*** Settings ***
Library Process
Library SSHLibrary
Suite Setup Open Connection And Log In
Suite Teardown Close All Connections
Library OperatingSystem
*** Variables ***
${HOST} 16.10.90.24
${USERNAME} root
${PASSWORD} admin123
${postgres_cmd} /etc/init.d/DB_Platform_TaskManager status
${PATTERN} (?m).*is\ running
*** Test Cases ***
Check whether postgres is running
Open Connection And Log In
Start Command ${postgres_cmd}
${rc}= Read Command Output return_stdout=True return_rc=False
Log ${rc}
Should Match Regexp ${rc} ${PATTERN}
*** Keywords ***
Open Connection And Log In
Open Connection ${HOST}
Login ${USERNAME} ${PASSWORD}
感谢您的评论,我将尝试回答,我的目的是检查如下
[root@hyinit.d]#MDB_平台_PostgreSQL状态pg_ctl:服务器正在运行(PID:9997)
。我想验证这个进程是否正在运行,就像这样,我有一组进程要验证。感谢您的评论,我将尝试回答,我的目的是检查如下所示的进程[root@hyinit.d]#MDB_平台_PostgreSQL状态pg_ctl:服务器正在运行(PID:9997)
。我想验证这个进程是否正在运行,就像这样,我有一组进程要验证。