2 Documentation Openstack library. This library is useful for tests to create network, subnet, router and vm instances
5 Library OperatingSystem
6 Library RequestsLibrary
9 Resource DataModels.robot
10 Resource DevstackUtils.robot
11 Resource L2GatewayOperations.robot
13 Resource SetupUtils.robot
14 Resource SSHKeywords.robot
15 Resource Tcpdump.robot
17 Resource ../variables/Variables.robot
18 Resource ../variables/netvirt/Variables.robot
19 Variables ../variables/netvirt/Modules.py
23 Get Tenant ID From Security Group
24 [Documentation] Returns tenant ID by reading it from existing default security-group.
25 ${output} = OpenStack CLI openstack security group show default | grep "| tenant_id" | awk '{print $4}'
28 Get Tenant ID From Network
29 [Documentation] Returns tenant ID by reading it from existing network.
30 [Arguments] ${network_uuid}
31 ${resp} = TemplatedRequests.Get_From_Uri
32 ... uri=${CONFIG_API}/neutron:neutron/networks/network/${network_uuid}/
33 ... accept=${ACCEPT_EMPTY}
35 ${temp_vars} = BuiltIn.Set Variable ['network'][0]['tenant-id']
36 ${tenant_id} = Utils.Extract Value From Content ${resp} ${temp_vars}
40 [Documentation] Create Network with neutron request.
41 [Arguments] ${network_name} ${additional_args}=${EMPTY} ${verbose}=TRUE
42 ${output} = OpenStack CLI openstack network create ${network_name} ${additional_args}
46 [Documentation] Update Network with neutron request.
47 [Arguments] ${network_name} ${additional_args}=${EMPTY}
48 ${cmd} = BuiltIn.Set Variable If
49 ... '${OPENSTACK_BRANCH}'=='stable/newton'
50 ... neutron -v net-update ${network_name} ${additional_args}
51 ... openstack network set ${network_name} ${additional_args}
52 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output ${cmd}
54 BuiltIn.Should Be True '${rc}' == '0'
58 [Documentation] Show Network with neutron request.
59 [Arguments] ${network_name}
60 ${output} = OpenStack CLI openstack network show ${network_name}
64 [Documentation] List networks and return output with neutron client.
65 ${output} = OpenStack CLI openstack network list
69 [Documentation] List subnets and return output with neutron client.
70 ${output} = OpenStack CLI openstack subnet list
74 [Documentation] Delete Network with neutron request.
75 [Arguments] ${network_name}
76 ${output} = OpenStack CLI openstack network delete ${network_name}
79 [Documentation] Create SubNet for the Network with neutron request.
80 [Arguments] ${network_name} ${subnet_name} ${range_ip} ${additional_args}=${EMPTY}
81 ${output} = OpenStack CLI
82 ... openstack subnet create --network ${network_name} --subnet-range ${range_ip} ${subnet_name} ${additional_args}
85 [Documentation] Update subnet with neutron request.
86 [Arguments] ${subnet_name} ${additional_args}=${EMPTY}
87 ${cmd} = BuiltIn.Set Variable If
88 ... '${OPENSTACK_BRANCH}'=='stable/newton'
89 ... neutron -v subnet-update ${subnet_name} ${additional_args}
90 ... openstack subnet set ${subnet_name} ${additional_args}
91 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output ${cmd}
93 BuiltIn.Should Be True '${rc}' == '0'
97 [Documentation] Show subnet with neutron request.
98 [Arguments] ${subnet_name}
99 ${output} = OpenStack CLI openstack subnet show ${subnet_name}
103 [Documentation] Create Port with neutron request.
104 [Arguments] ${network_name} ${port_name} ${sg}=default ${additional_args}=${EMPTY} ${allowed_address_pairs}=${EMPTY}
105 # if allowed_address_pairs is not empty we need to create the arguments to pass to the port create command. They are
106 # in a different format with the neutron vs openstack cli.
107 ${address_pair_length} = BuiltIn.Get Length ${allowed_address_pairs}
108 ${allowed_pairs_argv} = BuiltIn.Set Variable If
109 ... '${OPENSTACK_BRANCH}'=='stable/newton' and '${address_pair_length}'=='2'
110 ... --allowed-address-pairs type=dict list=true ip_address=${allowed_address_pairs}[0] ip_address=${allowed_address_pairs}[1]
111 ${allowed_pairs_argv} = BuiltIn.Set Variable If
112 ... '${OPENSTACK_BRANCH}'!='stable/newton' and '${address_pair_length}'=='2'
113 ... --allowed-address ip-address=${allowed_address_pairs}[0] --allowed-address ip-address=${allowed_address_pairs}[1]
114 ... ${allowed_pairs_argv}
115 ${allowed_pairs_argv} = BuiltIn.Set Variable If
116 ... '${address_pair_length}'=='0'
118 ... ${allowed_pairs_argv}
119 ${cmd} = BuiltIn.Set Variable If
120 ... '${OPENSTACK_BRANCH}'=='stable/newton'
121 ... neutron -v port-create ${network_name} --name ${port_name} --security-group ${sg} ${additional_args} ${allowed_pairs_argv}
122 ... openstack port create --network ${network_name} ${port_name} --security-group ${sg} ${additional_args} ${allowed_pairs_argv}
123 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output ${cmd}
124 BuiltIn.Log ${output}
125 BuiltIn.Should Be True '${rc}' == '0'
128 [Documentation] Update port with neutron request.
129 [Arguments] ${port_name} ${additional_args}=${EMPTY}
130 ${output} = OpenStack CLI openstack port set ${port_name} ${additional_args}
134 [Documentation] Show port with neutron request.
135 [Arguments] ${port_name}
136 ${output} = OpenStack CLI openstack port show ${port_name}
140 [Documentation] Delete Port with neutron request.
141 [Arguments] ${port_name}
142 ${output} = OpenStack CLI openstack port delete ${port_name}
145 [Arguments] ${user_name} ${domain} ${password} ${rc_file}=${EMPTY}
146 IF "${rc_file}" != "${EMPTY}"
147 ${rc} ${output} = Run And Return Rc And Output
148 ... source ${rc_file};openstack user create ${user_name} --domain ${domain} --password ${password}
150 ${rc} ${output} = Run And Return Rc And Output
151 ... openstack user create ${user_name} --domain ${domain} --password ${password}
154 Should Not Be True ${rc}
158 [Arguments] ${project_name} ${user_name} ${role} ${rc_file}=${EMPTY}
159 IF "${rc_file}" != "${EMPTY}"
160 ${rc} ${output} = Run And Return Rc And Output
161 ... source ${rc_file};openstack role add --project ${project_name} --user ${user_name} ${role}
163 ${rc} ${output} = Run And Return Rc And Output
164 ... openstack role add --project ${project_name} --user ${user_name} ${role}
167 Should Not Be True ${rc}
171 [Arguments] ${region_name} ${host_name} ${service_category} ${endpoint_category} ${port} ${rc_file}=${EMPTY}
172 IF "${rc_file}" != "${EMPTY}"
173 ${rc} ${output} = Run And Return Rc And Output
174 ... source ${rc_file};openstack endpoint create --region ${region_name} ${service_category} ${endpoint_category} http://${host_name}:${port}
176 ${rc} ${output} = Run And Return Rc And Output
177 ... openstack endpoint create --region ${region_name} ${service_category} ${endpoint_category} http://${host_name}:${port}
180 Should Not Be True ${rc}
183 [Documentation] List ports and return output with neutron client.
184 ${output} = OpenStack CLI openstack port list
188 [Documentation] List VMs and return output with nova client.
189 ${output} = OpenStack CLI openstack server list --all-projects
192 Create And Associate Floating IPs
193 [Documentation] Create and associate floating IPs to VMs with nova request
194 [Arguments] ${external_net} @{vm_list}
195 ${ip_list} = BuiltIn.Create List @{EMPTY}
196 FOR ${vm} IN @{vm_list}
197 ${output} = OpenStack CLI openstack floating ip create ${external_net}
198 @{ip} = String.Get Regexp Matches ${output} [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}
199 ${ip_length} = BuiltIn.Get Length ${ip}
201 Collections.Append To List ${ip_list} ${ip}[0]
203 Collections.Append To List ${ip_list} None
205 ${output} = OpenStack CLI openstack server add floating ip ${vm} ${ip}[0]
210 [Documentation] Delete floating ip with neutron request.
212 ${output} = OpenStack CLI openstack floating ip delete ${fip}
215 [Documentation] Delete SubNet for the Network with neutron request.
216 [Arguments] ${subnet}
217 ${output} = OpenStack CLI openstack subnet delete ${subnet}
220 [Documentation] Delete Vm instances using instance names.
221 [Arguments] ${vm_name}
222 ${output} = OpenStack CLI openstack server delete ${vm_name}
225 [Documentation] Retrieve the net id for the given network name to create specific vm instance
226 [Arguments] ${network_name}
227 ${output} = OpenStack CLI openstack network list | grep "${network_name}" | awk '{print $2}'
228 ${splitted_output} = String.Split String ${output} ${EMPTY}
229 ${net_id} = Collections.Get from List ${splitted_output} 0
233 [Documentation] Retrieve the subnet id for the given subnet name
234 [Arguments] ${subnet_name}
235 ${output} = OpenStack CLI openstack subnet show "${subnet_name}" | grep " id " | awk '{print $4}'
236 ${splitted_output} = String.Split String ${output} ${EMPTY}
237 ${subnet_id} = Collections.Get from List ${splitted_output} 0
241 [Documentation] Retrieve the port id for the given port name to attach specific vm instance to a particular port
242 [Arguments] ${port_name}
243 ${output} = OpenStack CLI openstack port list | grep "${port_name}" | awk '{print $2}'
244 ${splitted_output} = String.Split String ${output} ${EMPTY}
245 ${port_id} = Collections.Get from List ${splitted_output} 0
249 [Documentation] Retrieve the router id for the given router name
250 [Arguments] ${router1}
251 ${output} = OpenStack CLI openstack router show "${router1}" |awk '/ id / {print $4}'
252 ${splitted_output} = String.Split String ${output} ${EMPTY}
253 ${router_id} = Collections.Get from List ${splitted_output} 0
257 [Documentation] Create X Vm Instance with the net id of the Netowrk.
258 [Arguments] ${net_name} ${vm_instance_names} ${image}=${EMPTY} ${flavor}=m1.nano ${sg}=default ${min}=1
260 ${image} = BuiltIn.Set Variable If "${image}"=="${EMPTY}" ${CIRROS_${OPENSTACK_BRANCH}} ${image}
261 ${net_id} = OpenStackOperations.Get Net Id ${net_name}
262 FOR ${vm} IN @{vm_instance_names}
263 ${output} = OpenStack CLI
264 ... openstack server create --image ${image} --flavor ${flavor} --nic net-id=${net_id} ${vm} --security-group ${sg} --min ${min} --max ${max}
267 Create Vm Instance On Compute Node
268 [Documentation] Create a VM instance on a specific compute node.
269 [Arguments] ${net_name} ${vm_name} ${node_hostname} ${image}=${EMPTY} ${flavor}=m1.nano ${sg}=default
270 ${image} = BuiltIn.Set Variable If "${image}"=="${EMPTY}" ${CIRROS_${OPENSTACK_BRANCH}} ${image}
271 ${net_id} = OpenStackOperations.Get Net Id ${net_name}
272 ${output} = OpenStack CLI
273 ... openstack server create ${vm_name} --image ${image} --flavor ${flavor} --nic net-id=${net_id} --security-group ${sg} --availability-zone nova:${node_hostname}
275 Create Vm Instance With Port
276 [Documentation] Create One VM instance using given ${port_name} and for given ${compute_node}
277 [Arguments] ${port_name} ${vm_instance_name} ${image}=${EMPTY} ${flavor}=m1.nano ${sg}=default
278 ${image} = BuiltIn.Set Variable If "${image}"=="${EMPTY}" ${CIRROS_${OPENSTACK_BRANCH}} ${image}
279 ${port_id} = OpenStackOperations.Get Port Id ${port_name}
280 ${output} = OpenStack CLI
281 ... openstack server create --image ${image} --flavor ${flavor} --nic port-id=${port_id} ${vm_instance_name} --security-group ${sg}
283 Create Vm Instance With Ports
284 [Documentation] Create One VM instance using given ${port_name} and for given ${compute_node}
285 [Arguments] ${port_name} ${port2_name} ${vm_instance_name} ${image}=${EMPTY} ${flavor}=m1.nano ${sg}=default
286 ${image} = BuiltIn.Set Variable If "${image}"=="${EMPTY}" ${CIRROS_${OPENSTACK_BRANCH}} ${image}
287 ${port_id} = OpenStackOperations.Get Port Id ${port_name}
288 ${port2_id} = OpenStackOperations.Get Port Id ${port2_name}
289 ${output} = OpenStack CLI
290 ... openstack server create --image ${image} --flavor ${flavor} --nic port-id=${port_id} --nic port-id=${port2_id} ${vm_instance_name} --security-group ${sg}
292 Create Vm Instance With Port On Compute Node
293 [Documentation] Create One VM instance using given ${port_name} and for given ${compute_node}
294 [Arguments] ${port_name} ${vm_instance_name} ${node_hostname} ${image}=${EMPTY} ${flavor}=m1.nano ${sg}=default
295 ${image} = BuiltIn.Set Variable If "${image}"=="${EMPTY}" ${CIRROS_${OPENSTACK_BRANCH}} ${image}
296 ${port_id} = OpenStackOperations.Get Port Id ${port_name}
297 ${output} = OpenStack CLI
298 ... openstack server create --image ${image} --flavor ${flavor} --nic port-id=${port_id} --security-group ${sg} --availability-zone nova:${node_hostname} ${vm_instance_name}
300 Get Hypervisor Hostname From IP
301 [Documentation] Returns the hostname found for the given IP address if it's listed in hypervisor list. For debuggability
302 ... the full listing is logged first, then followed by a grep | cut to focus on the actual hostname to return
303 [Arguments] ${hypervisor_ip}
304 ${output} = OpenStack CLI openstack hypervisor list
305 ${hostname} = OpenStack CLI openstack hypervisor list -f value | grep "${hypervisor_ip} " | cut -d" " -f 2
309 [Documentation] Create a nano flavor
310 ${output} = OpenStack CLI openstack flavor create m1.nano --id auto --ram 64 --disk 0 --vcpus 1
313 [Documentation] Run these commands to check whether the created vm instance is active or not.
314 [Arguments] ${vm_name}
315 ${output} = OpenStack CLI openstack server show ${vm_name} | grep OS-EXT-STS:vm_state
316 BuiltIn.Should Contain ${output} active
319 [Documentation] Run these commands to check whether the created vm instance is active or not.
320 [Arguments] ${vm_name} ${retry}=600s ${retry_interval}=30s
321 BuiltIn.Wait Until Keyword Succeeds
323 ... ${retry_interval}
324 ... OpenStackOperations.Verify VM Is ACTIVE
327 Collect VM IP Addresses
328 [Documentation] Using the console-log on the provided ${vm_list} to search for the string "obtained" which
329 ... correlates to the instance receiving it's IP address via DHCP. Also retrieved is the ip of the nameserver
330 ... if available in the console-log output. The keyword will also return a list of the learned ips as it
331 ... finds them in the console log output, and will have "None" for Vms that no ip was found.
332 [Arguments] ${fail_on_none} @{vm_list}
333 ${ip_list} = Create List @{EMPTY}
334 FOR ${vm} IN @{vm_list}
335 ${rc} ${vm_ip_line} = Run And Return Rc And Output
336 ... openstack console log show ${vm} | grep -i "obtained"
337 @{vm_ip} = Get Regexp Matches ${vm_ip_line} [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}
338 ${vm_ip_length} = Get Length ${vm_ip}
340 Append To List ${ip_list} ${vm_ip}[0]
342 Append To List ${ip_list} None
344 ${rc} ${dhcp_ip_line} = Run And Return Rc And Output
345 ... openstack console log show ${vm} | grep "^nameserver"
346 ${dhcp_ip} = Get Regexp Matches ${dhcp_ip_line} [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}
347 ${dhcp_ip_length} = Get Length ${dhcp_ip}
348 IF ${dhcp_ip_length}<=0 Append To List ${dhcp_ip} None
349 ${vm_console_output} = Run openstack console log show ${vm}
350 Log ${vm_console_output}
352 ${dhcp_length} = Get Length ${dhcp_ip}
353 IF '${fail_on_none}' == 'true'
354 Should Not Contain ${ip_list} None
356 IF '${fail_on_none}' == 'true'
357 Should Not Contain ${dhcp_ip} None
359 # Should Be True ${dhcp_length} <= 1
360 IF ${dhcp_length}==0 RETURN ${ip_list} ${EMPTY}
361 RETURN ${ip_list} ${dhcp_ip}
364 [Documentation] Wrapper around String.Get Regexp Matches to return None if not found or the first match if found.
365 [Arguments] ${text} ${regexp} ${index}=0
366 @{matches} = String.Get Regexp Matches ${text} ${regexp}
367 ${matches_length} = BuiltIn.Get Length ${matches}
368 BuiltIn.Set Suite Variable ${OS_MATCH} None
369 IF ${matches_length} > ${index}
370 BuiltIn.Set Suite Variable ${OS_MATCH} ${matches}[${index}]
375 [Documentation] Get the vm ip address and nameserver by scraping the vm's console log.
376 ... Get VM IP returns three values: [0] the vm IP, [1] the DHCP IP and [2] the vm console log.
377 [Arguments] ${fail_on_none} ${vm}
378 ${vm_console_output} = OpenStack CLI With No Log openstack console log show ${vm}
379 ${vm_ip} = BuiltIn.Set Variable None
380 ${dhcp_ip} = BuiltIn.Set Variable None
381 ${match} = OpenStackOperations.Get Match ${vm_console_output} ${REGEX_OBTAINED}
382 ${vm_ip} = OpenStackOperations.Get Match ${match} ${REGEX_IPV4} 0
383 ${match} = OpenStackOperations.Get Match ${vm_console_output} ${REGEX_IPROUTE}
384 ${dhcp_ip} = OpenStackOperations.Get Match ${match} ${REGEX_IPV4} 1
385 IF '${fail_on_none}' == 'true'
386 BuiltIn.Should Not Contain ${vm_ip} None
388 IF '${fail_on_none}' == 'true'
389 BuiltIn.Should Not Contain ${dhcp_ip} None
391 RETURN ${vm_ip} ${dhcp_ip} ${vm_console_output}
394 [Documentation] Get the instance IP addresses and nameserver address for the list of given vms.
395 ... First poll for the vm instance to be in the active state, then poll for the vm ip address and nameserver.
396 ... Get VM IPs returns two things: [0] a list of the ips for the vms passed to this keyword (may contain values
397 ... of None) and [1] the dhcp ip address found in the last vm checked.
398 ... TODO: there is a potential issue for a caller that passes in VMs belonging to different networks that
399 ... may have different dhcp server addresses. Not sure what TODO about that, but noting it here for reference.
401 @{vm_ips} = BuiltIn.Create List @{EMPTY}
403 OpenStackOperations.Poll VM Is ACTIVE ${vm}
404 ${status} ${ips_and_console_log} = BuiltIn.Run Keyword And Ignore Error
405 ... BuiltIn.Wait Until Keyword Succeeds
408 ... OpenStackOperations.Get VM IP
411 # If there is trouble with Get VM IP, the status will be FAIL and the return value will be a string of what went
412 # wrong. We need to handle both the PASS and FAIL cases. In the FAIL case we know we wont have access to the
413 # console log, as it would not be returned; so we need to grab it again to log it. We also can append 'None' to
414 # the vm ip list if status is FAIL.
415 IF "${status}" == "PASS" BuiltIn.Log ${ips_and_console_log[2]}
416 IF "${status}" == "PASS"
417 Collections.Append To List ${vm_ips} ${ips_and_console_log[0]}
419 IF "${status}" == "FAIL"
420 Collections.Append To List ${vm_ips} None
422 IF "${status}" == "FAIL"
423 ${vm_console_output} = OpenStack CLI openstack console log show ${vm}
425 ${vm_console_output} = Set Variable ${None}
427 IF "${status}" == "FAIL" BuiltIn.Log ${vm_console_output}
429 OpenStackOperations.Copy DHCP Files From Control Node
430 RETURN @{vm_ips} ${ips_and_console_log[1]}
432 Collect VM IPv6 SLAAC Addresses
433 [Documentation] For each VM parse output of "openstack server show" to get its IPv6 address from Neutron DB.
434 ... Then try to connect to each VM by SSH and execute there "ip -6 a" command. This double-check allows to
435 ... obtain and compare IP info (Neutron DB vs dnsmasque/ODL DHCP) and to test L2 connectivity as well.
436 ... Returns an empty list if no IPv6 addresses found or if SSH connection fails.
437 ... Otherwise, returns a list of IPv6 addresses.
438 [Arguments] ${fail_on_none} ${vm_list} ${network} ${subnet}
439 ${ipv6_list} = BuiltIn.Create List @{EMPTY}
440 FOR ${vm} IN @{vm_list}
441 ${output} = OpenStack CLI openstack server show ${vm} -f shell
442 ${pattern} = String.Replace String ${subnet} ::/64 (:[a-f0-9]{,4}){,4}
443 @{vm_ipv6} = String.Get Regexp Matches ${output} ${pattern}
444 ${vm_ip_length} = BuiltIn.Get Length ${vm_ipv6}[0]
446 ${ipv6_data_from_vm} = OpenStackOperations.Execute Command on VM Instance
451 ${ipv6_data_from_vm} = Set Variable ${None}
453 @{ipv6} = String.Get Regexp Matches ${ipv6_data_from_vm} ${pattern}
454 ${ipv6_addr_list_length} = BuiltIn.Get Length @{ipv6}
455 IF ${ipv6_addr_list_length}>0
456 Collections.Append To List ${ipv6_list} ${ipv6[0]}
458 Collections.Append To List ${ipv6_list} None
464 [Documentation] View Console log of the created vm instances using nova show.
465 [Arguments] ${vm_instance_names}
466 FOR ${vm} IN @{vm_instance_names}
467 ${output} = OpenStack CLI openstack server show ${vm}
468 ${output} = OpenStack CLI openstack console log show ${vm}
471 Ping Vm From DHCP Namespace
472 [Documentation] Reach all Vm Instance with the net id of the Netowrk.
473 [Arguments] ${net_name} ${vm_ip}
474 OpenStackOperations.Get ControlNode Connection
475 ${net_id} = OpenStackOperations.Get Net Id ${net_name}
476 ${output} = DevstackUtils.Write Commands Until Prompt And Log
477 ... sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip}
479 BuiltIn.Should Contain ${output} 64 bytes
481 Ping From DHCP Should Not Succeed
482 [Documentation] Should Not Reach Vm Instance with the net id of the Netowrk.
483 [Arguments] ${net_name} ${vm_ip}
484 IF "skip_if_${SECURITY_GROUP_MODE}" in @{TEST_TAGS} RETURN
485 OpenStackOperations.Get ControlNode Connection
486 ${net_id} = OpenStackOperations.Get Net Id ${net_name}
487 ${output} = DevstackUtils.Write Commands Until Prompt And Log
488 ... sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip}
490 BuiltIn.Should Not Contain ${output} 64 bytes
492 Ping Vm From Control Node
493 [Documentation] Ping VM floating IP from control node
494 [Arguments] ${vm_floating_ip} ${additional_args}=${EMPTY}
495 OpenStackOperations.Get ControlNode Connection
496 ${output} = DevstackUtils.Write Commands Until Prompt And Log
497 ... ping ${additional_args} -c 3 ${vm_floating_ip}
499 BuiltIn.Should Contain ${output} 64 bytes
502 [Documentation] Ping to the expected destination ip.
503 ${output} = Utils.Write Commands Until Expected Prompt curl -i http://169.254.169.254 ${OS_SYSTEM_PROMPT}
504 DevstackUtils.Write Commands Until Prompt exit
505 BuiltIn.Should Contain ${output} 200
508 [Documentation] Exit the vm instance.
509 ${output} = DevstackUtils.Write Commands Until Prompt And Log exit
511 Check If Console Is VmInstance
512 [Documentation] Check if the session has been able to login to the VM instance
513 [Arguments] ${console}=cirros
514 ${output} = Utils.Write Commands Until Expected Prompt id ${OS_SYSTEM_PROMPT}
515 BuiltIn.Should Contain ${output} ${console}
518 [Documentation] Check if the session has been able to login to the VM instance and exit the instance
519 ${rcode} = BuiltIn.Run Keyword And Return Status OpenStackOperations.Check If Console Is VmInstance cirros
520 IF ${rcode} DevstackUtils.Write Commands Until Prompt exit
523 [Documentation] Run Ping command on the IP available as argument
524 [Arguments] ${ip_address} ${ttl}=64
525 ${ethertype} = String.Get Regexp Matches ${ip_address} ${IP_REGEX}
527 ${output} = Utils.Write Commands Until Expected Prompt
528 ... ping -t ${ttl} -c 3 ${ip_address}
529 ... ${OS_SYSTEM_PROMPT}
531 ${output} = Utils.Write Commands Until Expected Prompt
532 ... ping6 -t ${ttl} -c 3 ${ip_address}
533 ... ${OS_SYSTEM_PROMPT}
535 BuiltIn.Should Contain ${output} 64 bytes
538 [Documentation] Run Ping command to the IP given as argument, executing 3 times and expecting NOT to see "64 bytes"
539 [Arguments] ${ip_address} ${ttl}=64
540 ${output} = Utils.Write Commands Until Expected Prompt
541 ... ping -t ${ttl} -c 3 ${ip_address}
542 ... ${OS_SYSTEM_PROMPT}
543 BuiltIn.Should Not Contain ${output} 64 bytes
545 Check Metadata Access
546 [Documentation] Try curl on the Metadataurl and check if it is okay
547 ${output} = Utils.Write Commands Until Expected Prompt curl -i http://169.254.169.254 ${OS_SYSTEM_PROMPT}
548 BuiltIn.Should Contain ${output} 200
550 Execute Command on VM Instance
551 [Documentation] Login to the vm instance using ssh in the network, executes a command inside the VM and returns the ouput.
552 [Arguments] ${net_name} ${vm_ip} ${cmd} ${user}=cirros ${password}=cubswin:)
553 OpenStackOperations.Get ControlNode Connection
554 ${net_id} = OpenStackOperations.Get Net Id ${net_name}
555 ${output} = Utils.Write Commands Until Expected Prompt
556 ... sudo ip netns exec qdhcp-${net_id} ssh ${user}@${vm_ip} -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
558 ${output} = Utils.Write Commands Until Expected Prompt ${password} ${OS_SYSTEM_PROMPT}
559 ${rcode} = BuiltIn.Run Keyword And Return Status OpenStackOperations.Check If Console Is VmInstance
561 ${output} = Utils.Write Commands Until Expected Prompt ${cmd} ${OS_SYSTEM_PROMPT}
563 ${output} = Set Variable ${None}
566 [Teardown] Exit From Vm Console
568 Test Operations From Vm Instance
569 [Documentation] Login to the vm instance using ssh in the network.
570 [Arguments] ${net_name} ${src_ip} ${dest_ips} ${user}=cirros ${password}=cubswin:) ${ttl}=64
571 ... ${ping_should_succeed}=True ${check_metadata}=True
572 OpenStackOperations.Get ControlNode Connection
573 ${net_id} = OpenStackOperations.Get Net Id ${net_name}
574 ${output} = Utils.Write Commands Until Expected Prompt
575 ... sudo ip netns exec qdhcp-${net_id} ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no ${user}@${src_ip} -o UserKnownHostsFile=/dev/null
577 ${output} = Utils.Write Commands Until Expected Prompt ${password} ${OS_SYSTEM_PROMPT}
578 ${rcode} = BuiltIn.Run Keyword And Return Status OpenStackOperations.Check If Console Is VmInstance
580 Utils.Write Commands Until Expected Prompt ifconfig ${OS_SYSTEM_PROMPT}
583 Utils.Write Commands Until Expected Prompt route -n ${OS_SYSTEM_PROMPT}
586 Utils.Write Commands Until Expected Prompt route -A inet6 ${OS_SYSTEM_PROMPT}
589 Utils.Write Commands Until Expected Prompt arp -an ${OS_SYSTEM_PROMPT}
592 Utils.Write Commands Until Expected Prompt ip -f inet6 neigh show ${OS_SYSTEM_PROMPT}
594 FOR ${dest_ip} IN @{dest_ips}
595 ${string_empty} = BuiltIn.Run Keyword And Return Status Should Be Empty ${dest_ip}
596 IF ${string_empty} CONTINUE
597 IF ${rcode} and "${ping_should_succeed}" == "True"
598 OpenStackOperations.Check Ping ${dest_ip} ttl=${ttl}
600 OpenStackOperations.Check No Ping ${dest_ip} ttl=${ttl}
603 ${ethertype} = String.Get Regexp Matches ${src_ip} ${IP_REGEX}
604 IF ${rcode} and "${check_metadata}" and ${ethertype} == "True"
605 OpenStackOperations.Check Metadata Access
607 [Teardown] Exit From Vm Console
609 Test Netcat Operations From Vm Instance
610 [Documentation] Use Netcat to test TCP/UDP connections to the controller
611 [Arguments] ${net_name} ${vm_ip} ${dest_ip} ${additional_args}=${EMPTY} ${port}=12345 ${user}=cirros
612 ... ${password}=cubswin:)
613 ${client_data} = BuiltIn.Set Variable Test Client Data
614 ${server_data} = BuiltIn.Set Variable Test Server Data
615 OpenStackOperations.Get ControlNode Connection
616 ${output} = DevstackUtils.Write Commands Until Prompt And Log
617 ... ( ( echo "${server_data}" | sudo timeout 60 nc -l ${additional_args} ${port} ) & )
618 ${output} = DevstackUtils.Write Commands Until Prompt And Log sudo netstat -nlap | grep ${port}
619 ${nc_output} = OpenStackOperations.Execute Command on VM Instance
622 ... sudo echo "${client_data}" | nc -v -w 5 ${additional_args} ${dest_ip} ${port}
623 BuiltIn.Log ${output}
624 ${output} = OpenStackOperations.Execute Command on VM Instance ${net_name} ${vm_ip} sudo route -n
625 BuiltIn.Log ${output}
626 ${output} = OpenStackOperations.Execute Command on VM Instance ${net_name} ${vm_ip} sudo arp -an
627 BuiltIn.Log ${output}
628 BuiltIn.Should Match Regexp ${nc_output} ${server_data}
631 [Documentation] Check reachability with other network's instances.
632 [Arguments] ${list_of_external_dst_ips}
633 ${rcode} = BuiltIn.Run Keyword And Return Status OpenStackOperations.Check If Console Is VmInstance
634 FOR ${dest_ip} IN @{list_of_external_dst_ips}
635 OpenStackOperations.Check Ping ${dest_ip}
639 [Documentation] Create Router and Add Interface to the subnets.
640 [Arguments] ${router_name}
641 ${output} = OpenStack CLI openstack router create ${router_name}
644 [Documentation] List Routers and return output with neutron client.
645 ${output} = OpenStack CLI openstack router list -f value
649 [Arguments] ${router_name} ${interface_name}
650 ${output} = OpenStack CLI openstack router add subnet ${router_name} ${interface_name}
652 Show Router Interface
653 [Documentation] List Routers interface associated with given Router and return output with neutron client.
654 [Arguments] ${router_name}
655 ${output} = OpenStack CLI openstack port list --router ${router_name} -f value
659 [Arguments] ${router_name} ${external_network_name}
660 ${cmd} = BuiltIn.Set Variable If
661 ... '${OPENSTACK_BRANCH}'=='stable/newton'
662 ... neutron -v router-gateway-set ${router_name} ${external_network_name}
663 ... openstack router set ${router_name} --external-gateway ${external_network_name}
664 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output ${cmd}
665 BuiltIn.Should Be True '${rc}' == '0'
668 [Documentation] Remove Interface to the subnets.
669 [Arguments] ${router_name} ${interface_name}
670 ${output} = OpenStack CLI openstack router remove subnet ${router_name} ${interface_name}
673 [Documentation] Remove external gateway from the router.
674 [Arguments] ${router_name}
675 BuiltIn.Log openstack router unset ${router_name} --external-gateway
678 [Documentation] Update the router with the command. Router name and command should be passed as argument.
679 [Arguments] ${router_name} ${cmd}
680 ${output} = OpenStack CLI openstack router set ${router_name} ${cmd}
683 [Documentation] Show information of a given router. Router name and optional fields should be sent as arguments.
684 [Arguments] ${router_name} ${options}
685 ${output} = OpenStack CLI openstack router show ${router_name}
688 [Documentation] Delete Router and Interface to the subnets.
689 [Arguments] ${router_name}
690 ${output} = OpenStack CLI openstack router delete ${router_name}
692 Get DumpFlows And Ovsconfig
693 [Documentation] Get the OvsConfig and Flow entries from OVS from the Openstack Node
694 [Arguments] ${conn_id}
695 SSHLibrary.Switch Connection ${conn_id}
696 Utils.Write Commands Until Expected Prompt ip -o link ${DEFAULT_LINUX_PROMPT_STRICT}
697 Utils.Write Commands Until Expected Prompt ip -o addr ${DEFAULT_LINUX_PROMPT_STRICT}
698 Utils.Write Commands Until Expected Prompt ip route ${DEFAULT_LINUX_PROMPT_STRICT}
699 Utils.Write Commands Until Expected Prompt arp -an ${DEFAULT_LINUX_PROMPT_STRICT}
700 ${nslist} = Utils.Write Commands Until Expected Prompt
701 ... ip netns list | awk '{print $1}'
702 ... ${DEFAULT_LINUX_PROMPT_STRICT}
703 @{lines} = Split To Lines ${nslist} end=-1
704 FOR ${line} IN @{lines}
705 Utils.Write Commands Until Expected Prompt
706 ... sudo ip netns exec ${line} ip -o link
707 ... ${DEFAULT_LINUX_PROMPT_STRICT}
708 Utils.Write Commands Until Expected Prompt
709 ... sudo ip netns exec ${line} ip -o addr
710 ... ${DEFAULT_LINUX_PROMPT_STRICT}
711 Utils.Write Commands Until Expected Prompt
712 ... sudo ip netns exec ${line} ip route
713 ... ${DEFAULT_LINUX_PROMPT_STRICT}
715 Utils.Write Commands Until Expected Prompt sudo ovs-vsctl show ${DEFAULT_LINUX_PROMPT_STRICT}
716 Utils.Write Commands Until Expected Prompt sudo ovs-vsctl list Open_vSwitch ${DEFAULT_LINUX_PROMPT_STRICT}
717 Utils.Write Commands Until Expected Prompt
718 ... sudo ovs-ofctl show br-int -OOpenFlow13
719 ... ${DEFAULT_LINUX_PROMPT_STRICT}
720 Utils.Write Commands Until Expected Prompt
721 ... sudo ovs-ofctl dump-flows br-int -OOpenFlow13
722 ... ${DEFAULT_LINUX_PROMPT_STRICT}
723 Utils.Write Commands Until Expected Prompt
724 ... sudo ovs-ofctl dump-groups br-int -OOpenFlow13
725 ... ${DEFAULT_LINUX_PROMPT_STRICT}
726 Utils.Write Commands Until Expected Prompt
727 ... sudo ovs-ofctl dump-group-stats br-int -OOpenFlow13
728 ... ${DEFAULT_LINUX_PROMPT_STRICT}
730 Get Karaf Log Type From Test Start
731 [Arguments] ${ip} ${test_name} ${type} ${user}=${ODL_SYSTEM_USER} ${password}=${ODL_SYSTEM_PASSWORD} ${prompt}=${ODL_SYSTEM_PROMPT}
732 ... ${log_file}=${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
733 ${cmd} = BuiltIn.Set Variable
734 ... sed '1,/ROBOT MESSAGE: Starting test ${test_name}/d' ${log_file} | grep '${type}'
735 ${output} = Utils.Run Command On Controller ${ip} ${cmd} ${user} ${password} ${prompt}
738 Get Karaf Log Types From Test Start
739 [Arguments] ${ip} ${test_name} ${types} ${user}=${ODL_SYSTEM_USER} ${password}=${ODL_SYSTEM_PASSWORD} ${prompt}=${ODL_SYSTEM_PROMPT}
740 ... ${log_file}=${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
741 FOR ${type} IN @{types}
742 OpenStackOperations.Get Karaf Log Type From Test Start
752 Get Karaf Log Events From Test Start
753 [Arguments] ${test_name} ${user}=${ODL_SYSTEM_USER} ${password}=${ODL_SYSTEM_PASSWORD} ${prompt}=${ODL_SYSTEM_PROMPT}
754 ${log_types} = BuiltIn.Create List ERROR WARN Exception
755 IF 0 < ${NUM_ODL_SYSTEM}
756 OpenStackOperations.Get Karaf Log Types From Test Start ${ODL_SYSTEM_IP} ${test_name} ${log_types}
758 IF 1 < ${NUM_ODL_SYSTEM}
759 OpenStackOperations.Get Karaf Log Types From Test Start ${ODL_SYSTEM_2_IP} ${test_name} ${log_types}
761 IF 2 < ${NUM_ODL_SYSTEM}
762 OpenStackOperations.Get Karaf Log Types From Test Start ${ODL_SYSTEM_3_IP} ${test_name} ${log_types}
765 Get ControlNode Connection
766 SSHLibrary.Switch Connection ${OS_CNTL_CONN_ID}
767 RETURN ${OS_CNTL_CONN_ID}
770 [Documentation] Get the OvsConfig and Flow entries from all Openstack nodes
771 IF 0 < ${NUM_OS_SYSTEM}
772 OpenStackOperations.Get DumpFlows And Ovsconfig ${OS_CNTL_CONN_ID}
774 IF 1 < ${NUM_OS_SYSTEM}
775 OpenStackOperations.Get DumpFlows And Ovsconfig ${OS_CMP1_CONN_ID}
777 IF 2 < ${NUM_OS_SYSTEM}
778 OpenStackOperations.Get DumpFlows And Ovsconfig ${OS_CMP2_CONN_ID}
781 Get Test Teardown Debugs
782 [Arguments] ${test_name}=${TEST_NAME}
783 OpenStackOperations.Get OvsDebugInfo
784 BuiltIn.Run Keyword And Ignore Error DataModels.Get Model Dump ${HA_PROXY_IP} ${netvirt_data_models}
785 OpenStackOperations.Get Karaf Log Events From Test Start ${test_name}
787 Get Test Teardown Debugs For SFC
788 [Arguments] ${test_name}=${TEST_NAME}
789 BuiltIn.Run Keyword And Ignore Error DataModels.Get Model Dump ${HA_PROXY_IP} ${netvirt_sfc_data_models}
792 [Documentation] Run these commands for debugging, it can list state of VM instances and ip information in control node
793 [Arguments] @{vm_indices}
794 OpenStackOperations.Get ControlNode Connection
795 ${output} = DevstackUtils.Write Commands Until Prompt And Log sudo ip netns list
796 FOR ${index} IN @{vm_indices}
797 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output nova show ${index}
798 BuiltIn.Log ${output}
800 OpenStackOperations.List Nova VMs
801 OpenStackOperations.List Routers
802 OpenStackOperations.List Networks
803 OpenStackOperations.List Subnets
804 OpenStackOperations.List Ports
805 OpenStackOperations.List Security Groups
808 [Documentation] Logging keyword to display all security groups using the openstack cli. Assumes openstack
809 ... credentials are already sourced
810 ${output} = OpenStack CLI openstack security group list
813 Neutron Security Group Show
814 [Documentation] Displays the neutron security group configurations that belongs to a given neutron security group name
815 [Arguments] ${SecurityGroupRuleName}
816 ${output} = OpenStack CLI openstack security group show ${SecurityGroupRuleName}
820 [Documentation] Display the port configuration that belong to a given neutron port
821 [Arguments] ${PortName}
822 ${output} = OpenStack CLI openstack port show ${PortName}
825 Neutron Security Group Create
826 [Documentation] Create a security group with specified name ,description & protocol value according to security group template
827 [Arguments] ${SecurityGroupName} ${additional_args}=${EMPTY}
828 OpenStackOperations.Get ControlNode Connection
829 ${output} = OpenStack CLI openstack security group create ${SecurityGroupName} ${additional_args}
830 ${sgp_id} = BuiltIn.Should Match Regexp ${output} ${REGEX_UUID}
831 RETURN ${output} ${sgp_id}
833 Neutron Security Group Update
834 [Documentation] Updating security groups
835 [Arguments] ${SecurityGroupName} ${additional_args}=${EMPTY}
836 ${output} = OpenStack CLI openstack security group set ${SecurityGroupName} ${additional_args}
840 [Documentation] Delete Security group
841 [Arguments] ${sg_name}
842 ${output} = OpenStack CLI openstack security group delete ${sg_name}
844 Neutron Security Group Rule Create
845 [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 BuiltIn.Catenated with mandatory args, example of usage: "OpenStack Neutron Security Group Rule Create ${SGP_SSH} direction=${RULE_PARAMS[0]} ethertype=${RULE_PARAMS[1]} ..."
846 [Arguments] ${Security_group_name} &{Kwargs}
847 IF ${Kwargs} BuiltIn.Log ${Kwargs}
849 ${description} = Collections.Pop From Dictionary ${Kwargs} description default=${None}
851 ${description} = Set Variable ${None}
854 ${direction} = Collections.Pop From Dictionary ${Kwargs} direction default=${None}
856 ${direction} = Set Variable ${None}
859 ${ethertype} = Collections.Pop From Dictionary ${Kwargs} ethertype default=${None}
861 ${ethertype} = Set Variable ${None}
864 ${port_range_max} = Collections.Pop From Dictionary ${Kwargs} port_range_max default=${None}
866 ${port_range_max} = Set Variable ${None}
869 ${port_range_min} = Collections.Pop From Dictionary ${Kwargs} port_range_min default=${None}
871 ${port_range_min} = Set Variable ${None}
874 ${protocol} = Collections.Pop From Dictionary ${Kwargs} protocol default=${None}
876 ${protocol} = Set Variable ${None}
879 ${remote_group_id} = Collections.Pop From Dictionary ${Kwargs} remote_group_id default=${None}
881 ${remote_group_id} = Set Variable ${None}
884 ${remote_ip_prefix} = Collections.Pop From Dictionary ${Kwargs} remote_ip_prefix default=${None}
886 ${remote_ip_prefix} = Set Variable ${None}
888 ${cmd} = BuiltIn.Set Variable openstack security group rule create ${Security_group_name}
889 IF '${description}'!='None'
890 ${cmd} = BuiltIn.Catenate ${cmd} --description ${description}
892 ${cmd} = BuiltIn.Catenate ${cmd}
894 IF '${direction}'!='None'
895 ${cmd} = BuiltIn.Catenate ${cmd} --${direction}
897 ${cmd} = BuiltIn.Catenate ${cmd}
899 IF '${ethertype}'!='None'
900 ${cmd} = BuiltIn.Catenate ${cmd} --ethertype ${ethertype}
902 ${cmd} = BuiltIn.Catenate ${cmd}
904 IF '${port_range_min}'!='None' and '${port_range_max}'!='None'
905 ${cmd} = BuiltIn.Catenate ${cmd} --dst-port ${port_range_min}:${port_range_max}
906 ELSE IF '${port_range_max}'!='None'
907 ${cmd} = BuiltIn.Catenate ${cmd} --dst-port ${port_range_max}
908 ELSE IF '${port_range_min}'!='None'
909 ${cmd} = BuiltIn.Catenate ${cmd} --dst-port ${port_range_min}
911 ${cmd} = BuiltIn.Catenate ${cmd}
913 IF '${protocol}'!='None'
914 ${cmd} = BuiltIn.Catenate ${cmd} --protocol ${protocol}
916 ${cmd} = BuiltIn.Catenate ${cmd}
918 IF '${remote_group_id}'!='None'
919 ${cmd} = BuiltIn.Catenate ${cmd} --remote-group ${remote_group_id}
921 ${cmd} = BuiltIn.Catenate ${cmd}
923 IF '${remote_ip_prefix}'!='None'
924 ${cmd} = BuiltIn.Catenate ${cmd} --src-ip ${remote_ip_prefix}
926 ${cmd} = BuiltIn.Catenate ${cmd}
928 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output ${cmd}
929 ${rule_id} = BuiltIn.Should Match Regexp ${output} ${REGEX_UUID}
930 BuiltIn.Log ${rule_id}
931 BuiltIn.Should Be True '${rc}' == '0'
932 RETURN ${output} ${rule_id}
934 Security Group Create Without Default Security Rules
935 [Documentation] Create Neutron Security Group with no default rules, using specified name and optional arguments.
936 [Arguments] ${sg_name} ${additional_args}=${EMPTY}
937 OpenStackOperations.Neutron Security Group Create ${sg_name} ${additional_args}
938 Delete All Security Group Rules ${sg_name}
940 Delete All Security Group Rules
941 [Documentation] Delete all security rules from a specified security group
942 [Arguments] ${sg_name}
943 ${sg_rules_output} = OpenStack CLI openstack security group rule list ${sg_name} -cID -fvalue
944 @{sg_rules} = String.Split String ${sg_rules_output} \n
945 FOR ${rule} IN @{sg_rules}
946 ${output} = OpenStack CLI openstack security group rule delete ${rule}
949 Create Allow All SecurityGroup
950 [Documentation] Allow all TCP/UDP/ICMP packets for this suite
951 [Arguments] ${sg_name} ${ether_type}=IPv4
952 OpenStackOperations.Neutron Security Group Create ${sg_name}
953 OpenStackOperations.Neutron Security Group Rule Create
955 ... direction=ingress
956 ... ethertype=${ether_type}
957 ... port_range_max=65535
960 OpenStackOperations.Neutron Security Group Rule Create
963 ... ethertype=${ether_type}
964 ... port_range_max=65535
967 OpenStackOperations.Neutron Security Group Rule Create
969 ... direction=ingress
970 ... ethertype=${ether_type}
972 OpenStackOperations.Neutron Security Group Rule Create
975 ... ethertype=${ether_type}
977 OpenStackOperations.Neutron Security Group Rule Create
979 ... direction=ingress
980 ... ethertype=${ether_type}
981 ... port_range_max=65535
984 OpenStackOperations.Neutron Security Group Rule Create
987 ... ethertype=${ether_type}
988 ... port_range_max=65535
992 Create Neutron Port With Additional Params
993 [Documentation] Create Port With given additional parameters
994 [Arguments] ${network_name} ${port_name} ${additional_args}=${EMPTY}
995 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output
996 ... neutron -v port-create ${network_name} --name ${port_name} ${additional_args}
997 BuiltIn.Log ${output}
998 BuiltIn.Should Be True '${rc}' == '0'
999 ${port_id} = BuiltIn.Should Match Regexp ${OUTPUT} ${REGEX_UUID}
1000 RETURN ${OUTPUT} ${port_id}
1003 [Documentation] Retrieve the port MacAddr for the given list of port name and return the MAC address list.
1004 [Arguments] ${ports}
1005 ${macs} = BuiltIn.Create List
1006 FOR ${port} IN @{ports}
1007 ${mac} = OpenStackOperations.Get Port Mac ${port}
1008 Collections.Append To List ${macs} ${mac}
1013 [Documentation] Keyword would return the IP of the ${port_name} received.
1014 [Arguments] ${port_name}
1015 ${output} = OpenStack CLI openstack port list | grep "${port_name}" | awk -F\\' '{print $2}'
1016 ${splitted_output} = String.Split String ${output} ${EMPTY}
1017 ${port_ip} = Collections.Get from List ${splitted_output} 0
1021 [Documentation] Keyword would return the MAC ID of the ${port_name} received.
1022 [Arguments] ${port_name}
1023 ${output} = OpenStack CLI openstack port show ${port_name} | grep mac_address | awk '{print $4}'
1024 ${splitted_output} = String.Split String ${output} ${EMPTY}
1025 ${port_mac} = Collections.Get from List ${splitted_output} 0
1029 [Documentation] Keyword to create an L2 Gateway ${gw_name} for bridge ${bridge_name} connected to interface ${intf_name} (Using Neutron CLI).
1030 [Arguments] ${bridge_name} ${intf_name} ${gw_name}
1031 ${rc} ${l2gw_output} = OperatingSystem.Run And Return Rc And Output
1032 ... ${L2GW_CREATE} name=${bridge_name},interface_names=${intf_name} ${gw_name}
1033 BuiltIn.Log ${l2gw_output}
1034 RETURN ${l2gw_output}
1037 [Documentation] Keyword to add {intf_name_list} to an existing L2 Gateway ${gw_name} (Using Neutron CLI).
1038 [Arguments] ${bridge_name} ${gw_name} ${intf_name_1} ${intf_name_2}
1039 ${rc} ${l2gw_output} = Run And Return Rc And Output
1040 ... ${L2GW_UPDATE} name=${bridge_name},interface_names="${intf_name_1};${intf_name_2}" ${gw_name}
1042 RETURN ${l2gw_output}
1044 Create L2Gateway Connection
1045 [Documentation] Keyword would create a new L2 Gateway Connection for ${gw_name} to ${net_name} (Using Neutron CLI).
1046 [Arguments] ${gw_name} ${net_name}
1047 ${rc} ${l2gw_output} = OperatingSystem.Run And Return Rc And Output
1048 ... ${L2GW_CONN_CREATE} ${gw_name} ${net_name}
1049 BuiltIn.Log ${l2gw_output}
1050 BuiltIn.Should Be True '${rc}' == '0'
1051 RETURN ${l2gw_output}
1054 [Documentation] Keyword to return all the L2 Gateways available (Using Neutron CLI).
1055 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output ${L2GW_GET_YAML}
1056 BuiltIn.Should Be True '${rc}' == '0'
1059 Get All L2Gateway Connection
1060 [Documentation] Keyword to return all the L2 Gateway connections available (Using Neutron CLI).
1061 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output ${L2GW_GET_CONN_YAML}
1062 BuiltIn.Should Be True '${rc}' == '0'
1066 [Documentation] Keyword to check if the ${gw_id} is available in the L2 Gateway list (Using Neutron CLI).
1067 [Arguments] ${gw_id}
1068 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output ${L2GW_SHOW} ${gw_id}
1069 BuiltIn.Log ${output}
1070 BuiltIn.Should Be True '${rc}' == '0'
1074 [Documentation] Keyword to retrieve the L2 Gateway ID for the ${l2gw_name} (Using Neutron CLI).
1075 [Arguments] ${l2gw_name}
1076 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output
1077 ... ${L2GW_GET} | grep "${l2gw_name}" | awk '{print $2}'
1078 BuiltIn.Log ${output}
1079 BuiltIn.Should Be True '${rc}' == '0'
1080 ${splitted_output} = String.Split String ${output} ${EMPTY}
1081 ${l2gw_id} = Collections.Get from List ${splitted_output} 0
1084 Get L2gw Connection Id
1085 [Documentation] Keyword to retrieve the L2 Gateway Connection ID for the ${l2gw_name} (Using Neutron CLI).
1086 [Arguments] ${l2gw_name}
1087 ${l2gw_id} = OpenStackOperations.Get L2gw Id ${l2gw_name}
1088 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output
1089 ... ${L2GW_GET_CONN} | grep "${l2gw_id}" | awk '{print $2}'
1090 BuiltIn.Should Be True '${rc}' == '0'
1091 ${splitted_output} = String.Split String ${output} ${EMPTY}
1092 ${splitted_output} = String.Split String ${output} ${EMPTY}
1093 ${l2gw_conn_id} = Collections.Get from List ${splitted_output} 0
1094 RETURN ${l2gw_conn_id}
1096 Neutron Port List Rest
1097 [Documentation] Keyword to get all ports details in Neutron (Using REST).
1098 ${resp} = RequestsLibrary.Get Request session ${PORT_URL}
1099 BuiltIn.Log ${resp.content}
1100 BuiltIn.Should Be Equal As Strings ${resp.status_code} 200
1101 RETURN ${resp.content}
1103 Get Neutron Port Rest
1104 [Documentation] Keyword to get the specific port details in Neutron (Using REST).
1105 [Arguments] ${port_id}
1106 ${resp} = RequestsLibrary.Get Request session ${CONFIG_API}/${GET_PORT_URL}/${port_id}
1107 BuiltIn.Log ${resp.content}
1108 BuiltIn.Should Be Equal As Strings ${resp.status_code} 200
1109 RETURN ${resp.content}
1112 [Documentation] Keyword to update ${port_id} with json data received in ${json_data} (Using REST).
1113 [Arguments] ${port_id} ${json_data}
1114 BuiltIn.Log ${json_data}
1115 ${resp} = RequestsLibrary.Put Request session ${CONFIG_API}/${GET_PORT_URL}/${port_id} ${json_data}
1116 BuiltIn.Log ${resp.content}
1117 BuiltIn.Should Be Equal As Strings ${resp.status_code} 200
1118 RETURN ${resp.content}
1120 Create And Configure Security Group
1121 [Documentation] Create Security Group with given name, and default allow rules for TCP/UDP/ICMP protocols.
1122 [Arguments] ${sg-name}
1123 OpenStackOperations.Neutron Security Group Create ${sg-name}
1124 OpenStackOperations.Neutron Security Group Rule Create
1126 ... direction=ingress
1127 ... port_range_max=65535
1128 ... port_range_min=1
1130 ... remote_ip_prefix=0.0.0.0/0
1131 OpenStackOperations.Neutron Security Group Rule Create
1133 ... direction=egress
1134 ... port_range_max=65535
1135 ... port_range_min=1
1137 ... remote_ip_prefix=0.0.0.0/0
1138 OpenStackOperations.Neutron Security Group Rule Create
1140 ... direction=ingress
1142 ... remote_ip_prefix=0.0.0.0/0
1143 OpenStackOperations.Neutron Security Group Rule Create
1145 ... direction=egress
1147 ... remote_ip_prefix=0.0.0.0/0
1148 OpenStackOperations.Neutron Security Group Rule Create
1150 ... direction=ingress
1151 ... port_range_max=65535
1152 ... port_range_min=1
1154 ... remote_ip_prefix=0.0.0.0/0
1155 OpenStackOperations.Neutron Security Group Rule Create
1157 ... direction=egress
1158 ... port_range_max=65535
1159 ... port_range_min=1
1161 ... remote_ip_prefix=0.0.0.0/0
1163 Add Security Group To VM
1164 [Documentation] Add the security group provided to the given VM.
1165 [Arguments] ${vm} ${sg}
1166 ${output} = OpenStack CLI openstack server add security group ${vm} ${sg}
1168 Remove Security Group From VM
1169 [Documentation] Remove the security group provided to the given VM.
1170 [Arguments] ${vm} ${sg}
1171 OpenStackOperations.Get ControlNode Connection
1172 ${output} = OpenStack CLI openstack server remove security group ${vm} ${sg}
1174 Create SFC Flow Classifier
1175 [Documentation] Create a flow classifier for SFC
1176 [Arguments] ${name} ${src_ip} ${dest_ip} ${protocol} ${dest_port} ${neutron_src_port}
1177 ${output} = OpenStack CLI
1178 ... 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}
1179 BuiltIn.Should Contain ${output} ${name}
1182 Delete SFC Flow Classifier
1183 [Documentation] Delete a SFC flow classifier
1185 OpenStackOperations.Get ControlNode Connection
1186 ${output} = OpenStack CLI openstack sfc flow classifier delete ${name}
1189 Create SFC Port Pair
1190 [Documentation] Creates a neutron port pair for SFC
1191 [Arguments] ${name} ${port_in} ${port_out}
1192 OpenStackOperations.Get ControlNode Connection
1193 ${output} = OpenStack CLI openstack sfc port pair create --ingress=${port_in} --egress=${port_out} ${name}
1194 BuiltIn.Should Contain ${output} ${name}
1197 Delete SFC Port Pair
1198 [Documentation] Delete a SFC port pair
1200 ${output} = OpenStack CLI openstack sfc port pair delete ${name}
1203 Create SFC Port Pair Group
1204 [Documentation] Creates a port pair group with a single port pair for SFC
1205 [Arguments] ${name} ${port_pair}
1206 ${output} = OpenStack CLI openstack sfc port pair group create --port-pair ${port_pair} ${name}
1207 BuiltIn.Should Contain ${output} ${name}
1210 Create SFC Port Pair Group With Two Pairs
1211 [Documentation] Creates a port pair group with two port pairs for SFC
1212 [Arguments] ${name} ${port_pair1} ${port_pair2}
1213 ${output} = OpenStack CLI
1214 ... openstack sfc port pair group create --port-pair ${port_pair1} --port-pair ${port_pair2} ${name}
1215 BuiltIn.Should Contain ${output} ${name}
1218 Delete SFC Port Pair Group
1219 [Documentation] Delete a SFC port pair group
1221 OpenStackOperations.Get ControlNode Connection
1222 ${output} = OpenStack CLI openstack sfc port pair group delete ${name}
1225 Create SFC Port Chain
1226 [Documentation] Creates a port pair chain with two port groups and a singel classifier.
1227 [Arguments] ${name} ${pg1} ${pg2} ${fc}
1228 ${output} = OpenStack CLI
1229 ... openstack sfc port chain create --port-pair-group ${pg1} --port-pair-group ${pg2} --flow-classifier ${fc} ${name}
1230 BuiltIn.Should Contain ${output} ${name}
1233 Delete SFC Port Chain
1234 [Documentation] Delete a SFC port chain
1236 ${output} = OpenStack CLI openstack sfc port chain delete ${name}
1240 [Documentation] Reboot NOVA VM
1241 [Arguments] ${vm_name}
1242 ${output} = OpenStack CLI openstack server reboot --wait ${vm_name}
1243 BuiltIn.Wait Until Keyword Succeeds 35s 10s OpenStackOperations.Verify VM Is ACTIVE ${vm_name}
1245 Remove RSA Key From KnownHosts
1246 [Documentation] Remove RSA
1247 [Arguments] ${vm_ip}
1248 OpenStackOperations.Get ControlNode Connection
1249 ${output} = DevstackUtils.Write Commands Until Prompt And Log sudo cat /root/.ssh/known_hosts 30s
1250 ${output} = DevstackUtils.Write Commands Until Prompt And Log
1251 ... sudo ssh-keygen -f "/root/.ssh/known_hosts" -R ${vm_ip}
1253 ${output} = DevstackUtils.Write Commands Until Prompt sudo cat "/root/.ssh/known_hosts" 30s
1255 Wait For Routes To Propogate
1256 [Documentation] Check propagated routes
1257 [Arguments] ${networks} ${subnets}
1258 OpenStackOperations.Get ControlNode Connection
1259 FOR ${INDEX} IN RANGE 0 1
1260 ${net_id} = OpenStackOperations.Get Net Id ${networks}[${INDEX}]
1261 ${is_ipv6} = String.Get Regexp Matches ${subnets}[${INDEX}] ${IP6_REGEX}
1262 ${length} = BuiltIn.Get Length ${is_ipv6}
1263 ${cmd} = BuiltIn.Set Variable If ${length} == 0 ip route ip -6 route
1264 ${output} = Utils.Write Commands Until Expected Prompt sudo ip netns exec qdhcp-${net_id} ${cmd} ]>
1265 BuiltIn.Should Contain ${output} ${subnets}[${INDEX}]
1269 [Arguments] ${vms}=@{EMPTY} ${networks}=@{EMPTY} ${subnets}=@{EMPTY} ${ports}=@{EMPTY} ${sgs}=@{EMPTY}
1271 BuiltIn.Run Keyword And Ignore Error Delete Vm Instance ${vm}
1273 FOR ${port} IN @{ports}
1274 BuiltIn.Run Keyword And Ignore Error Delete Port ${port}
1276 FOR ${subnet} IN @{subnets}
1277 BuiltIn.Run Keyword And Ignore Error Delete SubNet ${subnet}
1279 FOR ${network} IN @{networks}
1280 BuiltIn.Run Keyword And Ignore Error Delete Network ${network}
1283 BuiltIn.Run Keyword And Ignore Error Delete SecurityGroup ${sg}
1287 [Documentation] Get a list of different OpenStack resources that might be in use.
1288 @{modules} = BuiltIn.Create List server port network subnet security group
1289 ... security group rule floating ip router
1290 FOR ${module} IN @{modules}
1291 ${output} = OpenStack CLI openstack ${module} list
1294 OpenStack CLI Get List
1295 [Documentation] Return a json list from the output of an OpenStack command.
1297 @{list} = BuiltIn.Create List
1298 ${json} = OpenStack CLI ${cmd}
1299 @{list} = RequestsLibrary.To Json ${json}
1304 [Documentation] Run the given OpenStack ${cmd} and log the output.
1306 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output ${cmd}
1307 BuiltIn.Log ${output}
1308 BuiltIn.Should Be True '${rc}' == '0'
1311 OpenStack CLI With No Log
1312 [Documentation] Run the given OpenStack ${cmd} and do not log the output.
1314 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output ${cmd}
1315 BuiltIn.Should Be True '${rc}' == '0'
1318 OpenStack Cleanup All
1319 [Documentation] Cleanup all Openstack resources with best effort. The keyword will query for all resources
1320 ... in use and then attempt to delete them. Errors are ignored to allow the cleanup to continue.
1321 @{fips} = OpenStack CLI Get List openstack floating ip list -f json
1322 FOR ${fip} IN @{fips}
1323 BuiltIn.Run Keyword And Ignore Error Delete Floating IP ${fip['ID']}
1325 @{vms} = OpenStack CLI Get List openstack server list -f json
1327 BuiltIn.Run Keyword And Ignore Error Delete Vm Instance ${vm['ID']}
1329 @{routers} = OpenStack CLI Get List openstack router list -f json
1330 FOR ${router} IN @{routers}
1331 BuiltIn.Run Keyword And Ignore Error Cleanup Router ${router['ID']}
1333 @{ports} = OpenStack CLI Get List openstack port list -f json
1334 FOR ${port} IN @{ports}
1335 BuiltIn.Run Keyword And Ignore Error Delete Port ${port['ID']}
1337 @{networks} = OpenStack CLI Get List openstack network list -f json
1338 FOR ${network} IN @{networks}
1339 BuiltIn.Run Keyword And Ignore Error Delete Subnet ${network['Subnets']}
1340 BuiltIn.Run Keyword And Ignore Error Delete Network ${network['ID']}
1342 @{security_groups} = OpenStack CLI Get List openstack security group list -f json
1343 FOR ${security_group} IN @{security_groups}
1344 IF "${security_group['Name']}" != "default"
1345 BuiltIn.Run Keyword And Ignore Error Delete SecurityGroup ${security_group['ID']}
1351 [Documentation] Delete a router, but first remove any interfaces or gateways so that the delete will be successful.
1353 @{ports} = OpenStack CLI Get List openstack port list --router ${id} -f json --long
1354 FOR ${port} IN @{ports}
1355 ${subnet_id} = OpenStackOperations.Get Match ${port['Fixed IP Addresses']} ${REGEX_UUID} 0
1356 IF "${port['Device Owner']}" == "network:router_gateway"
1357 BuiltIn.Run Keyword And Ignore Error Remove Gateway ${id}
1359 IF "${port['Device Owner']}" == "network:router_interface"
1360 BuiltIn.Run Keyword And Ignore Error Remove Interface ${id} ${subnet_id}
1363 BuiltIn.Run Keyword And Ignore Error Delete Router ${id}
1365 OpenStack Suite Setup
1366 [Documentation] Wrapper teardown keyword that can be used in any suite running in an openstack environement
1367 SetupUtils.Setup_Utils_For_Setup_And_Teardown
1368 DevstackUtils.Devstack Suite Setup
1369 @{tcpdump_port_6653_conn_ids} = OpenStackOperations.Start Packet Capture On Nodes
1370 ... tcpdump_port_6653
1373 BuiltIn.Set Suite Variable @{tcpdump_port_6653_conn_ids}
1374 IF "${PRE_CLEAN_OPENSTACK_ALL}"=="True" OpenStack Cleanup All
1375 OpenStackOperations.Add OVS Logging On All OpenStack Nodes
1377 OpenStack Suite Teardown
1378 [Documentation] Wrapper teardown keyword that can be used in any suite running in an openstack environement
1379 ... to clean up all openstack resources. For example, all instances, networks, ports, etc will be listed and
1380 ... and deleted. As other global cleanup tasks are needed, they can be added here and the suites will all
1381 ... benefit automatically.
1382 OpenStack Cleanup All
1383 OpenStackOperations.Stop Packet Capture On Nodes ${tcpdump_port_6653_conn_ids}
1384 SSHLibrary.Close All Connections
1386 Copy DHCP Files From Control Node
1387 [Documentation] Copy the current DHCP files to the robot vm. The keyword must be called
1388 ... after the subnet(s) are created and before the subnet(s) are deleted.
1389 ${suite_} = BuiltIn.Evaluate """${SUITE_NAME}""".replace(" ","_").replace("/","_").replace(".","_")
1390 ${dstdir} = BuiltIn.Set Variable /tmp/qdhcp/${suite_}
1391 OperatingSystem.Create Directory ${dstdir}
1392 OpenStackOperations.Get ControlNode Connection
1393 BuiltIn.Run Keyword And Ignore Error
1394 ... SSHLibrary.Get Directory
1395 ... /opt/stack/data/neutron/dhcp
1399 Is Feature Installed
1400 [Arguments] ${features}=none
1401 FOR ${feature} IN @{features}
1402 ${status} ${output} = BuiltIn.Run Keyword And Ignore Error
1403 ... BuiltIn.Should Contain
1404 ... ${CONTROLLERFEATURES}
1406 IF "${status}" == "PASS" RETURN True
1410 Add OVS Logging On All OpenStack Nodes
1411 [Documentation] Add higher levels of OVS logging to all the OpenStack nodes
1412 IF 0 < ${NUM_OS_SYSTEM} OVSDB.Add OVS Logging ${OS_CNTL_CONN_ID}
1413 IF 1 < ${NUM_OS_SYSTEM} OVSDB.Add OVS Logging ${OS_CMP1_CONN_ID}
1414 IF 2 < ${NUM_OS_SYSTEM} OVSDB.Add OVS Logging ${OS_CMP2_CONN_ID}
1416 Reset OVS Logging On All OpenStack Nodes
1417 [Documentation] Reset the OVS logging to all the OpenStack nodes
1418 IF 0 < ${NUM_OS_SYSTEM} OVSDB.Reset OVS Logging ${OS_CNTL_CONN_ID}
1419 IF 1 < ${NUM_OS_SYSTEM} OVSDB.Reset OVS Logging ${OS_CMP1_CONN_ID}
1420 IF 2 < ${NUM_OS_SYSTEM} OVSDB.Reset OVS Logging ${OS_CMP2_CONN_ID}
1422 Start Packet Capture On Nodes
1423 [Documentation] Wrapper keyword around the TcpDump packet capture that is catered to the Openstack setup.
1424 ... The caller must pass the three arguments with a variable number of ips at the end,
1425 ... but ${EMPTY} can be used for the tag and filter.
1426 [Arguments] ${tag} ${filter} @{ips}
1427 ${suite_} = BuiltIn.Evaluate """${SUITE_NAME}""".replace(" ","_").replace("/","_").replace(".","_")
1428 ${tag_} = BuiltIn.Catenate SEPARATOR=__ ${tag} ${suite_}
1429 @{conn_ids} = Tcpdump.Start Packet Capture on Nodes tag=${tag_} filter=${filter} ips=${ips}
1432 Stop Packet Capture On Nodes
1433 [Arguments] ${conn_ids}=@{EMPTY}
1434 Tcpdump.Stop Packet Capture on Nodes ${conn_ids}
1437 [Arguments] ${domain} ${description} ${name} ${rc_file}=${EMPTY}
1438 IF "${rc_file}" != "${EMPTY}"
1439 ${rc} ${output} = Run And Return Rc And Output
1440 ... source ${rc_file};openstack project create --domain ${domain} --description {description} ${name}
1442 ${rc} ${output} = Run And Return Rc And Output
1443 ... openstack project create --domain ${domain} --description {description} ${name}
1446 Should Not Be True ${rc}
1449 [Arguments] ${name} ${description} ${category} ${rc_file}=${EMPTY}
1450 IF "${rc_file}" != "${EMPTY}"
1451 ${rc} ${output} = Run And Return Rc And Output
1452 ... source ${rc_file};openstack service create --name ${name} --description ${description} ${category}
1454 ${rc} ${output} = Run And Return Rc And Output
1455 ... openstack service create --name ${name} --description ${description} ${category}
1458 Should Not Be True ${rc}
1461 [Arguments] ${name} ${file_path} ${rc_file}=${EMPTY}
1462 IF "${rc_file}" != "${EMPTY}"
1463 ${rc} ${output} = Run And Return Rc And Output
1464 ... source ${rc_file};openstack image create ${name} --file ${file_path} --disk-format qcow2 --container-format bare --public
1466 ${rc} ${output} = Set Variable ${None} ${None}
1469 Should Not Be True ${rc}
1472 [Arguments] ${name} ${ram} ${disk} ${rc_file}=${EMPTY}
1473 IF "${rc_file}" != "${EMPTY}"
1474 ${rc} ${output} = Run And Return Rc And Output
1475 ... source ${rc_file};openstack flavor create ${name} --ram ${ram} --disk ${disk}
1477 ${rc} ${output} = Set Variable ${None} ${None}
1480 Should Not Be True ${rc}
1483 [Arguments] ${keypair_name} ${key_path} ${rc_file}=${EMPTY}
1484 IF "${rc_file}" != "${EMPTY}"
1485 ${rc} ${output} = Run And Return Rc And Output
1486 ... source ${rc_file};openstack keypair create ${keypair_name} --public-key ${key_path}.pub
1488 ${rc} ${output} = Set Variable ${None} ${None}
1491 Should Not Be True ${rc}