zoukankan      html  css  js  c++  java
  • 工作记录:RobotFramework后端脚本模式

    *** Settings ***
    Documentation     *Level*: 1
    ...
    ...               *Group_1*: 待定
    ...
    ...               *Group_2*: 待定
    ...
    ...               *Author*: chenjy
    ...
    ...               *Date*: 2019.05.07
    ...
    ...               *功能名称*: 全路径功能中-增加一个开关控制wss转成https
    ...
    ...               *需求链接*: https://wiki.haplat.net/pages/viewpage.action?pageId=116130416
    ...
    ...               *配置项*: proxy_ssl_fullurl_wss_to_https
    ...
    ...               *版本号*: 1.52
    ...
    ...               *测试shark子版本号*: shark-1.5.49-header_control_1.el6.x86_64
    ...
    ...               *开发人员*: 罗明明
    ...
    ...               *自测报告*: https://wiki.haplat.net/pages/viewpage.action?pageId=116130520
    ...
    ...               *测试注意点*:
    Suite Setup       Suite setup
    Suite Teardown    Suite teardown
    Test Setup        Case setup
    Test Teardown     Case teardown    ${core_begin}    ${shark_master_pid}
    Library           OperatingSystem
    Library           wsLighttpd
    Library           wsSquid
    Library           wsHttp
    Library           wsShortCut.py    127.0.0.1:3128
    Library           wsSimpleWebServer
    Variables         Globals.py
    Library           wsShark.py
    Library           BuiltIn
    Library           Collections.py
    Library           String.py
    Library           wsFileProcessing.py
    Library           otherFun
    
    *** Variables ***
    ${error_log}      /usr/local/shark/var/log/error.log
    ${core_dir}       /usr/local/shark/var/lib/tmp
    ${url}            http://aaa.aa.com/wstest/index.html
    ${add_reqheader_list}    -H 'Accept:ori.Accept' -H 'Accept-Charset:ori.Accept-Charset' -H 'Accept-Encoding:ori.Accept-Encoding' -H 'Accept-Language:ori.Accept-Language' -H 'Accept-Ranges:ori.Accept-Ranges' -H 'Authorization:ori.Authorization' -H 'Cache-Control:ori.Cache-Control' -H 'Cookie:ori.Cookie' -H 'Content-Type:ori.Content-Type' -H 'Date:Tue, 15 Nov 2011 08' -H 'Expect:ori.Expect' -H 'From:ori.From' -H 'Host:ori.Host' -H 'If-Match:ori.If-Match' -H 'If-Modified-Since:Tue, 15 Nov 2010 08' -H 'If-None-Match:ori.If-None-Match' -H 'If-Range:ori.If-Range' -H 'If-Unmodified-Since:Tue, 15 Nov 2010 08' -H 'Max-Forwards:ori.Max-Forwards' -H 'Pragma:ori.Pragma' -H 'Proxy-Authorization:ori.Proxy-Authorization' -H 'Range:ori.Range' -H 'Referer:ori.Referer' -H 'TE:ori.TE' -H 'Upgrade:ori.Upgrade' -H 'User-Agent:ori.User-Agent' -H 'Via:ori.Via' -H 'Warning:ori.Warning'
    ${add_reqheader_list_for_rnm}    -H 'Accept:ori.Accept' -H 'Accept-Charset:ori.Accept-Charset' -H 'Accept-Encoding:ori.Accept-Encoding' -H 'Accept-Language:ori.Accept-Language' -H 'Accept-Ranges:ori.Accept-Ranges' -H 'Authorization:ori.Authorization' -H 'Cache-Control:ori.Cache-Control' -H 'Cookie:ori.Cookie' -H 'Content-Type:ori.Content-Type' -H 'Date:Tue, 15 Nov 2011 08' -H 'Expect:ori.Expect' -H 'From:ori.From' -H 'Host:ori.Host' -H 'If-Match:ori.If-Match' -H 'If-Modified-Since:Tue, 15 Nov 2010 08' -H 'If-None-Match:ori.If-None-Match' -H 'If-Range:ori.If-Range' -H 'If-Unmodified-Since:Tue, 15 Nov 2010 08' -H 'Max-Forwards:ori.Max-Forwards' -H 'Pragma:ori.Pragma' -H 'Proxy-Authorization:ori.Proxy-Authorization' -H 'Range:ori.Range' -H 'Referer:ori.Referer' -H 'TE:ori.TE' -H 'Upgrade:ori.Upgrade' -H 'User-Agent:ori.User-Agent' -H 'Via:ori.Via' -H 'Warning:ori.Warning' -H 'rnm-Accept:ori2.Accept' -H 'rnm-Accept-Charset:ori2.Accept-Charset' -H 'rnm-Accept-Encoding:ori2.Accept-Encoding' -H 'rnm-Accept-Language:ori2.Accept-Language' -H 'rnm-Accept-Ranges:ori2.Accept-Ranges' -H 'rnm-Authorization:ori2.Authorization' -H 'rnm-Cache-Control:ori2.Cache-Control' -H 'rnm-Cookie:ori2.Cookie' -H 'rnm-Content-Type:ori2.Content-Type' -H 'rnm-Date:Tue, 15 Nov 2011 08' -H 'rnm-Expect:ori2.Expect' -H 'rnm-From:ori2.From' -H 'rnm-Host:ori2.Host' -H 'rnm-If-Match:ori2.If-Match' -H 'rnm-If-Modified-Since:Tue, 15 Nov 2010 08' -H 'rnm-If-None-Match:ori2.If-None-Match' -H 'rnm-If-Range:ori2.If-Range' -H 'rnm-If-Unmodified-Since:Tue, 15 Nov 2010 08' -H 'rnm-Max-Forwards:ori2.Max-Forwards' -H 'rnm-Pragma:ori2.Pragma' -H 'rnm-Proxy-Authorization:ori2.Proxy-Authorization' -H 'rnm-Range:ori2.Range' -H 'rnm-Referer:ori2.Referer' -H 'rnm-TE:ori2.TE' -H 'rnm-Upgrade:ori2.Upgrade' -H 'rnm-User-Agent:ori2.User-Agent' -H 'rnm-Via:ori2.Via' -H 'rnm-Warning:ori2.Warning'
    
    *** Test Cases ***
    01-configuration of proxy_ssl_fullurl_wss_to_https
        [Documentation]    *描述* 配置项测试:proxy_ssl_fullurl_wss_to_https    #               proxy_never_direct on;    #               proxy_select $scheme://parent.com:81;   //回父 需和上个配置[proxy_never_direct on]一起    #proxy_ssl_fullurl_wss_to_https on;    #proxy_ssl_fullurl_wss_to_https off;
        ...
        ...    *配置*
        ...    默认配置为:
        ...    proxy_ssl_fullurl on;  
        ...
        ...    *步骤*
        ...    1. start shark
        ...    2. 准备配置文件tmp.conf:
        ...    1)proxy_ssl_fullurl_wss_to_https 配置值为空;【预期:无法reload】
        ...    2)proxy_ssl_fullurl_wss_to_https 配置值为非on/off;【预期:异常,无法reload】
        ...    3)proxy_ssl_fullurl_wss_to_https配置2个,前面为on,后面为off;【预期:异常,无法reload】
        ...    4)proxy_ssl_fullurl_wss_to_https配置为off;【预期:正常】
        ...    5)proxy_ssl_fullurl_wss_to_https配置为on;【预期:正常】
        ...    3. reload shark,使用tmp.conf
        ...
        ...    *预期结果*
        ...    见步骤中
        [Tags]    _case1
        ${core_begin}    Core Cnt Is    ${core_dir}
        Comment    step 0    重新启动服务
        Start shark    bin=${SHARK BIN}    conf=${CURDIR}/shark.conf
        Comment    step 0-1    获取对应的主进程pid
        ${shark_master_pid}    Get Shark Pid    8080
        Comment    step 1    准备配置文件: proxy_ssl_fullurl_wss_to_https 配置值为空    预期:reload失败    默认配置为: proxy_ssl_fullurl on;    #proxy_ssl_fullurl_wss_to_https on; #proxy_ssl_fullurl_wss_to_https off;
        edit shark conf    ${CURDIR}/shark.conf    #proxy_ssl_fullurl_wss_to_https on;    proxy_ssl_fullurl_wss_to_https;    result_conf_path=/tmp/shark.conf
        reload shark by master pid and check status    ${shark_master_pid}    /tmp/shark.conf    ifsuccess=no
        Comment    step 2    准备配置文件: proxy_ssl_fullurl_wss_to_https 配置值为非on/off    预期:reload失败    默认配置为: proxy_ssl_fullurl on;    #proxy_ssl_fullurl_wss_to_https on; #proxy_ssl_fullurl_wss_to_https off;
        edit shark conf    ${CURDIR}/shark.conf    #proxy_ssl_fullurl_wss_to_https on;    proxy_ssl_fullurl_wss_to_https test;    result_conf_path=/tmp/shark.conf
        reload shark by master pid and check status    ${shark_master_pid}    /tmp/shark.conf    ifsuccess=no
        Comment    step 3    proxy_ssl_fullurl_wss_to_https配置2个,前面为on,后面为off    预期:reload失败    默认配置为: proxy_ssl_fullurl on;    #proxy_ssl_fullurl_wss_to_https on; #proxy_ssl_fullurl_wss_to_https off;
        edit shark conf    ${CURDIR}/shark.conf    #proxy_ssl_fullurl_wss_to_https on;    proxy_ssl_fullurl_wss_to_https on;    result_conf_path=/tmp/shark2.conf
        Run    sed 's/#proxy_ssl_fullurl_wss_to_https off;/proxy_ssl_fullurl_wss_to_https off;/g' /tmp/shark2.conf > /tmp/shark.conf
        reload shark by master pid and check status    ${shark_master_pid}    /tmp/shark.conf    ifsuccess=no
        Comment    step 4    proxy_ssl_fullurl_wss_to_https配置为off    预期:配置正常    默认配置为: proxy_ssl_fullurl on;    #proxy_ssl_fullurl_wss_to_https on; #proxy_ssl_fullurl_wss_to_https off;
        edit shark conf    ${CURDIR}/shark.conf    #proxy_ssl_fullurl_wss_to_https off;    proxy_ssl_fullurl_wss_to_https off;    result_conf_path=/tmp/shark.conf
        reload shark by master pid and check status    ${shark_master_pid}    /tmp/shark.conf    ifsuccess=yes
        Comment    step 5    proxy_ssl_fullurl_wss_to_https配置为on    预期:配置正常    默认配置为: proxy_ssl_fullurl on;    #proxy_ssl_fullurl_wss_to_https on; #proxy_ssl_fullurl_wss_to_https off;
        edit shark conf    ${CURDIR}/shark.conf    #proxy_ssl_fullurl_wss_to_https on;    proxy_ssl_fullurl_wss_to_https on;    result_conf_path=/tmp/shark.conf
        reload shark by master pid and check status    ${shark_master_pid}    /tmp/shark.conf    ifsuccess=yes
    
    02-Switch effect test
        [Documentation]    *描述* 对proxy_ssl_fullurl_wss_to_https开关效果测试    #               proxy_never_direct on;    #               proxy_select $scheme://parent.com:81;   //回父 需和上个配置[proxy_never_direct on]一起    #proxy_ssl_fullurl_wss_to_https on;    #proxy_ssl_fullurl_wss_to_https off;
        ...
        ...    *配置*
        ...    默认配置为:
        ...    proxy_ssl_fullurl on;  
        ...
        ...    *步骤*
        ...    1. start shark
        ...    2. 准备配置文件tmp.conf:
        ...    1)只配置proxy_ssl_fullurl on 【预期:websocket请求以全路径wss://xxx的形式给后端】
        ...    2)只配置proxy_ssl_fullurl_wss_to_https on【预期:websocket请求以全路径wss://xxx的形式给后端】
        ...    3)配置proxy_ssl_fullurl off;proxy_ssl_fullurl_wss_to_https on【预期:..wss://xxx的形式给后端】
        ...    4)配置proxy_ssl_fullurl on;proxy_ssl_fullurl_wss_to_https off【预期:...wss://xxx的形式给后端】
        ...    5)配置proxy_ssl_fullurl on;proxy_ssl_fullurl_wss_to_https on【预期:...https//xxx的形式给后端】
        ...
        ...    3. reload shark,使用tmp.conf
        ...
        ...    *预期结果*
        ...    见步骤中
        [Tags]    _case2
        ${core_begin}    Core Cnt Is    ${core_dir}
        Comment    step 0    重新启动服务
        Start shark    bin=${SHARK BIN}    conf=${CURDIR}/shark.conf
        Comment    step 0-1    获取对应的主进程pid
        ${shark_master_pid}    Get Shark Pid    ${shark_port}
        Comment    step 1    准备配置文件: 只配置proxy_ssl_fullurl on    预期:websocket请求以全路径wss://xxx的形式给后端    默认配置为: proxy_ssl_fullurl on;    #proxy_ssl_fullurl_wss_to_https on; #proxy_ssl_fullurl_wss_to_https off;
        Comment    #默认配置即为只配置proxy_ssl_fullurl on的场景
        do request and check tcpflow result    ${CURDIR}/_expect_websocket.sh    HTTP/1.1 200 OK    GET wss://aaa.aa.com/v1/market
        Comment    step 2    准备配置文件: 只配置proxy_ssl_fullurl_wss_to_https on    预期:关闭全路径    默认配置为: proxy_ssl_fullurl on;    #proxy_ssl_fullurl_wss_to_https on; #proxy_ssl_fullurl_wss_to_https off;
        edit shark conf    ${CURDIR}/shark.conf    #proxy_ssl_fullurl_wss_to_https on;    proxy_ssl_fullurl_wss_to_https on;    result_conf_path=${CURDIR}/tmp_shark1.conf
        edit shark conf    ${CURDIR}/tmp_shark1.conf    proxy_ssl_fullurl on;    #proxy_ssl_fullurl on;    result_conf_path=${CURDIR}/tmp_shark.conf
        reload shark by master pid and check status    ${shark_master_pid}    ${CURDIR}/tmp_shark.conf    ifsuccess=yes
        do request and check tcpflow result    ${CURDIR}/_expect_websocket.sh    HTTP/1.1 200 OK    GET /v1/market
        Comment    step 3    准备配置文件: 配置proxy_ssl_fullurl off proxy_ssl_fullurl_wss_to_https on    预期:关闭全路径    默认配置为: proxy_ssl_fullurl on;    #proxy_ssl_fullurl_wss_to_https on; #proxy_ssl_fullurl_wss_to_https off;
        edit shark conf    ${CURDIR}/shark.conf    #proxy_ssl_fullurl_wss_to_https on;    proxy_ssl_fullurl_wss_to_https on;    result_conf_path=${CURDIR}/tmp_shark1.conf
        edit shark conf    ${CURDIR}/tmp_shark1.conf    proxy_ssl_fullurl on;    proxy_ssl_fullurl off;    result_conf_path=${CURDIR}/tmp_shark.conf
        reload shark by master pid and check status    ${shark_master_pid}    ${CURDIR}/tmp_shark.conf    ifsuccess=yes
        do request and check tcpflow result    ${CURDIR}/_expect_websocket.sh    HTTP/1.1 200 OK    GET /v1/market
        Comment    step 4    准备配置文件: 配置proxy_ssl_fullurl on proxy_ssl_fullurl_wss_to_https off    预期:全路径打开,websocket请求以全路径wss://xxx的形式给后端    默认配置为: proxy_ssl_fullurl on;    #proxy_ssl_fullurl_wss_to_https on; #proxy_ssl_fullurl_wss_to_https off;
        edit shark conf    ${CURDIR}/shark.conf    #proxy_ssl_fullurl_wss_to_https on;    proxy_ssl_fullurl_wss_to_https off;    result_conf_path=${CURDIR}/tmp_shark.conf
        reload shark by master pid and check status    ${shark_master_pid}    ${CURDIR}/tmp_shark.conf    ifsuccess=yes
        do request and check tcpflow result    ${CURDIR}/_expect_websocket.sh    HTTP/1.1 200 OK    GET wss://aaa.aa.com/v1/market
        Comment    step 5    准备配置文件: 配置proxy_ssl_fullurl on proxy_ssl_fullurl_wss_to_https off    预期:websocket请求以全路径https://xxx的形式给后端    默认配置为: proxy_ssl_fullurl on;    #proxy_ssl_fullurl_wss_to_https on; #proxy_ssl_fullurl_wss_to_https off;
        edit shark conf    ${CURDIR}/shark.conf    #proxy_ssl_fullurl_wss_to_https on;    proxy_ssl_fullurl_wss_to_https on;    result_conf_path=${CURDIR}/tmp_shark.conf
        reload shark by master pid and check status    ${shark_master_pid}    ${CURDIR}/tmp_shark.conf    ifsuccess=yes
        do request and check tcpflow result    ${CURDIR}/_expect_websocket.sh    HTTP/1.1 200 OK    GET https://aaa.aa.com/v1/market
    
    03-http/server/location model test
        [Documentation]    *描述* 将proxy_ssl_fullurl_wss_to_https配置在http/server/location区域测试    #               proxy_never_direct on;    #               proxy_select $scheme://parent.com:81;   //回父 需和上个配置[proxy_never_direct on]一起
        ...
        ...    *配置*
        ...    默认配置为:
        ...    proxy_ssl_fullurl on;   proxy_ssl_fullurl_wss_to_https on;
        ...
        ...    *步骤*
        ...    1. start shark
        ...    2. 准备配置文件tmp.conf:
        ...    1)配置在http区域:proxy_ssl_fullurl_wss_to_https on【预期:...https//xxx的形式给后端】
        ...    2)配置在server区域:proxy_ssl_fullurl_wss_to_https on【预期:...https//xxx的形式给后端】
        ...    3)配置在location区域:proxy_ssl_fullurl_wss_to_https on【预期:...https//xxx的形式给后端】
        ...    4)http区域配置为on,server区域配置为on,location区域配置为off【预期:...wss//xxx的形式给后端】
        ...    5)http区域配置为on,server区域配置为off,location区域配置为on【预期:...https//xxx的形式给后端】
        ...    3. reload shark,使用tmp.conf
        ...
        ...    *预期结果*
        ...    见步骤中
        [Tags]    _case3
        ${core_begin}    Core Cnt Is    ${core_dir}
        Comment    step 0    重新启动服务
        Start shark    bin=${SHARK BIN}    conf=${CURDIR}/shark.conf
        Comment    step 0-1    获取对应的主进程pid
        ${shark_master_pid}    Get Shark Pid    ${shark_port}
        Comment    step 1    将proxy_ssl_fullurl_wss_to_https on配置在http区域    预期:生效
        reload shark by master pid and check status    ${shark_master_pid}    ${CURDIR}/_3_1http_shark.conf    ifsuccess=yes
        do request and check tcpflow result    ${CURDIR}/_expect_websocket.sh    HTTP/1.1 200 OK    GET https://aaa.aa.com/v1/market
        Comment    step 2    将proxy_ssl_fullurl_wss_to_https on配置在server区域    预期:生效
        reload shark by master pid and check status    ${shark_master_pid}    ${CURDIR}/_3_2server_shark.conf    ifsuccess=yes
        do request and check tcpflow result    ${CURDIR}/_expect_websocket.sh    HTTP/1.1 200 OK    GET https://aaa.aa.com/v1/market
        Comment    step 3    将proxy_ssl_fullurl_wss_to_https on配置在location区域    预期:生效
        reload shark by master pid and check status    ${shark_master_pid}    ${CURDIR}/_3_3location_shark.conf    ifsuccess=yes
        do request and check tcpflow result    ${CURDIR}/_expect_websocket.sh    HTTP/1.1 200 OK    GET https://aaa.aa.com/v1/market
        Comment    step 4    优先级测试:  http区域配置为on,server区域配置为on,location区域配置为off    【预期:location区域的配置生效    ...wss//xxx的形式给后端】
        reload shark by master pid and check status    ${shark_master_pid}    ${CURDIR}/_3_4shark.conf    ifsuccess=yes
        do request and check tcpflow result    ${CURDIR}/_expect_websocket.sh    HTTP/1.1 200 OK    GET wss://aaa.aa.com/v1/market
        Comment    step 5    优先级测试:  http区域配置为on,server区域配置为off,location区域配置为on    【预期:location区域的配置生效    ...https//xxx的形式给后端】
        reload shark by master pid and check status    ${shark_master_pid}    ${CURDIR}/_3_5shark.conf    ifsuccess=yes
        do request and check tcpflow result    ${CURDIR}/_expect_websocket.sh    HTTP/1.1 200 OK    GET https://aaa.aa.com/v1/market
    
    04-other request
        [Documentation]    *描述* proxy_ssl_fullurl_wss_to_https开关效果不影响其它非wss请求    #               proxy_never_direct on;    #               proxy_select $scheme://parent.com:81;   //回父 需和上个配置[proxy_never_direct on]一起    #proxy_ssl_fullurl_wss_to_https on;    #proxy_ssl_fullurl_wss_to_https off;
        ...
        ...    *配置*
        ...    默认配置为:
        ...    proxy_ssl_fullurl on;  
        ...
        ...    *步骤*
        ...    1. start shark
        ...    2. 准备配置文件tmp.conf:
        ...    1)发起http请求【预期:...http//xxx的形式给后端】
        ...    2)发起https请求【预期:...https//xxx的形式给后端】
        ...
        ...    3. reload shark,使用tmp.conf
        ...
        ...    *预期结果*
        ...    见步骤中
        [Tags]    _case4
        ${core_begin}    Core Cnt Is    ${core_dir}
        Comment    step 0    重新启动服务
        Start shark    bin=${SHARK BIN}    conf=${CURDIR}/shark.conf
        Comment    step 0-1    获取对应的主进程pid
        ${shark_master_pid}    Get Shark Pid    ${shark_port}
        Comment    step 1    准备配置文件: 配置proxy_ssl_fullurl on proxy_ssl_fullurl_wss_to_https on    默认配置为: proxy_ssl_fullurl on;    #proxy_ssl_fullurl_wss_to_https on; #proxy_ssl_fullurl_wss_to_https off;
        edit shark conf    ${CURDIR}/shark.conf    #proxy_ssl_fullurl_wss_to_https on;    proxy_ssl_fullurl_wss_to_https on;    result_conf_path=${CURDIR}/tmp_shark.conf
        reload shark by master pid and check status    ${shark_master_pid}    ${CURDIR}/tmp_shark.conf    ifsuccess=yes
        Comment    step 2    发起https请求    预期:https://形式
        do request and check tcpflow result    ${CURDIR}/_expect_https.sh    HTTP/1.1 200 OK    GET https://aaa.aa.com/v1/market
        Comment    step 3    发起http请求    预期:http://形式
        do request and check tcpflow result    ${CURDIR}/_expect_http.sh    HTTP/1.1 200 OK    GET /v1/market
        Comment    step 4    发起post请求    预期:https://形式
        do request and check tcpflow result    ${CURDIR}/_expect_http.sh    HTTP/1.1 200 OK    POST https://aaa.aa.com/v1/market
    
    09-check memory leak
        [Documentation]    *描述* 请求头部改写_内存泄露检查
        ...
        ...    *配置*
        [Tags]    _memory_leak    _case9
        ${core_begin}    Core Cnt Is    ${core_dir}
        Start shark    bin=${SHARK BIN}    conf=${CURDIR}/shark.conf
        ${shark_master_pid}    Get Shark Pid    8080
        Round memory test shark    Round one    Round one    Round one    10
    
    *** Keywords ***
    Suite setup
        Ntpdate Time
        Stop process by port    8080
        Stop process by port    80
        Stop process by port    3128
        Remove directory    /www/wstest    recursive=True
        Copy directory    ${CURDIR}/wstest    /www/
        Set http proxy    127.0.0.1:8080
        Stop shark
        #hosts文件
        copy file    /etc/hosts    /etc/hosts.bk
        copy file    ${CURDIR}/_hosts    /etc/hosts
        Set Suite Variable    ${shark_port}    8080
    
    Suite teardown
        Comment    Stop shark
        #hosts文件
        copy file    /etc/hosts.bk    /etc/hosts
        Ntpdate Time
    
    Case setup
        Stop shark
    
    Case teardown
        [Arguments]    ${cnt1}    ${shark_master_pid}
        Core Should Be    ${cnt1}    ${core_dir}
        Run keyword if    '''${shark_master_pid}''' != '''${EMPTY}'''    Check shark pid    ${shark_master_pid}
    
    Stop process by port
        [Arguments]    ${port}
        [Documentation]    **描述** **关闭端口占用进程**
        RUN    netstat -tlnp | grep ':${port}' | awk '{print $7}' | awk -F '/' '{print $1}' | xargs echo | xargs kill
    
    Round one
        RUN    ab -n1000 -c50 -X 127.1:8080 ${url}
    
    start tcpflow
        [Arguments]    ${port}    ${tcpflow_result}=/tmp/tmp_tcpflow    # 抓包的端口|抓包结果报错的文件路径
        [Documentation]    *说明*  tcpflow抓包,并将抓包结果报错到指定文件中
        clear tcpflow result    ${tcpflow_result}
        log    ${port}
        ${process_count_1}    Run    ps -ef|grep tcpflow|grep -v grep|grep ${port}|wc -l
        Run    nohup tcpflow -i any -c port ${port} > ${tcpflow_result} 2>&1 &
        Wait Until Keyword Succeeds    5    0.5    check if equal    ps -ef|grep tcpflow|grep -v grep|grep ${port}|wc -l    ${process_count_1}    if_equal=no
    
    stop tcpflow by port
        [Arguments]    ${port}
        [Documentation]    *说明* 通过端口过来tcpflow进程,进程kill
        ...
        ...    *参数说明* port 端口
        log    ${port}
        ${process_count_1}    Run    ps -ef|grep tcpflow|grep -v grep|grep ${port}|wc -l
        Comment    step 1    根据端口过来出进程号后,执行kill进程的操作
        Run    ps -ef|grep tcpflow|grep -v grep|grep ${port}|awk -F ' ' '{print $2}'|xargs kill -9
        Comment    step 2    校验是否关闭
        Wait Until Keyword Succeeds    5    0.5    check if equal    ps -ef|grep tcpflow|grep -v grep|grep ${port}|wc -l    0    if_equal=yes
    
    clear tcpflow result
        [Arguments]    ${tcpflow_result}
        Run    >${tcpflow_result}
    
    reload shark by master pid and check status
        [Arguments]    ${master_pid}    ${new_conf_path}    ${ifsuccess}=yes    ${method}=req_hdr_ctrl    # 启动服务的配置文件路径|新的启动服务的配置文件路径|预期成果或者失败|操作名
        [Documentation]    *说明*  kill -HUP ${master_pid}的方式重载shark的配置
        ...
        ...    *参数说明*  ifsuccess: yes/no
        Comment    step 0-3    获取配置文件内容,方便排查问题时查看
        Run    cp -rf ${new_conf_path} /tmp/shark.conf
        Ws Get File Content    /tmp/shark.conf    #获取配置文件内容,方便排查问题时查看
        Comment    step 1    获取主进程号和子进程号,且不应为空
        ${child_pid}    run    ps -ef|grep shark|grep ${master_pid}|grep -v 'shark: master process'|grep -v grep|awk -F ' ' '{print $2}'
        should not be empty    ${master_pid}
        should not be empty    ${child_pid}
        Comment    step 2    执行reload操作
        Ws Restart Redirect Log    ${error_log}    /tmp/tmp_error.log
        run    kill -HUP ${master_pid}
        Ws Wait Until File Is Not Empty    /tmp/tmp_error.log    5    1
        Ws Get File Content    /tmp/tmp_error.log    #获取配置文件内容,方便排查问题时查看
        Comment    step 3    校验reload是否生效    生效条件:1.子进程的Pid更新2.日志出现gracefully shutting down    reload失败:error.log含有reconfigure fail    #只校验子进程更新会失败
        Run Keyword If    '${ifsuccess}'=='yes'    Wait Until Keyword Succeeds    5    1    check if equal    ps -ef|grep ${master_pid}|grep -v 'shark: master process'|grep -v grep|awk -F ' ' '{print $2}'
        ...    ${child_pid}    if_equal=no    #成功的情况下校验子进程号更新
        Run Keyword If    '${ifsuccess}'=='yes'    Ws Wait Until File Contain Keyword    /tmp/tmp_error.log    gracefully shutting down    1    5
        ...    1    #成功的情况下校验errorlog日志中含有gracefully shutting down
        Run Keyword If    '${ifsuccess}'=='no'    Ws Wait Until File Contain Keyword    /tmp/tmp_error.log    reconfigure fail    1    5
        ...    1    #失败的情况下校验日志中有reconfigure fail
        Run Keyword If    '${ifsuccess}'!='no' and '${ifsuccess}'!='yes'    Run Keywords    log    [ifsuccess] 应输入[yes]或者[no]    AND    FAIL
        Comment    step 4    停止重定向errlog操作
        Ws Stop Redirect Log    ${error_log}
    
    check if equal
        [Arguments]    ${cmd_line}    ${expect_result}    ${if_equal}=yes    # ${if_equal}:yes/no
        [Documentation]    *说明* 校验命令执行结果是否和期望的相当
        ...
        ...    *参数说明*  cmd_line:命令; expect_result:期望的结果;if_equal:yes/no
        Log    ${cmd_line}
        Log    ${expect_result}
        ${cmd_result}    Run    ${cmd_line}
        Run Keyword If    '${if_equal}'=='yes'    Should Be Equal    ${cmd_result}    ${expect_result}    ELSE IF    '${if_equal}'=='no'
        ...    Should Not Be Equal    ${cmd_result}    ${expect_result}    ELSE    log    [if_equal]should input yes/no
    
    edit shark conf
        [Arguments]    ${conf_path}    ${old_value}    ${new_value}    ${result_conf_path}=/tmp/shark.conf
        [Documentation]    *说明*   简单的修改shark配置文件操作,sed实现
        Comment    step 1    执行修改操作
        Run    cp -rf ${conf_path} /tmp/shark1.conf
        Run    sed 's/${old_value}/${new_value}/g' /tmp/shark1.conf > ${result_conf_path}
        Comment    Comment    step 2    校验修改是否完成
        Comment    Wait Until Keyword Succeeds    3    1    check if equal    cat ${result_conf_path}|grep '${old_value}'|wc -l    0
        ...    if_equal=yes    #校验旧值不存在
        Comment    Wait Until Keyword Succeeds    3    1    check if equal    cat ${result_conf_path}|grep '${new_value}'|wc -l    0
        ...    if_equal=no    #校验新值存在
    
    do request and check tcpflow result
        [Arguments]    ${expectfile}    ${check_expect_status}    ${check_tcpflow_result}
        [Documentation]    *描述*  发起webscoket请求,过程进行抓包,并对抓包结果校验是否含有指定的关键字
        Comment    step 1-2    开始抓包
        start tcpflow    ${shark_port}    /tmp/tmp_tcpflow
        Comment    step 1-3    发起websocket请求并校验请求的结果
        ${result}    Run    expect ${expectfile}
        log    ${result}
        Should Contain    ${result}    ${check_expect_status}
        Comment    step 1-4    停止抓包
        stop tcpflow by port    ${shark_port}
        Comment    step 1-5    抓包结果校验
        ${tcpflow_result}    Ws Get File Content    /tmp/tmp_tcpflow
        Should Contain    ${tcpflow_result}    ${check_tcpflow_result}
    View Code
    每天努力一点,每天学习一点。 Keep Moving...
  • 相关阅读:
    apue 第19章 伪终端
    apue 第18章 终端I/O
    linux IPC socket(2)
    linux IPC socket
    linux POSIX信号量
    【Luogu】【关卡2-16】线性动态规划(2017年10月)【还差三道题】
    【Luogu】【关卡2-15】动态规划的背包问题(2017年10月)【还差一道题】
    【Luogu】【关卡2-14】 树形数据结构(2017年10月)【AK】
    【Luogu】【关卡2-13】线性数据结构(2017年10月)【还差一道题】
    【Luogu】【关卡2-12】递推与递归二分(2017年10月)
  • 原文地址:https://www.cnblogs.com/channy14/p/11542542.html
Copyright © 2011-2022 走看看