2 Documentation Openstack library. This library is useful for tests to create network, subnet, router and vm instances
5 Variables ../variables/Variables.py
9 [Arguments] ${force}=no ${source_pwd}=yes
10 [Documentation] Sourcing the Openstack PAsswords for neutron configurations
11 Run Keyword If '${source_pwd}' == 'yes' or '${force}' == 'yes' Write Commands Until Prompt cd ${DEVSTACK_DEPLOY_PATH}; source openrc admin admin
13 Get Tenant ID From Security Group
14 [Documentation] Returns tenant ID by reading it from existing default security-group.
15 ${devstack_conn_id}= Get ControlNode Connection
16 Switch Connection ${devstack_conn_id}
17 ${output}= Write Commands Until Prompt neutron security-group-show default | grep "| tenant_id" | awk '{print $4}'
22 [Arguments] ${network_name} ${additional_args}=${EMPTY} ${verbose}=TRUE
23 [Documentation] Create Network with neutron request.
24 ${devstack_conn_id}= Get ControlNode Connection
25 Switch Connection ${devstack_conn_id}
26 ${command} Set Variable If "${verbose}" == "TRUE" neutron -v net-create ${network_name} ${additional_args} neutron net-create ${network_name} ${additional_args} | grep -w id | awk '{print $4}'
27 ${output}= Write Commands Until Prompt ${command} 30s
32 [Documentation] List networks and return output with neutron client.
33 ${devstack_conn_id}= Get ControlNode Connection
34 Switch Connection ${devstack_conn_id}
35 ${output}= Write Commands Until Prompt neutron net-list 30s
41 [Documentation] List subnets and return output with neutron client.
42 ${devstack_conn_id}= Get ControlNode Connection
43 Switch Connection ${devstack_conn_id}
44 ${output}= Write Commands Until Prompt neutron subnet-list 30s
50 [Arguments] ${network_name}
51 [Documentation] Delete Network with neutron request.
52 ${devstack_conn_id}= Get ControlNode Connection
53 Switch Connection ${devstack_conn_id}
54 ${output}= Write Commands Until Prompt neutron -v net-delete ${network_name} 30s
57 Should Contain ${output} Deleted network: ${network_name}
60 [Arguments] ${network_name} ${subnet} ${range_ip}
61 [Documentation] Create SubNet for the Network with neutron request.
62 ${devstack_conn_id}= Get ControlNode Connection
63 Switch Connection ${devstack_conn_id}
64 ${output}= Write Commands Until Prompt neutron -v subnet-create ${network_name} ${range_ip} --name ${subnet} 30s
67 Should Contain ${output} Created a new subnet
70 [Arguments] ${network_name} ${port_name}
71 [Documentation] Create Port with neutron request.
72 ${devstack_conn_id}= Get ControlNode Connection
73 Switch Connection ${devstack_conn_id}
74 ${output}= Write Commands Until Prompt neutron -v port-create ${network_name} --name ${port_name} 30s
77 Should Contain ${output} Created a new port
80 [Arguments] ${port_name}
81 [Documentation] Delete Port with neutron request.
82 ${devstack_conn_id}= Get ControlNode Connection
83 Switch Connection ${devstack_conn_id}
84 ${output}= Write Commands Until Prompt neutron -v port-delete ${port_name} 30s
87 Should Contain ${output} Deleted a new port
90 [Documentation] List ports and return output with neutron client.
91 ${devstack_conn_id}= Get ControlNode Connection
92 Switch Connection ${devstack_conn_id}
93 ${output}= Write Commands Until Prompt neutron port-list 30s
99 [Documentation] Verifies the Gateway Ips with dump flow.
100 ${output}= Write Commands Until Prompt sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
102 : FOR ${GatewayIpElement} IN @{GATEWAY_IPS}
103 \ Should Contain ${output} ${GatewayIpElement}
106 [Documentation] Verifies the Dhcp Ips with dump flow.
107 ${output}= Write Commands Until Prompt sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
109 : FOR ${DhcpIpElement} IN @{DHCP_IPS}
110 \ Should Contain ${output} ${DhcpIpElement}
113 [Documentation] Verifies the Dhcp Ips with dump flow.
114 ${output}= Write Commands Until Prompt sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
116 : FOR ${DhcpIpElement} IN @{DHCP_IPS}
117 \ Should Not Contain ${output} ${DhcpIpElement}
120 [Arguments] ${subnet}
121 [Documentation] Delete SubNet for the Network with neutron request.
123 ${devstack_conn_id}= Get ControlNode Connection
124 Switch Connection ${devstack_conn_id}
125 ${output}= Write Commands Until Prompt neutron -v subnet-delete ${subnet}
128 Should Contain ${output} Deleted subnet: ${subnet}
130 Verify No Gateway Ips
131 [Documentation] Verifies the Gateway Ips removed with dump flow.
132 ${output}= Write Commands Until Prompt sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
134 : FOR ${GatewayIpElement} IN @{GATEWAY_IPS}
135 \ Should Not Contain ${output} ${GatewayIpElement}
138 [Arguments] ${vm_name}
139 [Documentation] Delete Vm instances using instance names.
140 ${devstack_conn_id}= Get ControlNode Connection
141 Switch Connection ${devstack_conn_id}
142 ${output}= Write Commands Until Prompt nova force-delete ${vm_name} 40s
146 [Arguments] ${network_name} ${devstack_conn_id}
147 [Documentation] Retrieve the net id for the given network name to create specific vm instance
148 Switch Connection ${devstack_conn_id}
149 ${output}= Write Commands Until Prompt neutron net-list | grep "${network_name}" | get_field 1 30s
151 ${splitted_output}= Split String ${output} ${EMPTY}
152 ${net_id}= Get from List ${splitted_output} 0
157 [Arguments] ${port_name} ${devstack_conn_id}
158 [Documentation] Retrieve the port id for the given port name to attach specific vm instance to a particular port
159 Switch Connection ${devstack_conn_id}
160 ${port_id}= Write Commands Until Prompt neutron port-list | grep "${port_name}" | awk '{print $2}' 30s
165 [Arguments] ${net_name} ${vm_instance_names} ${image}=cirros-0.3.4-x86_64-uec ${flavor}=m1.nano ${sg}=default
166 [Documentation] Create X Vm Instance with the net id of the Netowrk.
167 ${devstack_conn_id}= Get ControlNode Connection
168 Switch Connection ${devstack_conn_id}
169 ${net_id}= Get Net Id ${net_name} ${devstack_conn_id}
170 : FOR ${VmElement} IN @{vm_instance_names}
171 \ ${output}= Write Commands Until Prompt nova boot --image ${image} --flavor ${flavor} --nic net-id=${net_id} ${VmElement} --security-groups ${sg} 30s
173 \ Wait Until Keyword Succeeds 25s 5s Verify VM Is ACTIVE ${VmElement}
175 Create Vm Instance With Port On Compute Node
176 [Arguments] ${port_name} ${vm_instance_name} ${compute_node} ${image}=cirros-0.3.4-x86_64-uec ${flavor}=m1.nano
177 [Documentation] Create One VM instance using given ${port_name} and for given ${compute_node}
178 ${devstack_conn_id}= Get ControlNode Connection
179 Switch Connection ${devstack_conn_id}
180 ${port_id}= Get Port Id ${port_name} ${devstack_conn_id}
181 ${hostname_compute_node}= Run Command On Remote System ${compute_node} hostname
182 ${output}= Write Commands Until Prompt nova boot --image ${image} --flavor ${flavor} --nic port-id=${port_id} ${vm_instance_name} --availability-zone nova:${hostname_compute_node} 30s
184 Wait Until Keyword Succeeds 25s 5s Verify VM Is ACTIVE ${vm_instance_name}
187 [Arguments] ${vm_name}
188 [Documentation] Run these commands to check whether the created vm instance is active or not.
189 ${output}= Write Commands Until Prompt nova show ${vm_name} | grep OS-EXT-STS:vm_state 30s
191 Should Contain ${output} active
194 [Arguments] ${vm_instance_names}
195 [Documentation] View Console log of the created vm instances using nova show.
196 : FOR ${VmElement} IN @{vm_instance_names}
197 \ ${output}= Write Commands Until Prompt nova show ${VmElement}
199 \ ${output}= Write Commands Until Prompt nova console-log ${VmElement}
202 Ping Vm From DHCP Namespace
203 [Arguments] ${net_name} ${vm_ip}
204 [Documentation] Reach all Vm Instance with the net id of the Netowrk.
206 ${devstack_conn_id}= Get ControlNode Connection
207 Switch Connection ${devstack_conn_id}
208 ${net_id}= Get Net Id ${net_name} ${devstack_conn_id}
210 ${output}= Write Commands Until Prompt sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip} 20s
213 Should Contain ${output} 64 bytes
215 Ping From DHCP Should Not Succeed
216 [Arguments] ${net_name} ${vm_ip}
217 [Documentation] Should Not Reach Vm Instance with the net id of the Netowrk.
219 ${devstack_conn_id}= Get ControlNode Connection
220 Switch Connection ${devstack_conn_id}
221 ${net_id}= Get Net Id ${net_name} ${devstack_conn_id}
223 ${output}= Write Commands Until Prompt sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip} 20s
226 Should Not Contain ${output} 64 bytes
229 [Arguments] ${dest_vm}
230 [Documentation] Ping to the expected destination ip.
231 ${output}= Write Commands Until Expected Prompt ping -c 3 ${dest_vm} ${OS_SYSTEM_PROMPT}
236 [Documentation] Ping to the expected destination ip.
237 ${output}= Write Commands Until Expected Prompt curl -i http://169.254.169.254 ${OS_SYSTEM_PROMPT}
238 Write Commands Until Prompt exit
239 Should Contain ${output} 200
242 [Documentation] Exit the vm instance.
243 ${output}= Write Commands Until Prompt exit
246 Check If Console Is VmInstance
247 [Arguments] ${console}=cirros
248 [Documentation] Check if the session has been able to login to the VM instance
249 ${output}= Write Commands Until Expected Prompt id ${OS_SYSTEM_PROMPT}
250 Should Contain ${output} ${console}
253 [Documentation] Check if the session has been able to login to the VM instance and exit the instance
254 ${rcode}= Run Keyword And Return Status Check If Console Is VmInstance cirros
255 Run Keyword If ${rcode} Write Commands Until Prompt exit
259 [Arguments] ${ip_address}
260 [Documentation] Run Ping command on the IP available as argument
261 ${output}= Write Commands Until Expected Prompt ping -c 3 ${ip_address} ${OS_SYSTEM_PROMPT}
262 Should Contain ${output} 64 bytes
264 Check Metadata Access
265 [Documentation] Try curl on the Metadataurl and check if it is okay
266 ${output}= Write Commands Until Expected Prompt curl -i http://169.254.169.254 ${OS_SYSTEM_PROMPT}
267 Should Contain ${output} 200
269 Test Operations From Vm Instance
270 [Arguments] ${net_name} ${src_ip} ${list_of_local_dst_ips} ${l2_or_l3}=l2 ${list_of_external_dst_ips}=${NONE} ${user}=cirros
271 ... ${password}=cubswin:)
272 [Documentation] Login to the vm instance using ssh in the network.
273 ${devstack_conn_id}= Get ControlNode Connection
274 Switch Connection ${devstack_conn_id}
275 ${net_id}= Get Net Id ${net_name} ${devstack_conn_id}
276 ${output}= Write Commands Until Expected Prompt sudo ip netns exec qdhcp-${net_id} ssh ${user}@${src_ip} -o ConnectTimeout=10 -o StrictHostKeyChecking=no d:
278 ${output}= Write Commands Until Expected Prompt ${password} ${OS_SYSTEM_PROMPT}
280 ${rcode}= Run Keyword And Return Status Check If Console Is VmInstance
281 Run Keyword If ${rcode} Write Commands Until Expected Prompt ifconfig ${OS_SYSTEM_PROMPT}
282 Run Keyword If ${rcode} Write Commands Until Expected Prompt route ${OS_SYSTEM_PROMPT}
283 Run Keyword If ${rcode} Write Commands Until Expected Prompt arp -an ${OS_SYSTEM_PROMPT}
284 ${dest_vm}= Get From List ${list_of_local_dst_ips} 0
286 Run Keyword If ${rcode} Check Ping ${dest_vm}
287 ${dest_dhcp}= Get From List ${list_of_local_dst_ips} 1
289 Run Keyword If ${rcode} Check Ping ${dest_dhcp}
290 ${dest_vm}= Get From List ${list_of_local_dst_ips} 2
292 Run Keyword If ${rcode} Check Ping ${dest_vm}
293 Run Keyword If ${rcode} Check Metadata Access
294 Run Keyword If '${l2_or_l3}' == 'l3' Ping Other Instances ${list_of_external_dst_ips}
295 [Teardown] Exit From Vm Console
298 [Arguments] ${list_of_external_dst_ips}
299 [Documentation] Check reachability with other network's instances.
300 ${rcode}= Run Keyword And Return Status Check If Console Is VmInstance
301 ${dest_vm}= Get From List ${list_of_external_dst_ips} 0
303 Run Keyword If ${rcode} Check Ping ${dest_vm}
304 ${dest_dhcp}= Get From List ${list_of_external_dst_ips} 1
306 Run Keyword If ${rcode} Check Ping ${dest_dhcp}
307 ${dest_vm}= Get From List ${list_of_external_dst_ips} 2
309 Run Keyword If ${rcode} Check Ping ${dest_vm}
312 [Arguments] ${router_name}
313 [Documentation] Create Router and Add Interface to the subnets.
314 ${devstack_conn_id}= Get ControlNode Connection
315 Switch Connection ${devstack_conn_id}
316 ${output}= Write Commands Until Prompt neutron -v router-create ${router_name} 30s
318 Should Contain ${output} Created a new router
321 [Arguments] ${router_name} ${interface_name}
322 ${devstack_conn_id}= Get ControlNode Connection
323 Switch Connection ${devstack_conn_id}
324 ${output}= Write Commands Until Prompt neutron -v router-interface-add ${router_name} ${interface_name}
326 Should Contain ${output} Added interface
329 [Arguments] ${router_name} ${interface_name}
330 [Documentation] Remove Interface to the subnets.
331 ${devstack_conn_id}= Get ControlNode Connection
332 Switch Connection ${devstack_conn_id}
333 ${output}= Write Commands Until Prompt neutron -v router-interface-delete ${router_name} ${interface_name}
335 Should Contain ${output} Removed interface from router
338 [Arguments] ${router_name}
339 [Documentation] Delete Router and Interface to the subnets.
340 ${devstack_conn_id}= Get ControlNode Connection
341 Switch Connection ${devstack_conn_id}
342 ${output}= Write Commands Until Prompt neutron -v router-delete ${router_name} 60s
344 Should Contain ${output} Deleted router:
346 Get DumpFlows And Ovsconfig
347 [Arguments] ${openstack_node_ip}
348 [Documentation] Get the OvsConfig and Flow entries from OVS from the Openstack Node
349 Log ${openstack_node_ip}
350 SSHLibrary.Open Connection ${openstack_node_ip} prompt=${DEFAULT_LINUX_PROMPT}
351 Utils.Flexible SSH Login ${OS_USER} ${DEVSTACK_SYSTEM_PASSWORD}
352 SSHLibrary.Set Client Configuration timeout=${default_devstack_prompt_timeout}
353 Write Commands Until Expected Prompt ip -o link ]>
354 Write Commands Until Expected Prompt ip -o addr ]>
355 Write Commands Until Expected Prompt ip route ]>
356 Write Commands Until Expected Prompt arp -an ]>
357 ${nslist}= Write Commands Until Expected Prompt ip netns list | awk '{print $1}' ]>
358 @{lines} Split To Lines ${nslist}
359 : FOR ${line} IN @{lines}
360 \ Write Commands Until Expected Prompt sudo ip netns exec ${line} ip -o link ]>
361 \ Write Commands Until Expected Prompt sudo ip netns exec ${line} ip -o addr ]>
362 \ Write Commands Until Expected Prompt sudo ip netns exec ${line} ip route ]>
363 Write Commands Until Expected Prompt sudo ovs-vsctl show ]>
364 Write Commands Until Expected Prompt sudo ovs-vsctl list Open_vSwitch ]>
365 Write Commands Until Expected Prompt sudo ovs-ofctl show br-int -OOpenFlow13 ]>
366 Write Commands Until Expected Prompt sudo ovs-ofctl dump-flows br-int -OOpenFlow13 ]>
367 Write Commands Until Expected Prompt sudo ovs-ofctl dump-groups br-int -OOpenFlow13 ]>
368 Write Commands Until Expected Prompt sudo ovs-ofctl dump-group-stats br-int -OOpenFlow13 ]>
370 Get ControlNode Connection
371 ${control_conn_id}= SSHLibrary.Open Connection ${OS_CONTROL_NODE_IP} prompt=${DEFAULT_LINUX_PROMPT_STRICT}
372 Utils.Flexible SSH Login ${OS_USER} ${DEVSTACK_SYSTEM_PASSWORD}
373 SSHLibrary.Set Client Configuration timeout=30s
374 Source Password force=yes
375 [Return] ${control_conn_id}
378 [Documentation] Get the OvsConfig and Flow entries from all Openstack nodes
379 Run Keyword If 0 < ${NUM_OS_SYSTEM} Get DumpFlows And Ovsconfig ${OS_CONTROL_NODE_IP}
380 Run Keyword If 1 < ${NUM_OS_SYSTEM} Get DumpFlows And Ovsconfig ${OS_COMPUTE_1_IP}
381 Run Keyword If 2 < ${NUM_OS_SYSTEM} Get DumpFlows And Ovsconfig ${OS_COMPUTE_2_IP}
384 [Arguments] ${vm_indices}
385 [Documentation] Run these commands for debugging, it can list state of VM instances and ip information in control node
386 ${devstack_conn_id}= Get ControlNode Connection
387 Switch Connection ${devstack_conn_id}
388 ${output}= Write Commands Until Prompt sudo ip netns list
390 : FOR ${index} IN @{vm_indices}
391 \ ${output}= Write Commands Until Prompt nova show ${index} 30s
398 Create Security Group
399 [Arguments] ${sg_name} ${desc}
400 ${devstack_conn_id}= Get ControlNode Connection
401 Switch Connection ${devstack_conn_id}
402 ${output}= Write Commands Until Prompt nova secgroup-create ${sg_name} ${desc} 40s
406 [Arguments] ${direction} ${protocol} ${min_port} ${max_port} ${remote_ip} ${sg_name}
407 ${devstack_conn_id}= Get ControlNode Connection
408 Switch Connection ${devstack_conn_id}
409 ${output}= Write Commands Until Prompt neutron security-group-rule-create --direction ${direction} --protocol ${protocol} --port-range-min ${min_port} --port-range-max ${max_port} --remote-ip-prefix ${remote_ip} ${sg_name}