【问题标题】:SSH connection on remote machine using robot framework: Channel Exception;(4,Resource Shortage")使用机器人框架在远程机器上建立 SSH 连接:Channel Exception;(4,Resource Shortage")
【发布时间】:2017-08-12 06:20:16
【问题描述】:

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

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 (仅供参考,Robot Framework 的新手)

【问题讨论】:

  • 目标是否有可能是 cisco-ish 交换机? :)

标签: python-2.7 testing ssh robotframework


【解决方案1】:

您必须使用 Run and Return RC 和 Output from 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
==============================================================================

【讨论】:

    【解决方案2】:
    1. SSH,也称为 Secure Shell 或 Secure Socket Shell,是一种网络协议,它为用户(尤其是系统管理员)提供了一种通过不安全网络访问计算机的安全方式。 SSH 也指实现 SSH 协议的实用程序套件。 Secure Shell 在通过互联网等开放网络连接的两台计算机之间提供强大的身份验证和加密数据通信。 SSH 被网络管理员广泛用于远程管理系统和应用程序,允许他们通过网络登录到另一台计算机、执行命令并将文件从一台计算机移动到另一台计算机。
    2. SSH 库用于连接 SSH 客户端
    3. 安装 sshlibrary 在命令提示符下执行命令
      • pip install robotframework-sshlibrary
    4. 在机器人框架中导入 sshlibrary
    5. 用于连接 ssh 并从服务器下载文件的示例机器人框架代码。

      打开连接 ${Host}
      登录 ${用户名} ${pwd}
      sshLibrary.Directory 应该存在 /ug05/abc/src/rpa ${XML_FILE} sshlibrary.Get 文件 /ug05/abc/src/rpa/*.xml
      关闭连接

    【讨论】:

      猜你喜欢
      • 2021-03-13
      • 2016-09-17
      • 1970-01-01
      • 2015-11-21
      • 1970-01-01
      • 2018-02-25
      • 2017-11-19
      • 2020-04-26
      • 1970-01-01
      相关资源
      最近更新 更多