LoginSignup
0
1

More than 3 years have passed since last update.

Robot Framework 使ってみる④

Last updated at Posted at 2019-09-13

リモートホストでコマンド実行してみる(3回目)

Robot Framework 使ってみる①
やってみたいことの3番目:vyos→vyos2へのpingを実行し100%成功する事を確認する に挑戦する。

show version の時と同じ感じでいけそう。
とりあえず手動。

vyos@vyos:~$ ping 172.17.0.3 count 5
PING 172.17.0.3 (172.17.0.3) 56(84) bytes of data.
64 bytes from 172.17.0.3: icmp_req=1 ttl=64 time=0.064 ms
64 bytes from 172.17.0.3: icmp_req=2 ttl=64 time=0.092 ms
64 bytes from 172.17.0.3: icmp_req=3 ttl=64 time=0.094 ms
64 bytes from 172.17.0.3: icmp_req=4 ttl=64 time=0.056 ms
64 bytes from 172.17.0.3: icmp_req=5 ttl=64 time=0.096 ms

--- 172.17.0.3 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 3999ms
rtt min/avg/max/mdev = 0.056/0.080/0.096/0.018 ms
vyos@vyos:~$
Write & Read until
test06.robot
# cat test06.robot
*** Settings ***
Library SSHLibrary

*** Variables ***
${user} vyos
${password} vyos
${ip1} 172.17.0.2
${ip2} 172.17.0.3

*** Test Cases ***
ssh test of vyos
    vyosに接続
    vyosにログイン
    ${output} = Execute Command echo SSH to vyos is OK!
    Log To Console ${\n}${output}
    Should Be Equal ${output} SSH to vyos is OK!

ping test
    Write ping 172.17.0.3 count 5
    ${out} = Read Until ~$
    Should Contain ${out} 0% packet loss
    Close All Connections

*** Keywords ***
vyosに接続
    Open Connection ${ip1}
vyosにログイン
    Login ${user} ${password}
#

で実行。

result
# robot test06.robot
==============================================================================
Test06
==============================================================================
ssh test of vyos ...
SSH to vyos is OK!
ssh test of vyos | PASS |
------------------------------------------------------------------------------
ping test | FAIL |
No match found for '~$' in 3 seconds
Output:
PING 172.17.0.3 (172.17.0.3) 56(84) bytes of data.
64 bytes from 172.17.0.3: icmp_req=1 ttl=64 time=0.105 ms
64 bytes from 172.17.0.3: icmp_req=2 ttl=64 time=0.091 ms
64 bytes from 172.17.0.3: icmp_req=3 ttl=64 time=0.083 ms
.
------------------------------------------------------------------------------
Test06 | FAIL |
2 critical tests, 1 passed, 1 failed
2 tests total, 1 passed, 1 failed
==============================================================================
Output: /root/output.xml
Log: /root/log.html
Report: /root/report.html
#

FAIL  出力の3秒内に ~$ がないって言われてるな。。。
3s以内に処理が終わるように、、、

ping test
    Write  ping 172.17.0.3 count 2
    ${out} =  Read Until  ~$
    Should Contain  ${out}  0% packet loss
    Close All Connections

で、再実行。

# robot test06.robot
==============================================================================
Test06
==============================================================================
ssh test of vyos                                                      ...
SSH to vyos is OK!
ssh test of vyos                                                      | PASS |
------------------------------------------------------------------------------
ping test                                                             | PASS |
------------------------------------------------------------------------------
Test06                                                                | PASS |
2 critical tests, 2 passed, 0 failed
2 tests total, 2 passed, 0 failed
==============================================================================
Output:  /root/output.xml
Log:     /root/log.html
Report:  /root/report.html
#

よしPASSした。

あとはtimeout値を大きくすればOKだな

Timeout
Argument timeout is used by Read Until variants. The default value is 3 seconds. See time
format below for supported timeout syntax.

Time format
All timeouts, delays or retry intervals can be given as numbers considered seconds (e.g. 0.5 or 42) or in Robot Framework's time syntax (e.g. 1.5 seconds or 1 min 30 s). For more information about the time syntax see the Robot Framework User Guide.

デフォ3sで変更もできそう。

*** Settings ***
Library  SSHLibrary
Test Timeout    30

Test Case の timeout を 30s にして再実行

# robot test06.robot
==============================================================================
Test06
==============================================================================
ssh test of vyos                                                      ...
SSH to vyos is OK!
ssh test of vyos                                                      | PASS |
------------------------------------------------------------------------------
ping test                                                             | FAIL |
No match found for '~$' in 3 seconds
Output:
PING 172.17.0.3 (172.17.0.3) 56(84) bytes of data.
64 bytes from 172.17.0.3: icmp_req=1 ttl=64 time=0.063 ms
64 bytes from 172.17.0.3: icmp_req=2 ttl=64 time=0.053 ms
64 bytes from 172.17.0.3: icmp_req=3 ttl=64 time=0.098 ms
.
------------------------------------------------------------------------------
Test06                                                                | FAIL |
2 critical tests, 1 passed, 1 failed
2 tests total, 1 passed, 1 failed
==============================================================================
Output:  /root/output.xml
Log:     /root/log.html
Report:  /root/report.html
#

んんん???効いていない。。。なんか壮絶な勘違いしてる???
タイムアウト超過のメッセージは Test timeout exceeded って書いてるけど出力違うしな。。。
google先生に聞いても教えてくれないな。。。。

諦める事も必要か。

他に使えそうなのをチートシートで探そう。。。

Builtinにsleepあるわ。

ping実行させてから格納待たせればいけるかな?

test06.robot
# cat test06.robot
*** Settings ***
Library  SSHLibrary

*** Variables ***
${user}       vyos
${password}   vyos
${ip1}  172.17.0.2
${ip2}  172.17.0.3

*** Test Cases ***
ssh test of vyos
    vyosに接続
    vyosにログイン
    ${output} =  Execute Command  echo SSH to vyos is OK!
    Log To Console  ${\n}${output}
    Should Be Equal  ${output}  SSH to vyos is OK!

ping test
    Write  ping 172.17.0.3 count 5
    sleep  10
    ${out} =  Read Until  ~$
    Should Contain  ${out}  0% packet loss
    Close All Connections

*** Keywords ***
vyosに接続
    Open Connection  ${ip1}
vyosにログイン
    Login  ${user}  ${password}
#

実行

result
# robot test06.robot
==============================================================================
Test06
==============================================================================
ssh test of vyos                                                      ...
SSH to vyos is OK!
ssh test of vyos                                                      | PASS |
------------------------------------------------------------------------------
ping test                                                             | PASS |
------------------------------------------------------------------------------
Test06                                                                | PASS |
2 critical tests, 2 passed, 0 failed
2 tests total, 2 passed, 0 failed
==============================================================================
Output:  /root/output.xml
Log:     /root/log.html
Report:  /root/report.html
#

PASSした。
001.png
一応やってみたいことはできたな。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1