LoginSignup
1
1

More than 3 years have passed since last update.

Robot Framework 使ってみる③

Last updated at Posted at 2019-09-09

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

Robot Framework 使ってみる①
やってみたいことの2番目:vyos内のファイルを取得する に挑戦する。

http://robotframework.org/SSHLibrary/SSHLibrary.html
get file : 絶対これだと思う!

とりあえず手動。

# scp vyos@172.17.0.2:/var/log/messages ./
Welcome to VyOS
vyos@172.17.0.2's password:
messages 100% 228KB 58.7MB/s 00:00
# ls -l
total 728
~snip~
-rw-r----- 1 root root 233350 Sep 9 02:46 messages
~snip~
#

Get file

test04
# cat test04.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!

get messages
    Get File /var/log/messages

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

で、実行。

# robot test04.robot
==============================================================================
Test04
==============================================================================
ssh test of vyos ...
SSH to vyos is OK!
ssh test of vyos | PASS |
------------------------------------------------------------------------------
get messages | PASS |
------------------------------------------------------------------------------
Test04 | 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

# ls -l messages
~snip~
-rw-r--r-- 1 root root 233575 Sep 9 02:54 messages
~snip~
#

catなどでもきちんとファイル開けました。あ、もちろん手動でscp実行した時のファイルは消してrobot実行してますよ。

いくつか試し

宛先指定
get messages
    Get File  /var/log/messages  /tmp/tmp/

destinationの指定もOK。

ファイル名の変更も可能
get messages
    Get File  /var/log/messages  /tmp/tmp/vyos_messages

今回は割とスムーズにできた。

1
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
1
1