简体   繁体   中英

About expected timeouts in RobotFramework SSHLibrary

I'm a newb with respect to Robot Framework.

I'm writing a test procedure that is expected to

connect to another machine perform an image update (which causes the unit to close all services and reboot itself) re-connect to the unit run a command that returns a known string.

This is all supposed to happen within the __init__.robot module

What I have noticed is that I must invoke the upgrade procedure in a synchronous, or blocking way, like so

Execute Command sysupgrade upgrade.img

This succeeds in upgrading the unit, but the robotframework script hangs executing the command. I suspect this works because it keeps the ssh session alive long enough for the upgrade to reach a critical junction where the session is closed by the remote host, the host expects this, the upgrade continues, and this does not cause the upgrade to fail.

But the remote host appears to close the ssh session in such a way that the robotframework script does not detect it, and the script hangs indefinitely.

Trying to work around this, I tried invoking the remote command like so

Execute Command sysupgrade upgrade.img &

But then the update fails because the connection appear to drop and leaves the upgrade procedure incomplete.

If instead I execute it like this

    Execute Command    sysupgrade upgrade.img &
    Sleep    600

Then this also fails, for some reason I am unable to deduce.

However, if I invoke it like this

Execute Command sysupgrade upgrade.img timeout=600

The the command succeeds in updating the unit, and after the set timeout period, the robotframework script does indeed resume, but since it has arrived at the timeout, the test has (from the point of view of robotframework) failed.

But this is actually an expected failure, and should be ignored. The rest of the script would then reconnect to the host and continue the remaining test(s)

Is there a way to treat the timeout condition as non-fatal?

Here is the code, as explained above, the __init__.robot initialization module is expected to perform the upgrade and then reconnect, leaving the other xyz .robot files to be run and continue testing the applications.

The __init__.robot file:

*** Settings ***
| Library | OperatingSystem |
| Library | SSHLibrary |
Suite Setup ValidationInit
Suite Teardown ValidationTeardown

*** Keywords ***
ValidationInit
    Enable SSH Logging validation.log
    Open Connection ${host}
    Login ${username} ${password}
    # Upload the firmware to the unit.

    Put File    ${firmware}    upgrade.img    scp=ALL

    # Perform firmware upgrade on the unit.

    log     "Launch upgrade on unit"
    Execute Command    sysupgrade upgrade.img    timeout=600
    log     "Restart comms"
    Close All Connections
    Open Connection    ${host}
    Login              ${username}    ${password}

ValidationTeardown
    Close All Connections
    log “End tests”

You can use 'Run Keyword And Ignore Error' to ignore the failgure. Or here I think you should use write command if you do not care the execution result.

This should work:

Comment Change ssh client timeout configuration set client configuration timeout=600 Comment "Launch upgrade on unit" SSHLibrary.Write sysupgrade upgrade.img SSHLibrary.Read Until expectedResult Close All Connections

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM