Upgrade RF syntax for v3.2 compatibility
[integration/test.git] / csit / libraries / SFC / DockerSfc.robot
1 *** Settings ***
2 Library           SSHLibrary
3 Resource          ../../variables/netvirt/Variables.robot
4
5 *** Variables ***
6
7 *** Keywords ***
8 Docker Ovs Start
9     [Arguments]    ${nodes}    ${guests}    ${tunnel}    ${odl_ip}    ${log_file}=myFile2.log
10     [Documentation]    Run the docker-ovs.sh script with specific input arguments. Run ./docker-ovs.sh --help for more info.
11     ${result}    SSHLibrary.Execute Command    ./docker-ovs.sh spawn --nodes=${nodes} --guests=${guests} --tun=${tunnel} --odl=${odl_ip} > >(tee ${log_file}) 2> >(tee ${log_file})    return_stderr=True    return_stdout=True    return_rc=True
12     log    ${result}
13     Should be equal as integers    ${result[2]}    0
14
15 Docker Ovs Clean
16     [Arguments]    ${log_file}=myFile3.log
17     [Documentation]    Run the docker-ovs.sh script with --clean option to clean up all containers deployment. Run ./docker-ovs.sh --help for more info.
18     ${result}    SSHLibrary.Execute Command    ./docker-ovs.sh clean > >(tee ${log_file}) 2> >(tee ${log_file})    return_stderr=True    return_stdout=True    return_rc=True
19     log    ${result}
20     Should be equal as integers    ${result[2]}    0
21
22 Get Docker Ids
23     [Documentation]    Execute command docker ps and retrieve the existing containers ids
24     ${output}    ${rc}    SSHLibrary.Execute Command    sudo docker ps -q -a    return_stdout=True    return_stderr=False    return_rc=True
25     Should Be Equal As Numbers    ${rc}    0
26     [Return]    ${output}
27
28 Get Docker Ids Formatted
29     [Arguments]    ${format}
30     [Documentation]    Execute command docker ps with --format argument and retrieve the existing containers names
31     ${output}    ${rc}    SSHLibrary.Execute Command    sudo docker ps -a --format ${format}    return_stdout=True    return_stderr=False    return_rc=True
32     Should Be Equal As Numbers    ${rc}    0
33     [Return]    ${output}
34
35 Get Docker Names As List
36     [Documentation]    Returns a list with the names of all running containers inside the tools system
37     ${docker_ps}=    DockerSfc.Get Docker Ids Formatted    "{{.Names}}" -f status=running
38     ${docker_name_list}=    Split String    ${docker_ps}    \n
39     [Return]    ${docker_name_list}
40
41 Get Docker IP
42     [Arguments]    ${docker_name}
43     [Documentation]    Obtain the IP address from a given container
44     ${output}    ${rc}    SSHLibrary.Execute Command    sudo docker inspect -f '{{.NetworkSettings.IPAddress }}' ${docker_name}    return_stdout=True    return_stderr=False    return_rc=True
45     Should Be Equal As Numbers    ${rc}    0
46     [Return]    ${output}
47
48 Docker Exec
49     [Arguments]    ${docker_name}    ${command}    ${return_contains}=${EMPTY}    ${result_code}=0
50     [Documentation]    Execute a command into a docker container.
51     ${output}    ${rc}    SSHLibrary.Execute Command    sudo docker exec ${docker_name} ${command}    return_stdout=True    return_stderr=False    return_rc=True
52     Run Keyword If    '${return_contains}'!='${EMPTY}'    Should Contain    ${output}    ${return_contains}
53     Should Be Equal As Numbers    ${rc}    ${result_code}
54     [Return]    ${output}
55
56 Multiple Docker Exec
57     [Arguments]    ${docker_name_list}    ${command}    ${return_contains}=${EMPTY}    ${result_code}=0
58     [Documentation]    Execute a command in a list of dockers and return all the outputs in a list
59     @{list_output}=    Create List
60     FOR    ${docker_id}    IN    @{docker_name_list}
61         ${exec_output}=    Docker Exec    ${docker_id}    ${command}    ${return_contains}    ${result_code}
62         Append To List    ${list_output}    ${exec_output}
63     END
64     [Return]    ${list_output}
65
66 Get Flows In Docker Containers
67     ${docker_list}=    DockerSfc.Get Docker Names As List
68     ${docker_flows}    DockerSfc.Multiple Docker Exec    ${docker_list}    ovs-ofctl dump-flows -OOpenflow13 ${INTEGRATION_BRIDGE}    OFPST_FLOW
69     [Return]    ${docker_flows}
70
71 Get Docker Bridge Subnet
72     [Documentation]    Obtain the subnet used by docker bridge using the docker inspect tool
73     ${output}    ${rc}    SSHLibrary.Execute Command    sudo docker network inspect bridge --format {{.IPAM.Config}} | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}[\/][0-9]{1,2}"    return_stdout=True    return_stderr=False    return_rc=True
74     Should Be Equal As Numbers    ${rc}    0
75     [Return]    ${output}