Robot Framework 使ってみる④

#リモートホストでコマンド実行してみる(3回目)
[Robot Framework 使ってみる①](https://qiita.com/navasato/items/862b7715595319a63239 "Robot Framework 使ってみる①")
やってみたいことの3番目：vyos→vyos2へのpingを実行し100%成功する事を確認する　に挑戦する。

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

```text
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

```text: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}
#
```

で実行。

```text: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以内に処理が終わるように、、、

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

で、再実行。

```text
# 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だな
http://robotframework.org/SSHLibrary/SSHLibrary.html#Timeout
>Timeout
Argument timeout is used by Read Until variants. The default value is 3 seconds. See time 
format below for supported timeout syntax.

http://robotframework.org/SSHLibrary/SSHLibrary.html#Time%20format
>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で変更もできそう。

```text
*** Settings ***
Library  SSHLibrary
Test Timeout    30
```

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

```text
# 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 <time> exceeded って書いてるけど出力違うしな。。。
google先生に聞いても教えてくれないな。。。。

####諦める事も必要か。
他に使えそうなのをチートシートで探そう。。。
#####Builtinにsleepあるわ。
ping実行させてから格納待たせればいけるかな？

```text: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}
#
```

実行

```text: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](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/284963/379e5d3f-cc94-71f5-dcae-a32373b856d8.png)
一応やってみたいことはできたな。