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