2 Documentation Openstack library. This library is useful for tests to create network, subnet, router and vm instances
4 Library OperatingSystem
5 Library RequestsLibrary
7 Resource DataModels.robot
8 Resource DevstackUtils.robot
9 Resource L2GatewayOperations.robot
10 Resource SetupUtils.robot
11 Resource SSHKeywords.robot
13 Resource ../variables/Variables.robot
14 Resource ../variables/netvirt/Variables.robot
15 Variables ../variables/netvirt/Modules.py
18 Get Tenant ID From Security Group
19 [Documentation] Returns tenant ID by reading it from existing default security-group.
20 ${rc} ${output}= Run And Return Rc And Output openstack security group show default | grep "| tenant_id" | awk '{print $4}'
21 Should Be True '${rc}' == '0'
24 Get Tenant ID From Network
25 [Arguments] ${network_uuid}
26 [Documentation] Returns tenant ID by reading it from existing network.
27 ${resp}= Get_From_Uri uri=${CONFIG_API}/neutron:neutron/networks/network/${network_uuid}/ accept=${ACCEPT_EMPTY} session=session
28 ${tenant_id}= Utils.Extract Value From Content ${resp} /network/0/tenant-id strip
32 [Arguments] ${network_name} ${additional_args}=${EMPTY} ${verbose}=TRUE
33 [Documentation] Create Network with neutron request.
34 ${rc} ${output}= Run And Return Rc And Output openstack network create ${network_name} ${additional_args}
36 Should Be True '${rc}' == '0'
40 [Arguments] ${network_name} ${additional_args}=${EMPTY}
41 [Documentation] Update Network with neutron request.
42 ${cmd}= Set Variable If '${OPENSTACK_BRANCH}'=='stable/newton' neutron -v net-update ${network_name} ${additional_args} openstack network set ${network_name} ${additional_args}
43 ${rc} ${output}= Run And Return Rc And Output ${cmd}
45 Should Be True '${rc}' == '0'
49 [Arguments] ${network_name}
50 [Documentation] Show Network with neutron request.
51 ${rc} ${output}= Run And Return Rc And Output openstack network show ${network_name}
53 Should Be True '${rc}' == '0'
57 [Documentation] List networks and return output with neutron client.
58 ${rc} ${output}= Run And Return Rc And Output openstack network list
60 Should Be True '${rc}' == '0'
64 [Documentation] List subnets and return output with neutron client.
65 ${rc} ${output}= Run And Return Rc And Output openstack subnet list
67 Should Be True '${rc}' == '0'
71 [Arguments] ${network_name}
72 [Documentation] Delete Network with neutron request.
73 ${rc} ${output}= Run And Return Rc And Output openstack network delete ${network_name}
75 Should Be True '${rc}' == '0'
78 [Arguments] ${network_name} ${subnet} ${range_ip} ${additional_args}=${EMPTY}
79 [Documentation] Create SubNet for the Network with neutron request.
80 ${rc} ${output}= Run And Return Rc And Output openstack subnet create --network ${network_name} --subnet-range ${range_ip} ${subnet} ${additional_args}
82 Should Be True '${rc}' == '0'
85 [Arguments] ${subnet_name} ${additional_args}=${EMPTY}
86 [Documentation] Update subnet with neutron request.
87 ${cmd}= Set Variable If '${OPENSTACK_BRANCH}'=='stable/newton' neutron -v subnet-update ${subnet_name} ${additional_args} openstack subnet set ${subnet_name} ${additional_args}
88 ${rc} ${output}= Run And Return Rc And Output ${cmd}
90 Should Be True '${rc}' == '0'
94 [Arguments] ${subnet_name}
95 [Documentation] Show subnet with neutron request.
96 ${rc} ${output}= Run And Return Rc And Output openstack subnet show ${subnet_name}
98 Should Be True '${rc}' == '0'
102 [Arguments] ${network_name} ${port_name} ${sg}=default ${additional_args}=${EMPTY} ${allowed_address_pairs}=${EMPTY}
103 [Documentation] Create Port with neutron request.
104 # if allowed_address_pairs is not empty we need to create the arguments to pass to the port create command. They are
105 # in a different format with the neutron vs openstack cli.
106 ${address_pair_length}= Get Length ${allowed_address_pairs}
107 ${allowed_pairs_argv}= Set Variable If '${OPENSTACK_BRANCH}'=='stable/newton' and '${address_pair_length}'=='2' --allowed-address-pairs type=dict list=true ip_address=@{allowed_address_pairs}[0] ip_address=@{allowed_address_pairs}[1]
108 ${allowed_pairs_argv}= Set Variable If '${OPENSTACK_BRANCH}'!='stable/newton' and '${address_pair_length}'=='2' --allowed-address ip-address=@{allowed_address_pairs}[0] --allowed-address ip-address=@{allowed_address_pairs}[1] ${allowed_pairs_argv}
109 ${allowed_pairs_argv}= Set Variable If '${address_pair_length}'=='0' ${EMPTY} ${allowed_pairs_argv}
110 ${cmd}= Set Variable If '${OPENSTACK_BRANCH}'=='stable/newton' neutron -v port-create ${network_name} --name ${port_name} --security-group ${sg} ${additional_args} ${allowed_pairs_argv} openstack port create --network ${network_name} ${port_name} --security-group ${sg} ${additional_args} ${allowed_pairs_argv}
111 ${rc} ${output}= Run And Return Rc And Output ${cmd}
113 Should Be True '${rc}' == '0'
116 [Arguments] ${port_name} ${additional_args}=${EMPTY}
117 [Documentation] Update port with neutron request.
118 ${rc} ${output}= Run And Return Rc And Output openstack port set ${port_name} ${additional_args}
120 Should Be True '${rc}' == '0'
124 [Arguments] ${port_name}
125 [Documentation] Show port with neutron request.
126 ${rc} ${output}= Run And Return Rc And Output openstack port show ${port_name}
128 Should Be True '${rc}' == '0'
132 [Arguments] ${port_name}
133 [Documentation] Delete Port with neutron request.
134 ${rc} ${output}= Run And Return Rc And Output openstack port delete ${port_name}
136 Should Be True '${rc}' == '0'
139 [Documentation] List ports and return output with neutron client.
140 ${rc} ${output}= Run And Return Rc And Output openstack port list
142 Should Be True '${rc}' == '0'
146 [Documentation] List VMs and return output with nova client.
147 ${rc} ${output}= Run And Return Rc And Output openstack server list --all-projects
149 Should Be True '${rc}' == '0'
152 Create And Associate Floating IPs
153 [Arguments] ${external_net} @{vm_list}
154 [Documentation] Create and associate floating IPs to VMs with nova request
155 ${ip_list}= Create List @{EMPTY}
156 : FOR ${vm} IN @{vm_list}
157 \ ${rc} ${output}= Run And Return Rc And Output openstack floating ip create ${external_net}
159 \ Should Be True '${rc}' == '0'
160 \ @{ip} Get Regexp Matches ${output} [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}
161 \ ${ip_length} Get Length ${ip}
162 \ Run Keyword If ${ip_length}>0 Append To List ${ip_list} @{ip}[0]
163 \ ... ELSE Append To List ${ip_list} None
164 \ ${rc} ${output}= Run And Return Rc And Output openstack server add floating ip ${vm} @{ip}[0]
166 \ Should Be True '${rc}' == '0'
171 [Documentation] Delete floating ip with neutron request.
172 ${rc} ${output}= Run And Return Rc And Output openstack floating ip delete ${fip}
174 Should Be True '${rc}' == '0'
177 [Documentation] Verifies the Gateway Ips with dump flow.
178 ${output}= Write Commands Until Prompt And Log sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
179 : FOR ${GatewayIpElement} IN @{GATEWAY_IPS}
180 \ Should Contain ${output} ${GatewayIpElement}
183 [Documentation] Verifies the Dhcp Ips with dump flow.
184 ${output}= Write Commands Until Prompt And Log sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
185 : FOR ${DhcpIpElement} IN @{DHCP_IPS}
186 \ Should Contain ${output} ${DhcpIpElement}
189 [Documentation] Verifies the Dhcp Ips with dump flow.
190 ${output}= Write Commands Until Prompt And Log sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
191 : FOR ${DhcpIpElement} IN @{DHCP_IPS}
192 \ Should Not Contain ${output} ${DhcpIpElement}
195 [Arguments] ${subnet}
196 [Documentation] Delete SubNet for the Network with neutron request.
198 ${rc} ${output}= Run And Return Rc And Output openstack subnet delete ${subnet}
199 Should Be True '${rc}' == '0'
201 Verify No Gateway Ips
202 [Documentation] Verifies the Gateway Ips removed with dump flow.
203 ${output}= Write Commands Until Prompt And Log sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
204 : FOR ${GatewayIpElement} IN @{GATEWAY_IPS}
205 \ Should Not Contain ${output} ${GatewayIpElement}
208 [Arguments] ${vm_name}
209 [Documentation] Delete Vm instances using instance names.
210 ${rc} ${output}= Run And Return Rc And Output openstack server delete ${vm_name}
214 [Arguments] ${network_name}
215 [Documentation] Retrieve the net id for the given network name to create specific vm instance
216 ${rc} ${output}= Run And Return Rc And Output openstack network list | grep "${network_name}" | awk '{print $2}'
217 Should Be True '${rc}' == '0'
218 ${splitted_output}= Split String ${output} ${EMPTY}
219 ${net_id}= Get from List ${splitted_output} 0
223 [Arguments] ${subnet_name}
224 [Documentation] Retrieve the subnet id for the given subnet name
225 ${rc} ${output}= Run And Return Rc And Output openstack subnet show "${subnet_name}" | grep " id " | awk '{print $4}'
226 Should Be True '${rc}' == '0'
227 ${splitted_output}= Split String ${output} ${EMPTY}
228 ${subnet_id}= Get from List ${splitted_output} 0
229 [Return] ${subnet_id}
232 [Arguments] ${port_name}
233 [Documentation] Retrieve the port id for the given port name to attach specific vm instance to a particular port
234 ${rc} ${output}= Run And Return Rc And Output openstack port list | grep "${port_name}" | awk '{print $2}'
235 Should Be True '${rc}' == '0'
236 ${splitted_output}= Split String ${output} ${EMPTY}
237 ${port_id}= Get from List ${splitted_output} 0
241 [Arguments] ${router1}
242 [Documentation] Retrieve the router id for the given router name
243 ${rc} ${output}= Run And Return Rc And Output openstack router list -f table | grep "${router1}" | awk '{print $2}'
244 Should Be True '${rc}' == '0'
245 ${splitted_output}= Split String ${output} ${EMPTY}
246 ${router_id}= Get from List ${splitted_output} 0
247 [Return] ${router_id}
250 [Arguments] ${net_name} ${vm_instance_names} ${image}=${EMPTY} ${flavor}=m1.nano ${sg}=default ${min}=1
252 [Documentation] Create X Vm Instance with the net id of the Netowrk.
253 ${image} Set Variable If "${image}"=="${EMPTY}" ${CIRROS_${OPENSTACK_BRANCH}} ${image}
254 ${net_id}= Get Net Id ${net_name}
255 : FOR ${VmElement} IN @{vm_instance_names}
256 \ ${rc} ${output}= Run And Return Rc And Output openstack server create --image ${image} --flavor ${flavor} --nic net-id=${net_id} ${VmElement} --security-group ${sg} --min ${min} --max ${max}
257 \ Should Be True '${rc}' == '0'
260 Create Vm Instance With Port
261 [Arguments] ${port_name} ${vm_instance_name} ${image}=${EMPTY} ${flavor}=m1.nano ${sg}=default
262 [Documentation] Create One VM instance using given ${port_name} and for given ${compute_node}
263 ${image} Set Variable If "${image}"=="${EMPTY}" ${CIRROS_${OPENSTACK_BRANCH}} ${image}
264 ${port_id}= Get Port Id ${port_name}
265 ${rc} ${output}= Run And Return Rc And Output openstack server create --image ${image} --flavor ${flavor} --nic port-id=${port_id} ${vm_instance_name} --security-group ${sg}
268 Create Vm Instance With Ports
269 [Arguments] ${port_name} ${port2_name} ${vm_instance_name} ${image}=${EMPTY} ${flavor}=m1.nano ${sg}=default
270 [Documentation] Create One VM instance using given ${port_name} and for given ${compute_node}
271 ${image} Set Variable If "${image}"=="${EMPTY}" ${CIRROS_${OPENSTACK_BRANCH}} ${image}
272 ${port_id}= Get Port Id ${port_name}
273 ${port2_id}= Get Port Id ${port2_name}
274 ${rc} ${output}= Run And Return Rc And Output openstack server create --image ${image} --flavor ${flavor} --nic port-id=${port_id} --nic port-id=${port2_id} ${vm_instance_name} --security-group ${sg}
276 Should Be True '${rc}' == '0'
278 Create Vm Instance With Port On Compute Node
279 [Arguments] ${port_name} ${vm_instance_name} ${compute_node} ${image}=${EMPTY} ${flavor}=m1.nano ${sg}=default
280 [Documentation] Create One VM instance using given ${port_name} and for given ${compute_node}
281 ${image} Set Variable If "${image}"=="${EMPTY}" ${CIRROS_${OPENSTACK_BRANCH}} ${image}
282 ${port_id}= Get Port Id ${port_name}
283 ${hostname_compute_node}= Get Hypervisor Hostname From IP ${compute_node}
284 ${rc} ${output}= Run And Return Rc And Output openstack server create --image ${image} --flavor ${flavor} --nic port-id=${port_id} --security-group ${sg} --availability-zone nova:${hostname_compute_node} ${vm_instance_name}
286 Should Be True '${rc}' == '0'
288 Get Hypervisor Hostname From IP
289 [Arguments] ${hypervisor_ip}
290 [Documentation] Returns the hostname found for the given IP address if it's listed in hypervisor list. For debuggability
291 ... the full listing is logged first, then followed by a grep | cut to focus on the actual hostname to return
292 ${rc} ${output} Run And Return Rc And Output openstack hypervisor list
294 ${rc} ${hostname}= Run And Return Rc And Output openstack hypervisor list -f value | grep "${hypervisor_ip} " | cut -d" " -f 2
296 Should Be True '${rc}' == '0'
300 [Documentation] Create a nano flavor
301 ${rc} ${output}= Run And Return Rc And Output openstack flavor create m1.nano --id auto --ram 64 --disk 0 --vcpus 1
303 Should Be True '${rc}' == '0'
306 [Arguments] ${vm_name}
307 [Documentation] Run these commands to check whether the created vm instance is active or not.
308 ${rc} ${output}= Run And Return Rc And Output openstack server show ${vm_name} | grep OS-EXT-STS:vm_state
309 Should Be True '${rc}' == '0'
310 Should Contain ${output} active
313 [Arguments] ${vm_name} ${retry}=600s ${retry_interval}=30s
314 [Documentation] Run these commands to check whether the created vm instance is active or not.
315 Wait Until Keyword Succeeds ${retry} ${retry_interval} Verify VM Is ACTIVE ${vm_name}
317 Collect VM IP Addresses
318 [Arguments] ${fail_on_none} @{vm_list}
319 [Documentation] Using the console-log on the provided ${vm_list} to search for the string "obtained" which
320 ... correlates to the instance receiving it's IP address via DHCP. Also retrieved is the ip of the nameserver
321 ... if available in the console-log output. The keyword will also return a list of the learned ips as it
322 ... finds them in the console log output, and will have "None" for Vms that no ip was found.
323 ${ip_list} Create List @{EMPTY}
324 : FOR ${vm} IN @{vm_list}
325 \ ${rc} ${vm_ip_line}= Run And Return Rc And Output openstack console log show ${vm} | grep -i "obtained"
326 \ @{vm_ip} Get Regexp Matches ${vm_ip_line} [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}
327 \ ${vm_ip_length} Get Length ${vm_ip}
328 \ Run Keyword If ${vm_ip_length}>0 Append To List ${ip_list} @{vm_ip}[0]
329 \ ... ELSE Append To List ${ip_list} None
330 \ ${rc} ${dhcp_ip_line}= Run And Return Rc And Output openstack console log show ${vm} | grep "^nameserver"
331 \ ${dhcp_ip} Get Regexp Matches ${dhcp_ip_line} [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}
332 \ ${dhcp_ip_length} Get Length ${dhcp_ip}
333 \ Run Keyword If ${dhcp_ip_length}<=0 Append To List ${dhcp_ip} None
334 \ ${vm_console_output}= Run openstack console log show ${vm}
335 \ Log ${vm_console_output}
336 ${dhcp_length} Get Length ${dhcp_ip}
337 Run Keyword If '${fail_on_none}' == 'true' Should Not Contain ${ip_list} None
338 Run Keyword If '${fail_on_none}' == 'true' Should Not Contain ${dhcp_ip} None
339 Should Be True ${dhcp_length} <= 1
340 Return From Keyword If ${dhcp_length}==0 ${ip_list} ${EMPTY}
341 [Return] ${ip_list} ${dhcp_ip}
344 [Arguments] ${text} ${regexp} ${index}=0
345 [Documentation] Wrapper around Get Regexp Matches to return None if not found or the first match if found.
346 @{matches} = String.Get Regexp Matches ${text} ${regexp}
347 ${matches_length} = Get Length ${matches}
348 BuiltIn.Set Suite Variable ${OS_MATCH} None
349 BuiltIn.Run Keyword If ${matches_length} > ${index} BuiltIn.Set Suite Variable ${OS_MATCH} @{matches}[${index}]
353 [Arguments] ${fail_on_none} ${vm}
354 [Documentation] Get the vm ip address and nameserver by scraping the vm's console log.
355 ... Get VM IP returns three values: [0] the vm IP, [1] the DHCP IP and [2] the vm console log.
356 ${rc} ${vm_console_output}= Run And Return Rc And Output openstack console log show ${vm}
357 ${vm_ip} = Set Variable None
358 ${dhcp_ip} = Set Variable None
359 ${match} = Get Match ${vm_console_output} ${REGEX_OBTAINED}
360 ${vm_ip} = Get Match ${match} ${REGEX_IPV4} 0
361 ${match} = Get Match ${vm_console_output} ${REGEX_IPROUTE}
362 ${dhcp_ip} = Get Match ${match} ${REGEX_IPV4} 1
363 BuiltIn.Run Keyword If '${fail_on_none}' == 'true' Should Not Contain ${vm_ip} None
364 BuiltIn.Run Keyword If '${fail_on_none}' == 'true' Should Not Contain ${dhcp_ip} None
365 [Return] ${vm_ip} ${dhcp_ip} ${vm_console_output}
369 [Documentation] Get the instance IP addresses and nameserver address for the list of given vms.
370 ... First poll for the vm instance to be in the active state, then poll for the vm ip address and nameserver.
371 ... Get VM IPs returns two things: [0] a list of the ips for the vms passed to this keyword (may contain values
372 ... of None) and [1] the dhcp ip address found in the last vm checked.
373 ... TODO: there is a potential issue for a caller that passes in VMs belonging to different networks that
374 ... may have different dhcp server addresses. Not sure what TODO about that, but noting it here for reference.
375 @{vm_ips} BuiltIn.Create List @{EMPTY}
376 : FOR ${vm} IN @{vms}
377 \ Poll VM Is ACTIVE ${vm}
378 \ ${status} ${ips_and_console_log} Run Keyword And Ignore Error Wait Until Keyword Succeeds 180s 15s
379 \ ... Get VM IP true ${vm}
380 \ # If there is trouble with Get VM IP, the status will be FAIL and the return value will be a string of what went
381 \ # wrong. We need to handle both the PASS and FAIL cases. In the FAIL case we know we wont have access to the
382 \ # console log, as it would not be returned; so we need to grab it again to log it. We also can append 'None' to
383 \ # the vm ip list if status is FAIL.
384 \ Run Keyword If "${status}" == "PASS" BuiltIn.Log ${ips_and_console_log[2]}
385 \ BuiltIn.Run Keyword If "${status}" == "PASS" Collections.Append To List ${vm_ips} ${ips_and_console_log[0]}
386 \ BuiltIn.Run Keyword If "${status}" == "FAIL" Collections.Append To List ${vm_ips} None
387 \ ${rc} ${vm_console_output}= BuiltIn.Run Keyword If "${status}" == "FAIL" Run And Return Rc And Output openstack console log show ${vm}
388 \ BuiltIn.Run Keyword If "${status}" == "FAIL" BuiltIn.Log ${vm_console_output}
389 Copy DHCP Files From Control Node
390 [Return] @{vm_ips} ${ips_and_console_log[1]}
392 Collect VM IPv6 SLAAC Addresses
393 [Arguments] ${fail_on_none} ${vm_list} ${network} ${subnet}
394 [Documentation] For each VM parse output of "openstack server show" to get its IPv6 address from Neutron DB.
395 ... Then try to connect to each VM by SSH and execute there "ip -6 a" command. This double-check allows to
396 ... obtain and compare IP info (Neutron DB vs dnsmasque/ODL DHCP) and to test L2 connectivity as well.
397 ... Returns an empty list if no IPv6 addresses found or if SSH connection fails.
398 ... Otherwise, returns a list of IPv6 addresses.
399 ${ipv6_list} Create List @{EMPTY}
400 : FOR ${vm} IN @{vm_list}
401 \ ${rc} ${output}= Run And Return Rc And Output openstack server show ${vm} -f shell
403 \ Should Be True '${rc}' == '0'
404 \ ${pattern}= Replace String ${subnet} ::/64 (:[a-f0-9]{,4}){,4}
405 \ @{vm_ipv6}= Get Regexp Matches ${output} ${pattern}
406 \ ${vm_ip_length} Get Length ${vm_ipv6}[0]
407 \ ${ipv6_data_from_vm}= Run Keyword If ${vm_ip_length}>0 Execute Command on VM Instance ${network} ${vm_ipv6[0]}
409 \ @{ipv6}= Get Regexp Matches ${ipv6_data_from_vm} ${pattern}
410 \ ${ipv6_addr_list_length} Get Length @{ipv6}
411 \ Run Keyword If ${ipv6_addr_list_length}>0 Append To List ${ipv6_list} ${ipv6[0]}
412 \ ... ELSE Append To List ${ipv6_list} None
413 [Return] ${ipv6_list}
416 [Arguments] ${vm_instance_names}
417 [Documentation] View Console log of the created vm instances using nova show.
418 : FOR ${VmElement} IN @{vm_instance_names}
419 \ ${rc} ${output}= Run And Return Rc And Output openstack server show ${VmElement}
421 \ Should Be True '${rc}' == '0'
422 \ ${rc} ${output}= Run And Return Rc And Output openstack console log show ${VmElement}
424 \ Should Be True '${rc}' == '0'
426 Ping Vm From DHCP Namespace
427 [Arguments] ${net_name} ${vm_ip}
428 [Documentation] Reach all Vm Instance with the net id of the Netowrk.
429 Get ControlNode Connection
430 ${net_id}= Get Net Id ${net_name}
431 ${output}= Write Commands Until Prompt And Log sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip} 20s
432 Should Contain ${output} 64 bytes
434 Ping From DHCP Should Not Succeed
435 [Arguments] ${net_name} ${vm_ip}
436 [Documentation] Should Not Reach Vm Instance with the net id of the Netowrk.
437 Return From Keyword If "skip_if_${SECURITY_GROUP_MODE}" in @{TEST_TAGS}
438 Get ControlNode Connection
439 ${net_id}= Get Net Id ${net_name}
440 ${output}= Write Commands Until Prompt And Log sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip} 20s
441 Should Not Contain ${output} 64 bytes
443 Ping Vm From Control Node
444 [Arguments] ${vm_floating_ip} ${additional_args}=${EMPTY}
445 [Documentation] Ping VM floating IP from control node
446 Get ControlNode Connection
447 ${output}= Write Commands Until Prompt And Log ping ${additional_args} -c 3 ${vm_floating_ip} 20s
448 Should Contain ${output} 64 bytes
451 [Documentation] Ping to the expected destination ip.
452 ${output}= Write Commands Until Expected Prompt curl -i http://169.254.169.254 ${OS_SYSTEM_PROMPT}
453 Write Commands Until Prompt exit
454 Should Contain ${output} 200
457 [Documentation] Exit the vm instance.
458 ${output}= Write Commands Until Prompt And Log exit
460 Check If Console Is VmInstance
461 [Arguments] ${console}=cirros
462 [Documentation] Check if the session has been able to login to the VM instance
463 ${output}= Write Commands Until Expected Prompt id ${OS_SYSTEM_PROMPT}
464 Should Contain ${output} ${console}
467 [Documentation] Check if the session has been able to login to the VM instance and exit the instance
468 ${rcode}= Run Keyword And Return Status Check If Console Is VmInstance cirros
469 Run Keyword If ${rcode} Write Commands Until Prompt exit
472 [Arguments] ${ip_address} ${ttl}=64
473 [Documentation] Run Ping command on the IP available as argument
474 ${ethertype}= Get Regexp Matches ${ip_address} ${IP_REGEX}
475 ${output}= Run Keyword If ${ethertype} Write Commands Until Expected Prompt ping -t ${ttl} -c 3 ${ip_address} ${OS_SYSTEM_PROMPT}
476 ... ELSE Write Commands Until Expected Prompt ping6 -t ${ttl} -c 3 ${ip_address} ${OS_SYSTEM_PROMPT}
477 Should Contain ${output} 64 bytes
480 [Arguments] ${ip_address} ${ttl}=64
481 [Documentation] Run Ping command to the IP given as argument, executing 3 times and expecting NOT to see "64 bytes"
482 ${output}= Write Commands Until Expected Prompt ping -t ${ttl} -c 3 ${ip_address} ${OS_SYSTEM_PROMPT}
483 Should Not Contain ${output} 64 bytes
485 Check Metadata Access
486 [Documentation] Try curl on the Metadataurl and check if it is okay
487 ${output}= Write Commands Until Expected Prompt curl -i http://169.254.169.254 ${OS_SYSTEM_PROMPT}
488 Should Contain ${output} 200
490 Execute Command on VM Instance
491 [Arguments] ${net_name} ${vm_ip} ${cmd} ${user}=cirros ${password}=cubswin:)
492 [Documentation] Login to the vm instance using ssh in the network, executes a command inside the VM and returns the ouput.
493 Get ControlNode Connection
494 ${net_id} = Get Net Id ${net_name}
495 ${output} = Write Commands Until Expected Prompt sudo ip netns exec qdhcp-${net_id} ssh ${user}@${vm_ip} -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null password:
496 ${output} = Write Commands Until Expected Prompt ${password} ${OS_SYSTEM_PROMPT}
497 ${rcode} = Run Keyword And Return Status Check If Console Is VmInstance
498 ${output} = Run Keyword If ${rcode} Write Commands Until Expected Prompt ${cmd} ${OS_SYSTEM_PROMPT}
499 [Teardown] Exit From Vm Console
502 Test Operations From Vm Instance
503 [Arguments] ${net_name} ${src_ip} ${dest_ips} ${user}=cirros ${password}=cubswin:) ${ttl}=64
504 ... ${ping_should_succeed}=True ${check_metadata}=True
505 [Documentation] Login to the vm instance using ssh in the network.
506 Get ControlNode Connection
507 ${net_id}= Get Net Id ${net_name}
508 ${output}= Write Commands Until Expected Prompt sudo ip netns exec qdhcp-${net_id} ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no ${user}@${src_ip} -o UserKnownHostsFile=/dev/null password:
509 ${output}= Write Commands Until Expected Prompt ${password} ${OS_SYSTEM_PROMPT}
510 ${rcode}= Run Keyword And Return Status Check If Console Is VmInstance
511 Run Keyword If ${rcode} Write Commands Until Expected Prompt ifconfig ${OS_SYSTEM_PROMPT}
512 Run Keyword If ${rcode} Write Commands Until Expected Prompt route -n ${OS_SYSTEM_PROMPT}
513 Run Keyword If ${rcode} Write Commands Until Expected Prompt route -A inet6 ${OS_SYSTEM_PROMPT}
514 Run Keyword If ${rcode} Write Commands Until Expected Prompt arp -an ${OS_SYSTEM_PROMPT}
515 Run Keyword If ${rcode} Write Commands Until Expected Prompt ip -f inet6 neigh show ${OS_SYSTEM_PROMPT}
516 : FOR ${dest_ip} IN @{dest_ips}
517 \ ${string_empty}= Run Keyword And Return Status Should Be Empty ${dest_ip}
518 \ Run Keyword If ${string_empty} Continue For Loop
519 \ Run Keyword If ${rcode} and "${ping_should_succeed}" == "True" Check Ping ${dest_ip} ttl=${ttl}
520 \ ... ELSE Check No Ping ${dest_ip} ttl=${ttl}
521 ${ethertype}= Get Regexp Matches ${src_ip} ${IP_REGEX}
522 Run Keyword If ${rcode} and "${check_metadata}" and ${ethertype} == "True" Check Metadata Access
523 [Teardown] Exit From Vm Console
525 Test Netcat Operations From Vm Instance
526 [Arguments] ${net_name} ${vm_ip} ${dest_ip} ${additional_args}=${EMPTY} ${port}=12345 ${user}=cirros
527 ... ${password}=cubswin:)
528 [Documentation] Use Netcat to test TCP/UDP connections to the controller
529 ${client_data} Set Variable Test Client Data
530 ${server_data} Set Variable Test Server Data
531 Get ControlNode Connection
532 ${output}= Write Commands Until Prompt And Log ( ( echo "${server_data}" | sudo timeout 60 nc -l ${additional_args} ${port} ) & )
533 ${output}= Write Commands Until Prompt And Log sudo netstat -nlap | grep ${port}
534 ${nc_output}= Execute Command on VM Instance ${net_name} ${vm_ip} sudo echo "${client_data}" | nc -v -w 5 ${additional_args} ${dest_ip} ${port}
535 ${output}= Execute Command on VM Instance ${net_name} ${vm_ip} sudo route -n
537 ${output}= Execute Command on VM Instance ${net_name} ${vm_ip} sudo arp -an
539 Should Match Regexp ${nc_output} ${server_data}
542 [Arguments] ${list_of_external_dst_ips}
543 [Documentation] Check reachability with other network's instances.
544 ${rcode}= Run Keyword And Return Status Check If Console Is VmInstance
545 : FOR ${dest_ip} IN @{list_of_external_dst_ips}
546 \ Check Ping ${dest_ip}
549 [Arguments] ${router_name}
550 [Documentation] Create Router and Add Interface to the subnets.
551 ${rc} ${output}= Run And Return Rc And Output openstack router create ${router_name}
552 Should Be True '${rc}' == '0'
555 [Documentation] List Routers and return output with neutron client.
556 ${rc} ${output}= Run And Return Rc And Output openstack router list -f value
558 Should Be True '${rc}' == '0'
562 [Arguments] ${router_name} ${interface_name}
563 ${rc} ${output}= Run And Return Rc And Output openstack router add subnet ${router_name} ${interface_name}
564 Should Be True '${rc}' == '0'
566 Show Router Interface
567 [Arguments] ${router_name}
568 [Documentation] List Routers interface associated with given Router and return output with neutron client.
569 ${rc} ${output}= Run And Return Rc And Output openstack port list --router ${router_name} -f value
570 Should Be True '${rc}' == '0'
574 [Arguments] ${router_name} ${external_network_name}
575 ${cmd}= Set Variable If '${OPENSTACK_BRANCH}'=='stable/newton' neutron -v router-gateway-set ${router_name} ${external_network_name} openstack router set ${router_name} --external-gateway ${external_network_name}
576 ${rc} ${output}= Run And Return Rc And Output ${cmd}
577 Should Be True '${rc}' == '0'
580 [Arguments] ${router_name} ${interface_name}
581 [Documentation] Remove Interface to the subnets.
582 ${rc} ${output}= Run And Return Rc And Output openstack router remove subnet ${router_name} ${interface_name}
583 Should Be True '${rc}' == '0'
586 [Arguments] ${router_name}
587 [Documentation] Remove external gateway from the router.
588 BuiltIn.Log openstack router unset ${router_name} --external-gateway
591 [Arguments] ${router_name} ${cmd}
592 [Documentation] Update the router with the command. Router name and command should be passed as argument.
593 ${rc} ${output} = Run And Return Rc And Output openstack router set ${router_name} ${cmd}
594 Should Be True '${rc}' == '0'
597 [Arguments] ${router_name} ${options}
598 [Documentation] Show information of a given router. Router name and optional fields should be sent as arguments.
599 ${rc} ${output} = Run And Return Rc And Output openstack router show ${router_name}
603 [Arguments] ${router_name}
604 [Documentation] Delete Router and Interface to the subnets.
605 ${rc} ${output}= Run And Return Rc And Output openstack router delete ${router_name}
607 Should Be True '${rc}' == '0'
609 Get DumpFlows And Ovsconfig
610 [Arguments] ${conn_id}
611 [Documentation] Get the OvsConfig and Flow entries from OVS from the Openstack Node
612 SSHLibrary.Switch Connection ${conn_id}
613 Write Commands Until Expected Prompt ip -o link ${DEFAULT_LINUX_PROMPT_STRICT}
614 Write Commands Until Expected Prompt ip -o addr ${DEFAULT_LINUX_PROMPT_STRICT}
615 Write Commands Until Expected Prompt ip route ${DEFAULT_LINUX_PROMPT_STRICT}
616 Write Commands Until Expected Prompt arp -an ${DEFAULT_LINUX_PROMPT_STRICT}
617 ${nslist}= Write Commands Until Expected Prompt ip netns list | awk '{print $1}' ${DEFAULT_LINUX_PROMPT_STRICT}
618 @{lines} Split To Lines ${nslist} end=-1
619 : FOR ${line} IN @{lines}
620 \ Write Commands Until Expected Prompt sudo ip netns exec ${line} ip -o link ${DEFAULT_LINUX_PROMPT_STRICT}
621 \ Write Commands Until Expected Prompt sudo ip netns exec ${line} ip -o addr ${DEFAULT_LINUX_PROMPT_STRICT}
622 \ Write Commands Until Expected Prompt sudo ip netns exec ${line} ip route ${DEFAULT_LINUX_PROMPT_STRICT}
623 Write Commands Until Expected Prompt sudo ovs-vsctl show ${DEFAULT_LINUX_PROMPT_STRICT}
624 Write Commands Until Expected Prompt sudo ovs-vsctl list Open_vSwitch ${DEFAULT_LINUX_PROMPT_STRICT}
625 Write Commands Until Expected Prompt sudo ovs-ofctl show br-int -OOpenFlow13 ${DEFAULT_LINUX_PROMPT_STRICT}
626 Write Commands Until Expected Prompt sudo ovs-ofctl dump-flows br-int -OOpenFlow13 ${DEFAULT_LINUX_PROMPT_STRICT}
627 Write Commands Until Expected Prompt sudo ovs-ofctl dump-groups br-int -OOpenFlow13 ${DEFAULT_LINUX_PROMPT_STRICT}
628 Write Commands Until Expected Prompt sudo ovs-ofctl dump-group-stats br-int -OOpenFlow13 ${DEFAULT_LINUX_PROMPT_STRICT}
630 Get Karaf Log Type From Test Start
631 [Arguments] ${ip} ${test_name} ${type} ${user}=${ODL_SYSTEM_USER} ${password}=${ODL_SYSTEM_PASSWORD} ${prompt}=${ODL_SYSTEM_PROMPT}
632 ... ${log_file}=${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
633 ${cmd} Set Variable sed '1,/ROBOT MESSAGE: Starting test ${test_name}/d' ${log_file} | grep '${type}'
634 ${output} Run Command On Controller ${ip} ${cmd} ${user} ${password} ${prompt}
637 Get Karaf Log Types From Test Start
638 [Arguments] ${ip} ${test_name} ${types} ${user}=${ODL_SYSTEM_USER} ${password}=${ODL_SYSTEM_PASSWORD} ${prompt}=${ODL_SYSTEM_PROMPT}
639 ... ${log_file}=${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
640 : FOR ${type} IN @{types}
641 \ Get Karaf Log Type From Test Start ${ip} ${test_name} ${type} ${user} ${password}
642 \ ... ${prompt} ${log_file}
644 Get Karaf Log Events From Test Start
645 [Arguments] ${test_name} ${user}=${ODL_SYSTEM_USER} ${password}=${ODL_SYSTEM_PASSWORD} ${prompt}=${ODL_SYSTEM_PROMPT}
646 ${log_types} = Create List ERROR WARN Exception
647 Run Keyword If 0 < ${NUM_ODL_SYSTEM} Get Karaf Log Types From Test Start ${ODL_SYSTEM_IP} ${test_name} ${log_types}
648 Run Keyword If 1 < ${NUM_ODL_SYSTEM} Get Karaf Log Types From Test Start ${ODL_SYSTEM_2_IP} ${test_name} ${log_types}
649 Run Keyword If 2 < ${NUM_ODL_SYSTEM} Get Karaf Log Types From Test Start ${ODL_SYSTEM_3_IP} ${test_name} ${log_types}
651 Get ControlNode Connection
652 SSHLibrary.Switch Connection ${OS_CNTL_CONN_ID}
653 [Return] ${OS_CNTL_CONN_ID}
656 [Documentation] Get the OvsConfig and Flow entries from all Openstack nodes
657 Run Keyword If 0 < ${NUM_OS_SYSTEM} Get DumpFlows And Ovsconfig ${OS_CNTL_CONN_ID}
658 Run Keyword If 1 < ${NUM_OS_SYSTEM} Get DumpFlows And Ovsconfig ${OS_CMP1_CONN_ID}
659 Run Keyword If 2 < ${NUM_OS_SYSTEM} Get DumpFlows And Ovsconfig ${OS_CMP2_CONN_ID}
661 Get Test Teardown Debugs
662 [Arguments] ${test_name}=${TEST_NAME}
664 Run Keyword And Ignore Error Get Model Dump ${HA_PROXY_IP} ${netvirt_data_models}
665 Get Karaf Log Events From Test Start ${test_name}
667 Get Test Teardown Debugs For SFC
668 [Arguments] ${test_name}=${TEST_NAME}
669 Run Keyword And Ignore Error Get Model Dump ${HA_PROXY_IP} ${netvirt_sfc_data_models}
672 [Arguments] @{vm_indices}
673 [Documentation] Run these commands for debugging, it can list state of VM instances and ip information in control node
674 Get ControlNode Connection
675 ${output}= Write Commands Until Prompt And Log sudo ip netns list
676 : FOR ${index} IN @{vm_indices}
677 \ ${rc} ${output}= Run And Return Rc And Output nova show ${index}
687 [Documentation] Logging keyword to display all security groups using the openstack cli. Assumes openstack
688 ... credentials are already sourced
689 ${rc} ${output}= Run And Return Rc And Output openstack security group list
691 Should Be True '${rc}' == '0'
694 Neutron Security Group Show
695 [Arguments] ${SecurityGroupRuleName}
696 [Documentation] Displays the neutron security group configurations that belongs to a given neutron security group name
697 ${rc} ${output}= Run And Return Rc And Output openstack security group show ${SecurityGroupRuleName}
699 Should Be True '${rc}' == '0'
703 [Arguments] ${PortName}
704 [Documentation] Display the port configuration that belong to a given neutron port
705 ${rc} ${output}= Run And Return Rc And Output openstack port show ${PortName}
707 Should Be True '${rc}' == '0'
710 Neutron Security Group Create
711 [Arguments] ${SecurityGroupName} ${additional_args}=${EMPTY}
712 [Documentation] Create a security group with specified name ,description & protocol value according to security group template
713 Get ControlNode Connection
714 ${rc} ${output}= Run And Return Rc And Output openstack security group create ${SecurityGroupName} ${additional_args}
716 Should Be True '${rc}' == '0'
717 ${sgp_id}= Should Match Regexp ${output} [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}
719 [Return] ${output} ${sgp_id}
721 Neutron Security Group Update
722 [Arguments] ${SecurityGroupName} ${additional_args}=${EMPTY}
723 [Documentation] Updating security groups
724 ${rc} ${output}= Run And Return Rc And Output openstack security group set ${SecurityGroupName} ${additional_args}
726 Should Be True '${rc}' == '0'
730 [Arguments] ${sg_name}
731 [Documentation] Delete Security group
732 ${rc} ${output}= Run And Return Rc And Output openstack security group delete ${sg_name}
734 Should Be True '${rc}' == '0'
736 Neutron Security Group Rule Create
737 [Arguments] ${Security_group_name} &{Kwargs}
738 [Documentation] Creates neutron security rule with Openstack CLI with or without optional params, here security group name is mandatory args, rule with optional params can be created by passing the optional args values ex: direction=${INGRESS_EGRESS}, Then these optional params are catenated with mandatory args, example of usage: "Neutron Security Group Rule Create ${SGP_SSH} direction=${RULE_PARAMS[0]} ethertype=${RULE_PARAMS[1]} ..."
739 Run Keyword If ${Kwargs} Log ${Kwargs}
740 ${description} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} description default=${None}
741 ${direction} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} direction default=${None}
742 ${ethertype} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} ethertype default=${None}
743 ${port_range_max} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} port_range_max default=${None}
744 ${port_range_min} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} port_range_min default=${None}
745 ${protocol} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} protocol default=${None}
746 ${remote_group_id} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} remote_group_id default=${None}
747 ${remote_ip_prefix} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} remote_ip_prefix default=${None}
748 ${cmd}= Set Variable openstack security group rule create ${Security_group_name}
749 ${cmd}= Run Keyword If '${description}'!='None' Catenate ${cmd} --description ${description}
750 ... ELSE Catenate ${cmd}
751 ${cmd}= Run Keyword If '${direction}'!='None' Catenate ${cmd} --${direction}
752 ... ELSE Catenate ${cmd}
753 ${cmd}= Run Keyword If '${ethertype}'!='None' Catenate ${cmd} --ethertype ${ethertype}
754 ... ELSE Catenate ${cmd}
755 ${cmd}= Run Keyword If '${port_range_min}'!='None' and '${port_range_max}'!='None' Catenate ${cmd} --dst-port ${port_range_min}:${port_range_max}
756 ... ELSE IF '${port_range_max}'!='None' Catenate ${cmd} --dst-port ${port_range_max}
757 ... ELSE IF '${port_range_min}'!='None' Catenate ${cmd} --dst-port ${port_range_min}
758 ... ELSE Catenate ${cmd}
759 ${cmd}= Run Keyword If '${protocol}'!='None' Catenate ${cmd} --protocol ${protocol}
760 ... ELSE Catenate ${cmd}
761 ${cmd}= Run Keyword If '${remote_group_id}'!='None' Catenate ${cmd} --remote-group ${remote_group_id}
762 ... ELSE Catenate ${cmd}
763 ${cmd}= Run Keyword If '${remote_ip_prefix}'!='None' Catenate ${cmd} --src-ip ${remote_ip_prefix}
764 ... ELSE Catenate ${cmd}
765 ${rc} ${output}= Run And Return Rc And Output ${cmd}
766 ${rule_id}= Should Match Regexp ${output} [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}
768 Should Be True '${rc}' == '0'
769 [Return] ${output} ${rule_id}
771 Neutron Security Group Rule Create Legacy Cli
772 [Arguments] ${Security_group_name} &{Kwargs}
773 [Documentation] Creates neutron security rule with neutron request with or without optional params, here security group name is mandatory args, rule with optional params can be created by passing the optional args values ex: direction=${INGRESS_EGRESS}, Then these optional params are catenated with mandatory args, example of usage: "Neutron Security Group Rule Create ${SGP_SSH} direction=${RULE_PARAMS[0]} ethertype=${RULE_PARAMS[1]} ..."
774 Run Keyword If ${Kwargs} Log ${Kwargs}
775 ${description} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} description default=${None}
776 ${direction} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} direction default=${None}
777 ${ethertype} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} ethertype default=${None}
778 ${port_range_max} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} port_range_max default=${None}
779 ${port_range_min} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} port_range_min default=${None}
780 ${protocol} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} protocol default=${None}
781 ${remote_group_id} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} remote_group_id default=${None}
782 ${remote_ip_prefix} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} remote_ip_prefix default=${None}
783 ${cmd}= Set Variable neutron security-group-rule-create ${Security_group_name}
784 ${cmd}= Run Keyword If '${description}'!='None' Catenate ${cmd} --description ${description}
785 ... ELSE Catenate ${cmd}
786 ${cmd}= Run Keyword If '${direction}'!='None' Catenate ${cmd} --direction ${direction}
787 ... ELSE Catenate ${cmd}
788 ${cmd}= Run Keyword If '${ethertype}'!='None' Catenate ${cmd} --ethertype ${ethertype}
789 ... ELSE Catenate ${cmd}
790 ${cmd}= Run Keyword If '${port_range_max}'!='None' Catenate ${cmd} --port_range_max ${port_range_max}
791 ... ELSE Catenate ${cmd}
792 ${cmd}= Run Keyword If '${port_range_min}'!='None' Catenate ${cmd} --port_range_min ${port_range_min}
793 ... ELSE Catenate ${cmd}
794 ${cmd}= Run Keyword If '${protocol}'!='None' Catenate ${cmd} --protocol ${protocol}
795 ... ELSE Catenate ${cmd}
796 ${cmd}= Run Keyword If '${remote_group_id}'!='None' Catenate ${cmd} --remote_group_id ${remote_group_id}
797 ... ELSE Catenate ${cmd}
798 ${cmd}= Run Keyword If '${remote_ip_prefix}'!='None' Catenate ${cmd} --remote_ip_prefix ${remote_ip_prefix}
799 ... ELSE Catenate ${cmd}
800 ${rc} ${output}= Run And Return Rc And Output ${cmd}
801 ${rule_id}= Should Match Regexp ${output} [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}
803 Should Be True '${rc}' == '0'
804 [Return] ${output} ${rule_id}
806 Security Group Create Without Default Security Rules
807 [Arguments] ${sg_name} ${additional_args}=${EMPTY}
808 [Documentation] Create Neutron Security Group with no default rules, using specified name and optional arguments.
809 Neutron Security Group Create ${sg_name} ${additional_args}
810 Delete All Security Group Rules ${sg_name}
812 Delete All Security Group Rules
813 [Arguments] ${sg_name}
814 [Documentation] Delete all security rules from a specified security group
815 ${rc} ${sg_rules_output}= Run And Return Rc And Output openstack security group rule list ${sg_name} -cID -fvalue
816 Log ${sg_rules_output}
817 Should Be True '${rc}' == '0'
818 @{sg_rules}= Split String ${sg_rules_output} \n
819 : FOR ${rule} IN @{sg_rules}
820 \ ${rc} ${output}= Run And Return Rc And Output openstack security group rule delete ${rule}
822 \ Should Be True '${rc}' == '0'
824 Create Allow All SecurityGroup
825 [Arguments] ${sg_name} ${ether_type}=IPv4
826 [Documentation] Allow all TCP/UDP/ICMP packets for this suite
827 Neutron Security Group Create ${sg_name}
828 Neutron Security Group Rule Create ${sg_name} direction=ingress ethertype=${ether_type} port_range_max=65535 port_range_min=1 protocol=tcp
829 Neutron Security Group Rule Create ${sg_name} direction=egress ethertype=${ether_type} port_range_max=65535 port_range_min=1 protocol=tcp
830 Neutron Security Group Rule Create ${sg_name} direction=ingress ethertype=${ether_type} protocol=icmp
831 Neutron Security Group Rule Create ${sg_name} direction=egress ethertype=${ether_type} protocol=icmp
832 Neutron Security Group Rule Create ${sg_name} direction=ingress ethertype=${ether_type} port_range_max=65535 port_range_min=1 protocol=udp
833 Neutron Security Group Rule Create ${sg_name} direction=egress ethertype=${ether_type} port_range_max=65535 port_range_min=1 protocol=udp
835 Create Neutron Port With Additional Params
836 [Arguments] ${network_name} ${port_name} ${additional_args}=${EMPTY}
837 [Documentation] Create Port With given additional parameters
838 ${rc} ${output}= Run And Return Rc And Output neutron -v port-create ${network_name} --name ${port_name} ${additional_args}
840 Should Be True '${rc}' == '0'
841 ${port_id}= Should Match Regexp ${OUTPUT} [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}
843 [Return] ${OUTPUT} ${port_id}
846 [Arguments] ${portName_list}
847 [Documentation] Retrieve the port MacAddr for the given list of port name and return the MAC address list.
848 ${MacAddr-list} Create List
849 : FOR ${portName} IN @{portName_list}
850 \ ${macAddr}= OpenStackOperations.Get Port Mac ${portName}
851 \ Append To List ${MacAddr-list} ${macAddr}
852 [Return] ${MacAddr-list}
855 [Arguments] ${port_name}
856 [Documentation] Keyword would return the IP of the ${port_name} received.
857 ${rc} ${output}= Run And Return Rc And Output openstack port list | grep "${port_name}" | awk -F\\' '{print $2}'
858 ${splitted_output}= Split String ${output} ${EMPTY}
859 ${port_ip}= Get from List ${splitted_output} 0
860 Should Be True '${rc}' == '0'
864 [Arguments] ${port_name}
865 [Documentation] Keyword would return the MAC ID of the ${port_name} received.
866 ${rc} ${output}= Run And Return Rc And Output openstack port show ${port_name} | grep mac_address | awk '{print $4}'
867 ${splitted_output}= Split String ${output} ${EMPTY}
868 ${port_mac}= Get from List ${splitted_output} 0
869 Should Be True '${rc}' == '0'
873 [Arguments] ${bridge_name} ${intf_name} ${gw_name}
874 [Documentation] Keyword to create an L2 Gateway ${gw_name} for bridge ${bridge_name} connected to interface ${intf_name} (Using Neutron CLI).
875 ${rc} ${l2gw_output}= Run And Return Rc And Output ${L2GW_CREATE} name=${bridge_name},interface_names=${intf_name} ${gw_name}
877 [Return] ${l2gw_output}
879 Create L2Gateway Connection
880 [Arguments] ${gw_name} ${net_name}
881 [Documentation] Keyword would create a new L2 Gateway Connection for ${gw_name} to ${net_name} (Using Neutron CLI).
882 ${rc} ${l2gw_output}= Run And Return Rc And Output ${L2GW_CONN_CREATE} ${gw_name} ${net_name}
884 Should Be True '${rc}' == '0'
885 [Return] ${l2gw_output}
888 [Documentation] Keyword to return all the L2 Gateways available (Using Neutron CLI).
889 ${rc} ${output}= Run And Return Rc And Output ${L2GW_GET_YAML}
890 Should Be True '${rc}' == '0'
893 Get All L2Gateway Connection
894 [Documentation] Keyword to return all the L2 Gateway connections available (Using Neutron CLI).
895 ${rc} ${output}= Run And Return Rc And Output ${L2GW_GET_CONN_YAML}
896 Should Be True '${rc}' == '0'
901 [Documentation] Keyword to check if the ${gw_id} is available in the L2 Gateway list (Using Neutron CLI).
902 ${rc} ${output}= Run And Return Rc And Output ${L2GW_SHOW} ${gw_id}
904 Should Be True '${rc}' == '0'
908 [Arguments] ${l2gw_name}
909 [Documentation] Keyword to retrieve the L2 Gateway ID for the ${l2gw_name} (Using Neutron CLI).
910 ${rc} ${output}= Run And Return Rc And Output ${L2GW_GET} | grep "${l2gw_name}" | awk '{print $2}'
912 Should Be True '${rc}' == '0'
913 ${splitted_output}= Split String ${output} ${EMPTY}
914 ${l2gw_id}= Get from List ${splitted_output} 0
917 Get L2gw Connection Id
918 [Arguments] ${l2gw_name}
919 [Documentation] Keyword to retrieve the L2 Gateway Connection ID for the ${l2gw_name} (Using Neutron CLI).
920 ${l2gw_id}= OpenStackOperations.Get L2gw Id ${l2gw_name}
921 ${rc} ${output}= Run And Return Rc And Output ${L2GW_GET_CONN} | grep "${l2gw_id}" | awk '{print $2}'
922 Should Be True '${rc}' == '0'
923 ${splitted_output}= Split String ${output} ${EMPTY}
924 ${splitted_output}= Split String ${output} ${EMPTY}
925 ${l2gw_conn_id}= Get from List ${splitted_output} 0
926 [Return] ${l2gw_conn_id}
928 Neutron Port List Rest
929 [Documentation] Keyword to get all ports details in Neutron (Using REST).
930 ${resp} = RequestsLibrary.Get Request session ${PORT_URL}
932 Should Be Equal As Strings ${resp.status_code} 200
933 [Return] ${resp.content}
935 Get Neutron Port Rest
936 [Arguments] ${port_id}
937 [Documentation] Keyword to get the specific port details in Neutron (Using REST).
938 ${resp} = RequestsLibrary.Get Request session ${CONFIG_API}/${GET_PORT_URL}/${port_id}
940 Should Be Equal As Strings ${resp.status_code} 200
941 [Return] ${resp.content}
944 [Arguments] ${port_id} ${json_data}
945 [Documentation] Keyword to update ${port_id} with json data received in ${json_data} (Using REST).
947 ${resp} = RequestsLibrary.Put Request session ${CONFIG_API}/${GET_PORT_URL}/${port_id} ${json_data}
949 Should Be Equal As Strings ${resp.status_code} 200
950 [Return] ${resp.content}
952 Create And Configure Security Group
953 [Arguments] ${sg-name}
954 [Documentation] Create Security Group with given name, and default allow rules for TCP/UDP/ICMP protocols.
955 Neutron Security Group Create ${sg-name}
956 Neutron Security Group Rule Create ${sg-name} direction=ingress port_range_max=65535 port_range_min=1 protocol=tcp remote_ip_prefix=0.0.0.0/0
957 Neutron Security Group Rule Create ${sg-name} direction=egress port_range_max=65535 port_range_min=1 protocol=tcp remote_ip_prefix=0.0.0.0/0
958 Neutron Security Group Rule Create ${sg-name} direction=ingress protocol=icmp remote_ip_prefix=0.0.0.0/0
959 Neutron Security Group Rule Create ${sg-name} direction=egress protocol=icmp remote_ip_prefix=0.0.0.0/0
960 Neutron Security Group Rule Create ${sg-name} direction=ingress port_range_max=65535 port_range_min=1 protocol=udp remote_ip_prefix=0.0.0.0/0
961 Neutron Security Group Rule Create ${sg-name} direction=egress port_range_max=65535 port_range_min=1 protocol=udp remote_ip_prefix=0.0.0.0/0
963 Add Security Group To VM
964 [Arguments] ${vm} ${sg}
965 [Documentation] Add the security group provided to the given VM.
966 ${rc} ${output}= Run And Return Rc And Output openstack server add security group ${vm} ${sg}
968 Should Be True '${rc}' == '0'
970 Remove Security Group From VM
971 [Arguments] ${vm} ${sg}
972 [Documentation] Remove the security group provided to the given VM.
973 Get ControlNode Connection
974 ${output}= Write Commands Until Prompt And Log openstack server remove security group ${vm} ${sg}
976 Create SFC Flow Classifier
977 [Arguments] ${name} ${src_ip} ${dest_ip} ${protocol} ${dest_port} ${neutron_src_port}
978 [Documentation] Create a flow classifier for SFC
979 ${rc} ${output}= Run And Return Rc And Output openstack sfc flow classifier create --ethertype IPv4 --source-ip-prefix ${src_ip}/32 --destination-ip-prefix ${dest_ip}/32 --protocol ${protocol} --destination-port ${dest_port}:${dest_port} --logical-source-port ${neutron_src_port} ${name}
981 Should Be True '${rc}' == '0'
982 Should Contain ${output} ${name}
985 Delete SFC Flow Classifier
987 [Documentation] Delete a SFC flow classifier
988 Get ControlNode Connection
989 ${rc} ${output}= Run And Return Rc And Output openstack sfc flow classifier delete ${name}
991 Should Be True '${rc}' == '0'
995 [Arguments] ${name} ${port_in} ${port_out}
996 [Documentation] Creates a neutron port pair for SFC
997 Get ControlNode Connection
998 ${rc} ${output}= Run And Return Rc And Output openstack sfc port pair create --ingress=${port_in} --egress=${port_out} ${name}
1000 Should Be True '${rc}' == '0'
1001 Should Contain ${output} ${name}
1004 Delete SFC Port Pair
1006 [Documentation] Delete a SFC port pair
1007 ${rc} ${output}= Run And Return Rc And Output openstack sfc port pair delete ${name}
1009 Should Be True '${rc}' == '0'
1012 Create SFC Port Pair Group
1013 [Arguments] ${name} ${port_pair}
1014 [Documentation] Creates a port pair group with a single port pair for SFC
1015 ${rc} ${output}= Run And Return Rc And Output openstack sfc port pair group create --port-pair ${port_pair} ${name}
1017 Should Be True '${rc}' == '0'
1018 Should Contain ${output} ${name}
1021 Create SFC Port Pair Group With Two Pairs
1022 [Arguments] ${name} ${port_pair1} ${port_pair2}
1023 [Documentation] Creates a port pair group with two port pairs for SFC
1024 ${rc} ${output}= Run And Return Rc And Output openstack sfc port pair group create --port-pair ${port_pair1} --port-pair ${port_pair2} ${name}
1026 Should Be True '${rc}' == '0'
1027 Should Contain ${output} ${name}
1030 Delete SFC Port Pair Group
1032 [Documentation] Delete a SFC port pair group
1033 Get ControlNode Connection
1034 ${rc} ${output}= Run And Return Rc And Output openstack sfc port pair group delete ${name}
1036 Should Be True '${rc}' == '0'
1039 Create SFC Port Chain
1040 [Arguments] ${name} ${pg1} ${pg2} ${fc}
1041 [Documentation] Creates a port pair chain with two port groups and a singel classifier.
1042 ${rc} ${output}= Run And Return Rc And Output openstack sfc port chain create --port-pair-group ${pg1} --port-pair-group ${pg2} --flow-classifier ${fc} ${name}
1044 Should Be True '${rc}' == '0'
1045 Should Contain ${output} ${name}
1048 Delete SFC Port Chain
1050 [Documentation] Delete a SFC port chain
1051 ${rc} ${output}= Run And Return Rc And Output openstack sfc port chain delete ${name}
1053 Should Be True '${rc}' == '0'
1057 [Arguments] ${vm_name}
1058 [Documentation] Reboot NOVA VM
1059 ${rc} ${output}= Run And Return Rc And Output openstack server reboot --wait ${vm_name}
1061 Should Be True '${rc}' == '0'
1062 Wait Until Keyword Succeeds 35s 10s Verify VM Is ACTIVE ${vm_name}
1064 Remove RSA Key From KnownHosts
1065 [Arguments] ${vm_ip}
1066 [Documentation] Remove RSA
1067 Get ControlNode Connection
1068 ${output}= Write Commands Until Prompt And Log sudo cat /root/.ssh/known_hosts 30s
1069 ${output}= Write Commands Until Prompt And Log sudo ssh-keygen -f "/root/.ssh/known_hosts" -R ${vm_ip} 30s
1070 ${output}= Write Commands Until Prompt sudo cat "/root/.ssh/known_hosts" 30s
1072 Wait For Routes To Propogate
1073 [Arguments] ${networks} ${subnets}
1074 [Documentation] Check propagated routes
1075 Get ControlNode Connection
1076 : FOR ${INDEX} IN RANGE 0 1
1077 \ ${net_id}= Get Net Id @{networks}[${INDEX}]
1078 \ ${is_ipv6}= Get Regexp Matches @{subnets}[${INDEX}] ${IP6_REGEX}
1079 \ ${length}= Get Length ${is_ipv6}
1080 \ ${cmd}= Set Variable If ${length} == 0 ip route ip -6 route
1081 \ ${output}= Write Commands Until Expected Prompt sudo ip netns exec qdhcp-${net_id} ${cmd} ]>
1082 \ Should Contain ${output} @{subnets}[${INDEX}]
1085 [Arguments] ${vms}=@{EMPTY} ${networks}=@{EMPTY} ${subnets}=@{EMPTY} ${ports}=@{EMPTY} ${sgs}=@{EMPTY}
1086 : FOR ${vm} IN @{vms}
1087 \ BuiltIn.Run Keyword And Ignore Error Delete Vm Instance ${vm}
1088 : FOR ${port} IN @{ports}
1089 \ BuiltIn.Run Keyword And Ignore Error Delete Port ${port}
1090 : FOR ${subnet} IN @{subnets}
1091 \ BuiltIn.Run Keyword And Ignore Error Delete SubNet ${subnet}
1092 : FOR ${network} IN @{networks}
1093 \ BuiltIn.Run Keyword And Ignore Error Delete Network ${network}
1094 : FOR ${sg} IN @{sgs}
1095 \ BuiltIn.Run Keyword And Ignore Error Delete SecurityGroup ${sg}
1098 [Documentation] Get a list of different OpenStack resources that might be in use.
1099 @{modules} = BuiltIn.Create List floating ip server router port network
1100 ... subnet security group security group rule
1101 : FOR ${module} IN @{modules}
1102 \ OpenStack CLI openstack ${module} list
1104 OpenStack CLI Get List
1106 [Documentation] Return a json list from the output of an OpenStack command.
1107 ${json} = OpenStack CLI ${cmd}
1108 @{list} = RequestsLibrary.To Json ${json}
1114 [Documentation] Run the given OpenStack ${cmd}.
1115 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output ${cmd}
1116 BuiltIn.Log ${output}
1117 Should Be True '${rc}' == '0'
1120 OpenStack Cleanup All
1121 [Documentation] Cleanup all Openstack resources with best effort. The keyword will query for all resources
1122 ... in use and then attempt to delete them. Errors are ignored to allow the cleanup to continue.
1123 @{fips} = OpenStack CLI Get List openstack floating ip list -f json
1124 : FOR ${fip} IN @{fips}
1125 \ BuiltIn.Run Keyword And Ignore Error Delete Floating IP ${fip['ID']}
1126 @{vms} = OpenStack CLI Get List openstack server list -f json
1127 : FOR ${vm} IN @{vms}
1128 \ BuiltIn.Run Keyword And Ignore Error Delete Vm Instance ${vm['ID']}
1129 @{routers} = OpenStack CLI Get List openstack router list -f json
1130 : FOR ${router} IN @{routers}
1131 \ BuiltIn.Run Keyword And Ignore Error Cleanup Router ${router['ID']}
1132 @{ports} = OpenStack CLI Get List openstack port list -f json
1133 : FOR ${port} IN @{ports}
1134 \ BuiltIn.Run Keyword And Ignore Error Delete Port ${port['ID']}
1135 @{networks} = OpenStack CLI Get List openstack network list -f json
1136 : FOR ${network} IN @{networks}
1137 \ BuiltIn.Run Keyword And Ignore Error Delete Subnet ${network['Subnets']}
1138 \ BuiltIn.Run Keyword And Ignore Error Delete Network ${network['ID']}
1139 @{security_groups} = OpenStack CLI Get List openstack security group list -f json
1140 : FOR ${security_group} IN @{security_groups}
1141 \ BuiltIn.Run Keyword If "${security_group['Name']}" != "default" BuiltIn.Run Keyword And Ignore Error Delete SecurityGroup ${security_group['ID']}
1146 [Documentation] Delete a router, but first remove any interfaces or gateways so that the delete will be successful.
1147 @{ports} = OpenStack CLI Get List openstack port list --router ${id} -f json --long
1148 : FOR ${port} IN @{ports}
1149 \ ${subnet_id} = Get Match ${port['Fixed IP Addresses']} [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} 0
1150 \ BuiltIn.Run Keyword If "${port['Device Owner']}" == "network:router_gateway" BuiltIn.Run Keyword And Ignore Error Remove Gateway ${id}
1151 \ BuiltIn.Run Keyword If "${port['Device Owner']}" == "network:router_interface" BuiltIn.Run Keyword And Ignore Error Remove Interface ${id} ${subnet_id}
1152 BuiltIn.Run Keyword And Ignore Error Delete Router ${id}
1154 OpenStack Suite Setup
1155 [Documentation] Wrapper teardown keyword that can be used in any suite running in an openstack environement
1156 SetupUtils.Setup_Utils_For_Setup_And_Teardown
1157 DevstackUtils.Devstack Suite Setup
1159 OpenStack Suite Teardown
1160 [Documentation] Wrapper teardown keyword that can be used in any suite running in an openstack environement
1161 ... to clean up all openstack resources. For example, all instances, networks, ports, etc will be listed and
1162 ... and deleted. As other global cleanup tasks are needed, they can be added here and the suites will all
1163 ... benefit automatically.
1164 OpenStack Cleanup All
1165 SSHLibrary.Close All Connections
1167 Copy DHCP Files From Control Node
1168 [Documentation] Copy the current DHCP files to the robot vm. The keyword must be called
1169 ... after the subnet(s) are created and before the subnet(s) are deleted.
1170 ${suite_} = BuiltIn.Evaluate """${SUITE_NAME}""".replace(" ","_").replace("/","_").replace(".","_")
1171 ${dstdir} = Set Variable /tmp/qdhcp/${suite_}
1172 OperatingSystem.Create Directory ${dstdir}
1173 Get ControlNode Connection
1174 BuiltIn.Run Keyword And Ignore Error SSHLibrary.Get Directory /opt/stack/data/neutron/dhcp ${dstdir} recursive=True
1176 Is Feature Installed
1177 [Arguments] ${features}=none
1178 : FOR ${feature} IN ${features}
1179 \ ${status} ${output} Run Keyword And Ignore Error Builtin.Should Contain ${CONTROLLERFEATURES} ${feature}
1180 \ Return From Keyword If "${status}" == "PASS" True