go.ligato.io/vpp-agent/v3@v3.5.0/tests/robot/libraries/docker.robot (about)

     1  [Documentation] Keywords for ssh sessions
     2  
     3  *** Settings ***
     4  Library       Collections
     5  Library       RequestsLibrary
     6  Library       SSHLibrary            timeout=15s    loglevel=TRACE
     7  Library       DateTime
     8  
     9  Resource      vat_term.robot
    10  
    11  *** Variables ***
    12  ${timeout_etcd}=      30s
    13  ${timeout_agent}=     20s
    14  
    15  *** Keywords ***
    16  Add Agent Node
    17      [Arguments]    ${node}
    18      Open SSH Connection    ${node}    ${DOCKER_HOST_IP}    ${DOCKER_HOST_USER}    ${DOCKER_HOST_PSWD}
    19      Execute On Machine     ${node}    ${DOCKER_COMMAND} create -e MICROSERVICE_LABEL=${node} -e KAFKA_CONFIG=disabled --sysctl net.ipv6.conf.all.disable_ipv6=0 -it -p ${${node}_REST_API_HOST_PORT}:${${node}_REST_API_PORT} --name ${node} ${${node}_DOCKER_IMAGE} bash
    20      #Execute On Machine     ${node}    ${DOCKER_COMMAND} create -e MICROSERVICE_LABEL=${node} -it -p ${${node}_PING_HOST_PORT}:${${node}_PING_PORT} -p ${${node}_REST_API_HOST_PORT}:${${node}_REST_API_PORT} --name ${node} ${${node}_DOCKER_IMAGE}
    21      Write To Machine       ${node}    ${DOCKER_COMMAND} start ${node}
    22      Append To List    ${NODES}    ${node}
    23      Create Session    ${node}    http://${DOCKER_HOST_IP}:${${node}_REST_API_HOST_PORT}
    24      ${hostname}=    Execute On Machine    docker    ${DOCKER_COMMAND} exec ${node} bash -c 'echo $HOSTNAME'
    25      Set Suite Variable    ${${node}_HOSTNAME}    ${hostname}
    26  
    27  Add Agent Node Again
    28      [Arguments]    ${node}
    29      Open SSH Connection    ${node}_again    ${DOCKER_HOST_IP}    ${DOCKER_HOST_USER}    ${DOCKER_HOST_PSWD}
    30      Execute On Machine     ${node}_again    ${DOCKER_COMMAND} create -e MICROSERVICE_LABEL=${node} -e KAFKA_CONFIG=disabled --sysctl net.ipv6.conf.all.disable_ipv6=0 -it -p ${${node}_AGAIN_REST_API_HOST_PORT}:${${node}_AGAIN_REST_API_PORT} --name ${node}_again ${${node}_DOCKER_IMAGE} bash
    31      #Execute On Machine     ${node}    ${DOCKER_COMMAND} create -e MICROSERVICE_LABEL=${node} -it -p ${${node}_PING_HOST_PORT}:${${node}_PING_PORT} -p ${${node}_REST_API_HOST_PORT}:${${node}_REST_API_PORT} --name ${node} ${${node}_DOCKER_IMAGE}
    32      Write To Machine       ${node}_again    ${DOCKER_COMMAND} start ${node}_again
    33      Append To List    ${NODES}    ${node}_again
    34      Create Session    ${node}_again    http://${DOCKER_HOST_IP}:${${node}_REST_API_HOST_PORT}
    35      ${hostname}=    Execute On Machine    docker    ${DOCKER_COMMAND} exec ${node} bash -c 'echo $HOSTNAME'
    36      Set Suite Variable    ${${node}_again_HOSTNAME}    ${hostname}
    37  
    38  Add Agent VPP Node
    39      [Arguments]    ${node}    ${vswitch}=${FALSE}
    40      ${add_params}=    Set Variable If    ${vswitch}    --pid=host -v "/var/run/docker.sock:/var/run/docker.sock"    ${EMPTY}
    41      Open SSH Connection    ${node}    ${DOCKER_HOST_IP}    ${DOCKER_HOST_USER}    ${DOCKER_HOST_PSWD}
    42      Execute On Machine     ${node}    ${DOCKER_COMMAND} create -e MICROSERVICE_LABEL=${node} -e KAFKA_CONFIG=disabled -e VPP_STATUS_PUBLISHERS=etcd -e INITIAL_LOGLVL=debug -e START_TIMEOUT=${timeout_agent} --sysctl net.ipv6.conf.all.disable_ipv6=0 -it --privileged -v "${VPP_AGENT_HOST_MEMIF_SOCKET_FOLDER}:${${node}_MEMIF_SOCKET_FOLDER}" -v "${DOCKER_SOCKET_FOLDER}:${${node}_SOCKET_FOLDER}" -p ${${node}_VPP_HOST_PORT}:${${node}_VPP_PORT} -p ${${node}_REST_API_HOST_PORT}:${${node}_REST_API_PORT} --name ${node} ${add_params} ${${node}_DOCKER_IMAGE}
    43      Write To Machine       ${node}    ${DOCKER_COMMAND} start ${node}
    44      Append To List    ${NODES}    ${node}
    45      Open SSH Connection    ${node}_term    ${DOCKER_HOST_IP}    ${DOCKER_HOST_USER}    ${DOCKER_HOST_PSWD}
    46      Open SSH Connection    ${node}_vat    ${DOCKER_HOST_IP}    ${DOCKER_HOST_USER}    ${DOCKER_HOST_PSWD}
    47      vpp_term: Open VPP Terminal    ${node}
    48      #TODO: do not open VAT terminal once we don't need it anymore
    49      vat_term: Open VAT Terminal    ${node}
    50      Create Session    ${node}    http://${DOCKER_HOST_IP}:${${node}_REST_API_HOST_PORT}
    51      ${hostname}=    Execute On Machine    docker    ${DOCKER_COMMAND} exec ${node} bash -c 'echo $HOSTNAME'
    52      Set Suite Variable    ${${node}_HOSTNAME}    ${hostname}
    53      Execute On Machine    docker    docker cp ${DOCKER_PAPI_FOLDER}/vpp_api_executor.py ${node}:${${node}_PAPI_FOLDER}/vpp_api_executor.py
    54  
    55  Add Agent VPP Node With Own Vpp Config
    56      [Arguments]    ${node}    ${vpp_conf_file}    ${vswitch}=${FALSE}
    57      ${add_params}=    Set Variable If    ${vswitch}    --pid=host -v "/var/run/docker.sock:/var/run/docker.sock"    ${EMPTY}
    58      Open SSH Connection    ${node}    ${DOCKER_HOST_IP}    ${DOCKER_HOST_USER}    ${DOCKER_HOST_PSWD}
    59      Execute On Machine     ${node}    ${DOCKER_COMMAND} create -e MICROSERVICE_LABEL=${node} -e KAFKA_CONFIG=disabled -e VPP_STATUS_PUBLISHERS=etcd -e INITIAL_LOGLVL=debug -e START_TIMEOUT=${timeout_agent} --sysctl net.ipv6.conf.all.disable_ipv6=0 -it --privileged -v "${VPP_AGENT_HOST_MEMIF_SOCKET_FOLDER}:${${node}_MEMIF_SOCKET_FOLDER}" -v "${DOCKER_SOCKET_FOLDER}:${${node}_SOCKET_FOLDER}" -p ${${node}_VPP_HOST_PORT}:${${node}_VPP_PORT} -p ${${node}_REST_API_HOST_PORT}:${${node}_REST_API_PORT} --name ${node} ${add_params} ${${node}_DOCKER_IMAGE}
    60      ${data}=               OperatingSystem.Get File      ${CURDIR}/../resources/${vpp_conf_file}
    61      Create File            ${RESULTS_FOLDER}/vpp-${node}.conf    ${data}
    62      Create File            ${RESULTS_FOLDER_SUITE}/vpp-${node}.conf    ${data}
    63      Execute On Machine     ${node}    touch ${vpp_conf_file}
    64      Execute On Machine     ${node}    ${data}
    65      Execute On Machine     ${node}    ${DOCKER_COMMAND} cp ${vpp_conf_file} ${node}:${VPP_CONF_PATH}
    66      Execute On Machine     ${node}    rm ${vpp_conf_file}
    67      Write To Machine       ${node}    ${DOCKER_COMMAND} start ${node}
    68      Append To List    ${NODES}    ${node}
    69      Open SSH Connection    ${node}_term    ${DOCKER_HOST_IP}    ${DOCKER_HOST_USER}    ${DOCKER_HOST_PSWD}
    70      Open SSH Connection    ${node}_vat    ${DOCKER_HOST_IP}    ${DOCKER_HOST_USER}    ${DOCKER_HOST_PSWD}
    71      vpp_term: Open VPP Terminal    ${node}
    72      vat_term: Open VAT Terminal    ${node}
    73      Create Session    ${node}    http://${DOCKER_HOST_IP}:${${node}_REST_API_HOST_PORT}
    74      ${hostname}=    Execute On Machine    docker    ${DOCKER_COMMAND} exec ${node} bash -c 'echo $HOSTNAME'
    75      Set Suite Variable    ${${node}_HOSTNAME}    ${hostname}
    76      Execute On Machine    docker    docker cp ${DOCKER_PAPI_FOLDER}/vpp_api_executor.py ${node}:${${node}_PAPI_FOLDER}/vpp_api_executor.py
    77  
    78  Add Agent Libmemif Node
    79      [Arguments]    ${node}
    80      Open SSH Connection    ${node}    ${DOCKER_HOST_IP}    ${DOCKER_HOST_USER}    ${DOCKER_HOST_PSWD}
    81      Execute On Machine     ${node}    ${DOCKER_COMMAND} create -e MICROSERVICE_LABEL=${node} -e KAFKA_CONFIG=disabled --sysctl net.ipv6.conf.all.disable_ipv6=0 -it --privileged -v "${VPP_AGENT_HOST_MEMIF_SOCKET_FOLDER}:${${node}_MEMIF_SOCKET_FOLDER}" --name ${node} ${${node}_DOCKER_IMAGE} /bin/bash
    82      Write To Machine       ${node}    ${DOCKER_COMMAND} start ${node}
    83      Append To List    ${NODES}    ${node}
    84      #${hostname}=    Execute On Machine    docker    ${DOCKER_COMMAND} exec ${node} bash -c 'echo $HOSTNAME'
    85      Sleep     3s
    86      ${hostname}=    Execute On Machine    docker    ${DOCKER_COMMAND} exec ${node} bash -c 'echo $HOSTNAME'
    87      Set Suite Variable    ${${node}_HOSTNAME}    ${hostname}
    88      Open SSH Connection    ${node}_lmterm    ${DOCKER_HOST_IP}    ${DOCKER_HOST_USER}    ${DOCKER_HOST_PSWD}
    89      lmterm: Open LM Terminal    ${node}
    90  
    91  Add Agent VPP Node With Physical Int
    92      [Arguments]    ${node}    ${int_nums}    ${vswitch}=${FALSE}
    93      ${add_params}=    Set Variable If    ${vswitch}    --pid=host -v "/var/run/docker.sock:/var/run/docker.sock"    ${EMPTY}
    94      Open SSH Connection    ${node}    ${DOCKER_HOST_IP}    ${DOCKER_HOST_USER}    ${DOCKER_HOST_PSWD}
    95      Execute On Machine     ${node}    ${DOCKER_COMMAND} create -e MICROSERVICE_LABEL=${node} -e KAFKA_CONFIG=disabled -e START_TIMEOUT=${timeout_agent} --sysctl net.ipv6.conf.all.disable_ipv6=0 -it --privileged -v "${DOCKER_SOCKET_FOLDER}:${${node}_SOCKET_FOLDER}" -p ${${node}_VPP_HOST_PORT}:${${node}_VPP_PORT} -p ${${node}_REST_API_HOST_PORT}:${${node}_REST_API_PORT} --name ${node} ${add_params}  ${${node}_DOCKER_IMAGE}
    96      ${devs}=               Set Variable    ${EMPTY}
    97      :FOR    ${int_num}    IN    @{int_nums}
    98      \    ${devs}=    Set Variable    ${devs}${\n}dev ${DOCKER_PHYSICAL_INT_${int_num}}
    99      ${data}=               OperatingSystem.Get File      ${CURDIR}/../resources/vpp_physical_int.conf
   100      ${data}=               Replace Variables             ${data}
   101      Create File            ${RESULTS_FOLDER}/vpp-${node}.conf    ${data}
   102      Create File            ${RESULTS_FOLDER_SUITE}/vpp-${node}.conf    ${data}
   103      Execute On Machine     ${node}    ${DOCKER_COMMAND} cp ${EXECDIR}/${RESULTS_FOLDER}/vpp-${node}.conf ${node}:${VPP_CONF_PATH}
   104      Execute On Machine     ${node}    ${DOCKER_COMMAND} cp ${EXECDIR}/${RESULTS_FOLDER_SUITE}/vpp-${node}.conf ${node}:${VPP_CONF_PATH}
   105      Write To Machine       ${node}    ${DOCKER_COMMAND} start ${node}
   106      Append To List    ${NODES}    ${node}
   107      Open SSH Connection    ${node}_term    ${DOCKER_HOST_IP}    ${DOCKER_HOST_USER}    ${DOCKER_HOST_PSWD}
   108      Open SSH Connection    ${node}_vat    ${DOCKER_HOST_IP}    ${DOCKER_HOST_USER}    ${DOCKER_HOST_PSWD}
   109      vpp_term: Open VPP Terminal    ${node}
   110      vat_term: Open VAT Terminal    ${node}
   111      Create Session    ${node}    http://${DOCKER_HOST_IP}:${${node}_REST_API_HOST_PORT}
   112      ${hostname}=    Execute On Machine    docker    ${DOCKER_COMMAND} exec ${node} bash -c 'echo $HOSTNAME'
   113      Set Suite Variable    ${${node}_HOSTNAME}    ${hostname}
   114      Execute On Machine    docker    docker cp ${DOCKER_PAPI_FOLDER}/vpp_api_executor.py ${node}:${${node}_PAPI_FOLDER}/vpp_api_executor.py
   115  
   116  Remove All Nodes
   117      :FOR    ${id}    IN    @{NODES}
   118      \    Remove Node    ${id}
   119      Execute On Machine    docker    ${DOCKER_COMMAND} ps -as
   120  
   121  Remove All VPP Nodes
   122      :FOR    ${id}    IN    @{NODES}
   123      \   Run Keyword If    "vpp" in "${id}"       Remove Node    ${id}
   124      Execute On Machine    docker    ${DOCKER_COMMAND} ps -as
   125  
   126  Remove Node
   127      [Arguments]    ${node}
   128      ${log}=    Execute On Machine    docker    ${DOCKER_COMMAND} logs --details -t ${node}    log=false
   129      Append To File    ${RESULTS_FOLDER}/output_${node}_container_agent.log    ${log}
   130      Append To File    ${RESULTS_FOLDER_SUITE}/output_${node}_container_agent.log    ${log}
   131      Switch Connection    ${node}
   132      Close Connection
   133      Run Keyword If    "vpp" in "${node}"    Remove VPP Connections    ${node}
   134      Run Keyword If    "libmemif" in "${node}"    Remove LM Connections    ${node}
   135      Remove Values From List    ${NODES}    ${node}
   136      Execute On Machine    docker    ${DOCKER_COMMAND} rm -f ${node}
   137  
   138  Remove VPP Connections
   139      [Arguments]    ${node}
   140      Switch Connection    ${node}_term
   141      Close Connection
   142      Switch Connection    ${node}_vat
   143      Close Connection
   144  
   145  Remove LM Connections
   146      [Arguments]    ${node}
   147      Switch Connection    ${node}_lmterm
   148      Close Connection
   149  
   150  Check ETCD Running
   151      ${out}=   Write To Machine    docker     ${DOCKER_COMMAND} exec -it etcd etcdctl version
   152      Should Contain     ${out}    etcdctl version:
   153      [Return]           ${out}
   154  
   155  Start ETCD Server
   156      Open SSH Connection    etcd    ${DOCKER_HOST_IP}    ${DOCKER_HOST_USER}    ${DOCKER_HOST_PSWD}
   157      Execute On Machine    etcd    ${ETCD_SERVER_CREATE}
   158      ${out}=  Write To Machine Until String    etcd    ${DOCKER_COMMAND} start -i etcd    ready to serve client requests
   159  #    ${hostname}=    Execute On Machine    docker    ${DOCKER_COMMAND} exec etcd bash -c 'echo $HOSTNAME'
   160  #   etcd nema bash, preto dame hostname natvrdo
   161      ${hostname}=    Set Variable    etcd
   162      Set Suite Variable    ${ETCD_HOSTNAME}    ${hostname}
   163      wait until keyword succeeds    ${timeout_etcd}   5s   Check ETCD Running
   164  
   165  Stop ETCD Server
   166      Execute On Machine    docker    ${ETCD_SERVER_DESTROY}
   167  
   168  Execute In Container
   169      [Arguments]              ${container}       ${command}
   170      Switch Connection        docker
   171      ${currdate}=             Get Current Date
   172      Append To File           ${RESULTS_FOLDER}/output_${container}.log    *** Time:${currdate} Command: ${command}${\n}
   173      Append To File           ${RESULTS_FOLDER_SUITE}/output_${container}.log    *** Time:${currdate} Command: ${command}${\n}
   174      ${out}  ${stderr}  ${rc}=      Execute Command    ${DOCKER_COMMAND} exec ${container} ${command}    return_stderr=True    return_rc=True
   175      ${status}=               Run Keyword And Return Status    Should be Empty    ${stderr}
   176      Run Keyword If           ${status}==False         Log     One or more error occured during execution of a command ${command} in container ${container}    level=WARN
   177      Append To File           ${RESULTS_FOLDER}/output_${container}.log    *** Time:${currdate} Response: ${out}${\n}***
   178      Append To File           ${RESULTS_FOLDER_SUITE}/output_${container}.log    *** Time:${currdate} Response: ${out}${\n}***
   179      Run Keyword If           ${status}==False         Append To File           ${RESULTS_FOLDER}/output_${container}.log      *** Error: ${stderr}${\n}
   180      Run Keyword If           ${status}==False         Append To File           ${RESULTS_FOLDER_SUITE}/output_${container}.log      *** Error: ${stderr}${\n}
   181      [Return]                 ${out}
   182  
   183  Execute In Container Background
   184      [Arguments]              ${container}       ${command}
   185      Switch Connection        docker
   186      ${currdate}=             Get Current Date
   187      Append To File           ${RESULTS_FOLDER}/output_${container}.log    *** Time:${currdate} Command: ${command}${\n}
   188      Append To File           ${RESULTS_FOLDER_SUITE}/output_${container}.log    *** Time:${currdate} Command: ${command}${\n}
   189      ${out}   ${stderr}=      Execute Command    ${DOCKER_COMMAND} exec -d ${container} ${command}    return_stderr=True
   190      ${status}=               Run Keyword And Return Status    Should be Empty    ${stderr}
   191      Run Keyword If           ${status}==False         Log     One or more error occured during execution of a command ${command} in container ${container}    level=WARN
   192      Append To File           ${RESULTS_FOLDER}/output_${container}.log    *** Time:${currdate} Response: ${out}${\n}
   193      Append To File           ${RESULTS_FOLDER_SUITE}/output_${container}.log    *** Time:${currdate} response: ${out}${\n}
   194      Run Keyword If           ${status}==False         Append To File           ${RESULTS_FOLDER}/output_${container}.log      *** Error: ${stderr}${\n}
   195      Run Keyword If           ${status}==False         Append To File           ${RESULTS_FOLDER_SUITE}/output_${container}.log      *** Error: ${stderr}${\n}
   196      [Return]                 ${out}
   197  
   198  Write To Container Until Prompt
   199     [Arguments]              ${container}               ${command}               ${prompt}=root@    ${delay}=${SSH_READ_DELAY}
   200     [Documentation]          *Write Container ${container} ${command}*
   201     ...                      Writing ${command} to connection with name ${container} and reading until prompt
   202     ...                      Output log is added to container output log
   203     Switch Connection        ${container}
   204     ${currdate}=             Get Current Date
   205     Append To File           ${RESULTS_FOLDER}/output_${container}.log    *** Time:${currdate} Command: ${command}${\n}
   206     Append To File           ${RESULTS_FOLDER_SUITE}/output_${container}.log    *** Time:${currdate} Command: ${command}${\n}
   207     Write                    ${command}
   208     ${out}=                  Read Until    ${prompt}${${container}_HOSTNAME}    loglevel=TRACE
   209     ${out2}=                 Read          loglevel=TRACE           delay=${delay}
   210     Append To File           ${RESULTS_FOLDER}/output_${container}.log    *** Time:${currdate} Response: ${out}${out2}${\n}
   211     Append To File           ${RESULTS_FOLDER_SUITE}/output_${container}.log    *** Time:${currdate} Response: ${out}${out2}${\n}
   212     [Return]                 ${out}${out2}
   213  
   214  Write Command to Container
   215     [Arguments]              ${container}      ${command}       ${delay}=${SSH_READ_DELAY}
   216     [Documentation]          *Write Container ${container} ${command}*
   217     ...                      Writing ${command} to connection with name ${container} and reading output
   218     ...                      Output log is added to container output log
   219     Switch Connection        ${container}
   220     ${currdate}=             Get Current Date
   221     Append To File           ${RESULTS_FOLDER}/output_${container}.log    *** Time:${currdate} Command: ${command}${\n}
   222     Append To File           ${RESULTS_FOLDER_SUITE}/output_${container}.log    *** Time:${currdate} Command: ${command}${\n}
   223     ${written}=              Write        ${command}
   224     ${out}=                  Read        loglevel=TRACE    delay=${delay}
   225     Should Not Contain       ${out}     ${written}               # Was consumed from the output
   226     ${out2}=                 Read        loglevel=TRACE    delay=${delay}
   227     Append To File           ${RESULTS_FOLDER}/output_${container}.log    *** Time:${currdate} Response: ${out}${out2}${\n}
   228     Append To File           ${RESULTS_FOLDER_SUITE}/output_${container}.log    *** Time:${currdate} Response: ${out}${out2}${\n}
   229     [Return]                 ${out}${out2}
   230  
   231  
   232  Start Dev Container
   233      [Arguments]            ${command}=bash
   234      Open SSH Connection    dev    ${DOCKER_HOST_IP}    ${DOCKER_HOST_USER}    ${DOCKER_HOST_PSWD}
   235      Execute On Machine     dev    ${DOCKER_COMMAND} create -it --name dev -e KAFKA_CONFIG=disabled --privileged ${DEV_IMAGE} ${command}
   236      Write To Machine       dev    ${DOCKER_COMMAND} start -i dev
   237      Switch Connection      dev
   238      Set Client Configuration    timeout=600s
   239      ${hostname}=           Execute On Machine    docker    ${DOCKER_COMMAND} exec dev bash -c 'echo $HOSTNAME'
   240      Set Suite Variable     ${DEV_HOSTNAME}    ${hostname}
   241  
   242  Stop Dev Container
   243      Execute On Machine    docker    ${DOCKER_COMMAND} rm -f dev
   244  
   245  Update Agent In Dev Container
   246      Write To Container Until Prompt    dev    cd $GOPATH/src/gitlab.cisco.com/ctao/vnf-agent
   247      Write To Container Until Prompt    dev    git pull
   248      Write To Container Until Prompt    dev    make
   249      Write To Container Until Prompt    dev    make install
   250  
   251  Start SFC Controller Container With Own Config
   252      [Arguments]            ${config}
   253      Open SSH Connection    sfc_controller    ${DOCKER_HOST_IP}    ${DOCKER_HOST_USER}    ${DOCKER_HOST_PSWD}
   254      Execute On Machine     sfc_controller    ${DOCKER_COMMAND} create -it --name sfc_controller ${SFC_CONTROLLER_IMAGE_NAME}
   255      SSHLibrary.Put_file    ${DATA_FOLDER}/${config}	    /tmp/
   256      Execute On Machine     sfc_controller    ${DOCKER_COMMAND} cp /tmp/${config} sfc_controller:${SFC_CONTROLLER_CONF_PATH}
   257      Write To Machine       sfc_controller    ${DOCKER_COMMAND} start -i sfc_controller
   258      ${hostname}=           Execute On Machine    docker    ${DOCKER_COMMAND} exec sfc_controller sh -c 'echo $HOSTNAME'
   259      Set Suite Variable     ${SFC_CONTROLLER_HOSTNAME}    ${hostname}
   260  
   261  Stop SFC Controller Container
   262      Execute On Machine    docker    ${DOCKER_COMMAND} rm -f sfc_controller