Use openstack cli instead of nova console-log cli
[integration/test.git] / csit / suites / openstack / extensions / sfc.robot
1 *** Settings ***
2 Documentation     Test suite to verify SFC configuration and packet flows.
3 Suite Setup       BuiltIn.Run Keywords    SetupUtils.Setup_Utils_For_Setup_And_Teardown
4 ...               AND    DevstackUtils.Devstack Suite Setup
5 Suite Teardown    BuiltIn.Run Keywords    Delete Configurations
6 ...               AND    Close All Connections
7 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
8 Test Teardown     Get Test Teardown Debugs
9 Library           SSHLibrary
10 Library           OperatingSystem
11 Library           RequestsLibrary
12 Resource          ../../../libraries/DevstackUtils.robot
13 Resource          ../../../libraries/OpenStackOperations.robot
14 Resource          ../../../libraries/SetupUtils.robot
15 Resource          ../../../libraries/Utils.robot
16 Resource          ../../../libraries/KarafKeywords.robot
17
18 *** Variables ***
19 ${SECURITY_GROUP}    sg-sfc
20 @{NETWORKS_NAME}    network_1
21 @{SUBNETS_NAME}    l2_subnet_1
22 @{VM_INSTANCES}    sf1    sf2    sf3    source_vm    dest_vm
23 @{SUBNETS_RANGE}    30.0.0.0/24
24 @{PORTS}          p1in    p1out    p2in    p2out    p3in    p3out    source_vm_port
25 ...               dest_vm_port
26
27 *** Test Cases ***
28 Create VXLAN Network (network_1)
29     [Documentation]    Create Network with neutron request.
30     Create Network    @{NETWORKS_NAME}[0]
31
32 Create Subnets For network_1
33     [Documentation]    Create Sub Nets for the Networks with neutron request.
34     Create SubNet    @{NETWORKS_NAME}[0]    @{SUBNETS_NAME}[0]    @{SUBNETS_RANGE}[0]
35
36 Add Allow All Rules
37     [Documentation]    Allow all TCP/UDP/ICMP packets for this suite
38     OpenStackOperations.Create Allow All SecurityGroup    ${SECURITY_GROUP}
39
40 Create Neutron Ports
41     [Documentation]    Precreate neutron ports to be used for SFC VMs
42     : FOR    ${port}    IN    @{PORTS}
43     \    Create Port    @{NETWORKS_NAME}[0]    ${port}    sg=${SECURITY_GROUP}
44
45 Create Vm Instances
46     [Documentation]    Create Four Vm instances using flavor and image names for a network.
47     Create Vm Instance With Ports    p1in    p1out    sf1    sg=${SECURITY_GROUP}
48     Create Vm Instance With Ports    p2in    p2out    sf2    sg=${SECURITY_GROUP}
49     Create Vm Instance With Ports    p3in    p3out    sf3    sg=${SECURITY_GROUP}
50     Create Vm Instance With Port    source_vm_port    source_vm    sg=${SECURITY_GROUP}
51     Create Vm Instance With Port    dest_vm_port    dest_vm    sg=${SECURITY_GROUP}
52
53 Check Vm Instances Have Ip Address
54     [Documentation]    Test case to verify that all created VMs are ready and have received their ip addresses.
55     ...    We are polling first and longest on the last VM created assuming that if it's received it's address
56     ...    already the other instances should have theirs already or at least shortly thereafter.
57     # first, ensure all VMs are in ACTIVE state.    if not, we can just fail the test case and not waste time polling
58     # for dhcp addresses
59     : FOR    ${vm}    IN    @{VM_INSTANCES}
60     \    Poll VM Is ACTIVE    ${vm}
61     ${status}    ${message}    Run Keyword And Ignore Error    Wait Until Keyword Succeeds    60s    5s    Collect VM IP Addresses
62     ...    true    @{VM_INSTANCES}
63     ${NET1_VM_IPS}    ${NET1_DHCP_IP}    Collect VM IP Addresses    false    @{VM_INSTANCES}
64     ${VM_INSTANCES}=    Collections.Combine Lists    ${VM_INSTANCES}
65     ${VM_IPS}=    Collections.Combine Lists    ${NET1_VM_IPS}
66     ${LOOP_COUNT}    Get Length    ${VM_INSTANCES}
67     : FOR    ${index}    IN RANGE    0    ${LOOP_COUNT}
68     \    ${status}    ${message}    Run Keyword And Ignore Error    Should Not Contain    @{VM_IPS}[${index}]    None
69     \    Run Keyword If    '${status}' == 'FAIL'    Write Commands Until Prompt    openstack console log show @{VM_INSTANCES}[${index}]    30s
70     Set Suite Variable    ${NET1_VM_IPS}
71     Should Not Contain    ${NET1_VM_IPS}    None
72     Should Not Contain    ${NET1_DHCP_IP}    None
73     [Teardown]    Run Keywords    Show Debugs    @{VM_INSTANCES}
74     ...    AND    Get Test Teardown Debugs
75
76 Create Flow Classifiers
77     [Documentation]    Create SFC Flow Classifier for TCP traffic between source VM and destination VM
78     Create SFC Flow Classifier    FC_http    @{NET1_VM_IPS}[3]    @{NET1_VM_IPS}[4]    tcp    80    source_vm_port
79
80 Create Port Pairs
81     [Documentation]    Create SFC Port Pairs
82     Create SFC Port Pair    PP1    p1in    p1out
83     Create SFC Port Pair    PP2    p2in    p2out
84     Create SFC Port Pair    PP3    p3in    p3out
85
86 Create Port Pair Groups
87     [Documentation]    Create SFC Port Pair Groups
88     Create SFC Port Pair Group With Two Pairs    PG1    PP1    PP2
89     Create SFC Port Pair Group    PG2    PP3
90
91 Create Port Chain
92     [Documentation]    Create SFC Port Chain using two port groups an classifier created previously
93     Create SFC Port Chain    PC1    PG1    PG2    FC_http
94
95 Start Web Server On Destination VM
96     [Documentation]    Start a simple web server on the destination VM
97     Execute Command on VM Instance    @{NETWORKS_NAME}[0]    @{NET1_VM_IPS}[4]    while true; do echo -e "HTTP/1.0 200 OK\r\nContent-Length: 21\r\n\r\nWelcome to web-server" | sudo nc -l -p 80 ; done &
98
99 Add Static Routing On Service Function VMs
100     [Documentation]    Enable eth1 and add static routing between the ports on the SF VMs
101     : FOR    ${INDEX}    IN RANGE    0    2
102     \    Execute Command on VM Instance    @{NETWORKS_NAME}[0]    @{NET1_VM_IPS}[${INDEX}]    sudo sh -c 'echo "auto eth1" >> /etc/network/interfaces'
103     \    Execute Command on VM Instance    @{NETWORKS_NAME}[0]    @{NET1_VM_IPS}[${INDEX}]    sudo sh -c 'echo "iface eth1 inet dhcp" >> /etc/network/interfaces'
104     \    Execute Command on VM Instance    @{NETWORKS_NAME}[0]    @{NET1_VM_IPS}[${INDEX}]    sudo /etc/init.d/S40network restart
105     \    Execute Command on VM Instance    @{NETWORKS_NAME}[0]    @{NET1_VM_IPS}[${INDEX}]    sudo sh -c 'echo 1 > /proc/sys/net/ipv4/ip_forward'
106     \    Execute Command on VM Instance    @{NETWORKS_NAME}[0]    @{NET1_VM_IPS}[${INDEX}]    sudo ip route add @{NET1_VM_IPS}[3] dev eth0
107     \    Execute Command on VM Instance    @{NETWORKS_NAME}[0]    @{NET1_VM_IPS}[${INDEX}]    sudo ip route add @{NET1_VM_IPS}[4] dev eth1
108
109 Connectivity Tests From Vm Instance1 In network_1
110     [Documentation]    Login to the source VM instance, and send a HTTP GET using curl to the destination VM instance
111     # FIXME need to somehow verify it goes through SFs (flows?)
112     ${DEST_VM_LIST}    Create List    @{NET1_VM_IPS}[4]
113     Test Operations From Vm Instance    network_1    @{NET1_VM_IPS}[3]    ${DEST_VM_LIST}
114     Execute Command on VM Instance    @{NETWORKS_NAME}[0]    @{NET1_VM_IPS}[3]    curl http://@{NET1_VM_IPS}[4]
115
116 *** Keywords ***
117 Delete Configurations
118     [Documentation]    Delete all elements that were created in the test case section. These are done
119     ...    in a local keyword so this can be called as part of the Suite Teardown. When called as part
120     ...    of the Suite Teardown, all steps will be attempted. This prevents robot framework from bailing
121     ...    on the rest of a test case if one step intermittently has trouble and fails. The goal is to attempt
122     ...    to leave the test environment as clean as possible upon completion of this suite.
123     : FOR    ${VmElement}    IN    @{VM_INSTANCES}
124     \    Delete Vm Instance    ${VmElement}
125     Delete SFC Port Chain    PC1
126     Delete SFC Port Pair Group    PG1
127     Delete SFC Port Pair Group    PG2
128     Delete SFC Port Pair    PP1
129     Delete SFC Port Pair    PP2
130     Delete SFC Port Pair    PP3
131     Delete SFC Flow Classifier    FC_http
132     : FOR    ${port}    IN    @{PORTS}
133     \    Delete Port    ${port}
134     Delete SubNet    l2_subnet_1
135     : FOR    ${NetworkElement}    IN    @{NETWORKS_NAME}
136     \    Delete Network    ${NetworkElement}