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
18 ... neutron security-group-show default | grep "| tenant_id" | awk '{print $4}'
23 [Arguments] ${network_name} ${additional_args}=${EMPTY} ${verbose}=TRUE
24 [Documentation] Create Network with neutron request.
25 ${devstack_conn_id}= Get ControlNode Connection
26 Switch Connection ${devstack_conn_id}
27 ${command} Set Variable If "${verbose}" == "TRUE" neutron -v net-create ${network_name} ${additional_args}
28 ... neutron net-create ${network_name} ${additional_args} | grep -w id | awk '{print $4}'
29 ${output}= Write Commands Until Prompt ${command} 30s
34 [Documentation] List networks and return output with neutron client.
35 ${devstack_conn_id}= Get ControlNode Connection
36 Switch Connection ${devstack_conn_id}
37 ${output}= Write Commands Until Prompt neutron net-list 30s
43 [Documentation] List subnets and return output with neutron client.
44 ${devstack_conn_id}= Get ControlNode Connection
45 Switch Connection ${devstack_conn_id}
46 ${output}= Write Commands Until Prompt neutron subnet-list 30s
52 [Arguments] ${network_name}
53 [Documentation] Delete Network with neutron request.
54 ${devstack_conn_id}= Get ControlNode Connection
55 Switch Connection ${devstack_conn_id}
56 ${output}= Write Commands Until Prompt neutron -v net-delete ${network_name} 30s
59 Should Contain ${output} Deleted network: ${network_name}
62 [Arguments] ${network_name} ${subnet} ${range_ip}
63 [Documentation] Create SubNet for the Network with neutron request.
64 ${devstack_conn_id}= Get ControlNode Connection
65 Switch Connection ${devstack_conn_id}
66 ${output}= Write Commands Until Prompt neutron -v subnet-create ${network_name} ${range_ip} --name ${subnet} 30s
69 Should Contain ${output} Created a new subnet
72 [Arguments] ${network_name} ${port_name}
73 [Documentation] Create Port with neutron request.
74 ${devstack_conn_id}= Get ControlNode Connection
75 Switch Connection ${devstack_conn_id}
76 ${output}= Write Commands Until Prompt neutron -v port-create ${network_name} --name ${port_name} 30s
79 Should Contain ${output} Created a new port
82 [Arguments] ${port_name}
83 [Documentation] Delete Port with neutron request.
84 ${devstack_conn_id}= Get ControlNode Connection
85 Switch Connection ${devstack_conn_id}
86 ${output}= Write Commands Until Prompt neutron -v port-delete ${port_name} 30s
89 Should Contain ${output} Deleted a new port
92 [Documentation] Verifies the Gateway Ips with dump flow.
93 ${output}= Write Commands Until Prompt sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
95 : FOR ${GatewayIpElement} IN @{GATEWAY_IPS}
96 \ Should Contain ${output} ${GatewayIpElement}
99 [Documentation] Verifies the Dhcp Ips with dump flow.
100 ${output}= Write Commands Until Prompt sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
102 : FOR ${DhcpIpElement} IN @{DHCP_IPS}
103 \ Should Contain ${output} ${DhcpIpElement}
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 Not Contain ${output} ${DhcpIpElement}
113 [Arguments] ${subnet}
114 [Documentation] Delete SubNet for the Network with neutron request.
116 ${devstack_conn_id}= Get ControlNode Connection
117 Switch Connection ${devstack_conn_id}
118 ${output}= Write Commands Until Prompt neutron -v subnet-delete ${subnet}
121 Should Contain ${output} Deleted subnet: ${subnet}
123 Verify No Gateway Ips
124 [Documentation] Verifies the Gateway Ips removed with dump flow.
125 ${output}= Write Commands Until Prompt sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
127 : FOR ${GatewayIpElement} IN @{GATEWAY_IPS}
128 \ Should Not Contain ${output} ${GatewayIpElement}
131 [Arguments] ${vm_name}
132 [Documentation] Delete Vm instances using instance names.
133 ${devstack_conn_id}= Get ControlNode Connection
134 Switch Connection ${devstack_conn_id}
135 ${output}= Write Commands Until Prompt nova force-delete ${vm_name} 40s
139 [Arguments] ${network_name} ${devstack_conn_id}
140 [Documentation] Retrieve the net id for the given network name to create specific vm instance
141 Switch Connection ${devstack_conn_id}
142 ${output}= Write Commands Until Prompt neutron net-list | grep "${network_name}" | get_field 1 30s
144 ${splitted_output}= Split String ${output} ${EMPTY}
145 ${net_id}= Get from List ${splitted_output} 0
150 [Arguments] ${port_name} ${devstack_conn_id}
151 [Documentation] Retrieve the port id for the given port name to attach specific vm instance to a particular port
152 Switch Connection ${devstack_conn_id}
153 ${port_id}= Write Commands Until Prompt neutron port-list | grep "${port_name}" | awk '{print $2}' 30s
158 [Arguments] ${net_name} ${vm_instance_names} ${image}=cirros-0.3.4-x86_64-uec ${flavor}=m1.nano
159 [Documentation] Create X Vm Instance with the net id of the Netowrk.
160 ${devstack_conn_id}= Get ControlNode Connection
161 Switch Connection ${devstack_conn_id}
162 ${net_id}= Get Net Id ${net_name} ${devstack_conn_id}
163 : FOR ${VmElement} IN @{vm_instance_names}
164 \ ${output}= Write Commands Until Prompt nova boot --image ${image} --flavor ${flavor} --nic net-id=${net_id} ${VmElement} 30s
166 \ Wait Until Keyword Succeeds 25s 5s Verify VM Is ACTIVE ${VmElement}
168 Create Vm Instance With Port On Compute Node
169 [Arguments] ${port_name} ${vm_instance_name} ${compute_node} ${image}=cirros-0.3.4-x86_64-uec ${flavor}=m1.nano
170 [Documentation] Create One VM instance using given ${port_name} and for given ${compute_node}
171 ${devstack_conn_id}= Get ControlNode Connection
172 Switch Connection ${devstack_conn_id}
173 ${port_id}= Get Port Id ${port_name} ${devstack_conn_id}
174 ${hostname_compute_node}= Run Command On Remote System ${compute_node} hostname
175 ${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
177 Wait Until Keyword Succeeds 25s 5s Verify VM Is ACTIVE ${vm_instance_name}
180 [Arguments] ${vm_name}
181 [Documentation] Run these commands to check whether the created vm instance is active or not.
182 ${output}= Write Commands Until Prompt nova show ${vm_name} | grep OS-EXT-STS:vm_state 30s
184 Should Contain ${output} active
187 [Arguments] ${vm_instance_names}
188 [Documentation] View Console log of the created vm instances using nova show.
189 : FOR ${VmElement} IN @{vm_instance_names}
190 \ ${output}= Write Commands Until Prompt nova show ${VmElement}
192 \ ${output}= Write Commands Until Prompt nova console-log ${VmElement}
195 Ping Vm From DHCP Namespace
196 [Arguments] ${net_name} ${vm_ip}
197 [Documentation] Reach all Vm Instance with the net id of the Netowrk.
199 ${devstack_conn_id}= Get ControlNode Connection
200 Switch Connection ${devstack_conn_id}
201 ${net_id}= Get Net Id ${net_name} ${devstack_conn_id}
203 ${output}= Write Commands Until Prompt sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip} 20s
206 Should Contain ${output} 64 bytes
208 Ping From DHCP Should Not Succeed
209 [Arguments] ${net_name} ${vm_ip}
210 [Documentation] Should Not Reach Vm Instance with the net id of the Netowrk.
212 ${devstack_conn_id}= Get ControlNode Connection
213 Switch Connection ${devstack_conn_id}
214 ${net_id}= Get Net Id ${net_name} ${devstack_conn_id}
216 ${output}= Write Commands Until Prompt sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip} 20s
219 Should Not Contain ${output} 64 bytes
222 [Arguments] ${dest_vm}
223 [Documentation] Ping to the expected destination ip.
224 ${output}= Write Commands Until Expected Prompt ping -c 3 ${dest_vm} ${OS_SYSTEM_PROMPT}
229 [Documentation] Ping to the expected destination ip.
230 ${output}= Write Commands Until Expected Prompt curl -i http://169.254.169.254 ${OS_SYSTEM_PROMPT}
231 Write Commands Until Prompt exit
232 Should Contain ${output} 200
235 [Documentation] Exit the vm instance.
236 ${output}= Write Commands Until Prompt exit
239 Check If Console Is VmInstance
240 [Arguments] ${console}=cirros
241 [Documentation] Check if the session has been able to login to the VM instance
242 ${output}= Write Commands Until Expected Prompt id ${OS_SYSTEM_PROMPT}
243 Should Contain ${output} ${console}
246 [Documentation] Check if the session has been able to login to the VM instance and exit the instance
247 ${rcode}= Run Keyword And Return Status Check If Console Is VmInstance cirros
248 Run Keyword If ${rcode} Write Commands Until Prompt exit
252 [Arguments] ${ip_address}
253 [Documentation] Run Ping command on the IP available as argument
254 ${output}= Write Commands Until Expected Prompt ping -c 3 ${ip_address} ${OS_SYSTEM_PROMPT}
255 Should Contain ${output} 64 bytes
257 Check Metadata Access
258 [Documentation] Try curl on the Metadataurl and check if it is okay
259 ${output}= Write Commands Until Expected Prompt curl -i http://169.254.169.254 ${OS_SYSTEM_PROMPT}
260 Should Contain ${output} 200
262 Test Operations From Vm Instance
263 [Arguments] ${net_name} ${src_ip} ${list_of_local_dst_ips} ${l2_or_l3}=l2 ${list_of_external_dst_ips}=${NONE} ${user}=cirros
264 ... ${password}=cubswin:)
265 [Documentation] Login to the vm instance using ssh in the network.
266 ${devstack_conn_id}= Get ControlNode Connection
267 Switch Connection ${devstack_conn_id}
268 ${net_id}= Get Net Id ${net_name} ${devstack_conn_id}
269 ${output}= Write Commands Until Expected Prompt sudo ip netns exec qdhcp-${net_id} ssh ${user}@${src_ip} -o ConnectTimeout=10 -o StrictHostKeyChecking=no d:
271 ${output}= Write Commands Until Expected Prompt ${password} ${OS_SYSTEM_PROMPT}
273 ${rcode}= Run Keyword And Return Status Check If Console Is VmInstance
274 Run Keyword If ${rcode} Write Commands Until Expected Prompt ifconfig ${OS_SYSTEM_PROMPT}
275 Run Keyword If ${rcode} Write Commands Until Expected Prompt route ${OS_SYSTEM_PROMPT}
276 ${dest_vm}= Get From List ${list_of_local_dst_ips} 0
278 Run Keyword If ${rcode} Check Ping ${dest_vm}
279 ${dest_dhcp}= Get From List ${list_of_local_dst_ips} 1
281 Run Keyword If ${rcode} Check Ping ${dest_dhcp}
282 ${dest_vm}= Get From List ${list_of_local_dst_ips} 2
284 Run Keyword If ${rcode} Check Ping ${dest_vm}
285 Run Keyword If ${rcode} Check Metadata Access
286 Run Keyword If '${l2_or_l3}' == 'l3' Ping Other Instances ${list_of_external_dst_ips}
287 [Teardown] Exit From Vm Console
290 [Arguments] ${list_of_external_dst_ips}
291 [Documentation] Check reachability with other network's instances.
292 ${rcode}= Run Keyword And Return Status Check If Console Is VmInstance
293 ${dest_vm}= Get From List ${list_of_external_dst_ips} 0
295 Run Keyword If ${rcode} Check Ping ${dest_vm}
296 ${dest_dhcp}= Get From List ${list_of_external_dst_ips} 1
298 Run Keyword If ${rcode} Check Ping ${dest_dhcp}
299 ${dest_vm}= Get From List ${list_of_external_dst_ips} 2
301 Run Keyword If ${rcode} Check Ping ${dest_vm}
304 [Arguments] ${router_name}
305 [Documentation] Create Router and Add Interface to the subnets.
306 ${devstack_conn_id}= Get ControlNode Connection
307 Switch Connection ${devstack_conn_id}
308 ${output}= Write Commands Until Prompt neutron -v router-create ${router_name} 30s
310 Should Contain ${output} Created a new router
313 [Arguments] ${router_name} ${interface_name}
314 ${devstack_conn_id}= Get ControlNode Connection
315 Switch Connection ${devstack_conn_id}
316 ${output}= Write Commands Until Prompt neutron -v router-interface-add ${router_name} ${interface_name}
318 Should Contain ${output} Added interface
321 [Arguments] ${router_name} ${interface_name}
322 [Documentation] Remove Interface to the subnets.
323 ${devstack_conn_id}= Get ControlNode Connection
324 Switch Connection ${devstack_conn_id}
325 ${output}= Write Commands Until Prompt neutron -v router-interface-delete ${router_name} ${interface_name}
327 Should Contain ${output} Removed interface from router
330 [Arguments] ${router_name}
331 [Documentation] Delete Router and Interface to the subnets.
332 ${devstack_conn_id}= Get ControlNode Connection
333 Switch Connection ${devstack_conn_id}
334 ${output}= Write Commands Until Prompt neutron -v router-delete ${router_name} 60s
336 Should Contain ${output} Deleted router:
338 Get DumpFlows And Ovsconfig
339 [Arguments] ${openstack_node_ip}
340 [Documentation] Get the OvsConfig and Flow entries from OVS from the Openstack Node
341 Log ${openstack_node_ip}
342 SSHLibrary.Open Connection ${openstack_node_ip} prompt=${DEFAULT_LINUX_PROMPT}
343 Utils.Flexible SSH Login ${OS_USER} ${DEVSTACK_SYSTEM_PASSWORD}
344 SSHLibrary.Set Client Configuration timeout=${default_devstack_prompt_timeout}
345 Write Commands Until Expected Prompt sudo ovs-vsctl show ]>
346 Write Commands Until Expected Prompt sudo ovs-ofctl dump-flows br-int -OOpenFlow13 ]>
348 Get ControlNode Connection
349 ${control_conn_id}= SSHLibrary.Open Connection ${OS_CONTROL_NODE_IP} prompt=${DEFAULT_LINUX_PROMPT_STRICT}
350 Utils.Flexible SSH Login ${OS_USER} ${DEVSTACK_SYSTEM_PASSWORD}
351 SSHLibrary.Set Client Configuration timeout=30s
352 Source Password force=yes
353 [Return] ${control_conn_id}
356 [Documentation] Get the OvsConfig and Flow entries from all Openstack nodes
357 Run Keyword If 0 < ${NUM_OS_SYSTEM} Get DumpFlows And Ovsconfig ${OS_CONTROL_NODE_IP}
358 Run Keyword If 1 < ${NUM_OS_SYSTEM} Get DumpFlows And Ovsconfig ${OS_COMPUTE_1_IP}
359 Run Keyword If 2 < ${NUM_OS_SYSTEM} Get DumpFlows And Ovsconfig ${OS_COMPUTE_2_IP}
362 [Arguments] ${vm_indices}
363 [Documentation] Run these commands for debugging, it can list state of VM instances and ip information in control node
364 ${output}= Write Commands Until Prompt sudo ip netns list
366 : FOR ${index} IN @{vm_indices}
367 \ ${output}= Write Commands Until Prompt nova show ${index} 30s