2 Documentation Openstack library. This library is useful for tests to create network, subnet, router and vm instances
4 Library OperatingSystem
5 Library RequestsLibrary
8 Resource DataModels.robot
9 Resource DevstackUtils.robot
10 Resource L2GatewayOperations.robot
12 Resource SetupUtils.robot
13 Resource SSHKeywords.robot
14 Resource Tcpdump.robot
16 Resource ../variables/Variables.robot
17 Resource ../variables/netvirt/Variables.robot
18 Variables ../variables/netvirt/Modules.py
21 Get Tenant ID From Security Group
22 [Documentation] Returns tenant ID by reading it from existing default security-group.
23 ${output} = OpenStack CLI openstack security group show default | grep "| tenant_id" | awk '{print $4}'
26 Get Tenant ID From Network
27 [Arguments] ${network_uuid}
28 [Documentation] Returns tenant ID by reading it from existing network.
29 ${resp} = TemplatedRequests.Get_From_Uri uri=${CONFIG_API}/neutron:neutron/networks/network/${network_uuid}/ accept=${ACCEPT_EMPTY} session=session
30 ${tenant_id} = Utils.Extract Value From Content ${resp} /network/0/tenant-id strip
34 [Arguments] ${network_name} ${additional_args}=${EMPTY} ${verbose}=TRUE
35 [Documentation] Create Network with neutron request.
36 ${output} = OpenStack CLI openstack network create ${network_name} ${additional_args}
40 [Arguments] ${network_name} ${additional_args}=${EMPTY}
41 [Documentation] Update Network with neutron request.
42 ${cmd} = BuiltIn.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} = OperatingSystem.Run And Return Rc And Output ${cmd}
45 BuiltIn.Should Be True '${rc}' == '0'
49 [Arguments] ${network_name}
50 [Documentation] Show Network with neutron request.
51 ${output} = OpenStack CLI openstack network show ${network_name}
55 [Documentation] List networks and return output with neutron client.
56 ${output} = OpenStack CLI openstack network list
60 [Documentation] List subnets and return output with neutron client.
61 ${output} = OpenStack CLI openstack subnet list
65 [Arguments] ${network_name}
66 [Documentation] Delete Network with neutron request.
67 ${output} = OpenStack CLI openstack network delete ${network_name}
70 [Arguments] ${network_name} ${subnet_name} ${range_ip} ${additional_args}=${EMPTY}
71 [Documentation] Create SubNet for the Network with neutron request.
72 ${output} = OpenStack CLI openstack subnet create --network ${network_name} --subnet-range ${range_ip} ${subnet_name} ${additional_args}
75 [Arguments] ${subnet_name} ${additional_args}=${EMPTY}
76 [Documentation] Update subnet with neutron request.
77 ${cmd} = BuiltIn.Set Variable If '${OPENSTACK_BRANCH}'=='stable/newton' neutron -v subnet-update ${subnet_name} ${additional_args} openstack subnet set ${subnet_name} ${additional_args}
78 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output ${cmd}
80 BuiltIn.Should Be True '${rc}' == '0'
84 [Arguments] ${subnet_name}
85 [Documentation] Show subnet with neutron request.
86 ${output} = OpenStack CLI openstack subnet show ${subnet_name}
90 [Arguments] ${network_name} ${port_name} ${sg}=default ${additional_args}=${EMPTY} ${allowed_address_pairs}=${EMPTY}
91 [Documentation] Create Port with neutron request.
92 # if allowed_address_pairs is not empty we need to create the arguments to pass to the port create command. They are
93 # in a different format with the neutron vs openstack cli.
94 ${address_pair_length} = BuiltIn.Get Length ${allowed_address_pairs}
95 ${allowed_pairs_argv} = BuiltIn.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]
96 ${allowed_pairs_argv} = BuiltIn.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}
97 ${allowed_pairs_argv} = BuiltIn.Set Variable If '${address_pair_length}'=='0' ${EMPTY} ${allowed_pairs_argv}
98 ${cmd} = BuiltIn.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}
99 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output ${cmd}
100 BuiltIn.Log ${output}
101 BuiltIn.Should Be True '${rc}' == '0'
104 [Arguments] ${port_name} ${additional_args}=${EMPTY}
105 [Documentation] Update port with neutron request.
106 ${output} = OpenStack CLI openstack port set ${port_name} ${additional_args}
110 [Arguments] ${port_name}
111 [Documentation] Show port with neutron request.
112 ${output} = OpenStack CLI openstack port show ${port_name}
116 [Arguments] ${port_name}
117 [Documentation] Delete Port with neutron request.
118 ${output} = OpenStack CLI openstack port delete ${port_name}
121 [Arguments] ${user_name} ${domain} ${password} ${rc_file}=${EMPTY}
122 ${rc} ${output}= Run Keyword If "${rc_file}" != "${EMPTY}" Run And Return Rc And Output source ${rc_file};openstack user create ${user_name} --domain ${domain} --password ${password}
123 ... ELSE Run And Return Rc And Output openstack user create ${user_name} --domain ${domain} --password ${password}
125 Should Not Be True ${rc}
129 [Arguments] ${project_name} ${user_name} ${role} ${rc_file}=${EMPTY}
130 ${rc} ${output}= Run Keyword If "${rc_file}" != "${EMPTY}" Run And Return Rc And Output source ${rc_file};openstack role add --project ${project_name} --user ${user_name} ${role}
131 ... ELSE Run And Return Rc And Output openstack role add --project ${project_name} --user ${user_name} ${role}
133 Should Not Be True ${rc}
137 [Arguments] ${region_name} ${host_name} ${service_category} ${endpoint_category} ${port} ${rc_file}=${EMPTY}
138 ${rc} ${output}= Run Keyword If "${rc_file}" != "${EMPTY}" Run And Return Rc And Output source ${rc_file};openstack endpoint create --region ${region_name} ${service_category} ${endpoint_category} http://${host_name}:${port}
139 ... ELSE Run And Return Rc And Output openstack endpoint create --region ${region_name} ${service_category} ${endpoint_category} http://${host_name}:${port}
141 Should Not Be True ${rc}
144 [Documentation] List ports and return output with neutron client.
145 ${output} = OpenStack CLI openstack port list
149 [Documentation] List VMs and return output with nova client.
150 ${output} = OpenStack CLI openstack server list --all-projects
153 Create And Associate Floating IPs
154 [Arguments] ${external_net} @{vm_list}
155 [Documentation] Create and associate floating IPs to VMs with nova request
156 ${ip_list} = BuiltIn.Create List @{EMPTY}
157 FOR ${vm} IN @{vm_list}
158 ${output} = OpenStack CLI openstack floating ip create ${external_net}
159 @{ip} = String.Get Regexp Matches ${output} [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}
160 ${ip_length} = BuiltIn.Get Length ${ip}
161 BuiltIn.Run Keyword If ${ip_length}>0 Collections.Append To List ${ip_list} @{ip}[0]
162 ... ELSE Collections.Append To List ${ip_list} None
163 ${output} = OpenStack CLI openstack server add floating ip ${vm} @{ip}[0]
169 [Documentation] Delete floating ip with neutron request.
170 ${output} = OpenStack CLI openstack floating ip delete ${fip}
173 [Arguments] ${subnet}
174 [Documentation] Delete SubNet for the Network with neutron request.
175 ${output} = OpenStack CLI openstack subnet delete ${subnet}
178 [Arguments] ${vm_name}
179 [Documentation] Delete Vm instances using instance names.
180 ${output} = OpenStack CLI openstack server delete ${vm_name}
183 [Arguments] ${network_name}
184 [Documentation] Retrieve the net id for the given network name to create specific vm instance
185 ${output} = OpenStack CLI openstack network list | grep "${network_name}" | awk '{print $2}'
186 ${splitted_output} = String.Split String ${output} ${EMPTY}
187 ${net_id} = Collections.Get from List ${splitted_output} 0
191 [Arguments] ${subnet_name}
192 [Documentation] Retrieve the subnet id for the given subnet name
193 ${output} = OpenStack CLI openstack subnet show "${subnet_name}" | grep " id " | awk '{print $4}'
194 ${splitted_output} = String.Split String ${output} ${EMPTY}
195 ${subnet_id} = Collections.Get from List ${splitted_output} 0
196 [Return] ${subnet_id}
199 [Arguments] ${port_name}
200 [Documentation] Retrieve the port id for the given port name to attach specific vm instance to a particular port
201 ${output} = OpenStack CLI openstack port list | grep "${port_name}" | awk '{print $2}'
202 ${splitted_output} = String.Split String ${output} ${EMPTY}
203 ${port_id} = Collections.Get from List ${splitted_output} 0
207 [Arguments] ${router1}
208 [Documentation] Retrieve the router id for the given router name
209 ${output} = OpenStack CLI openstack router show "${router1}" |awk '/ id / {print $4}'
210 ${splitted_output} = String.Split String ${output} ${EMPTY}
211 ${router_id} = Collections.Get from List ${splitted_output} 0
212 [Return] ${router_id}
215 [Arguments] ${net_name} ${vm_instance_names} ${image}=${EMPTY} ${flavor}=m1.nano ${sg}=default ${min}=1
217 [Documentation] Create X Vm Instance with the net id of the Netowrk.
218 ${image} BuiltIn.Set Variable If "${image}"=="${EMPTY}" ${CIRROS_${OPENSTACK_BRANCH}} ${image}
219 ${net_id} = OpenStackOperations.Get Net Id ${net_name}
220 FOR ${vm} IN @{vm_instance_names}
221 ${output} = OpenStack CLI openstack server create --image ${image} --flavor ${flavor} --nic net-id=${net_id} ${vm} --security-group ${sg} --min ${min} --max ${max}
224 Create Vm Instance On Compute Node
225 [Arguments] ${net_name} ${vm_name} ${node_hostname} ${image}=${EMPTY} ${flavor}=m1.nano ${sg}=default
226 [Documentation] Create a VM instance on a specific compute node.
227 ${image} = BuiltIn.Set Variable If "${image}"=="${EMPTY}" ${CIRROS_${OPENSTACK_BRANCH}} ${image}
228 ${net_id} = OpenStackOperations.Get Net Id ${net_name}
229 ${output} = OpenStack CLI openstack server create ${vm_name} --image ${image} --flavor ${flavor} --nic net-id=${net_id} --security-group ${sg} --availability-zone nova:${node_hostname}
231 Create Vm Instance With Port
232 [Arguments] ${port_name} ${vm_instance_name} ${image}=${EMPTY} ${flavor}=m1.nano ${sg}=default
233 [Documentation] Create One VM instance using given ${port_name} and for given ${compute_node}
234 ${image} = BuiltIn.Set Variable If "${image}"=="${EMPTY}" ${CIRROS_${OPENSTACK_BRANCH}} ${image}
235 ${port_id} = OpenStackOperations.Get Port Id ${port_name}
236 ${output} = OpenStack CLI openstack server create --image ${image} --flavor ${flavor} --nic port-id=${port_id} ${vm_instance_name} --security-group ${sg}
238 Create Vm Instance With Ports
239 [Arguments] ${port_name} ${port2_name} ${vm_instance_name} ${image}=${EMPTY} ${flavor}=m1.nano ${sg}=default
240 [Documentation] Create One VM instance using given ${port_name} and for given ${compute_node}
241 ${image} BuiltIn.Set Variable If "${image}"=="${EMPTY}" ${CIRROS_${OPENSTACK_BRANCH}} ${image}
242 ${port_id} = OpenStackOperations.Get Port Id ${port_name}
243 ${port2_id} = OpenStackOperations.Get Port Id ${port2_name}
244 ${output} = OpenStack CLI openstack server create --image ${image} --flavor ${flavor} --nic port-id=${port_id} --nic port-id=${port2_id} ${vm_instance_name} --security-group ${sg}
246 Create Vm Instance With Port On Compute Node
247 [Arguments] ${port_name} ${vm_instance_name} ${node_hostname} ${image}=${EMPTY} ${flavor}=m1.nano ${sg}=default
248 [Documentation] Create One VM instance using given ${port_name} and for given ${compute_node}
249 ${image} = BuiltIn.Set Variable If "${image}"=="${EMPTY}" ${CIRROS_${OPENSTACK_BRANCH}} ${image}
250 ${port_id} = OpenStackOperations.Get Port Id ${port_name}
251 ${output} = OpenStack CLI openstack server create --image ${image} --flavor ${flavor} --nic port-id=${port_id} --security-group ${sg} --availability-zone nova:${node_hostname} ${vm_instance_name}
253 Get Hypervisor Hostname From IP
254 [Arguments] ${hypervisor_ip}
255 [Documentation] Returns the hostname found for the given IP address if it's listed in hypervisor list. For debuggability
256 ... the full listing is logged first, then followed by a grep | cut to focus on the actual hostname to return
257 ${output} = OpenStack CLI openstack hypervisor list
258 ${hostname} = OpenStack CLI openstack hypervisor list -f value | grep "${hypervisor_ip} " | cut -d" " -f 2
262 [Documentation] Create a nano flavor
263 ${output} = OpenStack CLI openstack flavor create m1.nano --id auto --ram 64 --disk 0 --vcpus 1
266 [Arguments] ${vm_name}
267 [Documentation] Run these commands to check whether the created vm instance is active or not.
268 ${output} = OpenStack CLI openstack server show ${vm_name} | grep OS-EXT-STS:vm_state
269 BuiltIn.Should Contain ${output} active
272 [Arguments] ${vm_name} ${retry}=600s ${retry_interval}=30s
273 [Documentation] Run these commands to check whether the created vm instance is active or not.
274 BuiltIn.Wait Until Keyword Succeeds ${retry} ${retry_interval} OpenStackOperations.Verify VM Is ACTIVE ${vm_name}
276 Collect VM IP Addresses
277 [Arguments] ${fail_on_none} @{vm_list}
278 [Documentation] Using the console-log on the provided ${vm_list} to search for the string "obtained" which
279 ... correlates to the instance receiving it's IP address via DHCP. Also retrieved is the ip of the nameserver
280 ... if available in the console-log output. The keyword will also return a list of the learned ips as it
281 ... finds them in the console log output, and will have "None" for Vms that no ip was found.
282 ${ip_list} Create List @{EMPTY}
283 FOR ${vm} IN @{vm_list}
284 ${rc} ${vm_ip_line}= Run And Return Rc And Output openstack console log show ${vm} | grep -i "obtained"
285 @{vm_ip} Get Regexp Matches ${vm_ip_line} [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}
286 ${vm_ip_length} Get Length ${vm_ip}
287 Run Keyword If ${vm_ip_length}>0 Append To List ${ip_list} @{vm_ip}[0]
288 ... ELSE Append To List ${ip_list} None
289 ${rc} ${dhcp_ip_line}= Run And Return Rc And Output openstack console log show ${vm} | grep "^nameserver"
290 ${dhcp_ip} Get Regexp Matches ${dhcp_ip_line} [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}
291 ${dhcp_ip_length} Get Length ${dhcp_ip}
292 Run Keyword If ${dhcp_ip_length}<=0 Append To List ${dhcp_ip} None
293 ${vm_console_output}= Run openstack console log show ${vm}
294 Log ${vm_console_output}
296 ${dhcp_length} Get Length ${dhcp_ip}
297 Run Keyword If '${fail_on_none}' == 'true' Should Not Contain ${ip_list} None
298 Run Keyword If '${fail_on_none}' == 'true' Should Not Contain ${dhcp_ip} None
299 # Should Be True ${dhcp_length} <= 1
300 Return From Keyword If ${dhcp_length}==0 ${ip_list} ${EMPTY}
301 [Return] ${ip_list} ${dhcp_ip}
304 [Arguments] ${text} ${regexp} ${index}=0
305 [Documentation] Wrapper around String.Get Regexp Matches to return None if not found or the first match if found.
306 @{matches} = String.Get Regexp Matches ${text} ${regexp}
307 ${matches_length} = BuiltIn.Get Length ${matches}
308 BuiltIn.Set Suite Variable ${OS_MATCH} None
309 BuiltIn.Run Keyword If ${matches_length} > ${index} BuiltIn.Set Suite Variable ${OS_MATCH} @{matches}[${index}]
313 [Arguments] ${fail_on_none} ${vm}
314 [Documentation] Get the vm ip address and nameserver by scraping the vm's console log.
315 ... Get VM IP returns three values: [0] the vm IP, [1] the DHCP IP and [2] the vm console log.
316 ${vm_console_output} = OpenStack CLI With No Log openstack console log show ${vm}
317 ${vm_ip} = BuiltIn.Set Variable None
318 ${dhcp_ip} = BuiltIn.Set Variable None
319 ${match} = OpenStackOperations.Get Match ${vm_console_output} ${REGEX_OBTAINED}
320 ${vm_ip} = OpenStackOperations.Get Match ${match} ${REGEX_IPV4} 0
321 ${match} = OpenStackOperations.Get Match ${vm_console_output} ${REGEX_IPROUTE}
322 ${dhcp_ip} = OpenStackOperations.Get Match ${match} ${REGEX_IPV4} 1
323 BuiltIn.Run Keyword If '${fail_on_none}' == 'true' BuiltIn.Should Not Contain ${vm_ip} None
324 BuiltIn.Run Keyword If '${fail_on_none}' == 'true' BuiltIn.Should Not Contain ${dhcp_ip} None
325 [Return] ${vm_ip} ${dhcp_ip} ${vm_console_output}
329 [Documentation] Get the instance IP addresses and nameserver address for the list of given vms.
330 ... First poll for the vm instance to be in the active state, then poll for the vm ip address and nameserver.
331 ... Get VM IPs returns two things: [0] a list of the ips for the vms passed to this keyword (may contain values
332 ... of None) and [1] the dhcp ip address found in the last vm checked.
333 ... TODO: there is a potential issue for a caller that passes in VMs belonging to different networks that
334 ... may have different dhcp server addresses. Not sure what TODO about that, but noting it here for reference.
335 @{vm_ips} BuiltIn.Create List @{EMPTY}
337 OpenStackOperations.Poll VM Is ACTIVE ${vm}
338 ${status} ${ips_and_console_log} BuiltIn.Run Keyword And Ignore Error BuiltIn.Wait Until Keyword Succeeds 180s 15s
339 ... OpenStackOperations.Get VM IP true ${vm}
340 # If there is trouble with Get VM IP, the status will be FAIL and the return value will be a string of what went
341 # wrong. We need to handle both the PASS and FAIL cases. In the FAIL case we know we wont have access to the
342 # console log, as it would not be returned; so we need to grab it again to log it. We also can append 'None' to
343 # the vm ip list if status is FAIL.
344 BuiltIn.Run Keyword If "${status}" == "PASS" BuiltIn.Log ${ips_and_console_log[2]}
345 BuiltIn.Run Keyword If "${status}" == "PASS" Collections.Append To List ${vm_ips} ${ips_and_console_log[0]}
346 BuiltIn.Run Keyword If "${status}" == "FAIL" Collections.Append To List ${vm_ips} None
347 ${vm_console_output} = BuiltIn.Run Keyword If "${status}" == "FAIL" OpenStack CLI openstack console log show ${vm}
348 BuiltIn.Run Keyword If "${status}" == "FAIL" BuiltIn.Log ${vm_console_output}
350 OpenStackOperations.Copy DHCP Files From Control Node
351 [Return] @{vm_ips} ${ips_and_console_log[1]}
353 Collect VM IPv6 SLAAC Addresses
354 [Arguments] ${fail_on_none} ${vm_list} ${network} ${subnet}
355 [Documentation] For each VM parse output of "openstack server show" to get its IPv6 address from Neutron DB.
356 ... Then try to connect to each VM by SSH and execute there "ip -6 a" command. This double-check allows to
357 ... obtain and compare IP info (Neutron DB vs dnsmasque/ODL DHCP) and to test L2 connectivity as well.
358 ... Returns an empty list if no IPv6 addresses found or if SSH connection fails.
359 ... Otherwise, returns a list of IPv6 addresses.
360 ${ipv6_list} = BuiltIn.Create List @{EMPTY}
361 FOR ${vm} IN @{vm_list}
362 ${output} = OpenStack CLI openstack server show ${vm} -f shell
363 ${pattern} = String.Replace String ${subnet} ::/64 (:[a-f0-9]{,4}){,4}
364 @{vm_ipv6} = String.Get Regexp Matches ${output} ${pattern}
365 ${vm_ip_length} = BuiltIn.Get Length ${vm_ipv6}[0]
366 ${ipv6_data_from_vm} = BuiltIn.Run Keyword If ${vm_ip_length}>0 OpenStackOperations.Execute Command on VM Instance ${network} ${vm_ipv6[0]}
368 @{ipv6} = String.Get Regexp Matches ${ipv6_data_from_vm} ${pattern}
369 ${ipv6_addr_list_length} BuiltIn.Get Length @{ipv6}
370 BuiltIn.Run Keyword If ${ipv6_addr_list_length}>0 Collections.Append To List ${ipv6_list} ${ipv6[0]}
371 ... ELSE Collections.Append To List ${ipv6_list} None
373 [Return] ${ipv6_list}
376 [Arguments] ${vm_instance_names}
377 [Documentation] View Console log of the created vm instances using nova show.
378 FOR ${vm} IN @{vm_instance_names}
379 ${output} = OpenStack CLI openstack server show ${vm}
380 ${output} = OpenStack CLI openstack console log show ${vm}
383 Ping Vm From DHCP Namespace
384 [Arguments] ${net_name} ${vm_ip}
385 [Documentation] Reach all Vm Instance with the net id of the Netowrk.
386 OpenStackOperations.Get ControlNode Connection
387 ${net_id} = OpenStackOperations.Get Net Id ${net_name}
388 ${output} = DevstackUtils.Write Commands Until Prompt And Log sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip} 20s
389 BuiltIn.Should Contain ${output} 64 bytes
391 Ping From DHCP Should Not Succeed
392 [Arguments] ${net_name} ${vm_ip}
393 [Documentation] Should Not Reach Vm Instance with the net id of the Netowrk.
394 Return From Keyword If "skip_if_${SECURITY_GROUP_MODE}" in @{TEST_TAGS}
395 OpenStackOperations.Get ControlNode Connection
396 ${net_id} = OpenStackOperations.Get Net Id ${net_name}
397 ${output} = DevstackUtils.Write Commands Until Prompt And Log sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip} 20s
398 BuiltIn.Should Not Contain ${output} 64 bytes
400 Ping Vm From Control Node
401 [Arguments] ${vm_floating_ip} ${additional_args}=${EMPTY}
402 [Documentation] Ping VM floating IP from control node
403 OpenStackOperations.Get ControlNode Connection
404 ${output} = DevstackUtils.Write Commands Until Prompt And Log ping ${additional_args} -c 3 ${vm_floating_ip} 20s
405 BuiltIn.Should Contain ${output} 64 bytes
408 [Documentation] Ping to the expected destination ip.
409 ${output} = Utils.Write Commands Until Expected Prompt curl -i http://169.254.169.254 ${OS_SYSTEM_PROMPT}
410 DevstackUtils.Write Commands Until Prompt exit
411 BuiltIn.Should Contain ${output} 200
414 [Documentation] Exit the vm instance.
415 ${output} = DevstackUtils.Write Commands Until Prompt And Log exit
417 Check If Console Is VmInstance
418 [Arguments] ${console}=cirros
419 [Documentation] Check if the session has been able to login to the VM instance
420 ${output} = Utils.Write Commands Until Expected Prompt id ${OS_SYSTEM_PROMPT}
421 BuiltIn.Should Contain ${output} ${console}
424 [Documentation] Check if the session has been able to login to the VM instance and exit the instance
425 ${rcode} = BuiltIn.Run Keyword And Return Status OpenStackOperations.Check If Console Is VmInstance cirros
426 BuiltIn.Run Keyword If ${rcode} DevstackUtils.Write Commands Until Prompt exit
429 [Arguments] ${ip_address} ${ttl}=64
430 [Documentation] Run Ping command on the IP available as argument
431 ${ethertype} = String.Get Regexp Matches ${ip_address} ${IP_REGEX}
432 ${output} = BuiltIn.Run Keyword If ${ethertype} Utils.Write Commands Until Expected Prompt ping -t ${ttl} -c 3 ${ip_address} ${OS_SYSTEM_PROMPT}
433 ... ELSE Utils.Write Commands Until Expected Prompt ping6 -t ${ttl} -c 3 ${ip_address} ${OS_SYSTEM_PROMPT}
434 BuiltIn.Should Contain ${output} 64 bytes
437 [Arguments] ${ip_address} ${ttl}=64
438 [Documentation] Run Ping command to the IP given as argument, executing 3 times and expecting NOT to see "64 bytes"
439 ${output} = Utils.Write Commands Until Expected Prompt ping -t ${ttl} -c 3 ${ip_address} ${OS_SYSTEM_PROMPT}
440 BuiltIn.Should Not Contain ${output} 64 bytes
442 Check Metadata Access
443 [Documentation] Try curl on the Metadataurl and check if it is okay
444 ${output} = Utils.Write Commands Until Expected Prompt curl -i http://169.254.169.254 ${OS_SYSTEM_PROMPT}
445 BuiltIn.Should Contain ${output} 200
447 Execute Command on VM Instance
448 [Arguments] ${net_name} ${vm_ip} ${cmd} ${user}=cirros ${password}=cubswin:)
449 [Documentation] Login to the vm instance using ssh in the network, executes a command inside the VM and returns the ouput.
450 OpenStackOperations.Get ControlNode Connection
451 ${net_id} = OpenStackOperations.Get Net Id ${net_name}
452 ${output} = Utils.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:
453 ${output} = Utils.Write Commands Until Expected Prompt ${password} ${OS_SYSTEM_PROMPT}
454 ${rcode} = BuiltIn.Run Keyword And Return Status OpenStackOperations.Check If Console Is VmInstance
455 ${output} = BuiltIn.Run Keyword If ${rcode} Utils.Write Commands Until Expected Prompt ${cmd} ${OS_SYSTEM_PROMPT}
456 [Teardown] Exit From Vm Console
459 Test Operations From Vm Instance
460 [Arguments] ${net_name} ${src_ip} ${dest_ips} ${user}=cirros ${password}=cubswin:) ${ttl}=64
461 ... ${ping_should_succeed}=True ${check_metadata}=True
462 [Documentation] Login to the vm instance using ssh in the network.
463 OpenStackOperations.Get ControlNode Connection
464 ${net_id} = OpenStackOperations.Get Net Id ${net_name}
465 ${output} = Utils.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:
466 ${output} = Utils.Write Commands Until Expected Prompt ${password} ${OS_SYSTEM_PROMPT}
467 ${rcode} = BuiltIn.Run Keyword And Return Status OpenStackOperations.Check If Console Is VmInstance
468 BuiltIn.Run Keyword If ${rcode} Utils.Write Commands Until Expected Prompt ifconfig ${OS_SYSTEM_PROMPT}
469 BuiltIn.Run Keyword If ${rcode} Utils.Write Commands Until Expected Prompt route -n ${OS_SYSTEM_PROMPT}
470 BuiltIn.Run Keyword If ${rcode} Utils.Write Commands Until Expected Prompt route -A inet6 ${OS_SYSTEM_PROMPT}
471 BuiltIn.Run Keyword If ${rcode} Utils.Write Commands Until Expected Prompt arp -an ${OS_SYSTEM_PROMPT}
472 BuiltIn.Run Keyword If ${rcode} Utils.Write Commands Until Expected Prompt ip -f inet6 neigh show ${OS_SYSTEM_PROMPT}
473 FOR ${dest_ip} IN @{dest_ips}
474 ${string_empty} = BuiltIn.Run Keyword And Return Status Should Be Empty ${dest_ip}
475 BuiltIn.Run Keyword If ${string_empty} Continue For Loop
476 BuiltIn.Run Keyword If ${rcode} and "${ping_should_succeed}" == "True" OpenStackOperations.Check Ping ${dest_ip} ttl=${ttl}
477 ... ELSE OpenStackOperations.Check No Ping ${dest_ip} ttl=${ttl}
479 ${ethertype} = String.Get Regexp Matches ${src_ip} ${IP_REGEX}
480 BuiltIn.Run Keyword If ${rcode} and "${check_metadata}" and ${ethertype} == "True" OpenStackOperations.Check Metadata Access
481 [Teardown] Exit From Vm Console
483 Test Netcat Operations From Vm Instance
484 [Arguments] ${net_name} ${vm_ip} ${dest_ip} ${additional_args}=${EMPTY} ${port}=12345 ${user}=cirros
485 ... ${password}=cubswin:)
486 [Documentation] Use Netcat to test TCP/UDP connections to the controller
487 ${client_data} BuiltIn.Set Variable Test Client Data
488 ${server_data} BuiltIn.Set Variable Test Server Data
489 OpenStackOperations.Get ControlNode Connection
490 ${output} = DevstackUtils.Write Commands Until Prompt And Log ( ( echo "${server_data}" | sudo timeout 60 nc -l ${additional_args} ${port} ) & )
491 ${output} = DevstackUtils.Write Commands Until Prompt And Log sudo netstat -nlap | grep ${port}
492 ${nc_output} = OpenStackOperations.Execute Command on VM Instance ${net_name} ${vm_ip} sudo echo "${client_data}" | nc -v -w 5 ${additional_args} ${dest_ip} ${port}
493 BuiltIn.Log ${output}
494 ${output} = OpenStackOperations.Execute Command on VM Instance ${net_name} ${vm_ip} sudo route -n
495 BuiltIn.Log ${output}
496 ${output} = OpenStackOperations.Execute Command on VM Instance ${net_name} ${vm_ip} sudo arp -an
497 BuiltIn.Log ${output}
498 BuiltIn.Should Match Regexp ${nc_output} ${server_data}
501 [Arguments] ${list_of_external_dst_ips}
502 [Documentation] Check reachability with other network's instances.
503 ${rcode} = BuiltIn.Run Keyword And Return Status OpenStackOperations.Check If Console Is VmInstance
504 FOR ${dest_ip} IN @{list_of_external_dst_ips}
505 OpenStackOperations.Check Ping ${dest_ip}
509 [Arguments] ${router_name}
510 [Documentation] Create Router and Add Interface to the subnets.
511 ${output} = OpenStack CLI openstack router create ${router_name}
514 [Documentation] List Routers and return output with neutron client.
515 ${output} = OpenStack CLI openstack router list -f value
519 [Arguments] ${router_name} ${interface_name}
520 ${output} = OpenStack CLI openstack router add subnet ${router_name} ${interface_name}
522 Show Router Interface
523 [Arguments] ${router_name}
524 [Documentation] List Routers interface associated with given Router and return output with neutron client.
525 ${output} = OpenStack CLI openstack port list --router ${router_name} -f value
529 [Arguments] ${router_name} ${external_network_name}
530 ${cmd} = BuiltIn.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}
531 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output ${cmd}
532 BuiltIn.Should Be True '${rc}' == '0'
535 [Arguments] ${router_name} ${interface_name}
536 [Documentation] Remove Interface to the subnets.
537 ${output} = OpenStack CLI openstack router remove subnet ${router_name} ${interface_name}
540 [Arguments] ${router_name}
541 [Documentation] Remove external gateway from the router.
542 BuiltIn.Log openstack router unset ${router_name} --external-gateway
545 [Arguments] ${router_name} ${cmd}
546 [Documentation] Update the router with the command. Router name and command should be passed as argument.
547 ${output} = OpenStack CLI openstack router set ${router_name} ${cmd}
550 [Arguments] ${router_name} ${options}
551 [Documentation] Show information of a given router. Router name and optional fields should be sent as arguments.
552 ${output} = OpenStack CLI openstack router show ${router_name}
555 [Arguments] ${router_name}
556 [Documentation] Delete Router and Interface to the subnets.
557 ${output} = OpenStack CLI openstack router delete ${router_name}
559 Get DumpFlows And Ovsconfig
560 [Arguments] ${conn_id}
561 [Documentation] Get the OvsConfig and Flow entries from OVS from the Openstack Node
562 SSHLibrary.Switch Connection ${conn_id}
563 Utils.Write Commands Until Expected Prompt ip -o link ${DEFAULT_LINUX_PROMPT_STRICT}
564 Utils.Write Commands Until Expected Prompt ip -o addr ${DEFAULT_LINUX_PROMPT_STRICT}
565 Utils.Write Commands Until Expected Prompt ip route ${DEFAULT_LINUX_PROMPT_STRICT}
566 Utils.Write Commands Until Expected Prompt arp -an ${DEFAULT_LINUX_PROMPT_STRICT}
567 ${nslist} = Utils.Write Commands Until Expected Prompt ip netns list | awk '{print $1}' ${DEFAULT_LINUX_PROMPT_STRICT}
568 @{lines} Split To Lines ${nslist} end=-1
569 FOR ${line} IN @{lines}
570 Utils.Write Commands Until Expected Prompt sudo ip netns exec ${line} ip -o link ${DEFAULT_LINUX_PROMPT_STRICT}
571 Utils.Write Commands Until Expected Prompt sudo ip netns exec ${line} ip -o addr ${DEFAULT_LINUX_PROMPT_STRICT}
572 Utils.Write Commands Until Expected Prompt sudo ip netns exec ${line} ip route ${DEFAULT_LINUX_PROMPT_STRICT}
574 Utils.Write Commands Until Expected Prompt sudo ovs-vsctl show ${DEFAULT_LINUX_PROMPT_STRICT}
575 Utils.Write Commands Until Expected Prompt sudo ovs-vsctl list Open_vSwitch ${DEFAULT_LINUX_PROMPT_STRICT}
576 Utils.Write Commands Until Expected Prompt sudo ovs-ofctl show br-int -OOpenFlow13 ${DEFAULT_LINUX_PROMPT_STRICT}
577 Utils.Write Commands Until Expected Prompt sudo ovs-ofctl dump-flows br-int -OOpenFlow13 ${DEFAULT_LINUX_PROMPT_STRICT}
578 Utils.Write Commands Until Expected Prompt sudo ovs-ofctl dump-groups br-int -OOpenFlow13 ${DEFAULT_LINUX_PROMPT_STRICT}
579 Utils.Write Commands Until Expected Prompt sudo ovs-ofctl dump-group-stats br-int -OOpenFlow13 ${DEFAULT_LINUX_PROMPT_STRICT}
581 Get Karaf Log Type From Test Start
582 [Arguments] ${ip} ${test_name} ${type} ${user}=${ODL_SYSTEM_USER} ${password}=${ODL_SYSTEM_PASSWORD} ${prompt}=${ODL_SYSTEM_PROMPT}
583 ... ${log_file}=${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
584 ${cmd} = BuiltIn.Set Variable sed '1,/ROBOT MESSAGE: Starting test ${test_name}/d' ${log_file} | grep '${type}'
585 ${output} = Utils.Run Command On Controller ${ip} ${cmd} ${user} ${password} ${prompt}
588 Get Karaf Log Types From Test Start
589 [Arguments] ${ip} ${test_name} ${types} ${user}=${ODL_SYSTEM_USER} ${password}=${ODL_SYSTEM_PASSWORD} ${prompt}=${ODL_SYSTEM_PROMPT}
590 ... ${log_file}=${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
591 FOR ${type} IN @{types}
592 OpenStackOperations.Get Karaf Log Type From Test Start ${ip} ${test_name} ${type} ${user} ${password}
593 ... ${prompt} ${log_file}
596 Get Karaf Log Events From Test Start
597 [Arguments] ${test_name} ${user}=${ODL_SYSTEM_USER} ${password}=${ODL_SYSTEM_PASSWORD} ${prompt}=${ODL_SYSTEM_PROMPT}
598 ${log_types} = BuiltIn.Create List ERROR WARN Exception
599 BuiltIn.Run Keyword If 0 < ${NUM_ODL_SYSTEM} OpenStackOperations.Get Karaf Log Types From Test Start ${ODL_SYSTEM_IP} ${test_name} ${log_types}
600 BuiltIn.Run Keyword If 1 < ${NUM_ODL_SYSTEM} OpenStackOperations.Get Karaf Log Types From Test Start ${ODL_SYSTEM_2_IP} ${test_name} ${log_types}
601 BuiltIn.Run Keyword If 2 < ${NUM_ODL_SYSTEM} OpenStackOperations.Get Karaf Log Types From Test Start ${ODL_SYSTEM_3_IP} ${test_name} ${log_types}
603 Get ControlNode Connection
604 SSHLibrary.Switch Connection ${OS_CNTL_CONN_ID}
605 [Return] ${OS_CNTL_CONN_ID}
608 [Documentation] Get the OvsConfig and Flow entries from all Openstack nodes
609 BuiltIn.Run Keyword If 0 < ${NUM_OS_SYSTEM} OpenStackOperations.Get DumpFlows And Ovsconfig ${OS_CNTL_CONN_ID}
610 BuiltIn.Run Keyword If 1 < ${NUM_OS_SYSTEM} OpenStackOperations.Get DumpFlows And Ovsconfig ${OS_CMP1_CONN_ID}
611 BuiltIn.Run Keyword If 2 < ${NUM_OS_SYSTEM} OpenStackOperations.Get DumpFlows And Ovsconfig ${OS_CMP2_CONN_ID}
613 Get Test Teardown Debugs
614 [Arguments] ${test_name}=${TEST_NAME}
615 OpenStackOperations.Get OvsDebugInfo
616 BuiltIn.Run Keyword And Ignore Error DataModels.Get Model Dump ${HA_PROXY_IP} ${netvirt_data_models}
617 OpenStackOperations.Get Karaf Log Events From Test Start ${test_name}
619 Get Test Teardown Debugs For SFC
620 [Arguments] ${test_name}=${TEST_NAME}
621 BuiltIn.Run Keyword And Ignore Error DataModels.Get Model Dump ${HA_PROXY_IP} ${netvirt_sfc_data_models}
624 [Arguments] @{vm_indices}
625 [Documentation] Run these commands for debugging, it can list state of VM instances and ip information in control node
626 OpenStackOperations.Get ControlNode Connection
627 ${output} = DevstackUtils.Write Commands Until Prompt And Log sudo ip netns list
628 FOR ${index} IN @{vm_indices}
629 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output nova show ${index}
630 BuiltIn.Log ${output}
632 OpenStackOperations.List Nova VMs
633 OpenStackOperations.List Routers
634 OpenStackOperations.List Networks
635 OpenStackOperations.List Subnets
636 OpenStackOperations.List Ports
637 OpenStackOperations.List Security Groups
640 [Documentation] Logging keyword to display all security groups using the openstack cli. Assumes openstack
641 ... credentials are already sourced
642 ${output} = OpenStack CLI openstack security group list
645 Neutron Security Group Show
646 [Arguments] ${SecurityGroupRuleName}
647 [Documentation] Displays the neutron security group configurations that belongs to a given neutron security group name
648 ${output} = OpenStack CLI openstack security group show ${SecurityGroupRuleName}
652 [Arguments] ${PortName}
653 [Documentation] Display the port configuration that belong to a given neutron port
654 ${output} = OpenStack CLI openstack port show ${PortName}
657 Neutron Security Group Create
658 [Arguments] ${SecurityGroupName} ${additional_args}=${EMPTY}
659 [Documentation] Create a security group with specified name ,description & protocol value according to security group template
660 OpenStackOperations.Get ControlNode Connection
661 ${output} = OpenStack CLI openstack security group create ${SecurityGroupName} ${additional_args}
662 ${sgp_id} = BuiltIn.Should Match Regexp ${output} ${REGEX_UUID}
663 [Return] ${output} ${sgp_id}
665 Neutron Security Group Update
666 [Arguments] ${SecurityGroupName} ${additional_args}=${EMPTY}
667 [Documentation] Updating security groups
668 ${output} = OpenStack CLI openstack security group set ${SecurityGroupName} ${additional_args}
672 [Arguments] ${sg_name}
673 [Documentation] Delete Security group
674 ${output} = OpenStack CLI openstack security group delete ${sg_name}
676 Neutron Security Group Rule Create
677 [Arguments] ${Security_group_name} &{Kwargs}
678 [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]} ..."
679 BuiltIn.Run Keyword If ${Kwargs} BuiltIn.Log ${Kwargs}
680 ${description} BuiltIn.Run Keyword If ${Kwargs} Collections.Pop From Dictionary ${Kwargs} description default=${None}
681 ${direction} BuiltIn.Run Keyword If ${Kwargs} Collections.Pop From Dictionary ${Kwargs} direction default=${None}
682 ${ethertype} BuiltIn.Run Keyword If ${Kwargs} Collections.Pop From Dictionary ${Kwargs} ethertype default=${None}
683 ${port_range_max} BuiltIn.Run Keyword If ${Kwargs} Collections.Pop From Dictionary ${Kwargs} port_range_max default=${None}
684 ${port_range_min} BuiltIn.Run Keyword If ${Kwargs} Collections.Pop From Dictionary ${Kwargs} port_range_min default=${None}
685 ${protocol} BuiltIn.Run Keyword If ${Kwargs} Collections.Pop From Dictionary ${Kwargs} protocol default=${None}
686 ${remote_group_id} BuiltIn.Run Keyword If ${Kwargs} Collections.Pop From Dictionary ${Kwargs} remote_group_id default=${None}
687 ${remote_ip_prefix} BuiltIn.Run Keyword If ${Kwargs} Collections.Pop From Dictionary ${Kwargs} remote_ip_prefix default=${None}
688 ${cmd} = BuiltIn.Set Variable openstack security group rule create ${Security_group_name}
689 ${cmd} = BuiltIn.Run Keyword If '${description}'!='None' BuiltIn.Catenate ${cmd} --description ${description}
690 ... ELSE BuiltIn.Catenate ${cmd}
691 ${cmd} = BuiltIn.Run Keyword If '${direction}'!='None' BuiltIn.Catenate ${cmd} --${direction}
692 ... ELSE BuiltIn.Catenate ${cmd}
693 ${cmd} = BuiltIn.Run Keyword If '${ethertype}'!='None' BuiltIn.Catenate ${cmd} --ethertype ${ethertype}
694 ... ELSE BuiltIn.Catenate ${cmd}
695 ${cmd} = BuiltIn.Run Keyword If '${port_range_min}'!='None' and '${port_range_max}'!='None' BuiltIn.Catenate ${cmd} --dst-port ${port_range_min}:${port_range_max}
696 ... ELSE IF '${port_range_max}'!='None' BuiltIn.Catenate ${cmd} --dst-port ${port_range_max}
697 ... ELSE IF '${port_range_min}'!='None' BuiltIn.Catenate ${cmd} --dst-port ${port_range_min}
698 ... ELSE BuiltIn.Catenate ${cmd}
699 ${cmd} = BuiltIn.Run Keyword If '${protocol}'!='None' BuiltIn.Catenate ${cmd} --protocol ${protocol}
700 ... ELSE BuiltIn.Catenate ${cmd}
701 ${cmd} = BuiltIn.Run Keyword If '${remote_group_id}'!='None' BuiltIn.Catenate ${cmd} --remote-group ${remote_group_id}
702 ... ELSE BuiltIn.Catenate ${cmd}
703 ${cmd} = BuiltIn.Run Keyword If '${remote_ip_prefix}'!='None' BuiltIn.Catenate ${cmd} --src-ip ${remote_ip_prefix}
704 ... ELSE BuiltIn.Catenate ${cmd}
705 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output ${cmd}
706 ${rule_id} = BuiltIn.Should Match Regexp ${output} ${REGEX_UUID}
707 BuiltIn.Log ${rule_id}
708 BuiltIn.Should Be True '${rc}' == '0'
709 [Return] ${output} ${rule_id}
711 Security Group Create Without Default Security Rules
712 [Arguments] ${sg_name} ${additional_args}=${EMPTY}
713 [Documentation] Create Neutron Security Group with no default rules, using specified name and optional arguments.
714 OpenStackOperations.Neutron Security Group Create ${sg_name} ${additional_args}
715 Delete All Security Group Rules ${sg_name}
717 Delete All Security Group Rules
718 [Arguments] ${sg_name}
719 [Documentation] Delete all security rules from a specified security group
720 ${sg_rules_output} = OpenStack CLI openstack security group rule list ${sg_name} -cID -fvalue
721 @{sg_rules} = String.Split String ${sg_rules_output} \n
722 FOR ${rule} IN @{sg_rules}
723 ${output} = OpenStack CLI openstack security group rule delete ${rule}
726 Create Allow All SecurityGroup
727 [Arguments] ${sg_name} ${ether_type}=IPv4
728 [Documentation] Allow all TCP/UDP/ICMP packets for this suite
729 OpenStackOperations.Neutron Security Group Create ${sg_name}
730 OpenStackOperations.Neutron Security Group Rule Create ${sg_name} direction=ingress ethertype=${ether_type} port_range_max=65535 port_range_min=1 protocol=tcp
731 OpenStackOperations.Neutron Security Group Rule Create ${sg_name} direction=egress ethertype=${ether_type} port_range_max=65535 port_range_min=1 protocol=tcp
732 OpenStackOperations.Neutron Security Group Rule Create ${sg_name} direction=ingress ethertype=${ether_type} protocol=icmp
733 OpenStackOperations.Neutron Security Group Rule Create ${sg_name} direction=egress ethertype=${ether_type} protocol=icmp
734 OpenStackOperations.Neutron Security Group Rule Create ${sg_name} direction=ingress ethertype=${ether_type} port_range_max=65535 port_range_min=1 protocol=udp
735 OpenStackOperations.Neutron Security Group Rule Create ${sg_name} direction=egress ethertype=${ether_type} port_range_max=65535 port_range_min=1 protocol=udp
737 Create Neutron Port With Additional Params
738 [Arguments] ${network_name} ${port_name} ${additional_args}=${EMPTY}
739 [Documentation] Create Port With given additional parameters
740 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output neutron -v port-create ${network_name} --name ${port_name} ${additional_args}
741 BuiltIn.Log ${output}
742 BuiltIn.Should Be True '${rc}' == '0'
743 ${port_id} = BuiltIn.Should Match Regexp ${OUTPUT} ${REGEX_UUID}
744 [Return] ${OUTPUT} ${port_id}
748 [Documentation] Retrieve the port MacAddr for the given list of port name and return the MAC address list.
749 ${macs} BuiltIn.Create List
750 FOR ${port} IN @{ports}
751 ${mac} = OpenStackOperations.Get Port Mac ${port}
752 Collections.Append To List ${macs} ${mac}
757 [Arguments] ${port_name}
758 [Documentation] Keyword would return the IP of the ${port_name} received.
759 ${output} = OpenStack CLI openstack port list | grep "${port_name}" | awk -F\\' '{print $2}'
760 ${splitted_output} = String.Split String ${output} ${EMPTY}
761 ${port_ip} = Collections.Get from List ${splitted_output} 0
765 [Arguments] ${port_name}
766 [Documentation] Keyword would return the MAC ID of the ${port_name} received.
767 ${output} = OpenStack CLI openstack port show ${port_name} | grep mac_address | awk '{print $4}'
768 ${splitted_output} = String.Split String ${output} ${EMPTY}
769 ${port_mac} = Collections.Get from List ${splitted_output} 0
773 [Arguments] ${bridge_name} ${intf_name} ${gw_name}
774 [Documentation] Keyword to create an L2 Gateway ${gw_name} for bridge ${bridge_name} connected to interface ${intf_name} (Using Neutron CLI).
775 ${rc} ${l2gw_output} = OperatingSystem.Run And Return Rc And Output ${L2GW_CREATE} name=${bridge_name},interface_names=${intf_name} ${gw_name}
776 BuiltIn.Log ${l2gw_output}
777 [Return] ${l2gw_output}
780 [Arguments] ${bridge_name} ${gw_name} ${intf_name_1} ${intf_name_2}
781 [Documentation] Keyword to add {intf_name_list} to an existing L2 Gateway ${gw_name} (Using Neutron CLI).
782 ${rc} ${l2gw_output}= Run And Return Rc And Output ${L2GW_UPDATE} name=${bridge_name},interface_names="${intf_name_1};${intf_name_2}" ${gw_name}
784 [Return] ${l2gw_output}
786 Create L2Gateway Connection
787 [Arguments] ${gw_name} ${net_name}
788 [Documentation] Keyword would create a new L2 Gateway Connection for ${gw_name} to ${net_name} (Using Neutron CLI).
789 ${rc} ${l2gw_output} = OperatingSystem.Run And Return Rc And Output ${L2GW_CONN_CREATE} ${gw_name} ${net_name}
790 BuiltIn.Log ${l2gw_output}
791 BuiltIn.Should Be True '${rc}' == '0'
792 [Return] ${l2gw_output}
795 [Documentation] Keyword to return all the L2 Gateways available (Using Neutron CLI).
796 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output ${L2GW_GET_YAML}
797 BuiltIn.Should Be True '${rc}' == '0'
800 Get All L2Gateway Connection
801 [Documentation] Keyword to return all the L2 Gateway connections available (Using Neutron CLI).
802 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output ${L2GW_GET_CONN_YAML}
803 BuiltIn.Should Be True '${rc}' == '0'
808 [Documentation] Keyword to check if the ${gw_id} is available in the L2 Gateway list (Using Neutron CLI).
809 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output ${L2GW_SHOW} ${gw_id}
810 BuiltIn.Log ${output}
811 BuiltIn.Should Be True '${rc}' == '0'
815 [Arguments] ${l2gw_name}
816 [Documentation] Keyword to retrieve the L2 Gateway ID for the ${l2gw_name} (Using Neutron CLI).
817 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output ${L2GW_GET} | grep "${l2gw_name}" | awk '{print $2}'
818 BuiltIn.Log ${output}
819 BuiltIn.Should Be True '${rc}' == '0'
820 ${splitted_output} = String.Split String ${output} ${EMPTY}
821 ${l2gw_id} = Collections.Get from List ${splitted_output} 0
824 Get L2gw Connection Id
825 [Arguments] ${l2gw_name}
826 [Documentation] Keyword to retrieve the L2 Gateway Connection ID for the ${l2gw_name} (Using Neutron CLI).
827 ${l2gw_id} = OpenStackOperations.Get L2gw Id ${l2gw_name}
828 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output ${L2GW_GET_CONN} | grep "${l2gw_id}" | awk '{print $2}'
829 BuiltIn.Should Be True '${rc}' == '0'
830 ${splitted_output} = String.Split String ${output} ${EMPTY}
831 ${splitted_output} = String.Split String ${output} ${EMPTY}
832 ${l2gw_conn_id} = Collections.Get from List ${splitted_output} 0
833 [Return] ${l2gw_conn_id}
835 Neutron Port List Rest
836 [Documentation] Keyword to get all ports details in Neutron (Using REST).
837 ${resp} = RequestsLibrary.Get Request session ${PORT_URL}
838 BuiltIn.Log ${resp.content}
839 BuiltIn.Should Be Equal As Strings ${resp.status_code} 200
840 [Return] ${resp.content}
842 Get Neutron Port Rest
843 [Arguments] ${port_id}
844 [Documentation] Keyword to get the specific port details in Neutron (Using REST).
845 ${resp} = RequestsLibrary.Get Request session ${CONFIG_API}/${GET_PORT_URL}/${port_id}
846 BuiltIn.Log ${resp.content}
847 BuiltIn.Should Be Equal As Strings ${resp.status_code} 200
848 [Return] ${resp.content}
851 [Arguments] ${port_id} ${json_data}
852 [Documentation] Keyword to update ${port_id} with json data received in ${json_data} (Using REST).
853 BuiltIn.Log ${json_data}
854 ${resp} = RequestsLibrary.Put Request session ${CONFIG_API}/${GET_PORT_URL}/${port_id} ${json_data}
855 BuiltIn.Log ${resp.content}
856 BuiltIn.Should Be Equal As Strings ${resp.status_code} 200
857 [Return] ${resp.content}
859 Create And Configure Security Group
860 [Arguments] ${sg-name}
861 [Documentation] Create Security Group with given name, and default allow rules for TCP/UDP/ICMP protocols.
862 OpenStackOperations.Neutron Security Group Create ${sg-name}
863 OpenStackOperations.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
864 OpenStackOperations.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
865 OpenStackOperations.Neutron Security Group Rule Create ${sg-name} direction=ingress protocol=icmp remote_ip_prefix=0.0.0.0/0
866 OpenStackOperations.Neutron Security Group Rule Create ${sg-name} direction=egress protocol=icmp remote_ip_prefix=0.0.0.0/0
867 OpenStackOperations.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
868 OpenStackOperations.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
870 Add Security Group To VM
871 [Arguments] ${vm} ${sg}
872 [Documentation] Add the security group provided to the given VM.
873 ${output} = OpenStack CLI openstack server add security group ${vm} ${sg}
875 Remove Security Group From VM
876 [Arguments] ${vm} ${sg}
877 [Documentation] Remove the security group provided to the given VM.
878 OpenStackOperations.Get ControlNode Connection
879 ${output} = OpenStack CLI openstack server remove security group ${vm} ${sg}
881 Create SFC Flow Classifier
882 [Arguments] ${name} ${src_ip} ${dest_ip} ${protocol} ${dest_port} ${neutron_src_port}
883 [Documentation] Create a flow classifier for SFC
884 ${output} = OpenStack CLI 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}
885 BuiltIn.Should Contain ${output} ${name}
888 Delete SFC Flow Classifier
890 [Documentation] Delete a SFC flow classifier
891 OpenStackOperations.Get ControlNode Connection
892 ${output} = OpenStack CLI openstack sfc flow classifier delete ${name}
896 [Arguments] ${name} ${port_in} ${port_out}
897 [Documentation] Creates a neutron port pair for SFC
898 OpenStackOperations.Get ControlNode Connection
899 ${output} = OpenStack CLI openstack sfc port pair create --ingress=${port_in} --egress=${port_out} ${name}
900 BuiltIn.Should Contain ${output} ${name}
905 [Documentation] Delete a SFC port pair
906 ${output} = OpenStack CLI openstack sfc port pair delete ${name}
909 Create SFC Port Pair Group
910 [Arguments] ${name} ${port_pair}
911 [Documentation] Creates a port pair group with a single port pair for SFC
912 ${output} = OpenStack CLI openstack sfc port pair group create --port-pair ${port_pair} ${name}
913 BuiltIn.Should Contain ${output} ${name}
916 Create SFC Port Pair Group With Two Pairs
917 [Arguments] ${name} ${port_pair1} ${port_pair2}
918 [Documentation] Creates a port pair group with two port pairs for SFC
919 ${output} = OpenStack CLI openstack sfc port pair group create --port-pair ${port_pair1} --port-pair ${port_pair2} ${name}
920 BuiltIn.Should Contain ${output} ${name}
923 Delete SFC Port Pair Group
925 [Documentation] Delete a SFC port pair group
926 OpenStackOperations.Get ControlNode Connection
927 ${output} = OpenStack CLI openstack sfc port pair group delete ${name}
930 Create SFC Port Chain
931 [Arguments] ${name} ${pg1} ${pg2} ${fc}
932 [Documentation] Creates a port pair chain with two port groups and a singel classifier.
933 ${output} = OpenStack CLI openstack sfc port chain create --port-pair-group ${pg1} --port-pair-group ${pg2} --flow-classifier ${fc} ${name}
934 BuiltIn.Should Contain ${output} ${name}
937 Delete SFC Port Chain
939 [Documentation] Delete a SFC port chain
940 ${output} = OpenStack CLI openstack sfc port chain delete ${name}
944 [Arguments] ${vm_name}
945 [Documentation] Reboot NOVA VM
946 ${output} = OpenStack CLI openstack server reboot --wait ${vm_name}
947 BuiltIn.Wait Until Keyword Succeeds 35s 10s OpenStackOperations.Verify VM Is ACTIVE ${vm_name}
949 Remove RSA Key From KnownHosts
951 [Documentation] Remove RSA
952 OpenStackOperations.Get ControlNode Connection
953 ${output} = DevstackUtils.Write Commands Until Prompt And Log sudo cat /root/.ssh/known_hosts 30s
954 ${output} = DevstackUtils.Write Commands Until Prompt And Log sudo ssh-keygen -f "/root/.ssh/known_hosts" -R ${vm_ip} 30s
955 ${output} = DevstackUtils.Write Commands Until Prompt sudo cat "/root/.ssh/known_hosts" 30s
957 Wait For Routes To Propogate
958 [Arguments] ${networks} ${subnets}
959 [Documentation] Check propagated routes
960 OpenStackOperations.Get ControlNode Connection
961 FOR ${INDEX} IN RANGE 0 1
962 ${net_id} = OpenStackOperations.Get Net Id @{networks}[${INDEX}]
963 ${is_ipv6} = String.Get Regexp Matches @{subnets}[${INDEX}] ${IP6_REGEX}
964 ${length} = BuiltIn.Get Length ${is_ipv6}
965 ${cmd} = BuiltIn.Set Variable If ${length} == 0 ip route ip -6 route
966 ${output} = Utils.Write Commands Until Expected Prompt sudo ip netns exec qdhcp-${net_id} ${cmd} ]>
967 BuiltIn.Should Contain ${output} @{subnets}[${INDEX}]
971 [Arguments] ${vms}=@{EMPTY} ${networks}=@{EMPTY} ${subnets}=@{EMPTY} ${ports}=@{EMPTY} ${sgs}=@{EMPTY}
973 BuiltIn.Run Keyword And Ignore Error Delete Vm Instance ${vm}
975 FOR ${port} IN @{ports}
976 BuiltIn.Run Keyword And Ignore Error Delete Port ${port}
978 FOR ${subnet} IN @{subnets}
979 BuiltIn.Run Keyword And Ignore Error Delete SubNet ${subnet}
981 FOR ${network} IN @{networks}
982 BuiltIn.Run Keyword And Ignore Error Delete Network ${network}
985 BuiltIn.Run Keyword And Ignore Error Delete SecurityGroup ${sg}
989 [Documentation] Get a list of different OpenStack resources that might be in use.
990 @{modules} = BuiltIn.Create List server port network subnet security group
991 ... security group rule floating ip router
992 FOR ${module} IN @{modules}
993 ${output} = OpenStack CLI openstack ${module} list
996 OpenStack CLI Get List
998 [Documentation] Return a json list from the output of an OpenStack command.
999 @{list} = BuiltIn.Create List
1000 ${json} = OpenStack CLI ${cmd}
1001 @{list} = RequestsLibrary.To Json ${json}
1007 [Documentation] Run the given OpenStack ${cmd} and log the output.
1008 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output ${cmd}
1009 BuiltIn.Log ${output}
1010 BuiltIn.Should Be True '${rc}' == '0'
1013 OpenStack CLI With No Log
1015 [Documentation] Run the given OpenStack ${cmd} and do not log the output.
1016 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output ${cmd}
1017 BuiltIn.Should Be True '${rc}' == '0'
1020 OpenStack Cleanup All
1021 [Documentation] Cleanup all Openstack resources with best effort. The keyword will query for all resources
1022 ... in use and then attempt to delete them. Errors are ignored to allow the cleanup to continue.
1023 @{fips} = OpenStack CLI Get List openstack floating ip list -f json
1024 FOR ${fip} IN @{fips}
1025 BuiltIn.Run Keyword And Ignore Error Delete Floating IP ${fip['ID']}
1027 @{vms} = OpenStack CLI Get List openstack server list -f json
1029 BuiltIn.Run Keyword And Ignore Error Delete Vm Instance ${vm['ID']}
1031 @{routers} = OpenStack CLI Get List openstack router list -f json
1032 FOR ${router} IN @{routers}
1033 BuiltIn.Run Keyword And Ignore Error Cleanup Router ${router['ID']}
1035 @{ports} = OpenStack CLI Get List openstack port list -f json
1036 FOR ${port} IN @{ports}
1037 BuiltIn.Run Keyword And Ignore Error Delete Port ${port['ID']}
1039 @{networks} = OpenStack CLI Get List openstack network list -f json
1040 FOR ${network} IN @{networks}
1041 BuiltIn.Run Keyword And Ignore Error Delete Subnet ${network['Subnets']}
1042 BuiltIn.Run Keyword And Ignore Error Delete Network ${network['ID']}
1044 @{security_groups} = OpenStack CLI Get List openstack security group list -f json
1045 FOR ${security_group} IN @{security_groups}
1046 BuiltIn.Run Keyword If "${security_group['Name']}" != "default" BuiltIn.Run Keyword And Ignore Error Delete SecurityGroup ${security_group['ID']}
1052 [Documentation] Delete a router, but first remove any interfaces or gateways so that the delete will be successful.
1053 @{ports} = OpenStack CLI Get List openstack port list --router ${id} -f json --long
1054 FOR ${port} IN @{ports}
1055 ${subnet_id} = OpenStackOperations.Get Match ${port['Fixed IP Addresses']} ${REGEX_UUID} 0
1056 BuiltIn.Run Keyword If "${port['Device Owner']}" == "network:router_gateway" BuiltIn.Run Keyword And Ignore Error Remove Gateway ${id}
1057 BuiltIn.Run Keyword If "${port['Device Owner']}" == "network:router_interface" BuiltIn.Run Keyword And Ignore Error Remove Interface ${id} ${subnet_id}
1059 BuiltIn.Run Keyword And Ignore Error Delete Router ${id}
1061 OpenStack Suite Setup
1062 [Documentation] Wrapper teardown keyword that can be used in any suite running in an openstack environement
1063 SetupUtils.Setup_Utils_For_Setup_And_Teardown
1064 DevstackUtils.Devstack Suite Setup
1065 @{tcpdump_port_6653_conn_ids} = OpenStackOperations.Start Packet Capture On Nodes tcpdump_port_6653 port 6653 @{OS_ALL_IPS}
1066 BuiltIn.Set Suite Variable @{tcpdump_port_6653_conn_ids}
1067 BuiltIn.Run Keyword If "${PRE_CLEAN_OPENSTACK_ALL}"=="True" OpenStack Cleanup All
1068 OpenStackOperations.Add OVS Logging On All OpenStack Nodes
1070 OpenStack Suite Teardown
1071 [Documentation] Wrapper teardown keyword that can be used in any suite running in an openstack environement
1072 ... to clean up all openstack resources. For example, all instances, networks, ports, etc will be listed and
1073 ... and deleted. As other global cleanup tasks are needed, they can be added here and the suites will all
1074 ... benefit automatically.
1075 OpenStack Cleanup All
1076 OpenStackOperations.Stop Packet Capture On Nodes ${tcpdump_port_6653_conn_ids}
1077 SSHLibrary.Close All Connections
1079 Copy DHCP Files From Control Node
1080 [Documentation] Copy the current DHCP files to the robot vm. The keyword must be called
1081 ... after the subnet(s) are created and before the subnet(s) are deleted.
1082 ${suite_} = BuiltIn.Evaluate """${SUITE_NAME}""".replace(" ","_").replace("/","_").replace(".","_")
1083 ${dstdir} = BuiltIn.Set Variable /tmp/qdhcp/${suite_}
1084 OperatingSystem.Create Directory ${dstdir}
1085 OpenStackOperations.Get ControlNode Connection
1086 BuiltIn.Run Keyword And Ignore Error SSHLibrary.Get Directory /opt/stack/data/neutron/dhcp ${dstdir} recursive=True
1088 Is Feature Installed
1089 [Arguments] ${features}=none
1090 FOR ${feature} IN @{features}
1091 ${status} ${output} BuiltIn.Run Keyword And Ignore Error BuiltIn.Should Contain ${CONTROLLERFEATURES} ${feature}
1092 Return From Keyword If "${status}" == "PASS" True
1096 Add OVS Logging On All OpenStack Nodes
1097 [Documentation] Add higher levels of OVS logging to all the OpenStack nodes
1098 BuiltIn.Run Keyword If 0 < ${NUM_OS_SYSTEM} OVSDB.Add OVS Logging ${OS_CNTL_CONN_ID}
1099 BuiltIn.Run Keyword If 1 < ${NUM_OS_SYSTEM} OVSDB.Add OVS Logging ${OS_CMP1_CONN_ID}
1100 BuiltIn.Run Keyword If 2 < ${NUM_OS_SYSTEM} OVSDB.Add OVS Logging ${OS_CMP2_CONN_ID}
1102 Reset OVS Logging On All OpenStack Nodes
1103 [Documentation] Reset the OVS logging to all the OpenStack nodes
1104 BuiltIn.Run Keyword If 0 < ${NUM_OS_SYSTEM} OVSDB.Reset OVS Logging ${OS_CNTL_CONN_ID}
1105 BuiltIn.Run Keyword If 1 < ${NUM_OS_SYSTEM} OVSDB.Reset OVS Logging ${OS_CMP1_CONN_ID}
1106 BuiltIn.Run Keyword If 2 < ${NUM_OS_SYSTEM} OVSDB.Reset OVS Logging ${OS_CMP2_CONN_ID}
1108 Start Packet Capture On Nodes
1109 [Arguments] ${tag} ${filter} @{ips}
1110 [Documentation] Wrapper keyword around the TcpDump packet capture that is catered to the Openstack setup.
1111 ... The caller must pass the three arguments with a variable number of ips at the end,
1112 ... but ${EMPTY} can be used for the tag and filter.
1113 ${suite_} = BuiltIn.Evaluate """${SUITE_NAME}""".replace(" ","_").replace("/","_").replace(".","_")
1114 ${tag_} = BuiltIn.Catenate SEPARATOR=__ ${tag} ${suite_}
1115 @{conn_ids} = Tcpdump.Start Packet Capture on Nodes tag=${tag_} filter=${filter} ips=${ips}
1116 [Return] @{conn_ids}
1118 Stop Packet Capture On Nodes
1119 [Arguments] ${conn_ids}=@{EMPTY}
1120 Tcpdump.Stop Packet Capture on Nodes ${conn_ids}
1123 [Arguments] ${domain} ${description} ${name} ${rc_file}=${EMPTY}
1124 ${rc} ${output}= Run Keyword If "${rc_file}" != "${EMPTY}" Run And Return Rc And Output source ${rc_file};openstack project create --domain ${domain} --description {description} ${name}
1125 ... ELSE Run And Return Rc And Output openstack project create --domain ${domain} --description {description} ${name}
1127 Should Not Be True ${rc}
1130 [Arguments] ${name} ${description} ${category} ${rc_file}=${EMPTY}
1131 ${rc} ${output}= Run Keyword If "${rc_file}" != "${EMPTY}" Run And Return Rc And Output source ${rc_file};openstack service create --name ${name} --description ${description} ${category}
1132 ... ELSE Run And Return Rc And Output openstack service create --name ${name} --description ${description} ${category}
1134 Should Not Be True ${rc}
1137 [Arguments] ${name} ${file_path} ${rc_file}=${EMPTY}
1138 ${rc} ${output}= Run Keyword If "${rc_file}" != "${EMPTY}" Run And Return Rc And Output source ${rc_file};openstack image create ${name} --file ${file_path} --disk-format qcow2 --container-format bare --public
1140 Should Not Be True ${rc}
1143 [Arguments] ${name} ${ram} ${disk} ${rc_file}=${EMPTY}
1144 ${rc} ${output}= Run Keyword If "${rc_file}" != "${EMPTY}" Run And Return Rc And Output source ${rc_file};openstack flavor create ${name} --ram ${ram} --disk ${disk}
1146 Should Not Be True ${rc}
1149 [Arguments] ${keypair_name} ${key_path} ${rc_file}=${EMPTY}
1150 ${rc} ${output}= Run Keyword If "${rc_file}" != "${EMPTY}" Run And Return Rc And Output source ${rc_file};openstack keypair create ${keypair_name} --public-key ${key_path}.pub
1152 Should Not Be True ${rc}