我正在尝试使用机器人框架建立与远程计算机的SSH连接并执行一些命令。但是我收到错误说ChannelException:(4,'资源短缺')我不知道这意味着什么。
Script: test.robot
*** Settings ***
Library SSHLibrary
Suite Setup open_connection_and_login
Suite Teardown Close All Connections
*** Variables ***
${HOST} login
${USERNAME} root
${PASSWORD} password
*** Test Cases ***
available_disk_on_remote
${output}= Execute Command df -h
Log To Console "${output}"
*** Keywords ***
open_connection_and_login
Open Connection ${HOST}
Login ${USERNAME} ${PASSWORD} 4
Output:
[root@machine1 Robot]# robot test.robot
===========================================================================
Test
======================================================================
available_disk_on_remote | FAIL |
ChannelException: (4, 'Resource shortage')
--------------------------------------------------------------------------
Test | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
=========================================================================
Output: /root/Robot/output.xml
Log: /root/Robot/log.html
Report: /root/Robot/report.html
Python 2.7.5和Robot Framework 3.0.2 (仅供参考,机器人框架新手)
答案 0 :(得分:0)
您必须使用Run和Return RC以及OperatingSystem库的输出来实现此目的。请在下面找到工作代码。
*** Settings ***
Library OperatingSystem
*** Test Cases ***
Check disk usage
${rc} ${output} = Run And Return Rc And Output df -h
Should Be Equal As Integers ${rc} 0
Log to console ${output}
这将为您提供以下输出
[root@scripts]# pybot diskusage.robot
==============================================================================
Diskusage
==============================================================================
Check disk usage ..Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_tv274-lv_root
47G 20G 25G 44% /
tmpfs 4.9G 84K 4.9G 1% /dev/shm
/dev/sda1 485M 38M 423M 9% /boot
/dev/mapper/vg_tv274-lv_home
4.6G 138M 4.2G 4% /home
/dev/sr0 658M 658M 0 100% /media/Ubuntu-Server 12.04.1 LTS amd64
Check disk usage | PASS |
------------------------------------------------------------------------------
Diskusage | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
答案 1 :(得分:0)
示例机器人框架代码以连接ssh并从服务器下载文件。
打开连接$ {Host}
登录$ {用户名} $ {pwd}
sshLibrary.Directory应该存在/ ug05 / abc / src / rpa
$ {XML_FILE} sshlibrary。获取文件/ug05/abc/src/rpa/*.xml
关闭连接