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 [Documentation] Verifies the Gateway Ips with dump flow.
83 ${output}= Write Commands Until Prompt sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
85 : FOR ${GatewayIpElement} IN @{GATEWAY_IPS}
86 \ Should Contain ${output} ${GatewayIpElement}
89 [Documentation] Verifies the Dhcp Ips with dump flow.
90 ${output}= Write Commands Until Prompt sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
92 : FOR ${DhcpIpElement} IN @{DHCP_IPS}
93 \ Should Contain ${output} ${DhcpIpElement}
96 [Documentation] Verifies the Dhcp Ips with dump flow.
97 ${output}= Write Commands Until Prompt sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
99 : FOR ${DhcpIpElement} IN @{DHCP_IPS}
100 \ Should Not Contain ${output} ${DhcpIpElement}
103 [Arguments] ${subnet}
104 [Documentation] Delete SubNet for the Network with neutron request.
106 ${devstack_conn_id}= Get ControlNode Connection
107 Switch Connection ${devstack_conn_id}
108 ${output}= Write Commands Until Prompt neutron -v subnet-delete ${subnet}
111 Should Contain ${output} Deleted subnet: ${subnet}
113 Verify No Gateway Ips
114 [Documentation] Verifies the Gateway Ips removed with dump flow.
115 ${output}= Write Commands Until Prompt sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
117 : FOR ${GatewayIpElement} IN @{GATEWAY_IPS}
118 \ Should Not Contain ${output} ${GatewayIpElement}
121 [Arguments] ${vm_name}
122 [Documentation] Delete Vm instances using instance names.
123 ${devstack_conn_id}= Get ControlNode Connection
124 Switch Connection ${devstack_conn_id}
125 ${output}= Write Commands Until Prompt nova force-delete ${vm_name} 40s
129 [Arguments] ${network_name} ${devstack_conn_id}
130 [Documentation] Retrieve the net id for the given network name to create specific vm instance
131 Switch Connection ${devstack_conn_id}
132 ${output}= Write Commands Until Prompt neutron net-list | grep "${network_name}" | get_field 1 30s
134 ${splitted_output}= Split String ${output} ${EMPTY}
135 ${net_id}= Get from List ${splitted_output} 0
140 [Arguments] ${port_name} ${devstack_conn_id}
141 [Documentation] Retrieve the port id for the given port name to attach specific vm instance to a particular port
142 Switch Connection ${devstack_conn_id}
143 ${port_id}= Write Commands Until Prompt neutron port-list | grep "${port_name} | awk '{print $2}' 30s
148 [Arguments] ${net_name} ${vm_instance_names} ${image}=cirros-0.3.4-x86_64-uec ${flavor}=m1.nano
149 [Documentation] Create X Vm Instance with the net id of the Netowrk.
150 ${devstack_conn_id}= Get ControlNode Connection
151 Switch Connection ${devstack_conn_id}
152 ${net_id}= Get Net Id ${net_name} ${devstack_conn_id}
153 : FOR ${VmElement} IN @{vm_instance_names}
154 \ ${output}= Write Commands Until Prompt nova boot --image ${image} --flavor ${flavor} --nic net-id=${net_id} ${VmElement} 30s
156 \ Wait Until Keyword Succeeds 25s 5s Verify VM Is ACTIVE ${VmElement}
158 Create Vm Instance With Port On Compute Node
159 [Arguments] ${port_name} ${vm_instance_name} ${compute_node} ${image}=cirros-0.3.4-x86_64-uec ${flavor}=m1.nano
160 [Documentation] Create One VM instance using given ${port_name} and for given ${compute_node}
161 ${devstack_conn_id}= Get ControlNode Connection
162 Switch Connection ${devstack_conn_id}
163 ${port_id}= Get Port Id ${port_name} ${devstack_conn_id}
164 ${hostname_compute_node}= Run Command On Remote System ${compute_node} hostname
165 ${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
167 Wait Until Keyword Succeeds 25s 5s Verify VM Is ACTIVE ${vm_instance_name}
170 [Arguments] ${vm_name}
171 [Documentation] Run these commands to check whether the created vm instance is active or not.
172 ${output}= Write Commands Until Prompt nova show ${vm_name} | grep OS-EXT-STS:vm_state 30s
174 Should Contain ${output} active
177 [Arguments] ${vm_instance_names}
178 [Documentation] View Console log of the created vm instances using nova show.
179 : FOR ${VmElement} IN @{vm_instance_names}
180 \ ${output}= Write Commands Until Prompt nova show ${VmElement}
182 \ ${output}= Write Commands Until Prompt nova console-log ${VmElement}
185 Ping Vm From DHCP Namespace
186 [Arguments] ${net_name} ${vm_ip}
187 [Documentation] Reach all Vm Instance with the net id of the Netowrk.
189 ${devstack_conn_id}= Get ControlNode Connection
190 Switch Connection ${devstack_conn_id}
191 ${net_id}= Get Net Id ${net_name} ${devstack_conn_id}
193 ${output}= Write Commands Until Prompt sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip} 20s
196 Should Contain ${output} 64 bytes
198 Ping From DHCP Should Not Succeed
199 [Arguments] ${net_name} ${vm_ip}
200 [Documentation] Should Not Reach Vm Instance with the net id of the Netowrk.
202 ${devstack_conn_id}= Get ControlNode Connection
203 Switch Connection ${devstack_conn_id}
204 ${net_id}= Get Net Id ${net_name} ${devstack_conn_id}
206 ${output}= Write Commands Until Prompt sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip} 20s
209 Should Not Contain ${output} 64 bytes
212 [Arguments] ${dest_vm}
213 [Documentation] Ping to the expected destination ip.
214 ${output}= Write Commands Until Expected Prompt ping -c 3 ${dest_vm} ${OS_SYSTEM_PROMPT}
219 [Documentation] Ping to the expected destination ip.
220 ${output}= Write Commands Until Expected Prompt curl -i http://169.254.169.254 ${OS_SYSTEM_PROMPT}
221 Write Commands Until Prompt exit
222 Should Contain ${output} 200
225 [Documentation] Exit the vm instance.
226 ${output}= Write Commands Until Prompt exit
229 Check If Console Is VmInstance
230 [Arguments] ${console}=cirros
231 [Documentation] Check if the session has been able to login to the VM instance
232 ${output}= Write Commands Until Expected Prompt id ${OS_SYSTEM_PROMPT}
233 Should Contain ${output} ${console}
236 [Documentation] Check if the session has been able to login to the VM instance and exit the instance
237 ${rcode}= Run Keyword And Return Status Check If Console Is VmInstance cirros
238 Run Keyword If ${rcode} Write Commands Until Prompt exit
242 [Arguments] ${ip_address}
243 [Documentation] Run Ping command on the IP available as argument
244 ${output}= Write Commands Until Expected Prompt ping -c 3 ${ip_address} ${OS_SYSTEM_PROMPT}
245 Should Contain ${output} 64 bytes
247 Check Metadata Access
248 [Documentation] Try curl on the Metadataurl and check if it is okay
249 ${output}= Write Commands Until Expected Prompt curl -i http://169.254.169.254 ${OS_SYSTEM_PROMPT}
250 Should Contain ${output} 200
252 Test Operations From Vm Instance
253 [Arguments] ${net_name} ${src_ip} ${list_of_local_dst_ips} ${l2_or_l3}=l2 ${list_of_external_dst_ips}=${NONE} ${user}=cirros
254 ... ${password}=cubswin:)
255 [Documentation] Login to the vm instance using ssh in the network.
256 ${devstack_conn_id}= Get ControlNode Connection
257 Switch Connection ${devstack_conn_id}
258 ${net_id}= Get Net Id ${net_name} ${devstack_conn_id}
259 ${output}= Write Commands Until Expected Prompt sudo ip netns exec qdhcp-${net_id} ssh ${user}@${src_ip} -o ConnectTimeout=10 -o StrictHostKeyChecking=no d:
261 ${output}= Write Commands Until Expected Prompt ${password} ${OS_SYSTEM_PROMPT}
263 ${rcode}= Run Keyword And Return Status Check If Console Is VmInstance
264 Run Keyword If ${rcode} Write Commands Until Expected Prompt ifconfig ${OS_SYSTEM_PROMPT}
265 Run Keyword If ${rcode} Write Commands Until Expected Prompt route ${OS_SYSTEM_PROMPT}
266 ${dest_vm}= Get From List ${list_of_local_dst_ips} 0
268 Run Keyword If ${rcode} Check Ping ${dest_vm}
269 ${dest_dhcp}= Get From List ${list_of_local_dst_ips} 1
271 Run Keyword If ${rcode} Check Ping ${dest_dhcp}
272 ${dest_vm}= Get From List ${list_of_local_dst_ips} 2
274 Run Keyword If ${rcode} Check Ping ${dest_vm}
275 Run Keyword If ${rcode} Check Metadata Access
276 Run Keyword If '${l2_or_l3}' == 'l3' Ping Other Instances ${list_of_external_dst_ips}
277 [Teardown] Exit From Vm Console
280 [Arguments] ${list_of_external_dst_ips}
281 [Documentation] Check reachability with other network's instances.
282 ${rcode}= Run Keyword And Return Status Check If Console Is VmInstance
283 ${dest_vm}= Get From List ${list_of_external_dst_ips} 0
285 Run Keyword If ${rcode} Check Ping ${dest_vm}
286 ${dest_dhcp}= Get From List ${list_of_external_dst_ips} 1
288 Run Keyword If ${rcode} Check Ping ${dest_dhcp}
289 ${dest_vm}= Get From List ${list_of_external_dst_ips} 2
291 Run Keyword If ${rcode} Check Ping ${dest_vm}
294 [Arguments] ${router_name}
295 [Documentation] Create Router and Add Interface to the subnets.
296 ${devstack_conn_id}= Get ControlNode Connection
297 Switch Connection ${devstack_conn_id}
298 ${output}= Write Commands Until Prompt neutron -v router-create ${router_name} 30s
300 Should Contain ${output} Created a new router
303 [Arguments] ${router_name} ${interface_name}
304 ${devstack_conn_id}= Get ControlNode Connection
305 Switch Connection ${devstack_conn_id}
306 ${output}= Write Commands Until Prompt neutron -v router-interface-add ${router_name} ${interface_name}
308 Should Contain ${output} Added interface
311 [Arguments] ${router_name} ${interface_name}
312 [Documentation] Remove Interface to the subnets.
313 ${devstack_conn_id}= Get ControlNode Connection
314 Switch Connection ${devstack_conn_id}
315 ${output}= Write Commands Until Prompt neutron -v router-interface-delete ${router_name} ${interface_name}
317 Should Contain ${output} Removed interface from router
320 [Arguments] ${router_name}
321 [Documentation] Delete Router and Interface to the subnets.
322 ${devstack_conn_id}= Get ControlNode Connection
323 Switch Connection ${devstack_conn_id}
324 ${output}= Write Commands Until Prompt neutron -v router-delete ${router_name} 60s
326 Should Contain ${output} Deleted router:
328 Get DumpFlows And Ovsconfig
329 [Arguments] ${openstack_node_ip}
330 [Documentation] Get the OvsConfig and Flow entries from OVS from the Openstack Node
331 Log ${openstack_node_ip}
332 SSHLibrary.Open Connection ${openstack_node_ip} prompt=${DEFAULT_LINUX_PROMPT}
333 Utils.Flexible SSH Login ${OS_USER} ${DEVSTACK_SYSTEM_PASSWORD}
334 SSHLibrary.Set Client Configuration timeout=${default_devstack_prompt_timeout}
335 Write Commands Until Expected Prompt sudo ovs-vsctl show ]>
336 Write Commands Until Expected Prompt sudo ovs-ofctl dump-flows br-int -OOpenFlow13 ]>
338 Get ControlNode Connection
339 ${control_conn_id}= SSHLibrary.Open Connection ${OS_CONTROL_NODE_IP} prompt=${DEFAULT_LINUX_PROMPT_STRICT}
340 Utils.Flexible SSH Login ${OS_USER} ${DEVSTACK_SYSTEM_PASSWORD}
341 SSHLibrary.Set Client Configuration timeout=30s
342 Source Password force=yes
343 [Return] ${control_conn_id}
346 [Documentation] Get the OvsConfig and Flow entries from all Openstack nodes
347 Run Keyword If 0 < ${NUM_OS_SYSTEM} Get DumpFlows And Ovsconfig ${OS_CONTROL_NODE_IP}
348 Run Keyword If 1 < ${NUM_OS_SYSTEM} Get DumpFlows And Ovsconfig ${OS_COMPUTE_1_IP}
349 Run Keyword If 2 < ${NUM_OS_SYSTEM} Get DumpFlows And Ovsconfig ${OS_COMPUTE_2_IP}
352 [Arguments] ${vm_indices}
353 [Documentation] Run these commands for debugging, it can list state of VM instances and ip information in control node
354 ${output}= Write Commands Until Prompt sudo ip netns list
356 : FOR ${index} IN @{vm_indices}
357 \ ${output}= Write Commands Until Prompt nova show ${index} 30s