#背景
ネットワーク機器の試験自動化に向けてやらざるを得なくなった。
robotframeworkを選んだのは日本語ドキュメントが多そうなのと、レポートが綺麗だから。
#環境
VPS上にcentosとvyosのDockerコンテナを作成し、centosにrobotframeworkをインストール。
#やってみたいこと
- vyosのshowコマンドの出力結果を取得する
- vyos内のファイルを取得する
- vyos→vyos2へのpingを実行し100%成功する事を確認する
#はじめの一歩
とりあえず、ssh接続しないと何もできなさそうなので色々見ながらやってみる。
###SSH接続で基本的な記述を確認する
test00.robot
*** Settings ***
Library SSHLibrary
*** Test Cases ***
ssh test
Open Connection 172.17.0.2
Login vyos vyos
${output} = Execute Command echo SSH is succeeded!
Log To Console ${\n}${output}
Should Be Equal ${output} SSH is succeeded!
Close All Connections
result of test00.robot
# robot test00.robot
==============================================================================
Test00
==============================================================================
ssh test ...
SSH is succeeded!
ssh test | PASS |
------------------------------------------------------------------------------
Test00 | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output: /root/output.xml
Log: /root/log.html
Report: /root/report.html
#
10行程度で期待動作をしてくれた。
###変数テーブルの定義はしておいた方がよさげ
test01.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
Open Connection ${ip1}
Login ${user} ${password}
${output} = Execute Command echo SSH to vyos is OK!
Log To Console ${\n}${output}
Should Be Equal ${output} SSH to vyos is OK!
Close All Connections
ssh test of vyos2
Open Connection ${ip2}
Login ${user} ${password}
${output} = Execute Command echo SSH to vyos2 is OK!
Log To Console ${\n}${output}
Should Be Equal ${output} SSH to vyos2 is OK!
Close All Connections
result of test01.robot
# robot test01.robot
==============================================================================
Test01
==============================================================================
ssh test of vyos ...
SSH to vyos is OK!
ssh test of vyos | PASS |
------------------------------------------------------------------------------
ssh test of vyos2 ...
SSH to vyos2 is OK!
ssh test of vyos2 | PASS |
------------------------------------------------------------------------------
Test01 | 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
*** Variables *** でスカラ変数を定義するだけでOK。
log.htmlも見やすい。
###Keywordを定義することもできるようだ
test02.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!
Close All Connections
ssh test of vyos2
Open Connection ${ip2}
Login ${user} ${password}
${output} = Execute Command echo SSH to vyos2 is OK!
Log To Console ${\n}${output}
Should Be Equal ${output} SSH to vyos2 is OK!
Close All Connections
*** Keywords ***
vyosに接続
Open Connection ${ip1}
vyosにログイン
Login ${user} ${password}
result of test02.robot
# robot test02.robot
==============================================================================
Test02
==============================================================================
ssh test of vyos ...
SSH to vyos is OK!
ssh test of vyos | PASS |
------------------------------------------------------------------------------
ssh test of vyos2 ...
SSH to vyos2 is OK!
ssh test of vyos2 | PASS |
------------------------------------------------------------------------------
Test02 | 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
#
#次回はリモートホストでのコマンド実行をやってみよう