如何通过robotframework执行ssh命令

时间:2017-04-02 07:02:48

标签: ssh robotframework

有人可以告诉我在下面的代码中我做了什么错误,我正在尝试使用机器人框架运行shell命令,并且我使用以下命令安装了sshlibrary模块 - pip install robotframework-sshlibrary。但是我仍然收到导致SSHLibrary失败的错误。我的操作系统是Ubuntu14.04。

Deploy.robot

*** Settings ***
Library         SSHLibrary
Resource        configuration.txt

*** Variables ***
${OBR_HOST}      10.110.72.192
${OBR_USERNAME}  root
${OBR_PASSWORD}  password

*** Test Cases ***

Deploy OBR machine code 
    ${output}=  Execute Command  /root/deploy.sh
    log to console  ${\n}${output}

*** Keywords ***
open_connection_and_login
    Open Connection  ${OBR_HOST}
    Login  ${OBR_USERNAME}  ${OBR_PASSWORD}

执行日志

root@92:~# pybot ssh-example.robot 
[ ERROR ] Error in file '/root/ssh-example.robot': Importing test library 'SSHLibrary' failed: ImportError: Importing Paramiko library failed. Make sure you have Paramiko installed.
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/SSHLibrary/__init__.py", line 15, in <module>
    from .library import SSHLibrary
  File "/usr/local/lib/python2.7/dist-packages/SSHLibrary/library.py", line 22, in <module>
    from .client import SSHClient
  File "/usr/local/lib/python2.7/dist-packages/SSHLibrary/client.py", line 20, in <module>
    from pythonclient import PythonSSHClient as SSHClient
  File "/usr/local/lib/python2.7/dist-packages/SSHLibrary/pythonclient.py", line 21, in <module>
    'Importing Paramiko library failed. '
PYTHONPATH:
  /usr/local/bin
  /usr/lib/python2.7
  /usr/lib/python2.7/plat-x86_64-linux-gnu
  /usr/lib/python2.7/lib-tk
  /usr/lib/python2.7/lib-old
  /usr/lib/python2.7/lib-dynload
  /usr/local/lib/python2.7/dist-packages
  /usr/lib/python2.7/dist-packages
  /usr/lib/python2.7/dist-packages/PILcompat
  /usr/lib/python2.7/dist-packages/gtk-2.0
  /usr/lib/python2.7/dist-packages/ubuntu-sso-client
==============================================================================
Ssh-Example                                                                   
==============================================================================
Execute Deploy command                                                | FAIL |
Parent suite setup failed:
No keyword with name 'Open Connection' found.
------------------------------------------------------------------------------
Ssh-Example                                                           | FAIL |
Suite setup failed:
No keyword with name 'Open Connection' found.

Also suite teardown failed:
No keyword with name 'Close All Connections' found.

1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
Output:  /root/output.xml
Log:     /root/log.html
Report:  /root/report.html
root@92:~# pip install robotframework-sshlibrary
Requirement already satisfied (use --upgrade to upgrade): robotframework-sshlibrary in /usr/local/lib/python2.7/dist-packages
Requirement already satisfied (use --upgrade to upgrade): robotframework in /usr/local/lib/python2.7/dist-packages (from robotframework-sshlibrary)
Requirement already satisfied (use --upgrade to upgrade): paramiko>=1.8.0 in /usr/local/lib/python2.7/dist-packages (from robotframework-sshlibrary)
Cleaning up...

2 个答案:

答案 0 :(得分:2)

在涉及Robot Framework之前,看起来您的错误发生在SSHLibrary/pythonclient.py。尝试制作一个导入Paramiko的Python脚本。有时pippybot使用不同版本的Python。尝试将head -n1 $(which pip)的输出与head -n1 $(which pybot)进行比较以检查。

答案 1 :(得分:0)

我有一个非常相似的案例:

Importing test library 'SSHLibrary' failed: ImportError: No module named 'SSHLibrary'

感谢@MarkHu我检查了:

$ head -n1 $(which pip)
#!/usr/bin/python

和:

$ head -n1 $(which pybot)
#!/usr/bin/python3

一个简单的解决方案(来自:https://pypi.org/project/robotframework/)是使用python来将机器人版本也“降级”到2.7,如下所示:

python -m robot test.robot