Update Robot Framework format - step 11
[integration/test.git] / csit / suites / netvirt / snatdnat / snat_dnat.robot
1 *** Settings ***
2 Documentation       Test suite to validate network address translation(snat/dnat) functionality in openstack integrated environment.
3 ...                 All the testcases were written to do flow validation since dc gateway is unavailable in csit environment.
4 ...                 This suite assumes proper integration bridges and vxlan tunnels are configured in the environment.
5
6 Library             Collections
7 Library             RequestsLibrary
8 Library             SSHLibrary
9 Library             String
10 Resource            ../../../libraries/BgpOperations.robot
11 Resource            ../../../libraries/OpenStackOperations.robot
12 Resource            ../../../libraries/SetupUtils.robot
13 Resource            ../../../libraries/Tcpdump.robot
14 Resource            ../../../libraries/Utils.robot
15 Resource            ../../../libraries/VpnOperations.robot
16 Resource            ../../../variables/Variables.robot
17 Resource            ../../../variables/netvirt/Variables.robot
18
19 Suite Setup         Suite Setup
20 Suite Teardown      Stop Suite
21 Test Setup          SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
22 Test Teardown       OpenStackOperations.Get Test Teardown Debugs
23
24
25 *** Variables ***
26 ${SECURITY_GROUP}           nat_sg
27 ${NETWORK_TYPE}             gre
28 ${SNAT_ENABLED}             "enable_snat": true
29 ${SNAT_DISABLED}            "enable_snat": false
30 ${ROUTER}                   nat_router
31 ${AS_ID}                    100
32 ${DCGW_SYSTEM_IP}           ${TOOLS_SYSTEM_1_IP}
33 ${LOOPBACK_IP}              5.5.5.2
34 ${DCGW_RD}                  100:1
35 ${VPN_NAME}                 vpn_1
36 ${VPN_INSTANCE_ID}          4ae8cd92-48ca-49b5-94e1-b2921a261442
37 ${ExtIP}                    100.100.100.24
38 @{NETWORKS}                 nat_net_1    nat_net_2
39 @{EXTERNAL_NETWORKS}        nat_ext_11    nat_ext_22
40 @{EXTERNAL_SUB_NETWORKS}    nat_ext_sub_net_1    nat_ext_sub_net_2
41 @{SUBNETS}                  nat_sub_net_1    nat_sub_net_2
42 @{SUBNET_CIDRS}             10.1.1.0/24    20.1.1.0/24
43 @{EXT_SUBNET_CIDRS}         100.100.100.0/24    200.200.200.0/24
44 @{PORTS}                    nat_port_1    nat_port_2    nat_port_3    nat_port_4
45 @{NET_1_VMS}                nat_net_1_vm_1    nat_net_1_vm_2    nat_net_1_vm_3    nat_net_1_vm_4
46
47
48 *** Test Cases ***
49 Verify Successful Creation Of External Network With Router External Set To TRUE
50     [Documentation]    Create external network,enable snat on router and validate the same.
51     OpenStackOperations.Add Router Gateway    ${ROUTER}    ${EXTERNAL_NETWORKS}[0]    --enable-snat
52     ${output} =    OpenStackOperations.Show Router    ${ROUTER}
53     BuiltIn.Should Contain    ${output}    ${SNAT_ENABLED}
54     ${output} =    OpenStackOperations.Show Network    ${EXTERNAL_NETWORKS}[0]
55     BuiltIn.Should Contain    ${output}    ${EXTERNAL_NETWORKS}[0]
56
57 Verify Successful Update Of Router With External_gateway_info, Disable SNAT And Enable SNAT
58     [Documentation]    Disable snat, enable snat and validate the same.
59     OpenStackOperations.Add Router Gateway    ${ROUTER}    ${EXTERNAL_NETWORKS}[0]    --disable-snat
60     ${output} =    OpenStackOperations.Show Router    ${ROUTER}
61     BuiltIn.Should Contain    ${output}    ${SNAT_DISABLED}
62     OpenStackOperations.Add Router Gateway    ${ROUTER}    ${EXTERNAL_NETWORKS}[0]    --enable-snat
63     ${output} =    OpenStackOperations.Show Router    ${ROUTER}
64     BuiltIn.Should Contain    ${output}    ${SNAT_ENABLED}
65
66 Verify Successful Deletion Of External Network
67     [Documentation]    Delete the external network and validate the same.
68     OpenStackOperations.Remove Gateway    ${ROUTER}
69     ${output} =    OpenStackOperations.Show Router    ${ROUTER}
70     BuiltIn.Should Not Contain    ${output}    ${SNAT_ENABLED}
71
72 Verify Floating Ip Provision And Reachability From External Network Via Neutron Router Through L3vpn
73     [Documentation]    Check floating IP should be present in dump flows after creating the floating IP and associating it to external network
74     ...    which is associated to L3VPN
75     VpnOperations.VPN Create L3VPN
76     ...    vpnid=${VPN_INSTANCE_ID}
77     ...    name=${VPN_NAME}
78     ...    rd=["${DCGW_RD}"]
79     ...    exportrt=["${DCGW_RD}"]
80     ...    importrt=["${DCGW_RD}"]
81     ${ext_net_id} =    OpenStackOperations.Get Net Id    ${EXTERNAL_NETWORKS}[0]
82     VpnOperations.Associate L3VPN To Network    networkid=${ext_net_id}    vpnid=${VPN_INSTANCE_ID}
83     OpenStackOperations.Add Router Gateway    ${ROUTER}    ${EXTERNAL_NETWORKS}[0]    --disable-snat
84     ${output} =    OpenStackOperations.Show Router    ${ROUTER}
85     BuiltIn.Should Contain    ${output}    ${SNAT_DISABLED}
86     ${subnetid} =    OpenStackOperations.Get Subnet Id    ${EXTERNAL_SUB_NETWORKS}[0]
87     OpenStackOperations.Add Router Gateway
88     ...    ${ROUTER}
89     ...    ${EXTERNAL_NETWORKS}[0]
90     ...    --fixed-ip subnet=${subnetid},ip-address=${ExtIP}
91     ${float} =    OpenStackOperations.Create And Associate Floating IPs    ${EXTERNAL_NETWORKS}[0]    ${NET_1_VMS}[0]
92     ${float} =    BuiltIn.Set Variable    ${float}[0]
93     @{matching_paras} =    BuiltIn.Create List    nw_dst=${float}    goto_table:${DNAT_TABLE}
94     BuiltIn.Wait Until Keyword Succeeds
95     ...    10s
96     ...    5s
97     ...    OVSDB.Verify Dump Flows For Specific Table
98     ...    ${OS_CMP1_IP}
99     ...    ${PDNAT_TABLE}
100     ...    True
101     ...    ${EMPTY}
102     ...    @{matching_paras}
103     @{matching_paras} =    BuiltIn.Create List    actions=set_field:${float}    goto_table:${SNAT_TABLE}
104     BuiltIn.Wait Until Keyword Succeeds
105     ...    10s
106     ...    5s
107     ...    OVSDB.Verify Dump Flows For Specific Table
108     ...    ${OS_CMP1_IP}
109     ...    ${PSNAT_TABLE}
110     ...    True
111     ...    ${EMPTY}
112     ...    @{matching_paras}
113
114 Verify Floating Ip De-provision And Reachability From External Network Via Neutron Router Through L3vpn
115     [Documentation]    Check floating IP should not be present in dump flows after deleting the floating IP
116     ...    and removing the external gateway from router which is associated to L3VPN
117     OpenStackOperations.Get ControlNode Connection
118     ${output} =    OpenStackOperations.OpenStack CLI    openstack floating ip list |awk '{print$2}'
119     ${floating_id} =    BuiltIn.Should Match Regexp
120     ...    ${output}
121     ...    [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}
122     OpenStackOperations.Delete Floating IP    ${floating_id}
123     OpenStackOperations.Remove Gateway    ${ROUTER}
124     ${output} =    OVSDB.Get Flow Entries On Node    ${OS_CMP1_CONN_ID}
125     BuiltIn.Should Not Contain    ${output}    ${ExtIP}
126
127 Verify Floating Ip Re-provision And Reachability From External Network Via Neutron Router Through L3vpn
128     [Documentation]    Check floating IP should be present in dump flows after creating the floating IP again wnd associating it to external network
129     ...    which is associated to L3VPN
130     ${subnetid} =    OpenStackOperations.Get Subnet Id    ${EXTERNAL_SUB_NETWORKS}[0]
131     OpenStackOperations.Add Router Gateway
132     ...    ${ROUTER}
133     ...    ${EXTERNAL_NETWORKS}[0]
134     ...    --fixed-ip subnet=${subnetid},ip-address=${ExtIP}
135     ${float} =    OpenStackOperations.Create And Associate Floating IPs    ${EXTERNAL_NETWORKS}[0]    ${NET_1_VMS}[0]
136     ${float} =    BuiltIn.Set Variable    ${float}[0]
137     @{matching_paras} =    BuiltIn.Create List    nw_dst=${float}    goto_table:${DNAT_TABLE}
138     BuiltIn.Wait Until Keyword Succeeds
139     ...    10s
140     ...    5s
141     ...    OVSDB.Verify Dump Flows For Specific Table
142     ...    ${OS_CMP1_IP}
143     ...    ${PDNAT_TABLE}
144     ...    True
145     ...    ${EMPTY}
146     ...    @{matching_paras}
147     @{matching_paras} =    BuiltIn.Create List    actions=set_field:${float}    goto_table:${SNAT_TABLE}
148     BuiltIn.Wait Until Keyword Succeeds
149     ...    10s
150     ...    5s
151     ...    OVSDB.Verify Dump Flows For Specific Table
152     ...    ${OS_CMP1_IP}
153     ...    ${PSNAT_TABLE}
154     ...    True
155     ...    ${EMPTY}
156     ...    @{matching_paras}
157
158 Verify Multiple Floating Ip Creation and Association to external network
159     [Documentation]    Check Multiple floating IPs should be present in dump flows after creating multiple floating IPs and associating it to external network
160     ...    which is associated to L3VPN
161     ${subnetid} =    OpenStackOperations.Get Subnet Id    ${EXTERNAL_SUB_NETWORKS}[0]
162     OpenStackOperations.Add Router Gateway
163     ...    ${ROUTER}
164     ...    ${EXTERNAL_NETWORKS}[0]
165     ...    --fixed-ip subnet=${subnetid},ip-address=${ExtIP}
166     ${FloatIp1} =    OpenStackOperations.Create And Associate Floating IPs
167     ...    ${EXTERNAL_NETWORKS}[0]
168     ...    ${NET_1_VMS}[1]
169     ${FloatIp2} =    OpenStackOperations.Create And Associate Floating IPs
170     ...    ${EXTERNAL_NETWORKS}[0]
171     ...    ${NET_1_VMS}[2]
172     ${FloatIp3} =    OpenStackOperations.Create And Associate Floating IPs
173     ...    ${EXTERNAL_NETWORKS}[0]
174     ...    ${NET_1_VMS}[3]
175     ${output} =    OVSDB.Get Flow Entries On Node    ${OS_CMP2_CONN_ID}
176     BuiltIn.Should Match Regexp    ${output}    ${ExtIP}
177     BuiltIn.Should Match Regexp    ${output}    .*${FloatIp1}.*
178     BuiltIn.Should Match Regexp    ${output}    .*${FloatIp2}.*
179     BuiltIn.Should Match Regexp    ${output}    .*${FloatIp3}.*
180
181
182 *** Keywords ***
183 Suite Setup
184     [Documentation]    Test Suite for Subnet_Routing_and_Multicast_Deployments.
185     VpnOperations.Basic Suite Setup
186     BgpOperations.Start Quagga Processes On ODL    ${ODL_SYSTEM_IP}
187     BgpOperations.Start Quagga Processes On DCGW    ${DCGW_SYSTEM_IP}
188     Create Setup
189     OpenStackOperations.Show Debugs    @{NET_1_VMS}
190     OpenStackOperations.Get Suite Debugs
191
192 Create Setup
193     Create Neutron Networks
194     Create Neutron Subnets
195     OpenStackOperations.Create SubNet
196     ...    ${EXTERNAL_NETWORKS}[0]
197     ...    ${EXTERNAL_SUB_NETWORKS}[0]
198     ...    ${EXT_SUBNET_CIDRS}[0]
199     OpenStackOperations.Create Allow All SecurityGroup    ${SECURITY_GROUP}
200     Create Neutron Ports
201     Create Nova VMs
202     BgpOperations.Setup BGP Peering On ODL    ${ODL_SYSTEM_IP}    ${AS_ID}    ${DCGW_SYSTEM_IP}
203     BgpOperations.Setup BGP Peering On DCGW
204     ...    ${DCGW_SYSTEM_IP}
205     ...    ${AS_ID}
206     ...    ${ODL_SYSTEM_IP}
207     ...    ${VPN_NAME}
208     ...    ${DCGW_RD}
209     ...    ${LOOPBACK_IP}
210     OpenStackOperations.Create Router    ${ROUTER}
211     OpenStackOperations.Add Router Interface    ${ROUTER}    ${SUBNETS}[0]
212     OpenStackOperations.Add Router Interface    ${ROUTER}    ${SUBNETS}[1]
213
214 Create Neutron Networks
215     [Documentation]    Create required number of networks
216     FOR    ${NET}    IN    @{NETWORKS}
217         OpenStackOperations.Create Network    ${NET}
218     END
219     OpenStackOperations.Create Network    ${EXTERNAL_NETWORKS}[0]    --external --provider-network-type ${NETWORK_TYPE}
220     BuiltIn.Wait Until Keyword Succeeds    3s    1s    Utils.Check For Elements At URI    ${NETWORK_URL}    ${NETWORKS}
221
222 Create Neutron Subnets
223     [Documentation]    Create required number of subnets for previously created networks
224     ${num_of_networks} =    BuiltIn.Get Length    ${NETWORKS}
225     FOR    ${index}    IN RANGE    0    ${num_of_networks}
226         OpenStackOperations.Create SubNet    ${NETWORKS}[${index}]    ${SUBNETS}[${index}]    ${SUBNET_CIDRS}[${index}]
227     END
228     BuiltIn.Wait Until Keyword Succeeds
229     ...    3s
230     ...    1s
231     ...    Utils.Check For Elements At URI
232     ...    ${SUBNETWORK_URL}
233     ...    ${SUBNETS}
234
235 Create Neutron Ports
236     [Documentation]    Create required number of ports under previously created subnets
237     OpenStackOperations.Create Port    ${NETWORKS}[0]    ${PORTS}[0]    sg=${SECURITY_GROUP}
238     OpenStackOperations.Create Port    ${NETWORKS}[0]    ${PORTS}[1]    sg=${SECURITY_GROUP}
239     OpenStackOperations.Create Port    ${NETWORKS}[1]    ${PORTS}[2]    sg=${SECURITY_GROUP}
240     OpenStackOperations.Create Port    ${NETWORKS}[1]    ${PORTS}[3]    sg=${SECURITY_GROUP}
241     BuiltIn.Wait Until Keyword Succeeds
242     ...    3s
243     ...    1s
244     ...    Utils.Check For Elements At URI
245     ...    ${CONFIG_API}/neutron:neutron/ports/
246     ...    ${PORTS}
247
248 Create Nova VMs
249     [Documentation]    Create Vm instances on compute nodes
250     OpenStackOperations.Create Vm Instance With Port On Compute Node
251     ...    ${PORTS}[0]
252     ...    ${NET_1_VMS}[0]
253     ...    ${OS_CMP1_HOSTNAME}
254     ...    sg=${SECURITY_GROUP}
255     OpenStackOperations.Create Vm Instance With Port On Compute Node
256     ...    ${PORTS}[1]
257     ...    ${NET_1_VMS}[1]
258     ...    ${OS_CMP2_HOSTNAME}
259     ...    sg=${SECURITY_GROUP}
260     OpenStackOperations.Create Vm Instance With Port On Compute Node
261     ...    ${PORTS}[2]
262     ...    ${NET_1_VMS}[2]
263     ...    ${OS_CMP1_HOSTNAME}
264     ...    sg=${SECURITY_GROUP}
265     OpenStackOperations.Create Vm Instance With Port On Compute Node
266     ...    ${PORTS}[3]
267     ...    ${NET_1_VMS}[3]
268     ...    ${OS_CMP2_HOSTNAME}
269     ...    sg=${SECURITY_GROUP}
270     @{NET_1_VM_IPS}    ${NET_1_DHCP_IP} =    OpenStackOperations.Get VM IPs    @{NET_1_VMS}
271     BuiltIn.Set Suite Variable    @{NET_1_VM_IPS}
272     BuiltIn.Should Not Contain    ${NET_1_VM_IPS}    None
273     BuiltIn.Should Not Contain    ${NET_1_DHCP_IP}    None
274
275 Stop Suite
276     [Documentation]    Test teardown for snat suite.
277     BgpOperations.Delete BGP Configuration On ODL    session
278     BgpOperations.Delete BGP Config On Quagga    ${DCGW_SYSTEM_IP}    ${AS_ID}
279     BgpOperations.Stop BGP Processes On Node    ${ODL_SYSTEM_IP}
280     BgpOperations.Stop BGP Processes On Node    ${DCGW_SYSTEM_IP}
281     OpenStackOperations.OpenStack Suite Teardown