Replace Start Suite with Suite Setup
[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 Suite Setup       Suite Setup
6 Suite Teardown    Stop Suite
7 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
8 Test Teardown     OpenStackOperations.Get Test Teardown Debugs
9 Library           Collections
10 Library           RequestsLibrary
11 Library           SSHLibrary
12 Library           String
13 Resource          ../../../libraries/BgpOperations.robot
14 Resource          ../../../libraries/OpenStackOperations.robot
15 Resource          ../../../libraries/SetupUtils.robot
16 Resource          ../../../libraries/Tcpdump.robot
17 Resource          ../../../libraries/Utils.robot
18 Resource          ../../../libraries/VpnOperations.robot
19 Resource          ../../../variables/Variables.robot
20 Resource          ../../../variables/netvirt/Variables.robot
21
22 *** Variables ***
23 ${SECURITY_GROUP}    nat_sg
24 ${NETWORK_TYPE}    gre
25 ${SNAT_ENABLED}    "enable_snat": true
26 ${SNAT_DISABLED}    "enable_snat": false
27 ${ROUTER}         nat_router
28 ${AS_ID}          100
29 ${DCGW_SYSTEM_IP}    ${TOOLS_SYSTEM_1_IP}
30 ${LOOPBACK_IP}    5.5.5.2
31 ${DCGW_RD}        100:1
32 ${VPN_NAME}       vpn_1
33 ${VPN_INSTANCE_ID}    4ae8cd92-48ca-49b5-94e1-b2921a261442
34 ${FIP}            100.100.100.24
35 @{NETWORKS}       nat_net_1    nat_net_2
36 @{EXTERNAL_NETWORKS}    nat_ext_11    nat_ext_22
37 @{EXTERNAL_SUB_NETWORKS}    nat_ext_sub_net_1    nat_ext_sub_net_2
38 @{SUBNETS}        nat_sub_net_1    nat_sub_net_2
39 @{SUBNET_CIDRS}    10.1.1.0/24    20.1.1.0/24
40 @{EXT_SUBNET_CIDRS}    100.100.100.0/24    200.200.200.0/24
41 @{PORTS}          nat_port_1    nat_port_2    nat_port_3    nat_port_4
42 @{NET_1_VMS}      nat_net_1_vm_1    nat_net_1_vm_2    nat_net_1_vm_3    nat_net_1_vm_4
43
44 *** Test Cases ***
45 Verify Successful Creation Of External Network With Router External Set To TRUE
46     [Documentation]    Create external network,enable snat on router and validate the same.
47     OpenStackOperations.Add Router Gateway    ${ROUTER}    @{EXTERNAL_NETWORKS}[0]    --enable-snat
48     ${output} =    OpenStackOperations.Show Router    ${ROUTER}
49     BuiltIn.Should Contain    ${output}    ${SNAT_ENABLED}
50     ${output} =    OpenStackOperations.Show Network    @{EXTERNAL_NETWORKS}[0]
51     BuiltIn.Should Contain    ${output}    @{EXTERNAL_NETWORKS}[0]
52
53 Verify Successful Update Of Router With External_gateway_info, Disable SNAT And Enable SNAT
54     [Documentation]    Disable snat, enable snat and validate the same.
55     OpenStackOperations.Add Router Gateway    ${ROUTER}    @{EXTERNAL_NETWORKS}[0]    --disable-snat
56     ${output} =    OpenStackOperations.Show Router    ${ROUTER}
57     BuiltIn.Should Contain    ${output}    ${SNAT_DISABLED}
58     OpenStackOperations.Add Router Gateway    ${ROUTER}    @{EXTERNAL_NETWORKS}[0]    --enable-snat
59     ${output} =    OpenStackOperations.Show Router    ${ROUTER}
60     BuiltIn.Should Contain    ${output}    ${SNAT_ENABLED}
61
62 Verify Successful Deletion Of External Network
63     [Documentation]    Delete the external network and validate the same.
64     OpenStackOperations.Remove Gateway    ${ROUTER}
65     ${output} =    OpenStackOperations.Show Router    ${ROUTER}
66     BuiltIn.Should Not Contain    ${output}    ${SNAT_ENABLED}
67
68 Verify Floating Ip Provision And Reachability From External Network Via Neutron Router Through L3vpn
69     [Documentation]    Check floating IP should be present in dump flows after creating the floating IP and associating it to external network
70     ...    which is associated to L3VPN
71     VpnOperations.VPN Create L3VPN    vpnid=${VPN_INSTANCE_ID}    name=${VPN_NAME}    rd=["${DCGW_RD}"]    exportrt=["${DCGW_RD}"]    importrt=["${DCGW_RD}"]
72     ${ext_net_id} =    OpenStackOperations.Get Net Id    @{EXTERNAL_NETWORKS}[0]
73     VpnOperations.Associate L3VPN To Network    networkid=${ext_net_id}    vpnid=${VPN_INSTANCE_ID}
74     OpenStackOperations.Add Router Gateway    ${ROUTER}    @{EXTERNAL_NETWORKS}[0]    --disable-snat
75     ${output} =    OpenStackOperations.Show Router    ${ROUTER}
76     BuiltIn.Should Contain    ${output}    ${SNAT_DISABLED}
77     ${subnetid} =    OpenStackOperations.Get Subnet Id    @{EXTERNAL_SUB_NETWORKS}[0]
78     OpenStackOperations.Add Router Gateway    ${ROUTER}    @{EXTERNAL_NETWORKS}[0]    --fixed-ip subnet=${subnetid},ip-address=${FIP}
79     ${float} =    OpenStackOperations.Create And Associate Floating IPs    @{EXTERNAL_NETWORKS}[0]    @{NET_1_VMS}[0]
80     ${output} =    OVSDB.Get Flow Entries On Node    ${OS_CMP1_CONN_ID}
81     BuiltIn.Should Contain    ${output}    ${FIP}
82
83 Verify Floating Ip De-provision And Reachability From External Network Via Neutron Router Through L3vpn
84     [Documentation]    Check floating IP should not be present in dump flows after deleting the floating IP
85     ...    and removing the external gateway from router which is associated to L3VPN
86     OpenStackOperations.Get ControlNode Connection
87     ${output} =    OpenStackOperations.OpenStack CLI    openstack floating ip list |awk '{print$2}'
88     ${floating_id} =    BuiltIn.Should Match Regexp    ${output}    [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}
89     OpenStackOperations.Delete Floating IP    ${floating_id}
90     OpenStackOperations.Remove Gateway    ${ROUTER}
91     ${output} =    OVSDB.Get Flow Entries On Node    ${OS_CMP1_CONN_ID}
92     BuiltIn.Should Not Contain    ${output}    ${FIP}
93
94 Verify Floating Ip Re-provision And Reachability From External Network Via Neutron Router Through L3vpn
95     [Documentation]    Check floating IP should be present in dump flows after creating the floating IP again wnd associating it to external network
96     ...    which is associated to L3VPN
97     ${subnetid} =    OpenStackOperations.Get Subnet Id    @{EXTERNAL_SUB_NETWORKS}[0]
98     OpenStackOperations.Add Router Gateway    ${ROUTER}    @{EXTERNAL_NETWORKS}[0]    --fixed-ip subnet=${subnetid},ip-address=${FIP}
99     ${float} =    OpenStackOperations.Create And Associate Floating IPs    @{EXTERNAL_NETWORKS}[0]    @{NET_1_VMS}[0]
100     ${output} =    OVSDB.Get Flow Entries On Node    ${OS_CMP1_CONN_ID}
101     BuiltIn.Should Contain    ${output}    ${FIP}
102
103 *** Keywords ***
104 Suite Setup
105     [Documentation]    Test Suite for Subnet_Routing_and_Multicast_Deployments.
106     VpnOperations.Basic Suite Setup
107     BgpOperations.Start Quagga Processes On ODL    ${ODL_SYSTEM_IP}
108     BgpOperations.Start Quagga Processes On DCGW    ${DCGW_SYSTEM_IP}
109     Create Setup
110     OpenStackOperations.Show Debugs    @{NET_1_VMS}
111     OpenStackOperations.Get Suite Debugs
112
113 Create Setup
114     Create Neutron Networks
115     Create Neutron Subnets
116     OpenStackOperations.Create SubNet    @{EXTERNAL_NETWORKS}[0]    @{EXTERNAL_SUB_NETWORKS}[0]    @{EXT_SUBNET_CIDRS}[0]
117     OpenStackOperations.Create Allow All SecurityGroup    ${SECURITY_GROUP}
118     Create Neutron Ports
119     Create Nova VMs
120     BgpOperations.Setup BGP Peering On ODL    ${ODL_SYSTEM_IP}    ${AS_ID}    ${DCGW_SYSTEM_IP}
121     BgpOperations.Setup BGP Peering On DCGW    ${DCGW_SYSTEM_IP}    ${AS_ID}    ${ODL_SYSTEM_IP}    ${VPN_NAME}    ${DCGW_RD}    ${LOOPBACK_IP}
122     OpenStackOperations.Create Router    ${ROUTER}
123     OpenStackOperations.Add Router Interface    ${ROUTER}    @{SUBNETS}[0]
124
125 Create Neutron Networks
126     [Documentation]    Create required number of networks
127     : FOR    ${NET}    IN    @{NETWORKS}
128     \    OpenStackOperations.Create Network    ${NET}
129     OpenStackOperations.Create Network    @{EXTERNAL_NETWORKS}[0]    --external --provider-network-type ${NETWORK_TYPE}
130     BuiltIn.Wait Until Keyword Succeeds    3s    1s    Utils.Check For Elements At URI    ${NETWORK_URL}    ${NETWORKS}
131
132 Create Neutron Subnets
133     [Documentation]    Create required number of subnets for previously created networks
134     ${num_of_networks} =    BuiltIn.Get Length    ${NETWORKS}
135     : FOR    ${index}    IN RANGE    0    ${num_of_networks}
136     \    OpenStackOperations.Create SubNet    @{NETWORKS}[${index}]    @{SUBNETS}[${index}]    @{SUBNET_CIDRS}[${index}]
137     BuiltIn.Wait Until Keyword Succeeds    3s    1s    Utils.Check For Elements At URI    ${SUBNETWORK_URL}    ${SUBNETS}
138
139 Create Neutron Ports
140     [Documentation]    Create required number of ports under previously created subnets
141     OpenStackOperations.Create Port    @{NETWORKS}[0]    @{PORTS}[0]    sg=${SECURITY_GROUP}
142     OpenStackOperations.Create Port    @{NETWORKS}[0]    @{PORTS}[1]    sg=${SECURITY_GROUP}
143     OpenStackOperations.Create Port    @{NETWORKS}[1]    @{PORTS}[2]    sg=${SECURITY_GROUP}
144     OpenStackOperations.Create Port    @{NETWORKS}[1]    @{PORTS}[3]    sg=${SECURITY_GROUP}
145     BuiltIn.Wait Until Keyword Succeeds    3s    1s    Utils.Check For Elements At URI    ${CONFIG_API}/neutron:neutron/ports/    ${PORTS}
146
147 Create Nova VMs
148     [Documentation]    Create Vm instances on compute nodes
149     OpenStackOperations.Create Vm Instance With Port On Compute Node    @{PORTS}[0]    @{NET_1_VMS}[0]    ${OS_CMP1_HOSTNAME}    sg=${SECURITY_GROUP}
150     OpenStackOperations.Create Vm Instance With Port On Compute Node    @{PORTS}[1]    @{NET_1_VMS}[1]    ${OS_CMP2_HOSTNAME}    sg=${SECURITY_GROUP}
151     OpenStackOperations.Create Vm Instance With Port On Compute Node    @{PORTS}[2]    @{NET_1_VMS}[2]    ${OS_CMP1_HOSTNAME}    sg=${SECURITY_GROUP}
152     OpenStackOperations.Create Vm Instance With Port On Compute Node    @{PORTS}[3]    @{NET_1_VMS}[3]    ${OS_CMP2_HOSTNAME}    sg=${SECURITY_GROUP}
153     @{NET_1_VM_IPS}    ${NET_1_DHCP_IP} =    OpenStackOperations.Get VM IPs    @{NET_1_VMS}
154     BuiltIn.Set Suite Variable    @{NET_1_VM_IPS}
155     BuiltIn.Should Not Contain    ${NET_1_VM_IPS}    None
156     BuiltIn.Should Not Contain    ${NET_1_DHCP_IP}    None
157
158 Stop Suite
159     [Documentation]    Test teardown for snat suite.
160     BgpOperations.Delete BGP Configuration On ODL    session
161     BgpOperations.Delete BGP Config On Quagga    ${DCGW_SYSTEM_IP}    ${AS_ID}
162     BgpOperations.Stop BGP Processes On Node    ${ODL_SYSTEM_IP}
163     BgpOperations.Stop BGP Processes On Node    ${DCGW_SYSTEM_IP}
164     OpenStackOperations.OpenStack Suite Teardown