gpt4 book ai didi

python-2.7 - 使用机器人框架在远程计算机上进行 SSH 连接 : Channel Exception;(4, 资源短缺”)

转载 作者:行者123 更新时间:2023-11-28 20:51:58 25 4
gpt4 key购买 nike

我正在尝试使用机器人框架与远程机器建立 SSH 连接并执行一些命令。但是我收到一条错误消息 ChannelException:(4,'Resource shortage') 并且我不知道它是什么意思。

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 和机器人框架 3.0.2(仅供引用,机器人框架的新手)

最佳答案

您必须使用 OperatingSystem 库中的 Run and Return RC 和 Output 来实现此目的。请在下面找到工作代码。

*** 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
==============================================================================

关于python-2.7 - 使用机器人框架在远程计算机上进行 SSH 连接 : Channel Exception;(4, 资源短缺”),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42912629/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com