Robot Framework 사용해보기①

5708 단어 centos7robotframework

배경



네트워크 기기의 시험 자동화를 향해 할 수밖에 없었다.
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 *** 에서 스칼라 변수를 정의하기만 하면 됩니다.
    log.html도 보기 쉽다.


    키워드를 정의 할 수있는 것 같습니다.



    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
    #
    

    다음 번에는 원격 호스트에서 명령 실행을 시도합시다.

    좋은 웹페이지 즐겨찾기