2 Documentation Openstack library. This library is useful for tests to create network, subnet, router and vm instances
5 Library OperatingSystem
6 Library RequestsLibrary
7 Resource DataModels.robot
9 Resource SSHKeywords.robot
10 Resource L2GatewayOperations.robot
11 Resource ../variables/Variables.robot
12 Resource ../variables/netvirt/Variables.robot
13 Variables ../variables/netvirt/Modules.py
16 Get Tenant ID From Security Group
17 [Documentation] Returns tenant ID by reading it from existing default security-group.
18 ${rc} ${output}= Run And Return Rc And Output openstack security group show default | grep "| tenant_id" | awk '{print $4}'
19 Should Be True '${rc}' == '0'
22 Get Tenant ID From Network
23 [Arguments] ${network_uuid}
24 [Documentation] Returns tenant ID by reading it from existing network.
25 ${resp}= Get_From_Uri uri=${CONFIG_API}/neutron:neutron/networks/network/${network_uuid}/ accept=${ACCEPT_EMPTY} session=session
26 ${tenant_id}= Utils.Extract Value From Content ${resp} /network/0/tenant-id strip
30 [Arguments] ${network_name} ${additional_args}=${EMPTY} ${verbose}=TRUE
31 [Documentation] Create Network with neutron request.
32 ${rc} ${output}= Run And Return Rc And Output openstack network create ${network_name} ${additional_args}
34 Should Be True '${rc}' == '0'
38 [Arguments] ${network_name} ${additional_args}=${EMPTY}
39 [Documentation] Update Network with neutron request.
40 ${cmd}= Set Variable If '${OPENSTACK_BRANCH}'=='stable/newton' neutron -v net-update ${network_name} ${additional_args} openstack network set ${network_name} ${additional_args}
41 ${rc} ${output}= Run And Return Rc And Output ${cmd}
43 Should Be True '${rc}' == '0'
47 [Arguments] ${network_name}
48 [Documentation] Show Network with neutron request.
49 ${rc} ${output}= Run And Return Rc And Output openstack network show ${network_name}
51 Should Be True '${rc}' == '0'
55 [Documentation] List networks and return output with neutron client.
56 ${rc} ${output}= Run And Return Rc And Output openstack network list
58 Should Be True '${rc}' == '0'
62 [Documentation] List subnets and return output with neutron client.
63 ${rc} ${output}= Run And Return Rc And Output openstack subnet list
65 Should Be True '${rc}' == '0'
69 [Arguments] ${network_name}
70 [Documentation] Delete Network with neutron request.
71 ${rc} ${output}= Run And Return Rc And Output openstack network delete ${network_name}
73 Should Be True '${rc}' == '0'
76 [Arguments] ${network_name} ${subnet} ${range_ip} ${additional_args}=${EMPTY}
77 [Documentation] Create SubNet for the Network with neutron request.
78 ${rc} ${output}= Run And Return Rc And Output openstack subnet create --network ${network_name} --subnet-range ${range_ip} ${subnet} ${additional_args}
80 Should Be True '${rc}' == '0'
83 [Arguments] ${subnet_name} ${additional_args}=${EMPTY}
84 [Documentation] Update subnet with neutron request.
85 ${cmd}= Set Variable If '${OPENSTACK_BRANCH}'=='stable/newton' neutron -v subnet-update ${subnet_name} ${additional_args} openstack subnet set ${subnet_name} ${additional_args}
86 ${rc} ${output}= Run And Return Rc And Output ${cmd}
88 Should Be True '${rc}' == '0'
92 [Arguments] ${subnet_name}
93 [Documentation] Show subnet with neutron request.
94 ${rc} ${output}= Run And Return Rc And Output openstack subnet show ${subnet_name}
96 Should Be True '${rc}' == '0'
100 [Arguments] ${network_name} ${port_name} ${sg}=default ${additional_args}=${EMPTY} ${allowed_address_pairs}=${EMPTY}
101 [Documentation] Create Port with neutron request.
102 # if allowed_address_pairs is not empty we need to create the arguments to pass to the port create command. They are
103 # in a different format with the neutron vs openstack cli.
104 ${address_pair_length}= Get Length ${allowed_address_pairs}
105 ${allowed_pairs_argv}= Set Variable If '${OPENSTACK_BRANCH}'=='stable/newton' and '${address_pair_length}'=='2' --allowed-address-pairs type=dict list=true ip_address=@{allowed_address_pairs}[0] ip_address=@{allowed_address_pairs}[1]
106 ${allowed_pairs_argv}= Set Variable If '${OPENSTACK_BRANCH}'!='stable/newton' and '${address_pair_length}'=='2' --allowed-address ip-address=@{allowed_address_pairs}[0] --allowed-address ip-address=@{allowed_address_pairs}[1] ${allowed_pairs_argv}
107 ${allowed_pairs_argv}= Set Variable If '${address_pair_length}'=='0' ${EMPTY} ${allowed_pairs_argv}
108 ${cmd}= Set Variable If '${OPENSTACK_BRANCH}'=='stable/newton' neutron -v port-create ${network_name} --name ${port_name} --security-group ${sg} ${additional_args} ${allowed_pairs_argv} openstack port create --network ${network_name} ${port_name} --security-group ${sg} ${additional_args} ${allowed_pairs_argv}
109 ${rc} ${output}= Run And Return Rc And Output ${cmd}
111 Should Be True '${rc}' == '0'
114 [Arguments] ${port_name} ${additional_args}=${EMPTY}
115 [Documentation] Update port with neutron request.
116 ${rc} ${output}= Run And Return Rc And Output openstack port set ${port_name} ${additional_args}
118 Should Be True '${rc}' == '0'
122 [Arguments] ${port_name}
123 [Documentation] Show port with neutron request.
124 ${rc} ${output}= Run And Return Rc And Output openstack port show ${port_name}
126 Should Be True '${rc}' == '0'
130 [Arguments] ${port_name}
131 [Documentation] Delete Port with neutron request.
132 ${rc} ${output}= Run And Return Rc And Output openstack port delete ${port_name}
134 Should Be True '${rc}' == '0'
137 [Documentation] List ports and return output with neutron client.
138 ${rc} ${output}= Run And Return Rc And Output openstack port list
140 Should Be True '${rc}' == '0'
144 [Documentation] List VMs and return output with nova client.
145 ${rc} ${output}= Run And Return Rc And Output openstack server list --all-projects
147 Should Be True '${rc}' == '0'
150 Create And Associate Floating IPs
151 [Arguments] ${external_net} @{vm_list}
152 [Documentation] Create and associate floating IPs to VMs with nova request
153 ${ip_list}= Create List @{EMPTY}
154 : FOR ${vm} IN @{vm_list}
155 \ ${rc} ${output}= Run And Return Rc And Output openstack floating ip create ${external_net}
157 \ Should Be True '${rc}' == '0'
158 \ @{ip} Get Regexp Matches ${output} [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}
159 \ ${ip_length} Get Length ${ip}
160 \ Run Keyword If ${ip_length}>0 Append To List ${ip_list} @{ip}[0]
161 \ ... ELSE Append To List ${ip_list} None
162 \ ${rc} ${output}= Run And Return Rc And Output openstack server add floating ip ${vm} @{ip}[0]
164 \ Should Be True '${rc}' == '0'
169 [Documentation] Delete floating ip with neutron request.
170 ${rc} ${output}= Run And Return Rc And Output openstack floating ip delete ${fip}
172 Should Be True '${rc}' == '0'
175 [Documentation] Verifies the Gateway Ips with dump flow.
176 ${output}= Write Commands Until Prompt And Log sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
177 : FOR ${GatewayIpElement} IN @{GATEWAY_IPS}
178 \ Should Contain ${output} ${GatewayIpElement}
181 [Documentation] Verifies the Dhcp Ips with dump flow.
182 ${output}= Write Commands Until Prompt And Log sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
183 : FOR ${DhcpIpElement} IN @{DHCP_IPS}
184 \ Should Contain ${output} ${DhcpIpElement}
187 [Documentation] Verifies the Dhcp Ips with dump flow.
188 ${output}= Write Commands Until Prompt And Log sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
189 : FOR ${DhcpIpElement} IN @{DHCP_IPS}
190 \ Should Not Contain ${output} ${DhcpIpElement}
193 [Arguments] ${subnet}
194 [Documentation] Delete SubNet for the Network with neutron request.
196 ${rc} ${output}= Run And Return Rc And Output openstack subnet delete ${subnet}
197 Should Be True '${rc}' == '0'
199 Verify No Gateway Ips
200 [Documentation] Verifies the Gateway Ips removed with dump flow.
201 ${output}= Write Commands Until Prompt And Log sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
202 : FOR ${GatewayIpElement} IN @{GATEWAY_IPS}
203 \ Should Not Contain ${output} ${GatewayIpElement}
206 [Arguments] ${vm_name}
207 [Documentation] Delete Vm instances using instance names.
208 ${rc} ${output}= Run And Return Rc And Output openstack server delete ${vm_name}
212 [Arguments] ${network_name} ${devstack_conn_id}
213 [Documentation] Retrieve the net id for the given network name to create specific vm instance
214 ${rc} ${output}= Run And Return Rc And Output openstack network list | grep "${network_name}" | awk '{print $2}'
215 Should Be True '${rc}' == '0'
216 ${splitted_output}= Split String ${output} ${EMPTY}
217 ${net_id}= Get from List ${splitted_output} 0
221 [Arguments] ${subnet_name} ${devstack_conn_id}
222 [Documentation] Retrieve the subnet id for the given subnet name
223 ${rc} ${output}= Run And Return Rc And Output openstack subnet show "${subnet_name}" | grep " id " | awk '{print $4}'
224 Should Be True '${rc}' == '0'
225 ${splitted_output}= Split String ${output} ${EMPTY}
226 ${subnet_id}= Get from List ${splitted_output} 0
227 [Return] ${subnet_id}
230 [Arguments] ${port_name} ${devstack_conn_id}
231 [Documentation] Retrieve the port id for the given port name to attach specific vm instance to a particular port
232 ${rc} ${output}= Run And Return Rc And Output openstack port list | grep "${port_name}" | awk '{print $2}'
233 Should Be True '${rc}' == '0'
234 ${splitted_output}= Split String ${output} ${EMPTY}
235 ${port_id}= Get from List ${splitted_output} 0
239 [Arguments] ${router1} ${devstack_conn_id}
240 [Documentation] Retrieve the router id for the given router name
241 ${rc} ${output}= Run And Return Rc And Output openstack router list -f table | grep "${router1}" | awk '{print $2}'
242 Should Be True '${rc}' == '0'
243 ${splitted_output}= Split String ${output} ${EMPTY}
244 ${router_id}= Get from List ${splitted_output} 0
245 [Return] ${router_id}
248 [Arguments] ${net_name} ${vm_instance_names} ${image}=${EMPTY} ${flavor}=m1.nano ${sg}=default ${min}=1
250 [Documentation] Create X Vm Instance with the net id of the Netowrk.
251 ${image} Set Variable If "${image}"=="${EMPTY}" ${CIRROS_${OPENSTACK_BRANCH}} ${image}
252 ${net_id}= Get Net Id ${net_name} ${devstack_conn_id}
253 : FOR ${VmElement} IN @{vm_instance_names}
254 \ ${rc} ${output}= Run And Return Rc And Output openstack server create --image ${image} --flavor ${flavor} --nic net-id=${net_id} ${VmElement} --security-group ${sg} --min ${min} --max ${max}
255 \ Should Be True '${rc}' == '0'
258 Create Vm Instance With Port
259 [Arguments] ${port_name} ${vm_instance_name} ${image}=${EMPTY} ${flavor}=m1.nano ${sg}=default
260 [Documentation] Create One VM instance using given ${port_name} and for given ${compute_node}
261 ${image} Set Variable If "${image}"=="${EMPTY}" ${CIRROS_${OPENSTACK_BRANCH}} ${image}
262 ${port_id}= Get Port Id ${port_name} ${devstack_conn_id}
263 ${rc} ${output}= Run And Return Rc And Output openstack server create --image ${image} --flavor ${flavor} --nic port-id=${port_id} ${vm_instance_name} --security-group ${sg}
266 Create Vm Instance With Ports
267 [Arguments] ${port_name} ${port2_name} ${vm_instance_name} ${image}=${EMPTY} ${flavor}=m1.nano ${sg}=default
268 [Documentation] Create One VM instance using given ${port_name} and for given ${compute_node}
269 ${image} Set Variable If "${image}"=="${EMPTY}" ${CIRROS_${OPENSTACK_BRANCH}} ${image}
270 ${port_id}= Get Port Id ${port_name} ${devstack_conn_id}
271 ${port2_id}= Get Port Id ${port2_name} ${devstack_conn_id}
272 ${rc} ${output}= Run And Return Rc And Output openstack server create --image ${image} --flavor ${flavor} --nic port-id=${port_id} --nic port-id=${port2_id} ${vm_instance_name} --security-group ${sg}
274 Should Be True '${rc}' == '0'
276 Create Vm Instance With Port On Compute Node
277 [Arguments] ${port_name} ${vm_instance_name} ${compute_node} ${image}=${EMPTY} ${flavor}=m1.nano ${sg}=default
278 [Documentation] Create One VM instance using given ${port_name} and for given ${compute_node}
279 ${image} Set Variable If "${image}"=="${EMPTY}" ${CIRROS_${OPENSTACK_BRANCH}} ${image}
280 ${port_id}= Get Port Id ${port_name} ${devstack_conn_id}
281 ${hostname_compute_node}= Get Hypervisor Hostname From IP ${compute_node}
282 ${rc} ${output}= Run And Return Rc And Output openstack server create --image ${image} --flavor ${flavor} --nic port-id=${port_id} --security-group ${sg} --availability-zone nova:${hostname_compute_node} ${vm_instance_name}
284 Should Be True '${rc}' == '0'
286 Get Hypervisor Hostname From IP
287 [Arguments] ${hypervisor_ip}
288 [Documentation] Returns the hostname found for the given IP address if it's listed in hypervisor list. For debuggability
289 ... the full listing is logged first, then followed by a grep | cut to focus on the actual hostname to return
290 ${rc} ${output} Run And Return Rc And Output openstack hypervisor list
292 ${rc} ${hostname}= Run And Return Rc And Output openstack hypervisor list -f value | grep ${hypervisor_ip} | cut -d" " -f 2
294 Should Be True '${rc}' == '0'
298 [Documentation] Create a nano flavor
299 ${rc} ${output}= Run And Return Rc And Output openstack flavor create m1.nano --id auto --ram 64 --disk 0 --vcpus 1
301 Should Be True '${rc}' == '0'
304 [Arguments] ${vm_name}
305 [Documentation] Run these commands to check whether the created vm instance is active or not.
306 ${rc} ${output}= Run And Return Rc And Output openstack server show ${vm_name} | grep OS-EXT-STS:vm_state
307 Should Be True '${rc}' == '0'
308 Should Contain ${output} active
311 [Arguments] ${vm_name} ${retry}=600s ${retry_interval}=30s
312 [Documentation] Run these commands to check whether the created vm instance is active or not.
313 Wait Until Keyword Succeeds ${retry} ${retry_interval} Verify VM Is ACTIVE ${vm_name}
315 Collect VM IP Addresses
316 [Arguments] ${fail_on_none} @{vm_list}
317 [Documentation] Using the console-log on the provided ${vm_list} to search for the string "obtained" which
318 ... correlates to the instance receiving it's IP address via DHCP. Also retrieved is the ip of the nameserver
319 ... if available in the console-log output. The keyword will also return a list of the learned ips as it
320 ... finds them in the console log output, and will have "None" for Vms that no ip was found.
321 ${ip_list} Create List @{EMPTY}
322 : FOR ${vm} IN @{vm_list}
323 \ ${rc} ${vm_ip_line}= Run And Return Rc And Output openstack console log show ${vm} | grep -i "obtained"
324 \ @{vm_ip} Get Regexp Matches ${vm_ip_line} [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}
325 \ ${vm_ip_length} Get Length ${vm_ip}
326 \ Run Keyword If ${vm_ip_length}>0 Append To List ${ip_list} @{vm_ip}[0]
327 \ ... ELSE Append To List ${ip_list} None
328 \ ${rc} ${dhcp_ip_line}= Run And Return Rc And Output openstack console log show ${vm} | grep "^nameserver"
329 \ ${dhcp_ip} Get Regexp Matches ${dhcp_ip_line} [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}
330 \ ${dhcp_ip_length} Get Length ${dhcp_ip}
331 \ Run Keyword If ${dhcp_ip_length}<=0 Append To List ${dhcp_ip} None
332 \ ${vm_console_output}= Run openstack console log show ${vm}
333 \ Log ${vm_console_output}
334 ${dhcp_length} Get Length ${dhcp_ip}
335 Run Keyword If '${fail_on_none}' == 'true' Should Not Contain ${ip_list} None
336 Run Keyword If '${fail_on_none}' == 'true' Should Not Contain ${dhcp_ip} None
337 Should Be True ${dhcp_length} <= 1
338 Return From Keyword If ${dhcp_length}==0 ${ip_list} ${EMPTY}
339 [Return] ${ip_list} ${dhcp_ip}
342 [Arguments] ${text} ${regexp} ${index}=0
343 [Documentation] Wrapper around Get Regexp Matches to return None if not found or the first match if found.
344 @{matches} = String.Get Regexp Matches ${text} ${regexp}
345 ${matches_length} = Get Length ${matches}
346 BuiltIn.Set Suite Variable ${OS_MATCH} None
347 BuiltIn.Run Keyword If ${matches_length} > ${index} BuiltIn.Set Suite Variable ${OS_MATCH} @{matches}[${index}]
351 [Arguments] ${fail_on_none} ${vm}
352 [Documentation] Get the vm ip address and nameserver by scraping the vm's console log.
353 ... Get VM IP returns three values: [0] the vm IP, [1] the DHCP IP and [2] the vm console log.
354 ${rc} ${vm_console_output}= Run And Return Rc And Output openstack console log show ${vm}
355 ${vm_ip} = Set Variable None
356 ${dhcp_ip} = Set Variable None
357 ${match} = Get Match ${vm_console_output} ${REGEX_OBTAINED}
358 ${vm_ip} = Get Match ${match} ${REGEX_IPV4} 0
359 ${match} = Get Match ${vm_console_output} ${REGEX_IPROUTE}
360 ${dhcp_ip} = Get Match ${match} ${REGEX_IPV4} 1
361 BuiltIn.Run Keyword If '${fail_on_none}' == 'true' Should Not Contain ${vm_ip} None
362 BuiltIn.Run Keyword If '${fail_on_none}' == 'true' Should Not Contain ${dhcp_ip} None
363 [Return] ${vm_ip} ${dhcp_ip} ${vm_console_output}
367 [Documentation] Get the instance IP addresses and nameserver address for the list of given vms.
368 ... First poll for the vm instance to be in the active state, then poll for the vm ip address and nameserver.
369 ... Get VM IPs returns two things: [0] a list of the ips for the vms passed to this keyword (may contain values
370 ... of None) and [1] the dhcp ip address found in the last vm checked.
371 ... TODO: there is a potential issue for a caller that passes in VMs belonging to different networks that
372 ... may have different dhcp server addresses. Not sure what TODO about that, but noting it here for reference.
373 @{vm_ips} BuiltIn.Create List @{EMPTY}
374 : FOR ${vm} IN @{vms}
375 \ Poll VM Is ACTIVE ${vm}
376 \ ${status} ${ips_and_console_log} Run Keyword And Ignore Error Wait Until Keyword Succeeds 120s 15s
377 \ ... Get VM IP true ${vm}
378 \ # If there is trouble with Get VM IP, the status will be FAIL and the return value will be a string of what went
379 \ # wrong. We need to handle both the PASS and FAIL cases. In the FAIL case we know we wont have access to the
380 \ # console log, as it would not be returned; so we need to grab it again to log it. We also can append 'None' to
381 \ # the vm ip list if status is FAIL.
382 \ Run Keyword If "${status}" == "PASS" BuiltIn.Log ${ips_and_console_log[2]}
383 \ BuiltIn.Run Keyword If "${status}" == "PASS" Collections.Append To List ${vm_ips} ${ips_and_console_log[0]}
384 \ BuiltIn.Run Keyword If "${status}" == "FAIL" Collections.Append To List ${vm_ips} None
385 \ ${rc} ${vm_console_output}= BuiltIn.Run Keyword If "${status}" == "FAIL" Run And Return Rc And Output openstack console log show ${vm}
386 \ BuiltIn.Run Keyword If "${status}" == "FAIL" BuiltIn.Log ${vm_console_output}
387 [Return] @{vm_ips} ${ips_and_console_log[1]}
389 Collect VM IPv6 SLAAC Addresses
390 [Arguments] ${fail_on_none} ${prefix} @{vm_list}
391 [Documentation] Using the console-log on the provided ${vm_list} to search for the string "inet6" which
392 ... correlates to the instance generated IPv6 address, based on the ${prefix} received from ODL (SLAAC mode).
393 ${ip_list} Create List @{EMPTY}
394 : FOR ${vm} IN @{vm_list}
396 \ ${rc} ${vm_ip_line}= Run And Return Rc And Output openstack console log show ${vm} | grep -i "inet6"
399 \ @{vm_ip_list} Get Regexp Matches ${vm_ip_line} ${prefix}
400 \ ${vm_ip_length} Get Length ${vm_ip_list}
401 \ Run Keyword If ${vm_ip_length}>0 Append To List ${ip_list} @{vm_ip_list}[0]
402 \ ... ELSE Append To List ${ip_list} None
404 Run Keyword If '${fail_on_none}' == 'true' Should Not Contain ${ip_list} None
409 [Arguments] ${vm_instance_names}
410 [Documentation] View Console log of the created vm instances using nova show.
411 : FOR ${VmElement} IN @{vm_instance_names}
412 \ ${rc} ${output}= Run And Return Rc And Output openstack server show ${VmElement}
414 \ Should Be True '${rc}' == '0'
415 \ ${rc} ${output}= Run And Return Rc And Output openstack console log show ${VmElement}
417 \ Should Be True '${rc}' == '0'
419 Ping Vm From DHCP Namespace
420 [Arguments] ${net_name} ${vm_ip}
421 [Documentation] Reach all Vm Instance with the net id of the Netowrk.
423 ${devstack_conn_id}= Get ControlNode Connection
424 Switch Connection ${devstack_conn_id}
425 ${net_id}= Get Net Id ${net_name} ${devstack_conn_id}
427 ${output}= Write Commands Until Prompt And Log sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip} 20s
429 Should Contain ${output} 64 bytes
431 Ping From DHCP Should Not Succeed
432 [Arguments] ${net_name} ${vm_ip}
433 [Documentation] Should Not Reach Vm Instance with the net id of the Netowrk.
434 Return From Keyword If "skip_if_${SECURITY_GROUP_MODE}" in @{TEST_TAGS}
436 ${devstack_conn_id}= Get ControlNode Connection
437 Switch Connection ${devstack_conn_id}
438 ${net_id}= Get Net Id ${net_name} ${devstack_conn_id}
440 ${output}= Write Commands Until Prompt sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip} 20s
443 Should Not Contain ${output} 64 bytes
445 Ping Vm From Control Node
446 [Arguments] ${vm_floating_ip} ${additional_args}=${EMPTY}
447 [Documentation] Ping VM floating IP from control node
448 Log ${vm_floating_ip}
449 ${devstack_conn_id}= Get ControlNode Connection
450 Switch Connection ${devstack_conn_id}
451 ${output}= Write Commands Until Prompt And Log ping ${additional_args} -c 3 ${vm_floating_ip} 20s
453 Should Contain ${output} 64 bytes
456 [Arguments] ${dest_vm_ip}
457 [Documentation] Ping to the expected destination ip.
458 ${output}= Write Commands Until Expected Prompt ping -c 3 ${dest_vm_ip} ${OS_SYSTEM_PROMPT}
463 [Documentation] Ping to the expected destination ip.
464 ${output}= Write Commands Until Expected Prompt curl -i http://169.254.169.254 ${OS_SYSTEM_PROMPT}
465 Write Commands Until Prompt exit
466 Should Contain ${output} 200
469 [Documentation] Exit the vm instance.
470 ${output}= Write Commands Until Prompt And Log exit
472 Check If Console Is VmInstance
473 [Arguments] ${console}=cirros
474 [Documentation] Check if the session has been able to login to the VM instance
475 ${output}= Write Commands Until Expected Prompt id ${OS_SYSTEM_PROMPT}
476 Should Contain ${output} ${console}
479 [Documentation] Check if the session has been able to login to the VM instance and exit the instance
480 ${rcode}= Run Keyword And Return Status Check If Console Is VmInstance cirros
481 Run Keyword If ${rcode} Write Commands Until Prompt exit
485 [Arguments] ${ip_address} ${ttl}=64
486 [Documentation] Run Ping command on the IP available as argument
487 ${ethertype}= Get Regexp Matches ${ip_address} ${IP_REGEX}
488 ${output}= Run Keyword If ${ethertype} Write Commands Until Expected Prompt ping -t ${ttl} -c 3 ${ip_address} ${OS_SYSTEM_PROMPT}
489 ... ELSE Write Commands Until Expected Prompt ping6 -t ${ttl} -c 3 ${ip_address} ${OS_SYSTEM_PROMPT}
490 Should Contain ${output} 64 bytes
493 [Arguments] ${ip_address} ${ttl}=64
494 [Documentation] Run Ping command to the IP given as argument, executing 3 times and expecting NOT to see "64 bytes"
495 ${output}= Write Commands Until Expected Prompt ping -t ${ttl} -c 3 ${ip_address} ${OS_SYSTEM_PROMPT}
496 Should Not Contain ${output} 64 bytes
498 Check Metadata Access
499 [Documentation] Try curl on the Metadataurl and check if it is okay
500 ${output}= Write Commands Until Expected Prompt curl -i http://169.254.169.254 ${OS_SYSTEM_PROMPT}
501 Should Contain ${output} 200
503 Execute Command on VM Instance
504 [Arguments] ${net_name} ${vm_ip} ${cmd} ${user}=cirros ${password}=cubswin:)
505 [Documentation] Login to the vm instance using ssh in the network, executes a command inside the VM and returns the ouput.
506 ${devstack_conn_id} = Get ControlNode Connection
507 Switch Connection ${devstack_conn_id}
508 ${net_id} = Get Net Id ${net_name} ${devstack_conn_id}
510 ${output} = Write Commands Until Expected Prompt sudo ip netns exec qdhcp-${net_id} ssh ${user}@${vm_ip} -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null password:
512 ${output} = Write Commands Until Expected Prompt ${password} ${OS_SYSTEM_PROMPT}
514 ${rcode} = Run Keyword And Return Status Check If Console Is VmInstance
515 ${output} = Run Keyword If ${rcode} Write Commands Until Expected Prompt ${cmd} ${OS_SYSTEM_PROMPT}
516 [Teardown] Exit From Vm Console
519 Test Operations From Vm Instance
520 [Arguments] ${net_name} ${src_ip} ${dest_ips} ${user}=cirros ${password}=cubswin:) ${ttl}=64
521 ... ${ping_should_succeed}=True ${check_metadata}=True
522 [Documentation] Login to the vm instance using ssh in the network.
523 ${devstack_conn_id}= Get ControlNode Connection
524 Switch Connection ${devstack_conn_id}
526 ${net_id}= Get Net Id ${net_name} ${devstack_conn_id}
527 ${output}= Write Commands Until Expected Prompt sudo ip netns exec qdhcp-${net_id} ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no ${user}@${src_ip} -o UserKnownHostsFile=/dev/null password:
529 ${output}= Write Commands Until Expected Prompt ${password} ${OS_SYSTEM_PROMPT}
531 ${rcode}= Run Keyword And Return Status Check If Console Is VmInstance
532 Run Keyword If ${rcode} Write Commands Until Expected Prompt ifconfig ${OS_SYSTEM_PROMPT}
533 Run Keyword If ${rcode} Write Commands Until Expected Prompt route -n ${OS_SYSTEM_PROMPT}
534 Run Keyword If ${rcode} Write Commands Until Expected Prompt route -A inet6 ${OS_SYSTEM_PROMPT}
535 Run Keyword If ${rcode} Write Commands Until Expected Prompt arp -an ${OS_SYSTEM_PROMPT}
536 Run Keyword If ${rcode} Write Commands Until Expected Prompt ip -f inet6 neigh show ${OS_SYSTEM_PROMPT}
537 : FOR ${dest_ip} IN @{dest_ips}
539 \ ${string_empty}= Run Keyword And Return Status Should Be Empty ${dest_ip}
540 \ Run Keyword If ${string_empty} Continue For Loop
541 \ Run Keyword If ${rcode} and "${ping_should_succeed}" == "True" Check Ping ${dest_ip} ttl=${ttl}
542 \ ... ELSE Check No Ping ${dest_ip} ttl=${ttl}
543 ${ethertype}= Get Regexp Matches ${src_ip} ${IP_REGEX}
544 Run Keyword If ${rcode} and "${check_metadata}" and ${ethertype} == "True" Check Metadata Access
545 [Teardown] Exit From Vm Console
547 Test Netcat Operations From Vm Instance
548 [Arguments] ${net_name} ${vm_ip} ${dest_ip} ${additional_args}=${EMPTY} ${port}=12345 ${user}=cirros
549 ... ${password}=cubswin:)
550 [Documentation] Use Netcat to test TCP/UDP connections to the controller
551 ${client_data} Set Variable Test Client Data
552 ${server_data} Set Variable Test Server Data
553 ${devstack_conn_id}= Get ControlNode Connection
554 Switch Connection ${devstack_conn_id}
556 ${output}= Write Commands Until Prompt And Log ( ( echo "${server_data}" | sudo timeout 60 nc -l ${additional_args} ${port} ) & )
557 ${output}= Write Commands Until Prompt And Log sudo netstat -nlap | grep ${port}
558 ${nc_output}= Execute Command on VM Instance ${net_name} ${vm_ip} sudo echo "${client_data}" | nc -v -w 5 ${additional_args} ${dest_ip} ${port}
560 ${output}= Execute Command on VM Instance ${net_name} ${vm_ip} sudo route -n
562 ${output}= Execute Command on VM Instance ${net_name} ${vm_ip} sudo arp -an
564 Should Match Regexp ${nc_output} ${server_data}
567 [Arguments] ${list_of_external_dst_ips}
568 [Documentation] Check reachability with other network's instances.
569 ${rcode}= Run Keyword And Return Status Check If Console Is VmInstance
570 : FOR ${dest_ip} IN @{list_of_external_dst_ips}
572 \ Check Ping ${dest_ip}
575 [Arguments] ${router_name}
576 [Documentation] Create Router and Add Interface to the subnets.
577 ${rc} ${output}= Run And Return Rc And Output openstack router create ${router_name}
578 Should Be True '${rc}' == '0'
581 [Documentation] List Routers and return output with neutron client.
582 ${rc} ${output}= Run And Return Rc And Output openstack router list -f value
584 Should Be True '${rc}' == '0'
588 [Arguments] ${router_name} ${interface_name}
589 ${rc} ${output}= Run And Return Rc And Output openstack router add subnet ${router_name} ${interface_name}
590 Should Be True '${rc}' == '0'
592 Show Router Interface
593 [Arguments] ${router_name}
594 [Documentation] List Routers interface associated with given Router and return output with neutron client.
595 ${rc} ${output}= Run And Return Rc And Output openstack port list --router ${router_name} -f value
596 Should Be True '${rc}' == '0'
600 [Arguments] ${router_name} ${external_network_name}
601 ${cmd}= Set Variable If '${OPENSTACK_BRANCH}'=='stable/newton' neutron -v router-gateway-set ${router_name} ${external_network_name} openstack router set ${router_name} --external-gateway ${external_network_name}
602 ${rc} ${output}= Run And Return Rc And Output ${cmd}
603 Should Be True '${rc}' == '0'
606 [Arguments] ${router_name} ${interface_name}
607 [Documentation] Remove Interface to the subnets.
608 ${rc} ${output}= Run And Return Rc And Output openstack router remove subnet ${router_name} ${interface_name}
609 Should Be True '${rc}' == '0'
612 [Arguments] ${router_name}
613 [Documentation] Remove external gateway from the router.
614 BuiltIn.Log openstack router unset ${router_name} --external-gateway
617 [Arguments] ${router_name} ${cmd}
618 [Documentation] Update the router with the command. Router name and command should be passed as argument.
619 ${rc} ${output} = Run And Return Rc And Output openstack router set ${router_name} ${cmd}
620 Should Be True '${rc}' == '0'
623 [Arguments] ${router_name} ${options}
624 [Documentation] Show information of a given router. Router name and optional fields should be sent as arguments.
625 ${rc} ${output} = Run And Return Rc And Output openstack router show ${router_name}
629 [Arguments] ${router_name}
630 [Documentation] Delete Router and Interface to the subnets.
631 ${rc} ${output}= Run And Return Rc And Output openstack router delete ${router_name}
633 Should Be True '${rc}' == '0'
635 Get DumpFlows And Ovsconfig
636 [Arguments] ${openstack_node_ip}
637 [Documentation] Get the OvsConfig and Flow entries from OVS from the Openstack Node
638 Log ${openstack_node_ip}
639 SSHLibrary.Open Connection ${openstack_node_ip} prompt=${DEFAULT_LINUX_PROMPT}
640 SSHKeywords.Flexible SSH Login ${OS_USER} ${DEVSTACK_SYSTEM_PASSWORD}
641 SSHLibrary.Set Client Configuration timeout=${default_devstack_prompt_timeout}
642 Write Commands Until Expected Prompt ip -o link ${DEFAULT_LINUX_PROMPT_STRICT}
643 Write Commands Until Expected Prompt ip -o addr ${DEFAULT_LINUX_PROMPT_STRICT}
644 Write Commands Until Expected Prompt ip route ${DEFAULT_LINUX_PROMPT_STRICT}
645 Write Commands Until Expected Prompt arp -an ${DEFAULT_LINUX_PROMPT_STRICT}
646 ${nslist}= Write Commands Until Expected Prompt ip netns list | awk '{print $1}' ${DEFAULT_LINUX_PROMPT_STRICT}
647 @{lines} Split To Lines ${nslist} end=-1
648 : FOR ${line} IN @{lines}
649 \ Write Commands Until Expected Prompt sudo ip netns exec ${line} ip -o link ${DEFAULT_LINUX_PROMPT_STRICT}
650 \ Write Commands Until Expected Prompt sudo ip netns exec ${line} ip -o addr ${DEFAULT_LINUX_PROMPT_STRICT}
651 \ Write Commands Until Expected Prompt sudo ip netns exec ${line} ip route ${DEFAULT_LINUX_PROMPT_STRICT}
652 Write Commands Until Expected Prompt sudo ovs-vsctl show ${DEFAULT_LINUX_PROMPT_STRICT}
653 Write Commands Until Expected Prompt sudo ovs-vsctl list Open_vSwitch ${DEFAULT_LINUX_PROMPT_STRICT}
654 Write Commands Until Expected Prompt sudo ovs-ofctl show br-int -OOpenFlow13 ${DEFAULT_LINUX_PROMPT_STRICT}
655 Write Commands Until Expected Prompt sudo ovs-ofctl dump-flows br-int -OOpenFlow13 ${DEFAULT_LINUX_PROMPT_STRICT}
656 Write Commands Until Expected Prompt sudo ovs-ofctl dump-groups br-int -OOpenFlow13 ${DEFAULT_LINUX_PROMPT_STRICT}
657 Write Commands Until Expected Prompt sudo ovs-ofctl dump-group-stats br-int -OOpenFlow13 ${DEFAULT_LINUX_PROMPT_STRICT}
659 Get Karaf Log Type From Test Start
660 [Arguments] ${ip} ${test_name} ${type} ${user}=${ODL_SYSTEM_USER} ${password}=${ODL_SYSTEM_PASSWORD} ${prompt}=${ODL_SYSTEM_PROMPT}
661 ... ${log_file}=${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
662 ${cmd} Set Variable sed '1,/ROBOT MESSAGE: Starting test ${test_name}/d' ${log_file} | grep '${type}'
663 ${output} Run Command On Controller ${ip} ${cmd} ${user} ${password} ${prompt}
666 Get Karaf Log Types From Test Start
667 [Arguments] ${ip} ${test_name} ${types} ${user}=${ODL_SYSTEM_USER} ${password}=${ODL_SYSTEM_PASSWORD} ${prompt}=${ODL_SYSTEM_PROMPT}
668 ... ${log_file}=${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
669 : FOR ${type} IN @{types}
670 \ Get Karaf Log Type From Test Start ${ip} ${test_name} ${type} ${user} ${password}
671 \ ... ${prompt} ${log_file}
673 Get Karaf Log Events From Test Start
674 [Arguments] ${test_name} ${user}=${ODL_SYSTEM_USER} ${password}=${ODL_SYSTEM_PASSWORD} ${prompt}=${ODL_SYSTEM_PROMPT}
675 ${log_types} = Create List ERROR WARN Exception
676 Run Keyword If 0 < ${NUM_ODL_SYSTEM} Get Karaf Log Types From Test Start ${ODL_SYSTEM_IP} ${test_name} ${log_types}
677 Run Keyword If 1 < ${NUM_ODL_SYSTEM} Get Karaf Log Types From Test Start ${ODL_SYSTEM_2_IP} ${test_name} ${log_types}
678 Run Keyword If 2 < ${NUM_ODL_SYSTEM} Get Karaf Log Types From Test Start ${ODL_SYSTEM_3_IP} ${test_name} ${log_types}
680 Get ControlNode Connection
681 ${control_conn_id}= SSHLibrary.Open Connection ${OS_CONTROL_NODE_IP} prompt=${DEFAULT_LINUX_PROMPT_STRICT}
682 SSHKeywords.Flexible SSH Login ${OS_USER} ${DEVSTACK_SYSTEM_PASSWORD}
683 SSHLibrary.Set Client Configuration timeout=30s
684 [Return] ${control_conn_id}
687 [Documentation] Get the OvsConfig and Flow entries from all Openstack nodes
688 Run Keyword If 0 < ${NUM_OS_SYSTEM} Get DumpFlows And Ovsconfig ${OS_CONTROL_NODE_IP}
689 Run Keyword If 1 < ${NUM_OS_SYSTEM} Get DumpFlows And Ovsconfig ${OS_COMPUTE_1_IP}
690 Run Keyword If 2 < ${NUM_OS_SYSTEM} Get DumpFlows And Ovsconfig ${OS_COMPUTE_2_IP}
692 Get Test Teardown Debugs
693 [Arguments] ${test_name}=${TEST_NAME}
695 Run Keyword And Ignore Error Get Model Dump ${HA_PROXY_IP} ${netvirt_data_models}
696 Get Karaf Log Events From Test Start ${test_name}
698 Get Test Teardown Debugs For SFC
699 [Arguments] ${test_name}=${TEST_NAME}
700 Run Keyword And Ignore Error Get Model Dump ${HA_PROXY_IP} ${netvirt_sfc_data_models}
703 [Arguments] @{vm_indices}
704 [Documentation] Run these commands for debugging, it can list state of VM instances and ip information in control node
705 ${devstack_conn_id}= Get ControlNode Connection
706 Switch Connection ${devstack_conn_id}
707 ${output}= Write Commands Until Prompt And Log sudo ip netns list
709 : FOR ${index} IN @{vm_indices}
710 \ ${rc} ${output}= Run And Return Rc And Output nova show ${index}
720 [Documentation] Logging keyword to display all security groups using the openstack cli. Assumes openstack
721 ... credentials are already sourced
722 ${rc} ${output}= Run And Return Rc And Output openstack security group list
724 Should Be True '${rc}' == '0'
727 Neutron Security Group Show
728 [Arguments] ${SecurityGroupRuleName}
729 [Documentation] Displays the neutron security group configurations that belongs to a given neutron security group name
730 ${rc} ${output}= Run And Return Rc And Output openstack security group show ${SecurityGroupRuleName}
732 Should Be True '${rc}' == '0'
736 [Arguments] ${PortName}
737 [Documentation] Display the port configuration that belong to a given neutron port
738 ${rc} ${output}= Run And Return Rc And Output openstack port show ${PortName}
740 Should Be True '${rc}' == '0'
743 Neutron Security Group Create
744 [Arguments] ${SecurityGroupName} ${additional_args}=${EMPTY}
745 [Documentation] Create a security group with specified name ,description & protocol value according to security group template
746 ${devstack_conn_id}= Get ControlNode Connection
747 Switch Connection ${devstack_conn_id}
748 ${rc} ${output}= Run And Return Rc And Output openstack security group create ${SecurityGroupName} ${additional_args}
750 Should Be True '${rc}' == '0'
751 ${sgp_id}= Should Match Regexp ${output} [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}
753 [Return] ${output} ${sgp_id}
755 Neutron Security Group Update
756 [Arguments] ${SecurityGroupName} ${additional_args}=${EMPTY}
757 [Documentation] Updating security groups
758 ${rc} ${output}= Run And Return Rc And Output openstack security group set ${SecurityGroupName} ${additional_args}
760 Should Be True '${rc}' == '0'
764 [Arguments] ${sg_name}
765 [Documentation] Delete Security group
766 ${rc} ${output}= Run And Return Rc And Output openstack security group delete ${sg_name}
768 Should Be True '${rc}' == '0'
770 Neutron Security Group Rule Create
771 [Arguments] ${Security_group_name} &{Kwargs}
772 [Documentation] Creates neutron security rule with Openstack CLI with or without optional params, here security group name is mandatory args, rule with optional params can be created by passing the optional args values ex: direction=${INGRESS_EGRESS}, Then these optional params are catenated with mandatory args, example of usage: "Neutron Security Group Rule Create ${SGP_SSH} direction=${RULE_PARAMS[0]} ethertype=${RULE_PARAMS[1]} ..."
773 Run Keyword If ${Kwargs} Log ${Kwargs}
774 ${description} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} description default=${None}
775 ${direction} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} direction default=${None}
776 ${ethertype} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} ethertype default=${None}
777 ${port_range_max} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} port_range_max default=${None}
778 ${port_range_min} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} port_range_min default=${None}
779 ${protocol} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} protocol default=${None}
780 ${remote_group_id} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} remote_group_id default=${None}
781 ${remote_ip_prefix} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} remote_ip_prefix default=${None}
782 ${cmd}= Set Variable openstack security group rule create ${Security_group_name}
783 ${cmd}= Run Keyword If '${description}'!='None' Catenate ${cmd} --description ${description}
784 ... ELSE Catenate ${cmd}
785 ${cmd}= Run Keyword If '${direction}'!='None' Catenate ${cmd} --${direction}
786 ... ELSE Catenate ${cmd}
787 ${cmd}= Run Keyword If '${ethertype}'!='None' Catenate ${cmd} --ethertype ${ethertype}
788 ... ELSE Catenate ${cmd}
789 ${cmd}= Run Keyword If '${port_range_min}'!='None' and '${port_range_max}'!='None' Catenate ${cmd} --dst-port ${port_range_min}:${port_range_max}
790 ... ELSE IF '${port_range_max}'!='None' Catenate ${cmd} --dst-port ${port_range_max}
791 ... ELSE IF '${port_range_min}'!='None' Catenate ${cmd} --dst-port ${port_range_min}
792 ... ELSE Catenate ${cmd}
793 ${cmd}= Run Keyword If '${protocol}'!='None' Catenate ${cmd} --protocol ${protocol}
794 ... ELSE Catenate ${cmd}
795 ${cmd}= Run Keyword If '${remote_group_id}'!='None' Catenate ${cmd} --remote-group ${remote_group_id}
796 ... ELSE Catenate ${cmd}
797 ${cmd}= Run Keyword If '${remote_ip_prefix}'!='None' Catenate ${cmd} --src-ip ${remote_ip_prefix}
798 ... ELSE Catenate ${cmd}
799 ${rc} ${output}= Run And Return Rc And Output ${cmd}
800 ${rule_id}= Should Match Regexp ${output} [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}
802 Should Be True '${rc}' == '0'
803 [Return] ${output} ${rule_id}
805 Neutron Security Group Rule Create Legacy Cli
806 [Arguments] ${Security_group_name} &{Kwargs}
807 [Documentation] Creates neutron security rule with neutron request with or without optional params, here security group name is mandatory args, rule with optional params can be created by passing the optional args values ex: direction=${INGRESS_EGRESS}, Then these optional params are catenated with mandatory args, example of usage: "Neutron Security Group Rule Create ${SGP_SSH} direction=${RULE_PARAMS[0]} ethertype=${RULE_PARAMS[1]} ..."
808 Run Keyword If ${Kwargs} Log ${Kwargs}
809 ${description} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} description default=${None}
810 ${direction} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} direction default=${None}
811 ${ethertype} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} ethertype default=${None}
812 ${port_range_max} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} port_range_max default=${None}
813 ${port_range_min} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} port_range_min default=${None}
814 ${protocol} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} protocol default=${None}
815 ${remote_group_id} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} remote_group_id default=${None}
816 ${remote_ip_prefix} Run Keyword If ${Kwargs} Pop From Dictionary ${Kwargs} remote_ip_prefix default=${None}
817 ${cmd}= Set Variable neutron security-group-rule-create ${Security_group_name}
818 ${cmd}= Run Keyword If '${description}'!='None' Catenate ${cmd} --description ${description}
819 ... ELSE Catenate ${cmd}
820 ${cmd}= Run Keyword If '${direction}'!='None' Catenate ${cmd} --direction ${direction}
821 ... ELSE Catenate ${cmd}
822 ${cmd}= Run Keyword If '${ethertype}'!='None' Catenate ${cmd} --ethertype ${ethertype}
823 ... ELSE Catenate ${cmd}
824 ${cmd}= Run Keyword If '${port_range_max}'!='None' Catenate ${cmd} --port_range_max ${port_range_max}
825 ... ELSE Catenate ${cmd}
826 ${cmd}= Run Keyword If '${port_range_min}'!='None' Catenate ${cmd} --port_range_min ${port_range_min}
827 ... ELSE Catenate ${cmd}
828 ${cmd}= Run Keyword If '${protocol}'!='None' Catenate ${cmd} --protocol ${protocol}
829 ... ELSE Catenate ${cmd}
830 ${cmd}= Run Keyword If '${remote_group_id}'!='None' Catenate ${cmd} --remote_group_id ${remote_group_id}
831 ... ELSE Catenate ${cmd}
832 ${cmd}= Run Keyword If '${remote_ip_prefix}'!='None' Catenate ${cmd} --remote_ip_prefix ${remote_ip_prefix}
833 ... ELSE Catenate ${cmd}
834 ${rc} ${output}= Run And Return Rc And Output ${cmd}
835 ${rule_id}= Should Match Regexp ${output} [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}
837 Should Be True '${rc}' == '0'
838 [Return] ${output} ${rule_id}
840 Security Group Create Without Default Security Rules
841 [Arguments] ${sg_name} ${additional_args}=${EMPTY}
842 [Documentation] Create Neutron Security Group with no default rules, using specified name and optional arguments.
843 Neutron Security Group Create ${sg_name} ${additional_args}
844 Delete All Security Group Rules ${sg_name}
846 Delete All Security Group Rules
847 [Arguments] ${sg_name}
848 [Documentation] Delete all security rules from a specified security group
849 ${rc} ${sg_rules_output}= Run And Return Rc And Output openstack security group rule list ${sg_name} -cID -fvalue
850 Log ${sg_rules_output}
851 Should Be True '${rc}' == '0'
852 @{sg_rules}= Split String ${sg_rules_output} \n
853 : FOR ${rule} IN @{sg_rules}
854 \ ${rc} ${output}= Run And Return Rc And Output openstack security group rule delete ${rule}
856 \ Should Be True '${rc}' == '0'
858 Create Allow All SecurityGroup
859 [Arguments] ${sg_name} ${ether_type}=IPv4
860 [Documentation] Allow all TCP/UDP/ICMP packets for this suite
861 Neutron Security Group Create ${sg_name}
862 Neutron Security Group Rule Create ${sg_name} direction=ingress ethertype=${ether_type} port_range_max=65535 port_range_min=1 protocol=tcp
863 Neutron Security Group Rule Create ${sg_name} direction=egress ethertype=${ether_type} port_range_max=65535 port_range_min=1 protocol=tcp
864 Neutron Security Group Rule Create ${sg_name} direction=ingress ethertype=${ether_type} protocol=icmp
865 Neutron Security Group Rule Create ${sg_name} direction=egress ethertype=${ether_type} protocol=icmp
866 Neutron Security Group Rule Create ${sg_name} direction=ingress ethertype=${ether_type} port_range_max=65535 port_range_min=1 protocol=udp
867 Neutron Security Group Rule Create ${sg_name} direction=egress ethertype=${ether_type} port_range_max=65535 port_range_min=1 protocol=udp
869 Create Neutron Port With Additional Params
870 [Arguments] ${network_name} ${port_name} ${additional_args}=${EMPTY}
871 [Documentation] Create Port With given additional parameters
872 ${rc} ${output}= Run And Return Rc And Output neutron -v port-create ${network_name} --name ${port_name} ${additional_args}
874 Should Be True '${rc}' == '0'
875 ${port_id}= Should Match Regexp ${OUTPUT} [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}
877 [Return] ${OUTPUT} ${port_id}
880 [Arguments] ${portName_list}
881 [Documentation] Retrieve the port MacAddr for the given list of port name and return the MAC address list.
882 ${MacAddr-list} Create List
883 : FOR ${portName} IN @{portName_list}
884 \ ${macAddr}= OpenStackOperations.Get Port Mac ${portName} ${devstack_conn_id}
885 \ Append To List ${MacAddr-list} ${macAddr}
886 [Return] ${MacAddr-list}
889 [Arguments] ${port_name}
890 [Documentation] Keyword would return the IP of the ${port_name} received.
891 ${rc} ${output}= Run And Return Rc And Output openstack port list | grep "${port_name}" | awk -F\\' '{print $2}'
892 ${splitted_output}= Split String ${output} ${EMPTY}
893 ${port_ip}= Get from List ${splitted_output} 0
894 Should Be True '${rc}' == '0'
898 [Arguments] ${port_name} ${conn_id}=${devstack_conn_id}
899 [Documentation] Keyword would return the MAC ID of the ${port_name} received.
900 ${rc} ${output}= Run And Return Rc And Output openstack port show ${port_name} | grep mac_address | awk '{print $4}'
901 ${splitted_output}= Split String ${output} ${EMPTY}
902 ${port_mac}= Get from List ${splitted_output} 0
903 Should Be True '${rc}' == '0'
907 [Arguments] ${bridge_name} ${intf_name} ${gw_name}
908 [Documentation] Keyword to create an L2 Gateway ${gw_name} for bridge ${bridge_name} connected to interface ${intf_name} (Using Neutron CLI).
909 ${rc} ${l2gw_output}= Run And Return Rc And Output ${L2GW_CREATE} name=${bridge_name},interface_names=${intf_name} ${gw_name}
911 [Return] ${l2gw_output}
913 Create L2Gateway Connection
914 [Arguments] ${gw_name} ${net_name}
915 [Documentation] Keyword would create a new L2 Gateway Connection for ${gw_name} to ${net_name} (Using Neutron CLI).
916 ${rc} ${l2gw_output}= Run And Return Rc And Output ${L2GW_CONN_CREATE} ${gw_name} ${net_name}
918 Should Be True '${rc}' == '0'
919 [Return] ${l2gw_output}
922 [Documentation] Keyword to return all the L2 Gateways available (Using Neutron CLI).
923 ${rc} ${output}= Run And Return Rc And Output ${L2GW_GET_YAML}
924 Should Be True '${rc}' == '0'
927 Get All L2Gateway Connection
928 [Documentation] Keyword to return all the L2 Gateway connections available (Using Neutron CLI).
929 ${rc} ${output}= Run And Return Rc And Output ${L2GW_GET_CONN_YAML}
930 Should Be True '${rc}' == '0'
935 [Documentation] Keyword to check if the ${gw_id} is available in the L2 Gateway list (Using Neutron CLI).
936 ${rc} ${output}= Run And Return Rc And Output ${L2GW_SHOW} ${gw_id}
938 Should Be True '${rc}' == '0'
942 [Arguments] ${l2gw_name}
943 [Documentation] Keyword to retrieve the L2 Gateway ID for the ${l2gw_name} (Using Neutron CLI).
944 ${rc} ${output}= Run And Return Rc And Output ${L2GW_GET} | grep "${l2gw_name}" | awk '{print $2}'
946 Should Be True '${rc}' == '0'
947 ${splitted_output}= Split String ${output} ${EMPTY}
948 ${l2gw_id}= Get from List ${splitted_output} 0
951 Get L2gw Connection Id
952 [Arguments] ${l2gw_name}
953 [Documentation] Keyword to retrieve the L2 Gateway Connection ID for the ${l2gw_name} (Using Neutron CLI).
954 ${l2gw_id}= OpenStackOperations.Get L2gw Id ${l2gw_name}
955 ${rc} ${output}= Run And Return Rc And Output ${L2GW_GET_CONN} | grep "${l2gw_id}" | awk '{print $2}'
956 Should Be True '${rc}' == '0'
957 ${splitted_output}= Split String ${output} ${EMPTY}
958 ${splitted_output}= Split String ${output} ${EMPTY}
959 ${l2gw_conn_id}= Get from List ${splitted_output} 0
960 [Return] ${l2gw_conn_id}
962 Neutron Port List Rest
963 [Documentation] Keyword to get all ports details in Neutron (Using REST).
964 ${resp} = RequestsLibrary.Get Request session ${PORT_URL}
966 Should Be Equal As Strings ${resp.status_code} 200
967 [Return] ${resp.content}
969 Get Neutron Port Rest
970 [Arguments] ${port_id}
971 [Documentation] Keyword to get the specific port details in Neutron (Using REST).
972 ${resp} = RequestsLibrary.Get Request session ${CONFIG_API}/${GET_PORT_URL}/${port_id}
974 Should Be Equal As Strings ${resp.status_code} 200
975 [Return] ${resp.content}
978 [Arguments] ${port_id} ${json_data}
979 [Documentation] Keyword to update ${port_id} with json data received in ${json_data} (Using REST).
981 ${resp} = RequestsLibrary.Put Request session ${CONFIG_API}/${GET_PORT_URL}/${port_id} ${json_data}
983 Should Be Equal As Strings ${resp.status_code} 200
984 [Return] ${resp.content}
986 Create And Configure Security Group
987 [Arguments] ${sg-name}
988 [Documentation] Create Security Group with given name, and default allow rules for TCP/UDP/ICMP protocols.
989 Neutron Security Group Create ${sg-name}
990 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
991 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
992 Neutron Security Group Rule Create ${sg-name} direction=ingress protocol=icmp remote_ip_prefix=0.0.0.0/0
993 Neutron Security Group Rule Create ${sg-name} direction=egress protocol=icmp remote_ip_prefix=0.0.0.0/0
994 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
995 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
997 Add Security Group To VM
998 [Arguments] ${vm} ${sg}
999 [Documentation] Add the security group provided to the given VM.
1000 ${rc} ${output}= Run And Return Rc And Output openstack server add security group ${vm} ${sg}
1002 Should Be True '${rc}' == '0'
1004 Remove Security Group From VM
1005 [Arguments] ${vm} ${sg}
1006 [Documentation] Remove the security group provided to the given VM.
1007 ${devstack_conn_id}= Get ControlNode Connection
1008 Switch Connection ${devstack_conn_id}
1009 ${output}= Write Commands Until Prompt And Log openstack server remove security group ${vm} ${sg}
1012 Create SFC Flow Classifier
1013 [Arguments] ${name} ${src_ip} ${dest_ip} ${protocol} ${dest_port} ${neutron_src_port}
1014 [Documentation] Create a flow classifier for SFC
1015 ${rc} ${output}= Run And Return Rc And Output openstack sfc flow classifier create --ethertype IPv4 --source-ip-prefix ${src_ip}/32 --destination-ip-prefix ${dest_ip}/32 --protocol ${protocol} --destination-port ${dest_port}:${dest_port} --logical-source-port ${neutron_src_port} ${name}
1017 Should Be True '${rc}' == '0'
1018 Should Contain ${output} ${name}
1021 Delete SFC Flow Classifier
1023 [Documentation] Delete a SFC flow classifier
1024 ${devstack_conn_id}= Get ControlNode Connection
1025 Switch Connection ${devstack_conn_id}
1026 ${rc} ${output}= Run And Return Rc And Output openstack sfc flow classifier delete ${name}
1028 Should Be True '${rc}' == '0'
1031 Create SFC Port Pair
1032 [Arguments] ${name} ${port_in} ${port_out}
1033 [Documentation] Creates a neutron port pair for SFC
1034 ${devstack_conn_id}= Get ControlNode Connection
1035 Switch Connection ${devstack_conn_id}
1036 ${rc} ${output}= Run And Return Rc And Output openstack sfc port pair create --ingress=${port_in} --egress=${port_out} ${name}
1038 Should Be True '${rc}' == '0'
1039 Should Contain ${output} ${name}
1042 Delete SFC Port Pair
1044 [Documentation] Delete a SFC port pair
1045 ${rc} ${output}= Run And Return Rc And Output openstack sfc port pair delete ${name}
1047 Should Be True '${rc}' == '0'
1050 Create SFC Port Pair Group
1051 [Arguments] ${name} ${port_pair}
1052 [Documentation] Creates a port pair group with a single port pair for SFC
1053 ${rc} ${output}= Run And Return Rc And Output openstack sfc port pair group create --port-pair ${port_pair} ${name}
1055 Should Be True '${rc}' == '0'
1056 Should Contain ${output} ${name}
1059 Create SFC Port Pair Group With Two Pairs
1060 [Arguments] ${name} ${port_pair1} ${port_pair2}
1061 [Documentation] Creates a port pair group with two port pairs for SFC
1062 ${rc} ${output}= Run And Return Rc And Output openstack sfc port pair group create --port-pair ${port_pair1} --port-pair ${port_pair2} ${name}
1064 Should Be True '${rc}' == '0'
1065 Should Contain ${output} ${name}
1068 Delete SFC Port Pair Group
1070 [Documentation] Delete a SFC port pair group
1071 ${devstack_conn_id}= Get ControlNode Connection
1072 ${rc} ${output}= Run And Return Rc And Output openstack sfc port pair group delete ${name}
1074 Should Be True '${rc}' == '0'
1077 Create SFC Port Chain
1078 [Arguments] ${name} ${pg1} ${pg2} ${fc}
1079 [Documentation] Creates a port pair chain with two port groups and a singel classifier.
1080 ${rc} ${output}= Run And Return Rc And Output openstack sfc port chain create --port-pair-group ${pg1} --port-pair-group ${pg2} --flow-classifier ${fc} ${name}
1082 Should Be True '${rc}' == '0'
1083 Should Contain ${output} ${name}
1086 Delete SFC Port Chain
1088 [Documentation] Delete a SFC port chain
1089 ${rc} ${output}= Run And Return Rc And Output openstack sfc port chain delete ${name}
1091 Should Be True '${rc}' == '0'
1095 [Arguments] ${vm_name}
1096 [Documentation] Reboot NOVA VM
1097 ${rc} ${output}= Run And Return Rc And Output openstack server reboot --wait ${vm_name}
1099 Should Be True '${rc}' == '0'
1100 Wait Until Keyword Succeeds 35s 10s Verify VM Is ACTIVE ${vm_name}
1102 Remove RSA Key From KnownHosts
1103 [Arguments] ${vm_ip}
1104 [Documentation] Remove RSA
1105 ${devstack_conn_id}= Get ControlNode Connection
1106 Switch Connection ${devstack_conn_id}
1107 ${output}= Write Commands Until Prompt And Log sudo cat /root/.ssh/known_hosts 30s
1108 ${output}= Write Commands Until Prompt And Log sudo ssh-keygen -f "/root/.ssh/known_hosts" -R ${vm_ip} 30s
1109 ${output}= Write Commands Until Prompt sudo cat "/root/.ssh/known_hosts" 30s
1111 Wait For Routes To Propogate
1112 [Arguments] ${networks} ${subnets}
1113 [Documentation] Check propagated routes
1114 ${devstack_conn_id} = Get ControlNode Connection
1115 Switch Connection ${devstack_conn_id}
1116 : FOR ${INDEX} IN RANGE 0 1
1117 \ ${net_id}= Get Net Id @{networks}[${INDEX}] ${devstack_conn_id}
1118 \ ${is_ipv6}= Get Regexp Matches @{subnets}[${INDEX}] ${IP6_REGEX}
1119 \ ${length}= Get Length ${is_ipv6}
1120 \ ${cmd}= Set Variable If ${length} == 0 ip route ip -6 route
1121 \ ${output}= Write Commands Until Expected Prompt sudo ip netns exec qdhcp-${net_id} ${cmd} ]>
1122 \ Should Contain ${output} @{subnets}[${INDEX}]
1125 [Arguments] ${vms}=@{EMPTY} ${networks}=@{EMPTY} ${subnets}=@{EMPTY} ${ports}=@{EMPTY} ${sgs}=@{EMPTY}
1126 : FOR ${vm} IN @{vms}
1127 \ BuiltIn.Run Keyword And Ignore Error Delete Vm Instance ${vm}
1128 : FOR ${port} IN @{ports}
1129 \ BuiltIn.Run Keyword And Ignore Error Delete Port ${port}
1130 : FOR ${subnet} IN @{subnets}
1131 \ BuiltIn.Run Keyword And Ignore Error Delete SubNet ${subnet}
1132 : FOR ${network} IN @{networks}
1133 \ BuiltIn.Run Keyword And Ignore Error Delete Network ${network}
1134 : FOR ${sg} IN @{sgs}
1135 \ BuiltIn.Run Keyword And Ignore Error Delete SecurityGroup ${sg}
1138 [Documentation] Get a list of different OpenStack resources that might be in use.
1139 @{modules} = BuiltIn.Create List floating ip server router port network
1140 ... subnet security group security group rule
1141 : FOR ${module} IN @{modules}
1142 \ OpenStack CLI openstack ${module} list
1144 OpenStack CLI Get List
1146 [Documentation] Return a json list from the output of an OpenStack command.
1147 ${json} = OpenStack CLI ${cmd}
1148 @{list} = RequestsLibrary.To Json ${json}
1154 [Documentation] Run the given OpenStack ${cmd}.
1155 ${rc} ${output} = OperatingSystem.Run And Return Rc And Output ${cmd}
1156 BuiltIn.Log ${output}
1157 Should Be True '${rc}' == '0'
1160 OpenStack Cleanup All
1161 [Documentation] Cleanup all Openstack resources with best effort. The keyword will query for all resources
1162 ... in use and then attempt to delete them. Errors are ignored to allow the cleanup to continue.
1163 @{fips} = OpenStack CLI Get List openstack floating ip list -f json
1164 : FOR ${fip} IN @{fips}
1165 \ BuiltIn.Run Keyword And Ignore Error Delete Floating IP ${fip['ID']}
1166 @{vms} = OpenStack CLI Get List openstack server list -f json
1167 : FOR ${vm} IN @{vms}
1168 \ BuiltIn.Run Keyword And Ignore Error Delete Vm Instance ${vm['ID']}
1169 @{routers} = OpenStack CLI Get List openstack router list -f json
1170 : FOR ${router} IN @{routers}
1171 \ BuiltIn.Run Keyword And Ignore Error Cleanup Router ${router['ID']}
1172 @{ports} = OpenStack CLI Get List openstack port list -f json
1173 : FOR ${port} IN @{ports}
1174 \ BuiltIn.Run Keyword And Ignore Error Delete Port ${port['ID']}
1175 @{networks} = OpenStack CLI Get List openstack network list -f json
1176 : FOR ${network} IN @{networks}
1177 \ BuiltIn.Run Keyword And Ignore Error Delete Subnet ${network['Subnets']}
1178 \ BuiltIn.Run Keyword And Ignore Error Delete Network ${network['ID']}
1179 @{security_groups} = OpenStack CLI Get List openstack security group list -f json
1180 : FOR ${security_group} IN @{security_groups}
1181 \ BuiltIn.Run Keyword If "${security_group['Name']}" != "default" BuiltIn.Run Keyword And Ignore Error Delete SecurityGroup ${security_group['ID']}
1186 [Documentation] Delete a router, but first remove any interfaces or gateways so that the delete will be successful.
1187 @{ports} = OpenStack CLI Get List openstack port list --router ${id} -f json --long
1188 : FOR ${port} IN @{ports}
1189 \ ${subnet_id} = Get Match ${port['Fixed IP Addresses']} [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} 0
1190 \ BuiltIn.Run Keyword If "${port['Device Owner']}" == "network:router_gateway" BuiltIn.Run Keyword And Ignore Error Remove Gateway ${id}
1191 \ BuiltIn.Run Keyword If "${port['Device Owner']}" == "network:router_interface" BuiltIn.Run Keyword And Ignore Error Remove Interface ${id} ${subnet_id}
1192 BuiltIn.Run Keyword And Ignore Error Delete Router ${id}
1194 OpenStack Suite Teardown
1195 [Documentation] Wrapper teardown keyword that can be used in any suite running in an openstack environement
1196 ... to clean up all openstack resources. For example, all instances, networks, ports, etc will be listed and
1197 ... and deleted. As other global cleanup tasks are needed, they can be added here and the suites will all
1198 ... benefit automatically.
1199 OpenStack Cleanup All
1200 SSHLibrary.Close All Connections