robotframework ssh connection 问题总结

本文总结了使用Robotframework进行SSH连接时遇到的常见问题,包括Write命令无响应、Write方法异常处理、Execute Command假死、并发执行中的资源竞争与超时设置、Rebot API使用注意事项等,并提供了相应的解决方案和异常处理建议。

1、在Switch conection 后立刻使用Write 写command 会出现SHH hander 不响应
则先用Excute Command 或 Start Command 发commands 获取status,之后可以继续使用write

2、SSHLibrary 的pythonClient 的Write 方法没有异常处理,当Write send file会写死connection,需要对_write_file()
增加异常抛出

3、Execute Command 封装Start Command 和 Read output command, 在一些command 没有回复或不会立刻响应,或执行该command 设备SSH connection 环境发生变化,Execute command 会假死,此时应考虑Start command 不组合read output command,使得执行command后立刻返回!

4、pabot 并发执行在一个并发组或threadingpool 中,根据实际观察,如大哥case完成耗时,有先后关系,用时以10 ~ 50 seconds 递增,可能与设备差异,不同设备相应效率有关。

5、pabot 并发process 数设计:【应根据并发组中设备依赖关系设置】
如有可用的8组(系列/类),每组2台设备;当执行设备数 dev_counts <= 8/2, 并发process 数 runDevprocess =( dev_counts )*2
当执行设备数 dev_counts >= 8/2, 并发process 数 runDevprocess =( dev_counts )
这样case或process在争取或锁定设备资源时,不会出现链式锁死设备,并发变为串行,浪费时间或设备资源

6、pabot child process 竞争或锁定设备资源的timeout 应设置为单个case 最糟糕的耗时,在某case process 已占用部分资源等待竞争剩余所需资源的timeout,在尝试等待一轮pool执行完毕后任然没有竞争到全部所需资源,就应该将所占用的部分设备资源释放, 若是不考虑或感性决定超长timeuout,一方面会浪费资源,时间,另一方面会触发链式锁死,并发变为串行,甚至导致整个执行过程阻塞或中断;

7、pabot 引用rebot API combin 和 merger output.xml,
Rebot 有3种接口, API,rebot cli, rebot command, API可能出现combin pabot_results中每个output.xml时出现xml 元素查找不到,可能原因是testsuite 的output_dir 名称引起的,原因之一是pabot 默认 pabot_results 中的每个testsuite的folder 名称为SUITE_NAME, 且默认会将’_’ 转换为空格’ ‘,testsuites 层级之间以点号’.’分割,在系统文件管理机制中可能因此混淆文件和文件夹
【此种情况下,使用rebot command一定会出现文件(文件名被当做了文件名)找不到的情况,rebot cli的执行情况与rebot API相同】
这种情况,在windows 环境下(其他系统环境可能也存在),文件名最长为255个unicode 字节,文件以文件名从后往前数第一个’.’分割为名称和扩展名,文件夹名称不应有’.’
故应将pabot 的pabot_results中每个case的outs_dir 路径名改为case 名称,并将其中空格’ ’替换为’-‘或其他不会引起异常的字符;

8、在pabot中child process 是被动等待返回的,在case 耗时较长容易中断时要考虑其他中断不响的处理

9、使用Switch Connection 会从connection A 切换到New connection B,
立刻使用Write 发送字符串命令,会出现Write 异常,如果对pythonclient.py 添加异常处理,会抛出异常。
如果SSH Connection is not active or connection not open or connection closed,使用Start Command ,Execute Command 会抛出错误。
此时,可以使用 Run Keyword And Ignore Error 捕获异常,根据异常消息做后续处理;
使用Run Keyword And Except Error 能够捕获异常,但实现要了解异常信息,且其返回bool 值,较难做后续处理。

10、对于一些设备的不稳定型,终究可以从不断的异常恢复处理中凸显出来,像一下问题,就足以说明DUT的问题
对Write, Start Command,Execute Command 等由Run Keyword 执行返回的一个tuble对象:([status],[info]),
可根据[Info]的不同内容,区别处理异常;也可根据[Status]一次性处理该Command失败的情况。

KEYWORD SSHLibrary . Execute Command cat /proc/net/arp
Documentation:
Executes command on the remote machine and returns its outputs.
Start / End / Elapsed:
20170802 14:17:14.540 / 20170802 14:17:14.556 / 00:00:00.016
14:17:14.540
INFO
Executing command ‘cat /proc/net/arp’.

14:17:14.556
FAIL
error: [Errno 10054] An existing connection was forcibly closed by the remote host

14:17:14.556
INFO
${currLinkStat} = FAIL

14:17:14.556
INFO
${currLinkInfo} = error: [Errno 10054] An existing connection was forcibly closed by the remote host

“”“
你所看到的是别人给你看到的,考虑之所以给你看这些的动机和原因。
找对的人,说对的话,做对的事情。
”“”

RobotFramework中 中SSHLibrary学习与总结 学习与总结 ⼀、安装SSHLibrary ⼆.关键字 1.与连接相关的 Open Connection Get Connection Get Connections Switch Connection Close Connection Close All Connections Login Login With Public Key Set Client Configuration Set Default Configuration Enable Ssh Logging 2.与⽂件/⽬录相关的 2.1 File Should Exist , File Should Not Exist, Directory Should Exist , Directory Should Not Exist 2.2 List Directory, List Files In Directory , List Directories In Directory 2.3 Put Directory ,Get Directory,Put File,Get File 3.与读写执⾏相关的 Write Write Bare Write Until Expected Output Read Read Until Read Until Prompt Read Until Regexp Execute Command Start Command Read Command Output ⼀、安装 ⼀、安装SSHLibrary 安装命令:pip install robotframework-sshlibrary ⼆ ⼆.关键字 关键字 1.与连接相关的 与连接相关的 Open Connection ⽤法: [ host " alias=None " port=22 " timeout=None " newline=None " prompt=None " term_type=None " width=None " height=None " path_separator=None " encoding=None ] 默认设置:timeout=3 seconds, newline=LF, prompt=None, loglevel=INFO, term_type=vt100, width=80,height=24, path_separator=/, encoding=UTF-8.其 中,newline=LF/CRLF(\n,\r\n) 更改默认设置: 1.导⼊库时: Library SSHLibrary 10 seconds prompt=$ 2.使⽤ Set Client Configuration/Set Default Configuration 3.调⽤Open Connection时: 结果: ${con1} =index=1 path_separator=/ prompt=# width=80 newline= height=24 encoding=UTF-8 alias=backend host=10.69.140.112 timeout=3 seconds term_type=vt100 port=2222 Get Connection ⽤法:[ index_or_alias=None " index=False " host=False " alias=False " port=False " timeout=False " newline=False " prompt=False " term_type=False " width=False " height=False " encoding=False ] 1.获取connection的信息,如果调⽤时没有加 index_or_alias,返回当前的conection信息。 2.获取connection的特定属性信息,后边加属性名=⾮false/False字符串。 结果: ${con1} =index=1 path_separator=/ prompt=# width=80 newline= height=24 encoding=UTF-8 alias=backend host=10.69.140.112 timeout=3 seconds term_type=vt100 port=2222 ${con2} = (2222, 3.0) Get Connections ⽤法:没有输⼊值,获取所有打开的connection的信息 结果: ${con1} = index=1 path_separator=/ prompt=$ width
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值