Get IpAddresses of instances from console log
[integration/test.git] / csit / suites / openstack / vpnservice / basic_vpnservice.robot
1 *** Settings ***
2 Documentation     Test suite to validate vpnservice functionality in an openstack integrated environment.
3 ...               The assumption of this suite is that the environment is already configured with the proper
4 ...               integration bridges and vxlan tunnels.
5 Suite Setup       BuiltIn.Run Keywords    SetupUtils.Setup_Utils_For_Setup_And_Teardown
6 ...               AND    DevstackUtils.Devstack Suite Setup Tests
7 Suite Teardown    Close All Connections
8 Test Setup        SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
9 Test Teardown     Get OvsDebugInfo
10 Library           OperatingSystem
11 Library           RequestsLibrary
12 Resource          ../../../libraries/Utils.robot
13 Resource          ../../../libraries/OpenStackOperations.robot
14 Resource          ../../../libraries/DevstackUtils.robot
15 Resource          ../../../libraries/VpnOperations.robot
16 Resource          ../../../libraries/OVSDB.robot
17 Resource          ../../../libraries/SetupUtils.robot
18 Variables         ../../../variables/Variables.py
19
20 *** Variables ***
21 @{NETWORKS}       NET10    NET20
22 @{SUBNETS}        SUBNET1    SUBNET2
23 @{SUBNET_CIDR}    10.1.1.0/24    20.1.1.0/24
24 @{PORT_LIST}      PORT11    PORT21    PORT12    PORT22
25 @{VM_INSTANCES}    VM11    VM21    VM12    VM22
26 @{NET10_VM_IPS}    10.1.1.3    10.1.1.4
27 @{NET20_VM_IPS}    20.1.1.3    20.1.1.4
28 @{ROUTERS}        ROUTER_1    ROUTER_2
29 @{VPN_INSTANCE_ID}    4ae8cd92-48ca-49b5-94e1-b2921a261111    4ae8cd92-48ca-49b5-94e1-b2921a261112    4ae8cd92-48ca-49b5-94e1-b2921a261113
30 @{VPN_NAME}       vpn1    vpn2    vpn3
31 ${CREATE_RD}      ["2200:2"]
32 ${CREATE_EXPORT_RT}    ["2200:2","8800:2"]
33 ${CREATE_IMPORT_RT}    ["2200:2","8800:2"]
34 @{EXTRA_NW_IP}    40.1.1.2    50.1.1.2
35 # Values passed for extra routes
36 ${EXT_RT1}        destination=40.1.1.0/24,nexthop=10.1.1.3
37 ${EXT_RT2}        destination=50.1.1.0/24,nexthop=10.1.1.3
38 ${RT_OPTIONS}     --routes type=dict list=true
39 ${RT_CLEAR}       --routes action=clear
40
41 *** Test Cases ***
42 Create Neutron Networks
43     [Documentation]    Create two networks
44     Create Network    ${NETWORKS[0]}
45     Create Network    ${NETWORKS[1]}
46     ${NET_LIST}    List Networks
47     Log    ${NET_LIST}
48     Should Contain    ${NET_LIST}    ${NETWORKS[0]}
49     Should Contain    ${NET_LIST}    ${NETWORKS[1]}
50
51 Create Neutron Subnets
52     [Documentation]    Create two subnets for previously created networks
53     Create SubNet    ${NETWORKS[0]}    ${SUBNETS[0]}    ${SUBNET_CIDR[0]}
54     Create SubNet    ${NETWORKS[1]}    ${SUBNETS[1]}    ${SUBNET_CIDR[1]}
55     ${SUB_LIST}    List Subnets
56     Log    ${SUB_LIST}
57     Should Contain    ${SUB_LIST}    ${SUBNETS[0]}
58     Should Contain    ${SUB_LIST}    ${SUBNETS[1]}
59
60 Add Ssh Allow Rule
61     [Documentation]    Allow all TCP/UDP/ICMP packets for this suite
62     Neutron Security Group Create    sg-vpnservice
63     Neutron Security Group Rule Create    sg-vpnservice    direction=ingress    port_range_max=65535    port_range_min=1    protocol=tcp    remote_ip_prefix=0.0.0.0/0
64     Neutron Security Group Rule Create    sg-vpnservice    direction=egress    port_range_max=65535    port_range_min=1    protocol=tcp    remote_ip_prefix=0.0.0.0/0
65     Neutron Security Group Rule Create    sg-vpnservice    direction=ingress    protocol=icmp    remote_ip_prefix=0.0.0.0/0
66     Neutron Security Group Rule Create    sg-vpnservice    direction=egress    protocol=icmp    remote_ip_prefix=0.0.0.0/0
67     Neutron Security Group Rule Create    sg-vpnservice    direction=ingress    port_range_max=65535    port_range_min=1    protocol=udp    remote_ip_prefix=0.0.0.0/0
68     Neutron Security Group Rule Create    sg-vpnservice    direction=egress    port_range_max=65535    port_range_min=1    protocol=udp    remote_ip_prefix=0.0.0.0/0
69
70 Create Neutron Ports
71     [Documentation]    Create four ports under previously created subnets
72     Create Port    ${NETWORKS[0]}    ${PORT_LIST[0]}    sg=sg-vpnservice
73     Create Port    ${NETWORKS[0]}    ${PORT_LIST[1]}    sg=sg-vpnservice
74     Create Port    ${NETWORKS[1]}    ${PORT_LIST[2]}    sg=sg-vpnservice
75     Create Port    ${NETWORKS[1]}    ${PORT_LIST[3]}    sg=sg-vpnservice
76
77 Check OpenDaylight Neutron Ports
78     [Documentation]    Checking OpenDaylight Neutron API for known ports
79     ${resp}    RequestsLibrary.Get Request    session    ${NEUTRON_PORTS_API}
80     Log    ${resp.content}
81     Should be Equal As Strings    ${resp.status_code}    200
82
83 Create Nova VMs
84     [Documentation]    Create Vm instances on compute node with port
85     Create Vm Instance With Port On Compute Node    ${PORT_LIST[0]}    ${VM_INSTANCES[0]}    ${OS_COMPUTE_1_IP}    sg=sg-vpnservice
86     Create Vm Instance With Port On Compute Node    ${PORT_LIST[1]}    ${VM_INSTANCES[1]}    ${OS_COMPUTE_2_IP}    sg=sg-vpnservice
87     Create Vm Instance With Port On Compute Node    ${PORT_LIST[2]}    ${VM_INSTANCES[2]}    ${OS_COMPUTE_1_IP}    sg=sg-vpnservice
88     Create Vm Instance With Port On Compute Node    ${PORT_LIST[3]}    ${VM_INSTANCES[3]}    ${OS_COMPUTE_2_IP}    sg=sg-vpnservice
89     Log    Check for routes
90     Wait Until Keyword Succeeds    30s    10s    Wait For Routes To Propogate
91
92 Check ELAN Datapath Traffic Within The Networks
93     [Documentation]    Checks datapath within the same network with different vlans.
94     ${output} =    Execute Command on VM Instance    @{NETWORKS}[0]    @{NET10_VM_IPS}[0]    ping -c 3 @{NET10_VM_IPS}[1]
95     Should Contain    ${output}    64 bytes
96     ${output} =    Execute Command on VM Instance    @{NETWORKS}[1]    @{NET20_VM_IPS}[0]    ping -c 3 @{NET20_VM_IPS}[1]
97     Should Contain    ${output}    64 bytes
98
99 Create Routers
100     [Documentation]    Create Router
101     Create Router    ${ROUTERS[0]}
102
103 Add Interfaces To Router
104     [Documentation]    Add Interfaces
105     : FOR    ${INTERFACE}    IN    @{SUBNETS}
106     \    Add Router Interface    ${ROUTERS[0]}    ${INTERFACE}
107
108 Check L3_Datapath Traffic Across Networks With Router
109     [Documentation]    Datapath test across the networks using router for L3.
110     ${dst_ip_list} =    Create List    @{NET10_VM_IPS}[1]    @{NET20_VM_IPS}[0]    @{NET20_VM_IPS}[1]
111     Log    ${dst_ip_list}
112     Test Operations From Vm Instance    ${NETWORKS[0]}    @{NET10_VM_IPS}[0]    ${dst_ip_list}
113     ${dst_ip_list} =    Create List    @{NET20_VM_IPS}[1]    @{NET10_VM_IPS}[0]    @{NET10_VM_IPS}[1]
114     Log    ${dst_ip_list}
115     Test Operations From Vm Instance    ${NETWORKS[1]}    @{NET20_VM_IPS}[0]    ${dst_ip_list}
116
117 Add Multiple Extra Routes And Check Datapath Before L3VPN Creation
118     [Documentation]    Add multiple extra routes and check data path before L3VPN creation
119     Log    "Adding extra one route to VM"
120     ${CONFIG_EXTRA_ROUTE_IP1} =    Catenate    sudo ifconfig eth0:1 @{EXTRA_NW_IP}[0] netmask 255.255.255.0 up
121     ${output} =    Execute Command on VM Instance    @{NETWORKS}[0]    @{NET10_VM_IPS}[0]    ${CONFIG_EXTRA_ROUTE_IP1}
122     ${CONFIG_EXTRA_ROUTE_IP2} =    Catenate    sudo ifconfig eth0:2 @{EXTRA_NW_IP}[1] netmask 255.255.255.0 up
123     ${output} =    Execute Command on VM Instance    @{NETWORKS}[0]    @{NET10_VM_IPS}[0]    ${CONFIG_EXTRA_ROUTE_IP2}
124     ${output} =    Execute Command on VM Instance    @{NETWORKS}[0]    @{NET10_VM_IPS}[0]    ifconfig
125     ${cmd} =    Catenate    ${RT_OPTIONS}    ${EXT_RT1}    ${EXT_RT2}
126     Update Router    @{ROUTERS}[0]    ${cmd}
127     Show Router    @{ROUTERS}[0]    -D
128     ${output} =    Execute Command on VM Instance    @{NETWORKS}[0]    @{NET10_VM_IPS}[1]    ping -c 3 @{EXTRA_NW_IP}[1]
129     Should Contain    ${output}    64 bytes
130     ${output} =    Execute Command on VM Instance    @{NETWORKS}[1]    @{NET20_VM_IPS}[1]    ping -c 3 @{EXTRA_NW_IP}[1]
131     Should Contain    ${output}    64 bytes
132     ${output} =    Execute Command on VM Instance    @{NETWORKS}[0]    @{NET10_VM_IPS}[1]    ping -c 3 @{EXTRA_NW_IP}[0]
133     Should Contain    ${output}    64 bytes
134
135 Delete Extra Route
136     [Documentation]    Delete the extra routes
137     Update Router    @{ROUTERS}[0]    ${RT_CLEAR}
138     Show Router    @{ROUTERS}[0]    -D
139
140 Delete And Recreate Extra Route
141     [Documentation]    Recreate multiple extra route and check data path before L3VPN creation
142     Log    "Adding extra route to VM"
143     ${CONFIG_EXTRA_ROUTE_IP1} =    Catenate    sudo ifconfig eth0:1 @{EXTRA_NW_IP}[0] netmask 255.255.255.0 up
144     ${output} =    Execute Command on VM Instance    @{NETWORKS}[0]    @{NET10_VM_IPS}[0]    ${CONFIG_EXTRA_ROUTE_IP1}
145     ${cmd} =    Catenate    ${RT_OPTIONS}    ${EXT_RT1}
146     Update Router    @{ROUTERS}[0]    ${cmd}
147     Show Router    @{ROUTERS}[0]    -D
148     ${output} =    Execute Command on VM Instance    @{NETWORKS}[0]    @{NET10_VM_IPS}[1]    ping -c 3 @{EXTRA_NW_IP}[0]
149     Should Contain    ${output}    64 bytes
150     Update Router    @{ROUTERS}[0]    ${RT_CLEAR}
151     Show Router    @{ROUTERS}[0]    -D
152
153 Delete Router Interfaces
154     [Documentation]    Remove Interface to the subnets.
155     : FOR    ${INTERFACE}    IN    @{SUBNETS}
156     \    Remove Interface    ${ROUTERS[0]}    ${INTERFACE}
157
158 Create L3VPN
159     [Documentation]    Creates L3VPN and verify the same
160     ${devstack_conn_id} =    Get ControlNode Connection
161     Switch Connection    ${devstack_conn_id}
162     ${net_id} =    Get Net Id    @{NETWORKS}[0]    ${devstack_conn_id}
163     ${tenant_id} =    Get Tenant ID From Network    ${net_id}
164     VPN Create L3VPN    vpnid=${VPN_INSTANCE_ID[0]}    name=${VPN_NAME[0]}    rd=${CREATE_RD}    exportrt=${CREATE_EXPORT_RT}    importrt=${CREATE_IMPORT_RT}    tenantid=${tenant_id}
165     ${resp}=    VPN Get L3VPN    vpnid=${VPN_INSTANCE_ID[0]}
166     Should Contain    ${resp}    ${VPN_INSTANCE_ID[0]}
167
168 Associate L3VPN To Routers
169     [Documentation]    Associating router to L3VPN
170     ${devstack_conn_id}=    Get ControlNode Connection
171     ${router_id}=    Get Router Id    ${ROUTERS[0]}    ${devstack_conn_id}
172     Associate VPN to Router    routerid=${router_id}    vpnid=${VPN_INSTANCE_ID[0]}
173     ${resp}=    VPN Get L3VPN    vpnid=${VPN_INSTANCE_ID[0]}
174     Should Contain    ${resp}    ${router_id}
175
176 Dissociate L3VPN To Routers
177     [Documentation]    Dissociating router from L3VPN
178     ${devstack_conn_id}=    Get ControlNode Connection
179     ${router_id}=    Get Router Id    ${ROUTERS[0]}    ${devstack_conn_id}
180     Dissociate VPN to Router    routerid=${router_id}    vpnid=${VPN_INSTANCE_ID[0]}
181     ${resp}=    VPN Get L3VPN    vpnid=${VPN_INSTANCE_ID[0]}
182     Should Not Contain    ${resp}    ${router_id}
183
184 Associate L3VPN To Networks
185     [Documentation]    Associates L3VPN to networks and verify
186     ${devstack_conn_id} =    Get ControlNode Connection
187     ${network1_id} =    Get Net Id    ${NETWORKS[0]}    ${devstack_conn_id}
188     ${network2_id} =    Get Net Id    ${NETWORKS[1]}    ${devstack_conn_id}
189     Associate L3VPN To Network    networkid=${network1_id}    vpnid=${VPN_INSTANCE_ID[0]}
190     ${resp}=    VPN Get L3VPN    vpnid=${VPN_INSTANCE_ID[0]}
191     Should Contain    ${resp}    ${network1_id}
192     Associate L3VPN To Network    networkid=${network2_id}    vpnid=${VPN_INSTANCE_ID[0]}
193     ${resp}=    VPN Get L3VPN    vpnid=${VPN_INSTANCE_ID[0]}
194     Should Contain    ${resp}    ${network2_id}
195
196 Dissociate L3VPN From Networks
197     [Documentation]    Dissociate L3VPN from networks
198     ${devstack_conn_id} =    Get ControlNode Connection
199     ${network1_id} =    Get Net Id    ${NETWORKS[0]}    ${devstack_conn_id}
200     ${network2_id} =    Get Net Id    ${NETWORKS[1]}    ${devstack_conn_id}
201     Dissociate L3VPN From Networks    networkid=${network1_id}    vpnid=${VPN_INSTANCE_ID[0]}
202     ${resp}=    VPN Get L3VPN    vpnid=${VPN_INSTANCE_ID[0]}
203     Should Not Contain    ${resp}    ${network1_id}
204     Dissociate L3VPN From Networks    networkid=${network2_id}    vpnid=${VPN_INSTANCE_ID[0]}
205     ${resp}=    VPN Get L3VPN    vpnid=${VPN_INSTANCE_ID[0]}
206     Should Not Contain    ${resp}    ${network2_id}
207
208 Delete Routers
209     [Documentation]    Delete Router and Interface to the subnets.
210     Delete Router    ${ROUTERS[0]}
211
212 Delete L3VPN
213     [Documentation]    Delete L3VPN
214     VPN Delete L3VPN    vpnid=${VPN_INSTANCE_ID[0]}
215
216 Create Multiple L3VPN
217     [Documentation]    Creates three L3VPNs and then verify the same
218     ${devstack_conn_id} =    Get ControlNode Connection
219     Switch Connection    ${devstack_conn_id}
220     ${net_id} =    Get Net Id    @{NETWORKS}[0]    ${devstack_conn_id}
221     ${tenant_id} =    Get Tenant ID From Network    ${net_id}
222     VPN Create L3VPN    vpnid=${VPN_INSTANCE_ID[0]}    name=${VPN_NAME[0]}    rd=${CREATE_RD}    exportrt=${CREATE_EXPORT_RT}    importrt=${CREATE_IMPORT_RT}    tenantid=${tenant_id}
223     VPN Create L3VPN    vpnid=${VPN_INSTANCE_ID[1]}    name=${VPN_NAME[0]}    rd=${CREATE_RD}    exportrt=${CREATE_EXPORT_RT}    importrt=${CREATE_IMPORT_RT}    tenantid=${tenant_id}
224     VPN Create L3VPN    vpnid=${VPN_INSTANCE_ID[2]}    name=${VPN_NAME[0]}    rd=${CREATE_RD}    exportrt=${CREATE_EXPORT_RT}    importrt=${CREATE_IMPORT_RT}    tenantid=${tenant_id}
225     ${resp}=    VPN Get L3VPN    vpnid=${VPN_INSTANCE_ID[0]}
226     Should Contain    ${resp}    ${VPN_INSTANCE_ID[0]}
227     ${resp}=    VPN Get L3VPN    vpnid=${VPN_INSTANCE_ID[1]}
228     Should Contain    ${resp}    ${VPN_INSTANCE_ID[1]}
229     ${resp}=    VPN Get L3VPN    vpnid=${VPN_INSTANCE_ID[2]}
230     Should Contain    ${resp}    ${VPN_INSTANCE_ID[2]}
231
232 Delete Multiple L3VPN
233     [Documentation]    Delete three L3VPNs created using Multiple L3VPN Test
234     VPN Delete L3VPN    vpnid=${VPN_INSTANCE_ID[0]}
235     VPN Delete L3VPN    vpnid=${VPN_INSTANCE_ID[1]}
236     VPN Delete L3VPN    vpnid=${VPN_INSTANCE_ID[2]}
237
238 Check Datapath Traffic Across Networks With L3VPN
239     [Documentation]    Datapath Test Across the networks with VPN.
240     [Tags]    exclude
241     Log    This test will be added in the next patch
242
243 Delete Vm Instances
244     [Documentation]    Delete Vm instances in the given Instance List
245     : FOR    ${VmInstance}    IN    @{VM_INSTANCES}
246     \    Delete Vm Instance    ${VmInstance}
247
248 Delete Neutron Ports
249     [Documentation]    Delete Neutron Ports in the given Port List.
250     : FOR    ${Port}    IN    @{PORT_LIST}
251     \    Delete Port    ${Port}
252
253 Delete Sub Networks
254     [Documentation]    Delete Sub Nets in the given Subnet List.
255     : FOR    ${Subnet}    IN    @{SUBNETS}
256     \    Delete SubNet    ${Subnet}
257
258 Delete Networks
259     [Documentation]    Delete Networks in the given Net List
260     : FOR    ${Network}    IN    @{NETWORKS}
261     \    Delete Network    ${Network}
262
263 Create ITM Tunnel
264     [Documentation]    Checks that vxlan tunnels are created successfully. This testcase expects that the two DPNs are in the same network hence populates the gateway accordingly.
265     ${node_1_dpid} =    Get DPID    ${OS_COMPUTE_1_IP}
266     ${node_2_dpid} =    Get DPID    ${OS_COMPUTE_2_IP}
267     ${node_1_adapter} =    Get Ethernet Adapter    ${OS_COMPUTE_1_IP}
268     ${node_2_adapter} =    Get Ethernet Adapter    ${OS_COMPUTE_2_IP}
269     ${first_two_octets}    ${third_octet}    ${last_octet}=    Split String From Right    ${OS_COMPUTE_1_IP}    .    2
270     ${subnet} =    Set Variable    ${first_two_octets}.0.0/16
271     ${gateway} =    Get Default Gateway    ${OS_COMPUTE_1_IP}
272     ITM Create Tunnel    tunneltype=vxlan    vlanid=0    prefix=${subnet}    gateway=${gateway}    ipaddress1=${OS_COMPUTE_1_IP}    dpnid1=${node_1_dpid}
273     ...    portname1=${node_1_adapter}    ipaddress2=${OS_COMPUTE_2_IP}    dpnid2=${node_2_dpid}    portname2=${node_2_adapter}
274     Get DumpFlows And Ovsconfig    ${OS_COMPUTE_1_IP}
275     Get DumpFlows And Ovsconfig    ${OS_COMPUTE_2_IP}
276     ${output} =    ITM Get Tunnels
277     Log    ${output}
278
279 Delete ITM Tunnel
280     [Documentation]    Delete tunnels with specific transport-zone.
281     ITM Delete Tunnel    TZA
282
283 *** Keywords ***
284 Basic Vpnservice Suite Setup
285     Create Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS}
286
287 Basic Vpnservice Suite Teardown
288     Delete All Sessions
289
290 Wait For Routes To Propogate
291     ${devstack_conn_id} =    Get ControlNode Connection
292     Switch Connection    ${devstack_conn_id}
293     ${net_id} =    Get Net Id    @{NETWORKS}[0]    ${devstack_conn_id}
294     ${output} =    Write Commands Until Expected Prompt    sudo ip netns exec qdhcp-${net_id} ip route    ]>
295     Should Contain    ${output}    @{SUBNET_CIDR}[0]
296     ${net_id} =    Get Net Id    @{NETWORKS}[1]    ${devstack_conn_id}
297     ${output} =    Write Commands Until Expected Prompt    sudo ip netns exec qdhcp-${net_id} ip route    ]>
298     Should Contain    ${output}    @{SUBNET_CIDR}[1]