Update Robot Framework format - step 11
[integration/test.git] / csit / suites / netvirt / host_route / host_route_handling.robot
1 *** Settings ***
2 Documentation       Test suite for VM based Host Route Handling
3
4 Library             Collections
5 Library             RequestsLibrary
6 Library             SSHLibrary
7 Library             String
8 Resource            ../../../libraries/DevstackUtils.robot
9 Resource            ../../../libraries/OpenStackOperations.robot
10 Resource            ../../../libraries/VpnOperations.robot
11 Resource            ../../../variables/netvirt/Variables.robot
12 Resource            ../../../variables/Variables.robot
13
14 Suite Setup         Suite Setup
15 Suite Teardown      OpenStackOperations.OpenStack Suite Teardown
16 Test Setup          SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
17 Test Teardown       OpenStackOperations.Get Test Teardown Debugs
18
19
20 *** Variables ***
21 @{NETWORKS}
22 ...                             host_route_network_1
23 ...                             host_route_network_2
24 ...                             host_route_network_3
25 ...                             host_route_network_4
26 @{SUBNETS}
27 ...                             host_route_subnet_1
28 ...                             host_route_subnet_2
29 ...                             host_route_subnet_3
30 ...                             host_route_subnet_4
31 @{SUBNET_CIDR}                  10.10.10.0    10.20.20.0    10.30.30.0    10.40.40.0
32 ${PREFIX24}                     /24
33 ${SECURITY_GROUP}               host_route_security_group
34 @{PORTS}
35 ...                             host_route_port_1
36 ...                             host_route_port_2
37 ...                             host_route_port_3
38 ...                             host_route_port_4
39 ...                             host_route_port_5
40 ...                             host_route_port_6
41 ...                             host_route_port_7
42 @{GATEWAY_PORTS}
43 ...                             host_route_gw_port_1
44 ...                             host_route_gw_port_2
45 ...                             host_route_gw_port_3
46 ...                             host_route_gw_port_4
47 ...                             host_route_gw_port_5
48 ...                             host_route_gw_port_6
49 ...                             host_route_gw_port_7
50 ${ALLOWED_ADDRESS_PAIR}         0.0.0.0/0
51 ${NETWORK_1_VM}                 host_route_vm_1
52 @{NETWORK_2_VMS}                host_route_vm_2    host_route_vm_3
53 @{NETWORK_3_VMS}                host_route_vm_4    host_route_vm_5
54 @{NETWORK_4_VMS}                host_route_vm_6    host_route_vm_7
55 @{GATEWAY_VMS}                  host_route_gw_vm_1    host_route_gw_vm_2
56 ${ROUTER}                       host_route_router_1
57 @{NON_NEUTRON_DESTINATION}      5.5.5.0    6.6.6.0
58 ${NON_NEUTRON_NEXTHOP}          10.10.10.250
59
60
61 *** Test Cases ***
62 Verify creation of host route via openstack subnet create option
63     [Documentation]    Creating subnet host route via openstack cli and verifying in controller and openstack.
64     OpenStackOperations.Create SubNet
65     ...    ${NETWORKS}[0]
66     ...    ${SUBNETS}[0]
67     ...    ${SUBNET_CIDR}[0]${PREFIX24}
68     ...    --host-route destination=${SUBNET_CIDR}[2]${PREFIX24},gateway=${NON_NEUTRON_NEXTHOP}
69     ${SUBNET_GW_IP} =    BuiltIn.Create List
70     FOR    ${subnet}    IN    @{SUBNETS}
71         ${ip} =    OpenStackOperations.Get Subnet Gateway Ip    ${subnet}
72         Collections.Append To List    ${SUBNET_GW_IP}    ${ip}
73     END
74     BuiltIn.Set Suite Variable    ${SUBNET_GW_IP}
75     ${elements} =    BuiltIn.Create List
76     ...    "destination":"${SUBNET_CIDR}[2]${PREFIX24}","nexthop":"${NON_NEUTRON_NEXTHOP}"
77     BuiltIn.Wait Until Keyword Succeeds
78     ...    30s
79     ...    5s
80     ...    Utils.Check For Elements At URI
81     ...    ${SUBNETWORK_URL}
82     ...    ${elements}
83     Verify Hostroutes In Subnet
84     ...    ${SUBNETS}[0]
85     ...    destination='${SUBNET_CIDR}[2]${PREFIX24}',\\sgateway='${NON_NEUTRON_NEXTHOP}'
86     OpenStackOperations.Create Port
87     ...    ${NETWORKS}[0]
88     ...    ${PORTS}[0]
89     ...    sg=${SECURITY_GROUP}
90     ...    allowed_address_pairs=${ALLOWED_ADDRESS_PAIR}
91     OpenStackOperations.Create Vm Instance With Port On Compute Node
92     ...    ${PORTS}[0]
93     ...    ${NETWORK_1_VM}
94     ...    ${OS_CMP1_HOSTNAME}
95     ...    sg=${SECURITY_GROUP}
96     OpenStackOperations.Create Port
97     ...    ${NETWORKS}[0]
98     ...    ${GATEWAY_PORTS}[0]
99     ...    sg=${SECURITY_GROUP}
100     ...    allowed_address_pairs=${ALLOWED_ADDRESS_PAIR}
101     OpenStackOperations.Create Vm Instance With Ports On Compute Node
102     ...    ${GATEWAY_PORTS}[0]
103     ...    ${GATEWAY_PORTS}[1]
104     ...    ${GATEWAY_VMS}[0]
105     ...    ${OS_CMP1_HOSTNAME}
106     ...    sg=${SECURITY_GROUP}
107     OpenStackOperations.Create Vm Instance With Ports On Compute Node
108     ...    ${GATEWAY_PORTS}[4]
109     ...    ${GATEWAY_PORTS}[5]
110     ...    ${GATEWAY_VMS}[1]
111     ...    ${OS_CMP2_HOSTNAME}
112     ...    sg=${SECURITY_GROUP}
113     OpenStackOperations.Poll VM Is ACTIVE    ${NETWORK_1_VM}
114     BuiltIn.Wait Until Keyword Succeeds    180s    15s    OpenStackOperations.Get VM IP    true    ${NETWORK_1_VM}
115     ${NETWORK_1_VM_IPS}    ${NETWORK_1_DHCP_IP}    ${VM_COSOLE_OUTPUT} =    OpenStackOperations.Get VM IP
116     ...    true
117     ...    ${NETWORK_1_VM}
118     BuiltIn.Set Suite Variable    ${NETWORK_1_VM_IPS}
119     @{GATEWAY_VM_IPS}    ${GATEWAY_DHCP_IP} =    OpenStackOperations.Get VM IPs    @{GATEWAY_VMS}
120     BuiltIn.Set Suite Variable    @{GATEWAY_VM_IPS}
121     #TODO: Verifiy the routes in VM.
122     OpenStackOperations.Show Debugs    ${NETWORK_1_VM}    @{GATEWAY_VMS}
123     OpenStackOperations.Get Suite Debugs
124
125 Verify creation of host route via openstack subnet update option
126     [Documentation]    Creating host route using subnet update option and setting nexthop ip to subnet gateway ip. Verifying in controller and openstack.
127     OpenStackOperations.Update SubNet
128     ...    ${SUBNETS}[0]
129     ...    --host-route destination=${NON_NEUTRON_DESTINATION}[0]${PREFIX24},gateway=${SUBNET_GW_IP}[0]
130     ${elements} =    BuiltIn.Create List
131     ...    "destination":"${NON_NEUTRON_DESTINATION}[0]${PREFIX24}","nexthop":"${SUBNET_GW_IP}[0]"
132     BuiltIn.Wait Until Keyword Succeeds
133     ...    30s
134     ...    5s
135     ...    Utils.Check For Elements At URI
136     ...    ${SUBNETWORK_URL}
137     ...    ${elements}
138     Verify Hostroutes In Subnet
139     ...    ${SUBNETS}[0]
140     ...    destination='${NON_NEUTRON_DESTINATION}[0]${PREFIX24}',\\sgateway='${SUBNET_GW_IP}[0]'
141
142 Verify removal of host route
143     [Documentation]    Removing subnet host routes via cli and verifying in controller and openstack.
144     OpenStackOperations.Unset SubNet
145     ...    ${SUBNETS}[0]
146     ...    --host-route destination=${NON_NEUTRON_DESTINATION}[0]${PREFIX24},gateway=${SUBNET_GW_IP}[0]
147     ${elements} =    BuiltIn.Create List
148     ...    "destination":"${NON_NEUTRON_DESTINATION}[0]${PREFIX24}","nexthop":"${SUBNET_GW_IP}[0]"
149     BuiltIn.Wait Until Keyword Succeeds
150     ...    30s
151     ...    5s
152     ...    Utils.Check For Elements Not At URI
153     ...    ${SUBNETWORK_URL}
154     ...    ${elements}
155     Verify No Hostroutes In Subnet
156     ...    ${SUBNETS}[0]
157     ...    destination='${NON_NEUTRON_DESTINATION}[0]${PREFIX24}',\\sgateway='${SUBNET_GW_IP}[0]'
158
159 Verify creation of host route via openstack subnet set option with VM port as next hop IP
160     [Documentation]    Creating host route using subnet update option and setting nexthop to gateway vm ip and verifying in controller and openstack.
161     OpenStackOperations.Update SubNet
162     ...    ${SUBNETS}[0]
163     ...    --host-route destination=${SUBNET_CIDR}[2]${PREFIX24},gateway=${GATEWAY_VM_IPS}[0]
164     ${elements} =    BuiltIn.Create List
165     ...    "destination":"${SUBNET_CIDR}[2]${PREFIX24}","nexthop":"${GATEWAY_VM_IPS}[0]"
166     BuiltIn.Wait Until Keyword Succeeds
167     ...    30s
168     ...    5s
169     ...    Utils.Check For Elements At URI
170     ...    ${SUBNETWORK_URL}
171     ...    ${elements}
172     Verify Hostroutes In Subnet
173     ...    ${SUBNETS}[0]
174     ...    destination='${SUBNET_CIDR}[2]${PREFIX24}',\\sgateway='${GATEWAY_VM_IPS}[0]'
175
176 Verify creation of host route via openstack subnet set option with VM port as next hop IP with change in destination prefix
177     [Documentation]    Creating host route using subnet update option and setting nexthop ip to gateway vm ip and changing destination prefix.
178     ...    Verifying in controller and openstack.
179     OpenStackOperations.Update SubNet
180     ...    ${SUBNETS}[0]
181     ...    --host-route destination=${SUBNET_CIDR}[1]${PREFIX24},gateway=${GATEWAY_VM_IPS}[0]
182     ${elements} =    BuiltIn.Create List
183     ...    "destination":"${SUBNET_CIDR}[1]${PREFIX24}","nexthop":"${GATEWAY_VM_IPS}[0]"
184     BuiltIn.Wait Until Keyword Succeeds
185     ...    30s
186     ...    5s
187     ...    Utils.Check For Elements At URI
188     ...    ${SUBNETWORK_URL}
189     ...    ${elements}
190     Verify Hostroutes In Subnet
191     ...    ${SUBNETS}[0]
192     ...    destination='${SUBNET_CIDR}[1]${PREFIX24}',\\sgateway='${GATEWAY_VM_IPS}[0]'
193
194 Verify creation of host route via openstack subnet set option with change in next hop IP
195     [Documentation]    Creating host route using subnet update option and setting nexthop ip to new gateway vm ip without changing the
196     ...    destination prefix. Verifying in controller and openstack.
197     OpenStackOperations.Update SubNet
198     ...    ${SUBNETS}[0]
199     ...    --host-route destination=${SUBNET_CIDR}[1]${PREFIX24},gateway=${GATEWAY_VM_IPS}[1]
200     ${elements} =    BuiltIn.Create List
201     ...    "destination":"${SUBNET_CIDR}[1]${PREFIX24}","nexthop":"${GATEWAY_VM_IPS}[1]"
202     BuiltIn.Wait Until Keyword Succeeds
203     ...    30s
204     ...    5s
205     ...    Utils.Check For Elements At URI
206     ...    ${SUBNETWORK_URL}
207     ...    ${elements}
208     Verify Hostroutes In Subnet
209     ...    ${SUBNETS}[0]
210     ...    destination='${SUBNET_CIDR}[1]${PREFIX24}',\\sgateway='${GATEWAY_VM_IPS}[1]'
211
212
213 *** Keywords ***
214 Suite Setup
215     [Documentation]    Creates initial setup.
216     VpnOperations.Basic Suite Setup
217     OpenStackOperations.Create Allow All SecurityGroup    ${SECURITY_GROUP}
218     FOR    ${network}    IN    @{NETWORKS}
219         OpenStackOperations.Create Network    ${network}
220     END
221     FOR    ${i}    IN RANGE    1    4
222         OpenStackOperations.Create SubNet    ${NETWORKS}[${i}]    ${SUBNETS}[${i}]    ${SUBNET_CIDR}[${i}]${PREFIX24}
223         OpenStackOperations.Create Port
224         ...    ${NETWORKS}[${i}]
225         ...    ${PORTS}[${i}]
226         ...    sg=${SECURITY_GROUP}
227         ...    allowed_address_pairs=${ALLOWED_ADDRESS_PAIR}
228         OpenStackOperations.Create Vm Instance With Port On Compute Node
229         ...    ${PORTS}[${i}]
230         ...    ${NETWORK_${i+1}_VMS}[0]
231         ...    ${OS_CMP1_HOSTNAME}
232         ...    sg=${SECURITY_GROUP}
233         OpenStackOperations.Create Port
234         ...    ${NETWORKS}[${i}]
235         ...    ${PORTS}[${i+3}]
236         ...    sg=${SECURITY_GROUP}
237         ...    allowed_address_pairs=${ALLOWED_ADDRESS_PAIR}
238         OpenStackOperations.Create Vm Instance With Port On Compute Node
239         ...    ${PORTS}[${i+3}]
240         ...    ${NETWORK_${i+1}_VMS}[1]
241         ...    ${OS_CMP2_HOSTNAME}
242         ...    sg=${SECURITY_GROUP}
243         OpenStackOperations.Create Port
244         ...    ${NETWORKS}[${i}]
245         ...    ${GATEWAY_PORTS}[${i}]
246         ...    sg=${SECURITY_GROUP}
247         ...    allowed_address_pairs=${ALLOWED_ADDRESS_PAIR}
248         OpenStackOperations.Create Port
249         ...    ${NETWORKS}[${i}]
250         ...    ${GATEWAY_PORTS}[${i+3}]
251         ...    sg=${SECURITY_GROUP}
252         ...    allowed_address_pairs=${ALLOWED_ADDRESS_PAIR}
253     END
254     @{NETWORK_2_VM_IPS}    ${NETWORK_2_DHCP_IP} =    OpenStackOperations.Get VM IPs    @{NETWORK_2_VMS}
255     BuiltIn.Set Suite Variable    @{NETWORK_2_VM_IPS}
256     @{NETWORK_3_VM_IPS}    ${NETWORK_3_DHCP_IP} =    OpenStackOperations.Get VM IPs    @{NETWORK_3_VMS}
257     BuiltIn.Set Suite Variable    @{NETWORK_3_VM_IPS}
258     @{NETWORK_4_VM_IPS}    ${NETWORK_4_DHCP_IP} =    OpenStackOperations.Get VM IPs    @{NETWORK_4_VMS}
259     BuiltIn.Set Suite Variable    @{NETWORK_4_VM_IPS}
260     OpenStackOperations.Show Debugs    @{NETWORK_2_VMS}    @{NETWORK_3_VMS}    @(NETWORK_4_VMS)
261     OpenStackOperations.Get Suite Debugs
262
263 Verify Hostroutes In Subnet
264     [Documentation]    Show subnet with openstack request and verifies given hostroute in subnet.
265     [Arguments]    ${subnet_name}    @{elements}
266     ${output} =    OpenStackOperations.Show SubNet    ${subnet_name}
267     FOR    ${element}    IN    @{elements}
268         BuiltIn.Should Match Regexp    ${output}    ${element}
269     END
270
271 Verify No Hostroutes In Subnet
272     [Documentation]    Show subnet with openstack request and verifies no given hostroute in subnet.
273     [Arguments]    ${subnet_name}    @{elements}
274     ${output} =    OpenStackOperations.Show SubNet    ${subnet_name}
275     FOR    ${element}    IN    @{elements}
276         BuiltIn.Should Not Match Regexp    ${output}    ${element}
277     END