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