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