Ignore failure on trace:transactions w/ karaf cli
[integration/test.git] / csit / libraries / OpenStackOperations.robot
1 *** Settings ***
2 Documentation     Openstack library. This library is useful for tests to create network, subnet, router and vm instances
3 Library           Collections
4 Library           Process
5 Library           OperatingSystem
6 Library           RequestsLibrary
7 Library           SSHLibrary
8 Library           String
9 Resource          DataModels.robot
10 Resource          DevstackUtils.robot
11 Resource          KarafKeywords.robot
12 Resource          L2GatewayOperations.robot
13 Resource          ODLTools.robot
14 Resource          OVSDB.robot
15 Resource          SetupUtils.robot
16 Resource          SSHKeywords.robot
17 Resource          Tcpdump.robot
18 Resource          Utils.robot
19 Resource          ../variables/Variables.robot
20 Resource          ../variables/netvirt/Variables.robot
21 Variables         ../variables/netvirt/Modules.py
22
23 *** Variables ***
24 @{VALIDATION_KEYWORDS}    Verify Services    Verify Expected Default Tunnels    Verify Expected Default Tables On Nodes
25 ${VALIDATION_FILE}    /tmp/validations.txt
26
27 *** Keywords ***
28 Get Tenant ID From Security Group
29     [Documentation]    Returns tenant ID by reading it from existing default security-group.
30     ${output} =    OpenStack CLI    openstack security group show default | grep "| tenant_id" | awk '{print $4}'
31     [Return]    ${output}
32
33 Get Tenant ID From Network
34     [Arguments]    ${network_uuid}
35     [Documentation]    Returns tenant ID by reading it from existing network.
36     ${resp} =    TemplatedRequests.Get_From_Uri    uri=${CONFIG_API}/neutron:neutron/networks/network/${network_uuid}/    accept=${ACCEPT_EMPTY}    session=session
37     ${tenant_id} =    Utils.Extract Value From Content    ${resp}    /network/0/tenant-id    strip
38     [Return]    ${tenant_id}
39
40 Create Network
41     [Arguments]    ${network_name}    ${additional_args}=${EMPTY}    ${verbose}=TRUE
42     [Documentation]    Create Network with openstack request.
43     ${output} =    OpenStack CLI    openstack network create ${network_name} ${additional_args}
44     [Return]    ${output}
45
46 Update Network
47     [Arguments]    ${network_name}    ${additional_args}=${EMPTY}
48     [Documentation]    Update Network with neutron request.
49     ${output} =    OpenStack CLI    openstack network set ${network_name} ${additional_args}
50     [Return]    ${output}
51
52 Show Network
53     [Arguments]    ${network_name}
54     [Documentation]    Show Network with neutron request.
55     ${output} =    OpenStack CLI    openstack network show ${network_name}
56     [Return]    ${output}
57
58 List Networks
59     [Documentation]    List networks and return output with neutron client.
60     ${output} =    OpenStack CLI    openstack network list
61     [Return]    ${output}
62
63 List Subnets
64     [Documentation]    List subnets and return output with neutron client.
65     ${output} =    OpenStack CLI    openstack subnet list
66     [Return]    ${output}
67
68 Delete Network
69     [Arguments]    ${network_name}
70     [Documentation]    Delete Network with neutron request.
71     ${output} =    OpenStack CLI    openstack network delete ${network_name}
72
73 Create SubNet
74     [Arguments]    ${network_name}    ${subnet_name}    ${range_ip}    ${additional_args}=${EMPTY}
75     [Documentation]    Create SubNet for the Network with neutron request.
76     ${output} =    OpenStack CLI    openstack subnet create --network ${network_name} --subnet-range ${range_ip} ${subnet_name} ${additional_args}
77
78 Update SubNet
79     [Arguments]    ${subnet_name}    ${additional_args}=${EMPTY}
80     [Documentation]    Update subnet with openstack subnet set request.
81     ${output} =    OpenStack CLI    openstack subnet set ${subnet_name} ${additional_args}
82     [Return]    ${output}
83
84 Unset SubNet
85     [Arguments]    ${subnet_name}    ${additional_args}=${EMPTY}
86     [Documentation]    Update subnet with openstack subnet unset request
87     ${output} =    OpenStack CLI    openstack subnet unset ${subnet_name} ${additional_args}
88     [Return]    ${output}
89
90 Show SubNet
91     [Arguments]    ${subnet_name}
92     [Documentation]    Show subnet with neutron request.
93     ${output} =    OpenStack CLI    openstack subnet show ${subnet_name}
94     [Return]    ${output}
95
96 Create Port
97     [Arguments]    ${network_name}    ${port_name}    ${sg}=default    ${additional_args}=${EMPTY}    ${allowed_address_pairs}=${EMPTY}
98     [Documentation]    Create Port with neutron request.
99     # if allowed_address_pairs is not empty we need to create the arguments to pass to the port create command. They are
100     # in a different format with the neutron vs openstack cli.
101     ${address_pair_length} =    BuiltIn.Get Length    ${allowed_address_pairs}
102     ${allowed_pairs_argv} =    BuiltIn.Set Variable    ${EMPTY}
103     ${allowed_pairs_argv} =    BuiltIn.Set Variable If    '${address_pair_length}'=='2'    --allowed-address ip-address=@{allowed_address_pairs}[0] --allowed-address ip-address=@{allowed_address_pairs}[1]    ${allowed_pairs_argv}
104     ${output} =    OpenStack CLI    openstack port create --network ${network_name} ${port_name} --security-group ${sg} ${additional_args} ${allowed_pairs_argv}
105
106 Update Port
107     [Arguments]    ${port_name}    ${additional_args}=${EMPTY}
108     [Documentation]    Update port with neutron request.
109     ${output} =    OpenStack CLI    openstack port set ${port_name} ${additional_args}
110     [Return]    ${output}
111
112 Show Port
113     [Arguments]    ${port_name}
114     [Documentation]    Show port with neutron request.
115     ${output} =    OpenStack CLI    openstack port show ${port_name}
116     [Return]    ${output}
117
118 Delete Port
119     [Arguments]    ${port_name}
120     [Documentation]    Delete Port with neutron request.
121     ${output} =    OpenStack CLI    openstack port delete ${port_name}
122
123 List Ports
124     [Documentation]    List ports and return output with neutron client.
125     ${output} =    OpenStack CLI    openstack port list
126     [Return]    ${output}
127
128 List Nova VMs
129     [Documentation]    List VMs and return output with nova client.
130     ${output} =    OpenStack CLI    openstack server list --all-projects
131     [Return]    ${output}
132
133 Create And Associate Floating IPs
134     [Arguments]    ${external_net}    @{vm_list}
135     [Documentation]    Create and associate floating IPs to VMs with nova request
136     ${ip_list} =    BuiltIn.Create List    @{EMPTY}
137     : FOR    ${vm}    IN    @{vm_list}
138     \    ${output} =    OpenStack CLI    openstack floating ip create ${external_net}
139     \    @{ip} =    String.Get Regexp Matches    ${output}    [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}
140     \    ${ip_length} =    BuiltIn.Get Length    ${ip}
141     \    BuiltIn.Run Keyword If    ${ip_length}>0    Collections.Append To List    ${ip_list}    @{ip}[0]
142     \    ...    ELSE    Collections.Append To List    ${ip_list}    None
143     \    ${output} =    OpenStack CLI    openstack server add floating ip ${vm} @{ip}[0]
144     [Return]    ${ip_list}
145
146 Remove Floating Ip From Vm
147     [Arguments]    ${vm_name}    ${fip}
148     [Documentation]    Remove the Floating IP From VM Instance
149     ${output} =    OpenStack CLI    openstack server remove floating ip ${vm_name} ${fip}
150
151 Delete Floating IP
152     [Arguments]    ${fip}
153     [Documentation]    Delete floating ip with neutron request.
154     ${output} =    OpenStack CLI    openstack floating ip delete ${fip}
155
156 Delete SubNet
157     [Arguments]    ${subnet}
158     [Documentation]    Delete SubNet for the Network with neutron request.
159     ${output} =    OpenStack CLI    openstack subnet delete ${subnet}
160
161 Delete Vm Instance
162     [Arguments]    ${vm_name}
163     [Documentation]    Delete Vm instances using instance names.
164     ${output} =    OpenStack CLI    openstack server delete ${vm_name}
165
166 Get Net Id
167     [Arguments]    ${network_name}
168     [Documentation]    Retrieve the net id for the given network name to create specific vm instance
169     ${output} =    OpenStack CLI    openstack network list | grep "${network_name}" | awk '{print $2}'
170     ${splitted_output} =    String.Split String    ${output}    ${EMPTY}
171     ${net_id} =    Collections.Get from List    ${splitted_output}    0
172     [Return]    ${net_id}
173
174 Get Subnet Id
175     [Arguments]    ${subnet_name}
176     [Documentation]    Retrieve the subnet id for the given subnet name
177     ${output} =    OpenStack CLI    openstack subnet show "${subnet_name}" | grep " id " | awk '{print $4}'
178     ${splitted_output} =    String.Split String    ${output}    ${EMPTY}
179     ${subnet_id} =    Collections.Get from List    ${splitted_output}    0
180     [Return]    ${subnet_id}
181
182 Get Port Id
183     [Arguments]    ${port_name}
184     [Documentation]    Retrieve the port id for the given port name to attach specific vm instance to a particular port
185     ${output} =    OpenStack CLI    openstack port list | grep "${port_name}" | awk '{print $2}'
186     ${splitted_output} =    String.Split String    ${output}    ${EMPTY}
187     ${port_id} =    Collections.Get from List    ${splitted_output}    0
188     [Return]    ${port_id}
189
190 Get Sub Port Id
191     [Arguments]    ${portname}
192     [Documentation]    Retrieve the first 10 chars of the UUID for the given port name
193     ${port_id} =    OpenStackOperations.Get Port Id    ${portname}
194     ${output} =    String.Get Regexp Matches    ${port_id}    \\w{8}-\\w{2}
195     ${subport_id} =    Collections.Get from List    ${output}    0
196     [Return]    ${subport_id}
197
198 Get Router Id
199     [Arguments]    ${router1}
200     [Documentation]    Retrieve the router id for the given router name
201     ${output} =    OpenStack CLI    openstack router show "${router1}" |awk '/ id / {print $4}'
202     ${splitted_output} =    String.Split String    ${output}    ${EMPTY}
203     ${router_id} =    Collections.Get from List    ${splitted_output}    0
204     [Return]    ${router_id}
205
206 Add New Image From Url
207     [Arguments]    ${image_url}    ${image_name}
208     [Documentation]    To add new qcow2 images for testing.
209     ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    wget ${image_url} -O /tmp/new_image.qcow2
210     BuiltIn.Log    ${output}
211     BuiltIn.Should Be True    '${rc}' == '0'
212     ${output} =    OpenStack CLI    openstack image create ${image_name} --file /tmp/new_image.qcow2 --disk-format qcow2 --container-format bare --public
213
214 Create Flavor
215     [Arguments]    ${flavor_name}    ${ram_in_mb}    ${disk_in_gb}    ${ncpu}=1
216     [Documentation]    To create new flavors for instance deployment and testing
217     ${output} =    OpenStack CLI    openstack flavor create ${flavor_name} --ram ${ram_in_mb} --disk ${disk_in_gb} --vcpus ${ncpu}
218
219 Create Keypair
220     [Arguments]    ${keyname}    ${public_key_file}
221     [Documentation]    To add keypairs to Openstack that can be used when ssh to instances using publickey authentication
222     ${output} =    OpenStack CLI    openstack keypair create ${keyname} --public-key ${public_key_file}
223
224 Generate And Add Keypair
225     [Arguments]    ${keyname}    ${keyfilename}
226     [Documentation]    To generate keypair using ssh-keygen and add them to Openstack
227     ${result} =    Process.Run Process    ssh-keygen -b 2048 -t rsa -f ${JENKINS_WORKSPACE}/${keyfilename} -q -N ""    shell=True
228     BuiltIn.Log    ${result.stdout}
229     BuiltIn.Log    ${result.stderr}
230     BuiltIn.Should Be True    '${result.rc}' == '0'
231     OpenStackOperations.Create Keypair    ${keyname}    ${JENKINS_WORKSPACE}/${keyfilename}.pub
232     OpenStackOperations.Get ControlNode Connection
233     SSHLibrary.Put_File    ${JENKINS_WORKSPACE}/${keyfilename}    /tmp
234
235 Create Vm Instances
236     [Arguments]    ${net_name}    ${vm_instance_names}    ${image}=${EMPTY}    ${flavor}=m1.nano    ${sg}=default    ${min}=1
237     [Documentation]    Create X Vm Instance with the net id of the Netowrk.
238     ..    ${max}=1
239     ${image}    BuiltIn.Set Variable If    "${image}"=="${EMPTY}"    ${CIRROS_${OPENSTACK_BRANCH}}    ${image}
240     ${net_id} =    OpenStackOperations.Get Net Id    ${net_name}
241     : FOR    ${vm}    IN    @{vm_instance_names}
242     \    ${output} =    OpenStack CLI    openstack server create --image ${image} --flavor ${flavor} --nic net-id=${net_id} ${vm} --security-group ${sg} --min ${min} --max ${max}
243
244 Create Vm Instance On Compute Node
245     [Arguments]    ${net_name}    ${vm_name}    ${node_hostname}    ${image}=${EMPTY}    ${flavor}=m1.nano    ${sg}=default
246     [Documentation]    Create a VM instance on a specific compute node.
247     ${image} =    BuiltIn.Set Variable If    "${image}"=="${EMPTY}"    ${CIRROS_${OPENSTACK_BRANCH}}    ${image}
248     ${net_id} =    OpenStackOperations.Get Net Id    ${net_name}
249     ${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}
250
251 Create Vm Instance With Port
252     [Arguments]    ${port_name}    ${vm_instance_name}    ${image}=${EMPTY}    ${flavor}=m1.nano    ${sg}=default
253     [Documentation]    Create One VM instance using given ${port_name} and for given ${compute_node}
254     ${image} =    BuiltIn.Set Variable If    "${image}"=="${EMPTY}"    ${CIRROS_${OPENSTACK_BRANCH}}    ${image}
255     ${output} =    OpenStack CLI    openstack server create --image ${image} --flavor ${flavor} --port ${port_name} --security-group ${sg} ${vm_instance_name}
256
257 Create Vm Instance With Ports And Key On Compute Node
258     [Arguments]    ${port1_name}    ${port2_name}    ${vm_instance_name}    ${node_hostname}    ${image}=${EMPTY}    ${flavor}=m1.nano
259     ...    ${sg}=default    ${keyname}=${EMPTY}
260     [Documentation]    Create One VM instance using given ${port1_name} and ${port2_name} with keyname for ssh and also on a specific compute node
261     ${image}    BuiltIn.Set Variable If    "${image}"=="${EMPTY}"    ${CIRROS_${OPENSTACK_BRANCH}}    ${image}
262     ${output} =    OpenStack CLI    openstack server create --image ${image} --flavor ${flavor} --port ${port1_name} --port ${port2_name} ${vm_instance_name} --security-group ${sg} --availability-zone nova:${node_hostname} --key-name ${keyname}
263
264 Create Vm Instance With Port On Compute Node
265     [Arguments]    ${port_name}    ${vm_instance_name}    ${node_hostname}    ${image}=${EMPTY}    ${flavor}=m1.nano    ${sg}=default
266     [Documentation]    Create One VM instance using given ${port_name} and for given ${node_hostname}
267     ${image} =    BuiltIn.Set Variable If    "${image}"=="${EMPTY}"    ${CIRROS_${OPENSTACK_BRANCH}}    ${image}
268     ${output} =    OpenStack CLI    openstack server create --image ${image} --flavor ${flavor} --port ${port_name} --security-group ${sg} --availability-zone nova:${node_hostname} ${vm_instance_name}
269
270 Remove Security Group From Vm Instance
271     [Arguments]    ${vm_instance_name}    ${security_group}
272     [Documentation]    Delete the Security Group from the VM Instance.
273     ${output} =    OpenStack CLI    openstack server remove security group ${vm_instance_name} ${security_group}
274
275 Create Vm Instance With Ports On Compute Node
276     [Arguments]    ${port1_name}    ${port2_name}    ${vm_instance_name}    ${node_hostname}    ${image}=${EMPTY}    ${flavor}=m1.nano
277     ...    ${sg}=default
278     [Documentation]    Create One VM instance using given ${port1_name}, ${port2_name} and for given ${node_hostname} with no keys (cirros like)
279     ${image} =    BuiltIn.Set Variable If    "${image}"=="${EMPTY}"    ${CIRROS_${OPENSTACK_BRANCH}}    ${image}
280     ${port1_id} =    OpenStackOperations.Get Port Id    ${port1_name}
281     ${port2_id} =    OpenStackOperations.Get Port Id    ${port2_name}
282     ${output} =    OpenStack CLI    openstack server create --image ${image} --flavor ${flavor} --nic port-id=${port1_id} --nic port-id=${port2_id} --security-group ${sg} --availability-zone nova:${node_hostname} ${vm_instance_name}
283
284 Get Hypervisor Hostname From IP
285     [Arguments]    ${hypervisor_ip}
286     [Documentation]    Returns the hostname found for the given IP address if it's listed in hypervisor list. For debuggability
287     ...    the full listing is logged first, then followed by a grep | cut to focus on the actual hostname to return
288     ${output} =    OpenStack CLI    openstack hypervisor list
289     ${hostname} =    OpenStack CLI    openstack hypervisor list -f value | grep "${hypervisor_ip} " | cut -d" " -f 2
290     [Return]    ${hostname}
291
292 Create Nano Flavor
293     [Documentation]    Create a nano flavor
294     ${output} =    OpenStack CLI    openstack flavor create m1.nano --id auto --ram 64 --disk 0 --vcpus 1
295
296 Verify VM Is ACTIVE
297     [Arguments]    ${vm_name}
298     [Documentation]    Run these commands to check whether the created vm instance is active or not.
299     ${output} =    OpenStack CLI    openstack server show ${vm_name} | grep OS-EXT-STS:vm_state
300     BuiltIn.Should Contain    ${output}    active
301
302 Poll VM Is ACTIVE
303     [Arguments]    ${vm_name}    ${retry}=600s    ${retry_interval}=30s
304     [Documentation]    Run these commands to check whether the created vm instance is active or not.
305     BuiltIn.Wait Until Keyword Succeeds    ${retry}    ${retry_interval}    OpenStackOperations.Verify VM Is ACTIVE    ${vm_name}
306
307 Get Match
308     [Arguments]    ${text}    ${regexp}    ${index}=0
309     [Documentation]    Wrapper around String.Get Regexp Matches to return None if not found or the first match if found.
310     @{matches} =    String.Get Regexp Matches    ${text}    ${regexp}
311     ${matches_length} =    BuiltIn.Get Length    ${matches}
312     BuiltIn.Set Suite Variable    ${OS_MATCH}    None
313     BuiltIn.Run Keyword If    ${matches_length} > ${index}    BuiltIn.Set Suite Variable    ${OS_MATCH}    @{matches}[${index}]
314     [Return]    ${OS_MATCH}
315
316 Get VM IP
317     [Arguments]    ${fail_on_none}    ${vm}
318     [Documentation]    Get the vm ip address and nameserver by scraping the vm's console log.
319     ...    Get VM IP returns three values: [0] the vm IP, [1] the DHCP IP and [2] the vm console log.
320     ${vm_console_output} =    OpenStack CLI With No Log    openstack console log show ${vm}
321     ${vm_ip} =    BuiltIn.Set Variable    None
322     ${dhcp_ip} =    BuiltIn.Set Variable    None
323     ${match} =    OpenStackOperations.Get Match    ${vm_console_output}    ${REGEX_OBTAINED}
324     ${vm_ip} =    OpenStackOperations.Get Match    ${match}    ${REGEX_IPV4}    0
325     ${match} =    OpenStackOperations.Get Match    ${vm_console_output}    ${REGEX_IPROUTE}
326     ${dhcp_ip} =    OpenStackOperations.Get Match    ${match}    ${REGEX_IPV4}    1
327     BuiltIn.Run Keyword If    '${fail_on_none}' == 'true'    BuiltIn.Should Not Contain    ${vm_ip}    None
328     BuiltIn.Run Keyword If    '${fail_on_none}' == 'true'    BuiltIn.Should Not Contain    ${dhcp_ip}    None
329     [Return]    ${vm_ip}    ${dhcp_ip}    ${vm_console_output}
330
331 Verify If Instance Is Arpingable From DHCP Namespace
332     [Arguments]    ${net_name}    ${mac}    ${ip}
333     [Documentation]    Get the Port IP and check the arp -a from DHCP NS to ensure that the VM's have been assigned IP's
334     OpenStackOperations.Get ControlNode Connection
335     ${net_id} =    OpenStackOperations.Get Net Id    ${net_name}
336     ${output} =    Utils.Write Commands Until Expected Prompt    sudo ip netns exec qdhcp-${net_id} arping ${ip} -c3    ${DEFAULT_LINUX_PROMPT_STRICT}    timeout=60s
337     ${mac_uppercase} =    String.Convert To Upper Case    ${mac}
338     BuiltIn.Should Contain    ${output}    [${mac_uppercase}]
339
340 Check If Instance Is Ready For Ssh Login Using PublicKey
341     [Arguments]    ${net_name}    ${vm_ip}    ${user}=centos    ${idfile}=/tmp/odlkey    ${console}=cirros
342     [Documentation]    Ensure the VM is reachable from ssh as tests would require. This keyword will use publickey authentication
343     ${output} =    Execute Command on VM Instance with PublicKey Auth    ${net_name}    ${vm_ip}    ifconfig    user=${user}    idfile=${idfile}
344     ...    console=${console}
345     BuiltIn.Should Contain    ${output}    ${vm_ip}
346
347 Check If Instance Is Ready For Ssh Login Using Password
348     [Arguments]    ${net_name}    ${vm_ip}    ${user}=cirros    ${console}=cirros
349     [Documentation]    Ensure the VM is reachable from ssh as tests would require. This keyword will use password authentication
350     ${output} =    Execute Command on VM Instance    ${net_name}    ${vm_ip}    ifconfig    console=${console}
351     BuiltIn.Should Contain    ${output}    ${vm_ip}
352
353 Get VM IPs
354     [Arguments]    @{vms}
355     [Documentation]    Get the instance IP addresses and nameserver address for the list of given vms.
356     ...    First poll for the vm instance to be in the active state, then poll for the vm ip address and nameserver.
357     ...    Get VM IPs returns two things: [0] a list of the ips for the vms passed to this keyword (may contain values
358     ...    of None) and [1] the dhcp ip address found in the last vm checked.
359     ...    TODO: there is a potential issue for a caller that passes in VMs belonging to different networks that
360     ...    may have different dhcp server addresses. Not sure what TODO about that, but noting it here for reference.
361     @{vm_ips}    BuiltIn.Create List    @{EMPTY}
362     : FOR    ${vm}    IN    @{vms}
363     \    OpenStackOperations.Poll VM Is ACTIVE    ${vm}
364     \    ${status}    ${ips_and_console_log}    BuiltIn.Run Keyword And Ignore Error    BuiltIn.Wait Until Keyword Succeeds    180s    15s
365     \    ...    OpenStackOperations.Get VM IP    true    ${vm}
366     \    # If there is trouble with Get VM IP, the status will be FAIL and the return value will be a string of what went
367     \    # wrong. We need to handle both the PASS and FAIL cases. In the FAIL case we know we wont have access to the
368     \    # console log, as it would not be returned; so we need to grab it again to log it. We also can append 'None' to
369     \    # the vm ip list if status is FAIL.
370     \    BuiltIn.Run Keyword If    "${status}" == "PASS"    BuiltIn.Log    ${ips_and_console_log[2]}
371     \    BuiltIn.Run Keyword If    "${status}" == "PASS"    Collections.Append To List    ${vm_ips}    ${ips_and_console_log[0]}
372     \    BuiltIn.Run Keyword If    "${status}" == "FAIL"    Collections.Append To List    ${vm_ips}    None
373     \    ${vm_console_output} =    BuiltIn.Run Keyword If    "${status}" == "FAIL"    OpenStack CLI    openstack console log show ${vm}
374     \    BuiltIn.Run Keyword If    "${status}" == "FAIL"    BuiltIn.Log    ${vm_console_output}
375     OpenStackOperations.Copy DHCP Files From Control Node
376     [Return]    @{vm_ips}    ${ips_and_console_log[1]}
377
378 Get Subnet Gateway Ip
379     [Arguments]    ${subnet_name}
380     [Documentation]    Show information of a subnet and grep for subnet gateway ip address
381     ${output} =    OpenStackOperations.OpenStack CLI    openstack subnet show ${subnet_name} | grep gateway_ip | awk '{print $4}'
382     ${splitted_output} =    String.Split String    ${output}    ${EMPTY}
383     ${matches} =    Collections.Get Matches    ${splitted_output}    regexp=(\\d\.)+
384     ${subnet_gateway_ip} =    String.Strip String    ${matches[0]}    characters=','
385     [Return]    ${subnet_gateway_ip}
386
387 Collect VM IPv6 SLAAC Addresses
388     [Arguments]    ${fail_on_none}    ${vm_list}    ${network}    ${subnet}
389     [Documentation]    For each VM parse output of "openstack server show" to get its IPv6 address from Neutron DB.
390     ...    Then try to connect to each VM by SSH and execute there "ip -6 a" command. This double-check allows to
391     ...    obtain and compare IP info (Neutron DB vs dnsmasque/ODL DHCP) and to test L2 connectivity as well.
392     ...    Returns an empty list if no IPv6 addresses found or if SSH connection fails.
393     ...    Otherwise, returns a list of IPv6 addresses.
394     ${ipv6_list} =    BuiltIn.Create List    @{EMPTY}
395     : FOR    ${vm}    IN    @{vm_list}
396     \    ${output} =    OpenStack CLI    openstack server show ${vm} -f shell
397     \    ${pattern} =    String.Replace String    ${subnet}    ::/64    (:[a-f0-9]{,4}){,4}
398     \    @{vm_ipv6} =    String.Get Regexp Matches    ${output}    ${pattern}
399     \    ${vm_ip_length} =    BuiltIn.Get Length    ${vm_ipv6}[0]
400     \    ${ipv6_data_from_vm} =    BuiltIn.Run Keyword If    ${vm_ip_length}>0    OpenStackOperations.Execute Command on VM Instance    ${network}    ${vm_ipv6[0]}
401     \    ...    ip -6 a
402     \    @{ipv6} =    String.Get Regexp Matches    ${ipv6_data_from_vm}    ${pattern}
403     \    ${ipv6_addr_list_length}    BuiltIn.Get Length    @{ipv6}
404     \    BuiltIn.Run Keyword If    ${ipv6_addr_list_length}>0    Collections.Append To List    ${ipv6_list}    ${ipv6[0]}
405     \    ...    ELSE    Collections.Append To List    ${ipv6_list}    None
406     [Return]    ${ipv6_list}
407
408 View Vm Console
409     [Arguments]    ${vm_instance_names}
410     [Documentation]    View Console log of the created vm instances using nova show.
411     : FOR    ${vm}    IN    @{vm_instance_names}
412     \    ${output} =    OpenStack CLI    openstack server show ${vm}
413     \    ${output} =    OpenStack CLI    openstack console log show ${vm}
414
415 Ping Vm From DHCP Namespace
416     [Arguments]    ${net_name}    ${vm_ip}
417     [Documentation]    Reach all Vm Instance with the net id of the Netowrk.
418     OpenStackOperations.Get ControlNode Connection
419     ${net_id} =    OpenStackOperations.Get Net Id    ${net_name}
420     ${output} =    DevstackUtils.Write Commands Until Prompt And Log    sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip}    20s
421     BuiltIn.Should Contain    ${output}    64 bytes
422
423 Ping From DHCP Should Not Succeed
424     [Arguments]    ${net_name}    ${vm_ip}
425     [Documentation]    Should Not Reach Vm Instance with the net id of the Netowrk.
426     Return From Keyword If    "skip_if_${SECURITY_GROUP_MODE}" in @{TEST_TAGS}
427     OpenStackOperations.Get ControlNode Connection
428     ${net_id} =    OpenStackOperations.Get Net Id    ${net_name}
429     ${output} =    DevstackUtils.Write Commands Until Prompt And Log    sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip}    20s
430     BuiltIn.Should Not Contain    ${output}    64 bytes
431
432 Ping Vm From Control Node
433     [Arguments]    ${vm_floating_ip}    ${additional_args}=${EMPTY}
434     [Documentation]    Ping VM floating IP from control node
435     OpenStackOperations.Get ControlNode Connection
436     ${output} =    DevstackUtils.Write Commands Until Prompt And Log    ping ${additional_args} -c 3 ${vm_floating_ip}    20s
437     BuiltIn.Should Contain    ${output}    64 bytes
438
439 Curl Metadata Server
440     [Documentation]    Ping to the expected destination ip.
441     ${output} =    Utils.Write Commands Until Expected Prompt    curl -i http://169.254.169.254    ${OS_SYSTEM_PROMPT}
442     DevstackUtils.Write Commands Until Prompt    exit
443     BuiltIn.Should Contain    ${output}    200
444
445 Close Vm Instance
446     [Documentation]    Exit the vm instance.
447     ${output} =    DevstackUtils.Write Commands Until Prompt And Log    exit
448
449 Check If Console Is VmInstance
450     [Arguments]    ${console}=cirros
451     [Documentation]    Check if the session has been able to login to the VM instance
452     ${output} =    Utils.Write Commands Until Expected Prompt    id    ${OS_SYSTEM_PROMPT}
453     BuiltIn.Should Contain    ${output}    ${console}
454
455 Exit From Vm Console
456     [Arguments]    ${console}=cirros
457     [Documentation]    Check if the session has been able to login to the VM instance and exit the instance
458     ${rcode} =    BuiltIn.Run Keyword And Return Status    OpenStackOperations.Check If Console Is VmInstance    ${console}
459     BuiltIn.Run Keyword If    ${rcode}    DevstackUtils.Write Commands Until Prompt    exit
460
461 Check Ping
462     [Arguments]    ${ip_address}    ${ttl}=64
463     [Documentation]    Run Ping command on the IP available as argument
464     ${ethertype} =    String.Get Regexp Matches    ${ip_address}    ${IP_REGEX}
465     ${output} =    BuiltIn.Run Keyword If    ${ethertype}    Utils.Write Commands Until Expected Prompt    ping -t ${ttl} -c 3 ${ip_address}    ${OS_SYSTEM_PROMPT}
466     ...    ELSE    Utils.Write Commands Until Expected Prompt    ping6 -t ${ttl} -c 3 ${ip_address}    ${OS_SYSTEM_PROMPT}
467     BuiltIn.Should Contain    ${output}    64 bytes
468
469 Check No Ping
470     [Arguments]    ${ip_address}    ${ttl}=64
471     [Documentation]    Run Ping command to the IP given as argument, executing 3 times and expecting NOT to see "64 bytes"
472     ${output} =    Utils.Write Commands Until Expected Prompt    ping -t ${ttl} -c 3 ${ip_address}    ${OS_SYSTEM_PROMPT}
473     BuiltIn.Should Not Contain    ${output}    64 bytes
474
475 Check Metadata Access
476     [Documentation]    Try curl on the Metadataurl and check if it is okay
477     ${output} =    Utils.Write Commands Until Expected Prompt    curl -i http://169.254.169.254    ${OS_SYSTEM_PROMPT}
478     BuiltIn.Should Contain    ${output}    200
479
480 Execute Command on VM Instance
481     [Arguments]    ${net_name}    ${vm_ip}    ${cmd}    ${user}=cirros    ${password}=cubswin:)    ${cmd_timeout}=30s
482     ...    ${console}=cirros
483     [Documentation]    Login to the vm instance using ssh in the network, executes a command inside the VM and returns the ouput.
484     OpenStackOperations.Get ControlNode Connection
485     ${net_id} =    OpenStackOperations.Get Net Id    ${net_name}
486     ${output} =    Utils.Write Commands Until Expected Prompt    sudo ip netns exec qdhcp-${net_id} ssh ${user}@${vm_ip} -o MACs=hmac-sha1 -o ConnectTimeout=5 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o PreferredAuthentications=password    password:
487     ${output} =    Utils.Write Commands Until Expected Prompt    ${password}    ${OS_SYSTEM_PROMPT}
488     ${rcode} =    BuiltIn.Run Keyword And Return Status    OpenStackOperations.Check If Console Is VmInstance    ${console}
489     ${output} =    BuiltIn.Run Keyword If    ${rcode}    Utils.Write Commands Until Expected Prompt    ${cmd}    ${OS_SYSTEM_PROMPT}    timeout=${cmd_timeout}
490     [Teardown]    Exit From Vm Console    ${console}
491     [Return]    ${output}
492
493 Execute Command on VM Instance With PublicKey Auth
494     [Arguments]    ${net_name}    ${vm_ip}    ${cmd}    ${user}=centos    ${idfile}=/tmp/odlkey    ${console}=cirros
495     [Documentation]    Login to the vm instance using ssh publickey in the network, executes a command inside the VM and returns the ouput.
496     OpenStackOperations.Get ControlNode Connection
497     ${net_id} =    OpenStackOperations.Get Net Id    ${net_name}
498     ${output} =    Utils.Write Commands Until Expected Prompt    sudo ip netns exec qdhcp-${net_id} ssh -i ${idfile} ${user}@${vm_ip} -o MACs=hmac-sha1 -o ConnectTimeout=5 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o PreferredAuthentications=publickey    prompt=${OS_SYSTEM_PROMPT}    timeout=60s
499     ${rcode} =    BuiltIn.Run Keyword And Return Status    OpenStackOperations.Check If Console Is VmInstance    ${console}
500     ${output} =    BuiltIn.Run Keyword If    ${rcode}    Utils.Write Commands Until Expected Prompt    ${cmd}    ${OS_SYSTEM_PROMPT}
501     [Teardown]    Exit From Vm Console    ${console}
502     [Return]    ${output}
503
504 Copy File To VM Instance With PublicKey Auth
505     [Arguments]    ${net_name}    ${vm_ip}    ${file_to_copy}    ${user}=centos    ${idfile}=/tmp/odlkey
506     [Documentation]    Login to the vm instance using ssh publickey in the network, executes a command inside the VM and returns the ouput.
507     OpenStackOperations.Get ControlNode Connection
508     ${net_id} =    OpenStackOperations.Get Net Id    ${net_name}
509     ${rc} =    SSHLibrary.Execute Command    sudo ip netns exec qdhcp-${net_id} scp -i ${idfile} -o MACs=hmac-sha1 -o ConnectTimeout=5 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o PreferredAuthentications=publickey ${file_to_copy} ${user}@${vm_ip}:/tmp/    return_stdout=False    return_rc=True
510     BuiltIn.Should Be True    '${rc}' == '0'
511
512 Test Operations From Vm Instance
513     [Arguments]    ${net_name}    ${src_ip}    ${dest_ips}    ${user}=cirros    ${password}=cubswin:)    ${ttl}=64
514     ...    ${ping_should_succeed}=True    ${check_metadata}=True    ${console}=cirros
515     [Documentation]    Login to the vm instance using ssh in the network.
516     OpenStackOperations.Get ControlNode Connection
517     ${net_id} =    OpenStackOperations.Get Net Id    ${net_name}
518     ${output} =    Utils.Write Commands Until Expected Prompt    sudo ip netns exec qdhcp-${net_id} ssh -o MACs=hmac-sha1 -o ConnectTimeout=5 -o StrictHostKeyChecking=no ${user}@${src_ip} -o UserKnownHostsFile=/dev/null    password:    10s
519     ${output} =    Utils.Write Commands Until Expected Prompt    ${password}    ${OS_SYSTEM_PROMPT}
520     ${rcode} =    BuiltIn.Run Keyword And Return Status    OpenStackOperations.Check If Console Is VmInstance    ${console}
521     BuiltIn.Run Keyword If    ${rcode}    Utils.Write Commands Until Expected Prompt    ifconfig    ${OS_SYSTEM_PROMPT}
522     BuiltIn.Run Keyword If    ${rcode}    Utils.Write Commands Until Expected Prompt    route -n    ${OS_SYSTEM_PROMPT}
523     BuiltIn.Run Keyword If    ${rcode}    Utils.Write Commands Until Expected Prompt    route -A inet6    ${OS_SYSTEM_PROMPT}
524     BuiltIn.Run Keyword If    ${rcode}    Utils.Write Commands Until Expected Prompt    arp -an    ${OS_SYSTEM_PROMPT}
525     BuiltIn.Run Keyword If    ${rcode}    Utils.Write Commands Until Expected Prompt    ip -f inet6 neigh show    ${OS_SYSTEM_PROMPT}
526     : FOR    ${dest_ip}    IN    @{dest_ips}
527     \    ${string_empty} =    BuiltIn.Run Keyword And Return Status    Should Be Empty    ${dest_ip}
528     \    BuiltIn.Run Keyword If    ${string_empty}    Continue For Loop
529     \    BuiltIn.Run Keyword If    ${rcode} and "${ping_should_succeed}" == "True"    OpenStackOperations.Check Ping    ${dest_ip}    ttl=${ttl}
530     \    ...    ELSE    OpenStackOperations.Check No Ping    ${dest_ip}    ttl=${ttl}
531     ${ethertype} =    String.Get Regexp Matches    ${src_ip}    ${IP_REGEX}
532     BuiltIn.Run Keyword If    ${rcode} and "${check_metadata}" and ${ethertype} == "True"    OpenStackOperations.Check Metadata Access
533     [Teardown]    Exit From Vm Console    ${console}
534
535 Test Netcat Operations From Vm Instance
536     [Arguments]    ${net_name}    ${vm_ip}    ${dest_ip}    ${additional_args}=${EMPTY}    ${port}=12345    ${user}=cirros
537     ...    ${password}=cubswin:)
538     [Documentation]    Use Netcat to test TCP/UDP connections to the controller
539     ${client_data}    BuiltIn.Set Variable    Test Client Data
540     ${server_data}    BuiltIn.Set Variable    Test Server Data
541     OpenStackOperations.Get ControlNode Connection
542     ${output} =    DevstackUtils.Write Commands Until Prompt And Log    ( ( echo "${server_data}" | sudo timeout 60 nc -l ${additional_args} ${port} ) & )
543     ${output} =    DevstackUtils.Write Commands Until Prompt And Log    sudo netstat -nlap | grep ${port}
544     ${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}
545     BuiltIn.Log    ${output}
546     ${output} =    OpenStackOperations.Execute Command on VM Instance    ${net_name}    ${vm_ip}    sudo route -n
547     BuiltIn.Log    ${output}
548     ${output} =    OpenStackOperations.Execute Command on VM Instance    ${net_name}    ${vm_ip}    sudo arp -an
549     BuiltIn.Log    ${output}
550     BuiltIn.Should Match Regexp    ${nc_output}    ${server_data}
551
552 Ping Other Instances
553     [Arguments]    ${list_of_external_dst_ips}    ${console}=cirros
554     [Documentation]    Check reachability with other network's instances.
555     ${rcode} =    BuiltIn.Run Keyword And Return Status    OpenStackOperations.Check If Console Is VmInstance    ${console}
556     : FOR    ${dest_ip}    IN    @{list_of_external_dst_ips}
557     \    OpenStackOperations.Check Ping    ${dest_ip}
558
559 Create Router
560     [Arguments]    ${router_name}
561     [Documentation]    Create Router and Add Interface to the subnets.
562     ${output} =    OpenStack CLI    openstack router create ${router_name}
563
564 List Routers
565     [Documentation]    List Routers and return output with neutron client.
566     ${output} =    OpenStack CLI    openstack router list -f value
567     [Return]    ${output}
568
569 Add Router Interface
570     [Arguments]    ${router_name}    ${interface_name}
571     ${output} =    OpenStack CLI    openstack router add subnet ${router_name} ${interface_name}
572
573 Show Router Interface
574     [Arguments]    ${router_name}
575     [Documentation]    List Routers interface associated with given Router and return output with neutron client.
576     ${output} =    OpenStack CLI    openstack port list --router ${router_name} -f value
577     [Return]    ${output}
578
579 Add Router Gateway
580     [Arguments]    ${router_name}    ${external_network_name}    ${additional_args}=${EMPTY}
581     ${output} =    OpenStack CLI    openstack router set ${router_name} --external-gateway ${external_network_name} ${additional_args}
582
583 Remove Interface
584     [Arguments]    ${router_name}    ${interface_name}
585     [Documentation]    Remove Interface to the subnets.
586     ${output} =    OpenStack CLI    openstack router remove subnet ${router_name} ${interface_name}
587
588 Remove Gateway
589     [Arguments]    ${router_name}
590     [Documentation]    Remove external gateway from the router.
591     ${output} =    OpenStack CLI    openstack router unset ${router_name} --external-gateway
592
593 Update Router
594     [Arguments]    ${router_name}    ${cmd}
595     [Documentation]    Update the router with the command. Router name and command should be passed as argument.
596     ${output} =    OpenStack CLI    openstack router set ${router_name} ${cmd}
597
598 Show Router
599     [Arguments]    ${router_name}    ${additional_args}=${EMPTY}
600     [Documentation]    Show information of a given router. Router name and optional fields should be sent as arguments.
601     ${output} =    OpenStack CLI    openstack router show ${router_name} ${additional_args}
602     [Return]    ${output}
603
604 Delete Router
605     [Arguments]    ${router_name}
606     [Documentation]    Delete Router and Interface to the subnets.
607     ${output} =    OpenStack CLI    openstack router delete ${router_name}
608
609 Get DumpFlows And Ovsconfig
610     [Arguments]    ${conn_id}
611     [Documentation]    Get the OvsConfig and Flow entries from OVS from the Openstack Node
612     SSHLibrary.Switch Connection    ${conn_id}
613     Utils.Write Commands Until Expected Prompt    ip -o link    ${DEFAULT_LINUX_PROMPT_STRICT}
614     Utils.Write Commands Until Expected Prompt    ip -o addr    ${DEFAULT_LINUX_PROMPT_STRICT}
615     Utils.Write Commands Until Expected Prompt    ip route    ${DEFAULT_LINUX_PROMPT_STRICT}
616     Utils.Write Commands Until Expected Prompt    arp -an    ${DEFAULT_LINUX_PROMPT_STRICT}
617     ${nslist} =    Utils.Write Commands Until Expected Prompt    ip netns list | awk '{print $1}'    ${DEFAULT_LINUX_PROMPT_STRICT}
618     @{lines}    Split To Lines    ${nslist}    end=-1
619     : FOR    ${line}    IN    @{lines}
620     \    Utils.Write Commands Until Expected Prompt    sudo ip netns exec ${line} ip -o link    ${DEFAULT_LINUX_PROMPT_STRICT}
621     \    Utils.Write Commands Until Expected Prompt    sudo ip netns exec ${line} ip -o addr    ${DEFAULT_LINUX_PROMPT_STRICT}
622     \    Utils.Write Commands Until Expected Prompt    sudo ip netns exec ${line} ip route    ${DEFAULT_LINUX_PROMPT_STRICT}
623     Utils.Write Commands Until Expected Prompt    sudo ovs-vsctl show    ${DEFAULT_LINUX_PROMPT_STRICT}
624     Utils.Write Commands Until Expected Prompt    sudo ovs-vsctl list Open_vSwitch    ${DEFAULT_LINUX_PROMPT_STRICT}
625     Utils.Write Commands Until Expected Prompt    sudo ovs-ofctl show ${INTEGRATION_BRIDGE} -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
626     Utils.Write Commands Until Expected Prompt    sudo ovs-ofctl dump-flows ${INTEGRATION_BRIDGE} -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
627     Utils.Write Commands Until Expected Prompt    sudo ovs-ofctl dump-groups ${INTEGRATION_BRIDGE} -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
628     Utils.Write Commands Until Expected Prompt    sudo ovs-ofctl dump-group-stats ${INTEGRATION_BRIDGE} -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
629
630 Get ControlNode Connection
631     SSHLibrary.Switch Connection    ${OS_CNTL_CONN_ID}
632     [Return]    ${OS_CNTL_CONN_ID}
633
634 Get OvsDebugInfo
635     [Documentation]    Get the OvsConfig and Flow entries from all Openstack nodes
636     : FOR    ${conn_id}    IN    @{OS_ALL_CONN_IDS}
637     \    OpenStackOperations.Get DumpFlows And Ovsconfig    ${conn_id}
638
639 Get Test Teardown Debugs
640     [Arguments]    ${test_name}=${SUITE_NAME}.${TEST_NAME}    ${fail}=${FAIL_ON_EXCEPTIONS}
641     ODLTools.Get All    node_ip=${HA_PROXY_IP}    test_name=${test_name}
642     OpenStackOperations.Get OvsDebugInfo
643     BuiltIn.Run Keyword And Ignore Error    DataModels.Get Model Dump    ${HA_PROXY_IP}    ${netvirt_data_models}
644     KarafKeywords.Fail If Exceptions Found During Test    ${test_name}    fail=${fail}
645     : FOR    ${i}    IN RANGE    ${NUM_ODL_SYSTEM}
646     \    BuiltIn.Run Keyword And Ignore Error    Issue_Command_On_Karaf_Console    trace:transactions    ${ODL_SYSTEM_${i+1}_IP}
647
648 Get Suite Debugs
649     Get Test Teardown Debugs    test_name=${SUITE_NAME}    fail=False
650
651 Get Test Teardown Debugs For SFC
652     [Arguments]    ${test_name}=${TEST_NAME}
653     BuiltIn.Run Keyword And Ignore Error    DataModels.Get Model Dump    ${HA_PROXY_IP}    ${netvirt_sfc_data_models}
654
655 Show Debugs
656     [Arguments]    @{vm_indices}
657     [Documentation]    Run these commands for debugging, it can list state of VM instances and ip information in control node
658     OpenStackOperations.Get ControlNode Connection
659     ${output} =    DevstackUtils.Write Commands Until Prompt And Log    sudo ip netns list
660     : FOR    ${index}    IN    @{vm_indices}
661     \    ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    nova show ${index}
662     \    BuiltIn.Log    ${output}
663     OpenStackOperations.List Nova VMs
664     OpenStackOperations.List Routers
665     OpenStackOperations.List Networks
666     OpenStackOperations.List Subnets
667     OpenStackOperations.List Ports
668     OpenStackOperations.List Security Groups
669
670 List Security Groups
671     [Documentation]    Logging keyword to display all security groups using the openstack cli. Assumes openstack
672     ...    credentials are already sourced
673     ${output} =    OpenStack CLI    openstack security group list
674     [Return]    ${output}
675
676 Neutron Security Group Show
677     [Arguments]    ${SecurityGroupRuleName}
678     [Documentation]    Displays the neutron security group configurations that belongs to a given neutron security group name
679     ${output} =    OpenStack CLI    openstack security group show ${SecurityGroupRuleName}
680     [Return]    ${output}
681
682 Neutron Port Show
683     [Arguments]    ${PortName}
684     [Documentation]    Display the port configuration that belong to a given neutron port
685     ${output} =    OpenStack CLI    openstack port show ${PortName}
686     [Return]    ${output}
687
688 Neutron Security Group Create
689     [Arguments]    ${SecurityGroupName}    ${additional_args}=${EMPTY}
690     [Documentation]    Create a security group with specified name ,description & protocol value according to security group template
691     OpenStackOperations.Get ControlNode Connection
692     ${output} =    OpenStack CLI    openstack security group create ${SecurityGroupName} ${additional_args}
693     ${sgp_id} =    BuiltIn.Should Match Regexp    ${output}    ${REGEX_UUID}
694     [Return]    ${output}    ${sgp_id}
695
696 Neutron Security Group Update
697     [Arguments]    ${SecurityGroupName}    ${additional_args}=${EMPTY}
698     [Documentation]    Updating security groups
699     ${output} =    OpenStack CLI    openstack security group set ${SecurityGroupName} ${additional_args}
700     [Return]    ${output}
701
702 Delete SecurityGroup
703     [Arguments]    ${sg_name}
704     [Documentation]    Delete Security group
705     ${output} =    OpenStack CLI    openstack security group delete ${sg_name}
706
707 Neutron Security Group Rule Create
708     [Arguments]    ${Security_group_name}    &{Kwargs}
709     [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]} ..."
710     BuiltIn.Run Keyword If    ${Kwargs}    BuiltIn.Log    ${Kwargs}
711     ${description}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    description    default=${None}
712     ${direction}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    direction    default=${None}
713     ${ethertype}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    ethertype    default=${None}
714     ${port_range_max}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    port_range_max    default=${None}
715     ${port_range_min}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    port_range_min    default=${None}
716     ${protocol}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    protocol    default=${None}
717     ${remote_group_id}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    remote_group_id    default=${None}
718     ${remote_ip_prefix}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    remote_ip_prefix    default=${None}
719     ${cmd} =    BuiltIn.Set Variable    openstack security group rule create ${Security_group_name}
720     ${cmd} =    BuiltIn.Run Keyword If    '${description}'!='None'    BuiltIn.Catenate    ${cmd}    --description ${description}
721     ...    ELSE    BuiltIn.Catenate    ${cmd}
722     ${cmd} =    BuiltIn.Run Keyword If    '${direction}'!='None'    BuiltIn.Catenate    ${cmd}    --${direction}
723     ...    ELSE    BuiltIn.Catenate    ${cmd}
724     ${cmd} =    BuiltIn.Run Keyword If    '${ethertype}'!='None'    BuiltIn.Catenate    ${cmd}    --ethertype ${ethertype}
725     ...    ELSE    BuiltIn.Catenate    ${cmd}
726     ${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}
727     ...    ELSE IF    '${port_range_max}'!='None'    BuiltIn.Catenate    ${cmd}    --dst-port ${port_range_max}
728     ...    ELSE IF    '${port_range_min}'!='None'    BuiltIn.Catenate    ${cmd}    --dst-port ${port_range_min}
729     ...    ELSE    BuiltIn.Catenate    ${cmd}
730     ${cmd} =    BuiltIn.Run Keyword If    '${protocol}'!='None'    BuiltIn.Catenate    ${cmd}    --protocol ${protocol}
731     ...    ELSE    BuiltIn.Catenate    ${cmd}
732     ${cmd} =    BuiltIn.Run Keyword If    '${remote_group_id}'!='None'    BuiltIn.Catenate    ${cmd}    --remote-group ${remote_group_id}
733     ...    ELSE    BuiltIn.Catenate    ${cmd}
734     ${cmd} =    BuiltIn.Run Keyword If    '${remote_ip_prefix}'!='None'    BuiltIn.Catenate    ${cmd}    --src-ip ${remote_ip_prefix}
735     ...    ELSE    BuiltIn.Catenate    ${cmd}
736     ${output} =    OpenStack CLI    ${cmd}
737     ${rule_id} =    BuiltIn.Should Match Regexp    ${output}    ${REGEX_UUID}
738     [Return]    ${output}    ${rule_id}
739
740 Security Group Create Without Default Security Rules
741     [Arguments]    ${sg_name}    ${additional_args}=${EMPTY}
742     [Documentation]    Create Neutron Security Group with no default rules, using specified name and optional arguments.
743     OpenStackOperations.Neutron Security Group Create    ${sg_name}    ${additional_args}
744     Delete All Security Group Rules    ${sg_name}
745
746 Delete All Security Group Rules
747     [Arguments]    ${sg_name}
748     [Documentation]    Delete all security rules from a specified security group
749     ${sg_rules_output} =    OpenStack CLI    openstack security group rule list ${sg_name} -cID -fvalue
750     @{sg_rules} =    String.Split String    ${sg_rules_output}    \n
751     : FOR    ${rule}    IN    @{sg_rules}
752     \    ${output} =    OpenStack CLI    openstack security group rule delete ${rule}
753
754 Create Allow All SecurityGroup
755     [Arguments]    ${sg_name}    ${ether_type}=IPv4    ${dual}=False
756     [Documentation]    Allow all TCP/UDP/ICMP packets for this suite
757     OpenStackOperations.Neutron Security Group Create    ${sg_name}
758     OpenStackOperations.Neutron Security Group Rule Create    ${sg_name}    direction=ingress    ethertype=${ether_type}    port_range_max=65535    port_range_min=1    protocol=tcp
759     OpenStackOperations.Neutron Security Group Rule Create    ${sg_name}    direction=egress    ethertype=${ether_type}    port_range_max=65535    port_range_min=1    protocol=tcp
760     OpenStackOperations.Neutron Security Group Rule Create    ${sg_name}    direction=ingress    ethertype=${ether_type}    protocol=icmp
761     OpenStackOperations.Neutron Security Group Rule Create    ${sg_name}    direction=egress    ethertype=${ether_type}    protocol=icmp
762     OpenStackOperations.Neutron Security Group Rule Create    ${sg_name}    direction=ingress    ethertype=${ether_type}    port_range_max=65535    port_range_min=1    protocol=udp
763     OpenStackOperations.Neutron Security Group Rule Create    ${sg_name}    direction=egress    ethertype=${ether_type}    port_range_max=65535    port_range_min=1    protocol=udp
764     BuiltIn.Run Keyword If    "${dual}"=="True"    Run Keywords    OpenStackOperations.Neutron Security Group Rule Create    ${sg_name}    direction=ingress    ethertype=IPv6
765     ...    port_range_max=65535    port_range_min=1    protocol=tcp
766     ...    AND    OpenStackOperations.Neutron Security Group Rule Create    ${sg_name}    direction=egress    ethertype=IPv6    port_range_max=65535
767     ...    port_range_min=1    protocol=tcp
768     ...    AND    OpenStackOperations.Neutron Security Group Rule Create    ${sg_name}    direction=ingress    ethertype=IPv6    protocol=icmp
769     ...    AND    OpenStackOperations.Neutron Security Group Rule Create    ${sg_name}    direction=egress    ethertype=IPv6    protocol=icmp
770     ...    AND    OpenStackOperations.Neutron Security Group Rule Create    ${sg_name}    direction=ingress    ethertype=IPv6    port_range_max=65535
771     ...    port_range_min=1    protocol=udp
772     ...    AND    OpenStackOperations.Neutron Security Group Rule Create    ${sg_name}    direction=egress    ethertype=IPv6    port_range_max=65535
773     ...    port_range_min=1    protocol=udp
774
775 Create Neutron Port With Additional Params
776     [Arguments]    ${network_name}    ${port_name}    ${additional_args}=${EMPTY}
777     [Documentation]    Create Port With given additional parameters
778     ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    neutron -v port-create ${network_name} --name ${port_name} ${additional_args}
779     BuiltIn.Log    ${output}
780     BuiltIn.Should Be True    '${rc}' == '0'
781     ${port_id} =    BuiltIn.Should Match Regexp    ${OUTPUT}    ${REGEX_UUID}
782     [Return]    ${OUTPUT}    ${port_id}
783
784 Get Ports MacAddr
785     [Arguments]    ${ports}
786     [Documentation]    Retrieve the port MacAddr for the given list of port name and return the MAC address list.
787     ${macs}    BuiltIn.Create List
788     : FOR    ${port}    IN    @{ports}
789     \    ${mac} =    OpenStackOperations.Get Port Mac    ${port}
790     \    Collections.Append To List    ${macs}    ${mac}
791     [Return]    ${macs}
792
793 Get Port Ip
794     [Arguments]    ${port_name}
795     [Documentation]    Keyword would return the IP of the ${port_name} received.
796     ${output} =    OpenStack CLI    openstack port list | grep "${port_name}" | awk -F\\' '{print $2}'
797     ${splitted_output} =    String.Split String    ${output}    ${EMPTY}
798     ${port_ip} =    Collections.Get from List    ${splitted_output}    0
799     [Return]    ${port_ip}
800
801 Get Port Mac
802     [Arguments]    ${port_name}
803     [Documentation]    Keyword would return the MAC ID of the ${port_name} received.
804     ${output} =    OpenStack CLI    openstack port show ${port_name} | grep mac_address | awk '{print $4}'
805     ${splitted_output} =    String.Split String    ${output}    ${EMPTY}
806     ${port_mac} =    Collections.Get from List    ${splitted_output}    0
807     [Return]    ${port_mac}
808
809 Get Port Mac Address From Ip
810     [Arguments]    ${ip}
811     [Documentation]    Retrieve the mac address for a port that matches any given ip.
812     ${output} =    OpenStack CLI    openstack port list | grep -w ${ip} | awk '{print $5}'
813     ${splitted_output} =    String.Split String    ${output}    ${EMPTY}
814     ${mac_addr} =    Collections.Get from List    ${splitted_output}    0
815     [Return]    ${mac_addr}
816
817 Create L2Gateway
818     [Arguments]    ${bridge_name}    ${intf_name}    ${gw_name}
819     [Documentation]    Keyword to create an L2 Gateway ${gw_name} for bridge ${bridge_name} connected to interface ${intf_name} (Using Neutron CLI).
820     ${rc}    ${l2gw_output} =    OperatingSystem.Run And Return Rc And Output    ${L2GW_CREATE} name=${bridge_name},interface_names=${intf_name} ${gw_name}
821     BuiltIn.Log    ${l2gw_output}
822     [Return]    ${l2gw_output}
823
824 Update L2Gateway
825     [Arguments]    ${bridge_name}    ${gw_name}    ${intf_name_1}    ${intf_name_2}
826     [Documentation]    Keyword to add {intf_name_list} to an existing L2 Gateway ${gw_name} (Using Neutron CLI).
827     ${rc}    ${l2gw_output}=    Run And Return Rc And Output    ${L2GW_UPDATE} name=${bridge_name},interface_names="${intf_name_1};${intf_name_2}" ${gw_name}
828     Log    ${l2gw_output}
829     [Return]    ${l2gw_output}
830
831 Create L2Gateway Connection
832     [Arguments]    ${gw_name}    ${net_name}
833     [Documentation]    Keyword would create a new L2 Gateway Connection for ${gw_name} to ${net_name} (Using Neutron CLI).
834     ${rc}    ${l2gw_output} =    OperatingSystem.Run And Return Rc And Output    ${L2GW_CONN_CREATE} ${gw_name} ${net_name}
835     BuiltIn.Log    ${l2gw_output}
836     BuiltIn.Should Be True    '${rc}' == '0'
837     [Return]    ${l2gw_output}
838
839 Get All L2Gateway
840     [Documentation]    Keyword to return all the L2 Gateways available (Using Neutron CLI).
841     ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    ${L2GW_GET_YAML}
842     BuiltIn.Should Be True    '${rc}' == '0'
843     [Return]    ${output}
844
845 Get All L2Gateway Connection
846     [Documentation]    Keyword to return all the L2 Gateway connections available (Using Neutron CLI).
847     ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    ${L2GW_GET_CONN_YAML}
848     BuiltIn.Should Be True    '${rc}' == '0'
849     [Return]    ${output}
850
851 Get L2Gateway
852     [Arguments]    ${gw_id}
853     [Documentation]    Keyword to check if the ${gw_id} is available in the L2 Gateway list (Using Neutron CLI).
854     ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    ${L2GW_SHOW} ${gw_id}
855     BuiltIn.Log    ${output}
856     BuiltIn.Should Be True    '${rc}' == '0'
857     [Return]    ${output}
858
859 Get L2gw Id
860     [Arguments]    ${l2gw_name}
861     [Documentation]    Keyword to retrieve the L2 Gateway ID for the ${l2gw_name} (Using Neutron CLI).
862     ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    ${L2GW_GET} | grep "${l2gw_name}" | awk '{print $2}'
863     BuiltIn.Log    ${output}
864     BuiltIn.Should Be True    '${rc}' == '0'
865     ${splitted_output} =    String.Split String    ${output}    ${EMPTY}
866     ${l2gw_id} =    Collections.Get from List    ${splitted_output}    0
867     [Return]    ${l2gw_id}
868
869 Get L2gw Connection Id
870     [Arguments]    ${l2gw_name}
871     [Documentation]    Keyword to retrieve the L2 Gateway Connection ID for the ${l2gw_name} (Using Neutron CLI).
872     ${l2gw_id} =    OpenStackOperations.Get L2gw Id    ${l2gw_name}
873     ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    ${L2GW_GET_CONN} | grep "${l2gw_id}" | awk '{print $2}'
874     BuiltIn.Should Be True    '${rc}' == '0'
875     ${splitted_output} =    String.Split String    ${output}    ${EMPTY}
876     ${splitted_output} =    String.Split String    ${output}    ${EMPTY}
877     ${l2gw_conn_id} =    Collections.Get from List    ${splitted_output}    0
878     [Return]    ${l2gw_conn_id}
879
880 Neutron Port List Rest
881     [Documentation]    Keyword to get all ports details in Neutron (Using REST).
882     ${resp} =    RequestsLibrary.Get Request    session    ${PORT_URL}
883     BuiltIn.Log    ${resp.content}
884     BuiltIn.Should Be Equal As Strings    ${resp.status_code}    200
885     [Return]    ${resp.content}
886
887 Get Neutron Port Rest
888     [Arguments]    ${port_id}
889     [Documentation]    Keyword to get the specific port details in Neutron (Using REST).
890     ${resp} =    RequestsLibrary.Get Request    session    ${CONFIG_API}/${GET_PORT_URL}/${port_id}
891     BuiltIn.Log    ${resp.content}
892     BuiltIn.Should Be Equal As Strings    ${resp.status_code}    200
893     [Return]    ${resp.content}
894
895 Update Port Rest
896     [Arguments]    ${port_id}    ${json_data}
897     [Documentation]    Keyword to update ${port_id} with json data received in ${json_data} (Using REST).
898     BuiltIn.Log    ${json_data}
899     ${resp} =    RequestsLibrary.Put Request    session    ${CONFIG_API}/${GET_PORT_URL}/${port_id}    ${json_data}
900     BuiltIn.Log    ${resp.content}
901     BuiltIn.Should Be Equal As Strings    ${resp.status_code}    200
902     [Return]    ${resp.content}
903
904 Get Neutron Network Rest
905     [Arguments]    ${net_id}
906     [Documentation]    Keyword to get the specific network details in Neutron (Using REST).
907     ${resp} =    RequestsLibrary.Get Request    session    ${NETWORK_URL}/network/${net_id}
908     BuiltIn.Log    ${resp.content}
909     BuiltIn.Should Be Equal As Strings    ${resp.status_code}    200
910     [Return]    ${resp.content}
911
912 Create And Configure Security Group
913     [Arguments]    ${sg-name}
914     [Documentation]    Create Security Group with given name, and default allow rules for TCP/UDP/ICMP protocols.
915     OpenStackOperations.Neutron Security Group Create    ${sg-name}
916     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
917     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
918     OpenStackOperations.Neutron Security Group Rule Create    ${sg-name}    direction=ingress    protocol=icmp    remote_ip_prefix=0.0.0.0/0
919     OpenStackOperations.Neutron Security Group Rule Create    ${sg-name}    direction=egress    protocol=icmp    remote_ip_prefix=0.0.0.0/0
920     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
921     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
922
923 Add Security Group To VM
924     [Arguments]    ${vm}    ${sg}
925     [Documentation]    Add the security group provided to the given VM.
926     ${output} =    OpenStack CLI    openstack server add security group ${vm} ${sg}
927
928 Remove Security Group From VM
929     [Arguments]    ${vm}    ${sg}
930     [Documentation]    Remove the security group provided to the given VM.
931     OpenStackOperations.Get ControlNode Connection
932     ${output} =    OpenStack CLI    openstack server remove security group ${vm} ${sg}
933
934 Create SFC Flow Classifier
935     [Arguments]    ${name}    ${src_ip}    ${dest_ip}    ${protocol}    ${neutron_src_port}    ${args}=${EMPTY}
936     [Documentation]    Create a flow classifier for SFC
937     ${output} =    OpenStack CLI    openstack sfc flow classifier create --ethertype IPv4 --source-ip-prefix ${src_ip}/32 --destination-ip-prefix ${dest_ip}/32 --protocol ${protocol} --logical-source-port ${neutron_src_port} ${args} ${name}
938     BuiltIn.Should Contain    ${output}    ${name}
939     [Return]    ${output}
940
941 Delete SFC Flow Classifier
942     [Arguments]    ${name}
943     [Documentation]    Delete a SFC flow classifier
944     ${output} =    OpenStack CLI    openstack sfc flow classifier delete ${name}
945     [Return]    ${output}
946
947 Create SFC Port Pair
948     [Arguments]    ${name}    ${port_in}    ${port_out}
949     [Documentation]    Creates a neutron port pair for SFC
950     ${output} =    OpenStack CLI    openstack sfc port pair create --ingress=${port_in} --egress=${port_out} ${name}
951     BuiltIn.Should Contain    ${output}    ${name}
952     [Return]    ${output}
953
954 Delete SFC Port Pair
955     [Arguments]    ${name}
956     [Documentation]    Delete a SFC port pair
957     ${output} =    OpenStack CLI    openstack sfc port pair delete ${name}
958     [Return]    ${output}
959
960 Create SFC Port Pair Group
961     [Arguments]    ${name}    ${port_pair}
962     [Documentation]    Creates a port pair group with a single port pair for SFC
963     ${output} =    OpenStack CLI    openstack sfc port pair group create --port-pair ${port_pair} ${name}
964     BuiltIn.Should Contain    ${output}    ${name}
965     [Return]    ${output}
966
967 Create SFC Port Pair Group With Two Pairs
968     [Arguments]    ${name}    ${port_pair1}    ${port_pair2}
969     [Documentation]    Creates a port pair group with two port pairs for SFC
970     ${output} =    OpenStack CLI    openstack sfc port pair group create --port-pair ${port_pair1} --port-pair ${port_pair2} ${name}
971     BuiltIn.Should Contain    ${output}    ${name}
972     [Return]    ${output}
973
974 Delete SFC Port Pair Group
975     [Arguments]    ${name}
976     [Documentation]    Delete a SFC port pair group
977     OpenStackOperations.Get ControlNode Connection
978     ${output} =    OpenStack CLI    openstack sfc port pair group delete ${name}
979     [Return]    ${output}
980
981 Create SFC Port Chain
982     [Arguments]    ${name}    ${args}=${EMPTY}
983     [Documentation]    Creates a port pair chain with two port groups and a singel classifier.
984     ${output} =    OpenStack CLI    openstack sfc port chain create ${name} ${args}
985     BuiltIn.Should Contain    ${output}    ${name}
986     [Return]    ${output}
987
988 Update SFC Port Chain With A New Flow Classifier
989     [Arguments]    ${name}    ${fc}
990     [Documentation]    Adds a Flow Classifier to a Port Chain
991     ${output} =    OpenStack CLI    openstack sfc port chain set ${name} --flow-classifier ${fc}
992     [Return]    ${output}
993
994 Update SFC Port Chain Removing A Flow Classifier
995     [Arguments]    ${name}    ${fc}
996     [Documentation]    Adds a Flow Classifier to a Port Chain
997     ${output} =    OpenStack CLI    openstack sfc port chain unset ${name} --flow-classifier ${fc}
998     [Return]    ${output}
999
1000 Delete SFC Port Chain
1001     [Arguments]    ${name}
1002     [Documentation]    Delete a SFC port chain
1003     ${output} =    OpenStack CLI    openstack sfc port chain delete ${name}
1004     [Return]    ${output}
1005
1006 Reboot Nova VM
1007     [Arguments]    ${vm_name}
1008     [Documentation]    Reboot NOVA VM
1009     ${output} =    OpenStack CLI    openstack server reboot --wait ${vm_name}
1010     BuiltIn.Wait Until Keyword Succeeds    35s    10s    OpenStackOperations.Verify VM Is ACTIVE    ${vm_name}
1011
1012 Remove RSA Key From KnownHosts
1013     [Arguments]    ${vm_ip}
1014     [Documentation]    Remove RSA
1015     OpenStackOperations.Get ControlNode Connection
1016     ${output} =    DevstackUtils.Write Commands Until Prompt And Log    sudo cat /root/.ssh/known_hosts    30s
1017     ${output} =    DevstackUtils.Write Commands Until Prompt And Log    sudo ssh-keygen -f "/root/.ssh/known_hosts" -R ${vm_ip}    30s
1018     ${output} =    DevstackUtils.Write Commands Until Prompt    sudo cat "/root/.ssh/known_hosts"    30s
1019
1020 Wait For Routes To Propogate
1021     [Arguments]    ${networks}    ${subnets}
1022     [Documentation]    Check propagated routes
1023     OpenStackOperations.Get ControlNode Connection
1024     : FOR    ${INDEX}    IN RANGE    0    1
1025     \    ${net_id} =    OpenStackOperations.Get Net Id    @{networks}[${INDEX}]
1026     \    ${is_ipv6} =    String.Get Regexp Matches    @{subnets}[${INDEX}]    ${IP6_REGEX}
1027     \    ${length} =    BuiltIn.Get Length    ${is_ipv6}
1028     \    ${cmd} =    BuiltIn.Set Variable If    ${length} == 0    ip route    ip -6 route
1029     \    ${output} =    Utils.Write Commands Until Expected Prompt    sudo ip netns exec qdhcp-${net_id} ${cmd}    ${DEFAULT_LINUX_PROMPT_STRICT}
1030     \    BuiltIn.Should Contain    ${output}    @{subnets}[${INDEX}]
1031
1032 Neutron Cleanup
1033     [Arguments]    ${vms}=@{EMPTY}    ${networks}=@{EMPTY}    ${subnets}=@{EMPTY}    ${ports}=@{EMPTY}    ${sgs}=@{EMPTY}
1034     : FOR    ${vm}    IN    @{vms}
1035     \    BuiltIn.Run Keyword And Ignore Error    Delete Vm Instance    ${vm}
1036     : FOR    ${port}    IN    @{ports}
1037     \    BuiltIn.Run Keyword And Ignore Error    Delete Port    ${port}
1038     : FOR    ${subnet}    IN    @{subnets}
1039     \    BuiltIn.Run Keyword And Ignore Error    Delete SubNet    ${subnet}
1040     : FOR    ${network}    IN    @{networks}
1041     \    BuiltIn.Run Keyword And Ignore Error    Delete Network    ${network}
1042     : FOR    ${sg}    IN    @{sgs}
1043     \    BuiltIn.Run Keyword And Ignore Error    Delete SecurityGroup    ${sg}
1044
1045 OpenStack List All
1046     [Documentation]    Get a list of different OpenStack resources that might be in use.
1047     @{modules} =    BuiltIn.Create List    server    port    network    subnet    security group
1048     ...    security group rule    floating ip    router
1049     : FOR    ${module}    IN    @{modules}
1050     \    ${output} =    OpenStack CLI    openstack ${module} list
1051
1052 OpenStack CLI Get List
1053     [Arguments]    ${cmd}
1054     [Documentation]    Return a json list from the output of an OpenStack command.
1055     @{list} =    BuiltIn.Create List
1056     ${json} =    OpenStack CLI    ${cmd}
1057     @{list} =    RequestsLibrary.To Json    ${json}
1058     BuiltIn.Log    ${list}
1059     [Return]    @{list}
1060
1061 OpenStack CLI
1062     [Arguments]    ${cmd}
1063     [Documentation]    Run the given OpenStack ${cmd} and log the output.
1064     ${result} =    Process.Run Process    ${cmd}    shell=True
1065     BuiltIn.Log    ${result.stdout}
1066     BuiltIn.Log    ${result.stderr}
1067     BuiltIn.Should Be True    '${result.rc}' == '0'
1068     [Return]    ${result.stdout}
1069
1070 OpenStack CLI With No Log
1071     [Arguments]    ${cmd}
1072     [Documentation]    Run the given OpenStack ${cmd} and do not log the output.
1073     ${result} =    Process.Run Process    ${cmd}    shell=True
1074     BuiltIn.Should Be True    '${result.rc}' == '0'
1075     [Return]    ${result.stdout}
1076
1077 OpenStack Cleanup All
1078     [Documentation]    Cleanup all Openstack resources with best effort. The keyword will query for all resources
1079     ...    in use and then attempt to delete them. Errors are ignored to allow the cleanup to continue.
1080     @{fips} =    OpenStack CLI Get List    openstack floating ip list -f json
1081     : FOR    ${fip}    IN    @{fips}
1082     \    BuiltIn.Run Keyword And Ignore Error    Delete Floating IP    ${fip['ID']}
1083     @{vms} =    OpenStack CLI Get List    openstack server list -f json
1084     : FOR    ${vm}    IN    @{vms}
1085     \    OpenStack CLI    openstack server show ${vm['ID']}
1086     \    BuiltIn.Run Keyword And Ignore Error    Delete Vm Instance    ${vm['ID']}
1087     @{routers} =    OpenStack CLI Get List    openstack router list -f json
1088     : FOR    ${router}    IN    @{routers}
1089     \    BuiltIn.Run Keyword And Ignore Error    Cleanup Router    ${router['ID']}
1090     @{ports} =    OpenStack CLI Get List    openstack port list -f json
1091     : FOR    ${port}    IN    @{ports}
1092     \    BuiltIn.Run Keyword And Ignore Error    Delete Port    ${port['ID']}
1093     @{networks} =    OpenStack CLI Get List    openstack network list -f json
1094     : FOR    ${network}    IN    @{networks}
1095     \    BuiltIn.Run Keyword And Ignore Error    Delete Subnet    ${network['Subnets']}
1096     \    BuiltIn.Run Keyword And Ignore Error    Delete Network    ${network['ID']}
1097     @{security_groups} =    OpenStack CLI Get List    openstack security group list -f json
1098     : FOR    ${security_group}    IN    @{security_groups}
1099     \    BuiltIn.Run Keyword If    "${security_group['Name']}" != "default"    BuiltIn.Run Keyword And Ignore Error    Delete SecurityGroup    ${security_group['ID']}
1100     OpenStack List All
1101
1102 Cleanup Router
1103     [Arguments]    ${id}
1104     [Documentation]    Delete a router, but first remove any interfaces or gateways so that the delete will be successful.
1105     @{ports} =    OpenStack CLI Get List    openstack port list --router ${id} -f json --long
1106     : FOR    ${port}    IN    @{ports}
1107     \    ${subnet_id} =    OpenStackOperations.Get Match    ${port['Fixed IP Addresses']}    ${REGEX_UUID}    0
1108     \    BuiltIn.Run Keyword If    "${port['Device Owner']}" == "network:router_gateway"    BuiltIn.Run Keyword And Ignore Error    Remove Gateway    ${id}
1109     \    BuiltIn.Run Keyword If    "${port['Device Owner']}" == "network:router_interface"    BuiltIn.Run Keyword And Ignore Error    Remove Interface    ${id}    ${subnet_id}
1110     BuiltIn.Run Keyword And Ignore Error    Delete Router    ${id}
1111
1112 OpenStack Suite Setup
1113     [Documentation]    Wrapper teardown keyword that can be used in any suite running in an openstack environement
1114     SetupUtils.Setup_Utils_For_Setup_And_Teardown
1115     @{loggers} =    BuiltIn.Create List    org.apache.karaf.shell.support.ShellUtil    org.apache.sshd.server.session.ServerSessionImpl
1116     Setuputils.Setup_Logging_For_Debug_Purposes_On_List_Or_All    OFF    ${loggers}
1117     DevstackUtils.Devstack Suite Setup
1118     @{tcpdump_port_6653_conn_ids} =    OpenStackOperations.Start Packet Capture On Nodes    tcpdump_port_6653    port 6653    @{OS_ALL_IPS}
1119     BuiltIn.Set Suite Variable    @{tcpdump_port_6653_conn_ids}
1120     BuiltIn.Run Keyword If    "${PRE_CLEAN_OPENSTACK_ALL}"=="True"    OpenStack Cleanup All
1121     OpenStackOperations.Add OVS Logging On All OpenStack Nodes
1122     Validate Deployment
1123
1124 OpenStack Suite Teardown
1125     [Documentation]    Wrapper teardown keyword that can be used in any suite running in an openstack environement
1126     ...    to clean up all openstack resources. For example, all instances, networks, ports, etc will be listed and
1127     ...    and deleted. As other global cleanup tasks are needed, they can be added here and the suites will all
1128     ...    benefit automatically.
1129     # TODO: followup patch will add the list of vms to pass to Show Debugs
1130     # OpenStackOperations.Show Debugs    @{NET_1_VMS}    @{NET_2_VMS}
1131     OpenStackOperations.Get Suite Debugs
1132     OpenStack Cleanup All
1133     OpenStackOperations.Stop Packet Capture On Nodes    ${tcpdump_port_6653_conn_ids}
1134     SSHLibrary.Close All Connections
1135     : FOR    ${i}    IN RANGE    ${NUM_ODL_SYSTEM}
1136     \    KarafKeywords.Issue Command On Karaf Console    threads --list | wc -l    ${ODL_SYSTEM_${i+1}_IP}
1137
1138 Validate Deployment
1139     [Documentation]    Validate the deployment. Examples to validate are verifying default table
1140     ...    flows are installed and that the tunnel mesh has been built correctly.
1141     Write To Validate File    ----------------------------------------\n${SUITE_NAME}\n
1142     : FOR    ${keyword}    IN    @{VALIDATION_KEYWORDS}
1143     \    ${status} =    Builtin.Run Keyword And Return Status    ${keyword}
1144     \    BuiltIn.Run Keyword If    "${status}" == "FAIL"    BuiltIn.Run Keywords    Write To Validate File    Failed: ${keyword}
1145     \    ...    AND    BuiltIn.Fail
1146     \    ...    ELSE    Write To Validate File    Passed: ${keyword}
1147
1148 Write To Validate File
1149     [Arguments]    ${msg}
1150     [Documentation]    Write the given ${msg} to ${VALIDATION_FILE}. Create the file if not present.
1151     ${status} =    BuiltIn.Run Keyword And Return Status    OperatingSystem.File Should Exist    ${VALIDATION_FILE}
1152     BuiltIn.Run Keyword If    "${status}" == "False"    OperatingSystem.Create File    ${VALIDATION_FILE}
1153     OperatingSystem.Append To File    ${VALIDATION_FILE}    ${msg}\n
1154
1155 Copy DHCP Files From Control Node
1156     [Documentation]    Copy the current DHCP files to the robot vm. The keyword must be called
1157     ...    after the subnet(s) are created and before the subnet(s) are deleted.
1158     ${suite_} =    BuiltIn.Evaluate    """${SUITE_NAME}""".replace(" ","_").replace("/","_").replace(".","_")
1159     ${dstdir} =    BuiltIn.Set Variable    /tmp/qdhcp/${suite_}
1160     OperatingSystem.Create Directory    ${dstdir}
1161     OpenStackOperations.Get ControlNode Connection
1162     BuiltIn.Run Keyword And Ignore Error    SSHLibrary.Get Directory    /opt/stack/data/neutron/dhcp    ${dstdir}    recursive=True
1163
1164 Is Feature Installed
1165     [Arguments]    ${features}=none
1166     : FOR    ${feature}    IN    @{features}
1167     \    ${status}    ${output}    BuiltIn.Run Keyword And Ignore Error    BuiltIn.Should Contain    ${CONTROLLERFEATURES}    ${feature}
1168     \    Return From Keyword If    "${status}" == "PASS"    True
1169     [Return]    False
1170
1171 Add OVS Logging On All OpenStack Nodes
1172     [Documentation]    Add higher levels of OVS logging to all the OpenStack nodes
1173     : FOR    ${conn_id}    IN    @{OS_ALL_CONN_IDS}
1174     \    OVSDB.Add OVS Logging    ${conn_id}
1175
1176 Reset OVS Logging On All OpenStack Nodes
1177     [Documentation]    Reset the OVS logging to all the OpenStack nodes
1178     : FOR    ${conn_id}    IN    @{OS_ALL_CONN_IDS}
1179     \    OVSDB.Reset OVS Logging    ${conn_id}
1180
1181 Start Packet Capture On Nodes
1182     [Arguments]    ${tag}    ${filter}    @{ips}
1183     [Documentation]    Wrapper keyword around the TcpDump packet capture that is catered to the Openstack setup.
1184     ...    The caller must pass the three arguments with a variable number of ips at the end,
1185     ...    but ${EMPTY} can be used for the tag and filter.
1186     ${suite_} =    BuiltIn.Evaluate    """${SUITE_NAME}""".replace(" ","_").replace("/","_").replace(".","_")
1187     ${tag_} =    BuiltIn.Catenate    SEPARATOR=__    ${tag}    ${suite_}
1188     @{conn_ids} =    Tcpdump.Start Packet Capture on Nodes    tag=${tag_}    filter=${filter}    ips=${ips}
1189     [Return]    @{conn_ids}
1190
1191 Stop Packet Capture On Nodes
1192     [Arguments]    ${conn_ids}=@{EMPTY}
1193     Tcpdump.Stop Packet Capture on Nodes    ${conn_ids}
1194
1195 Server Live Migrate
1196     [Arguments]    ${vm_instance_name}
1197     [Documentation]    Keyword for live migration of VM instance
1198     ...    additional_agrs is to select particular migration(live/shared-migration/block-migration)
1199     ...    if the additional_agrs is not given default migration(shared-migration) will happen
1200     ${output} =    OpenStackOperations.OpenStack CLI    nova live-migration ${vm_instance_name}
1201
1202 Get Hypervisor Host Of Vm
1203     [Arguments]    ${vm_name}
1204     [Documentation]    Show server with neutron request.
1205     ${output} =    OpenStackOperations.OpenStack CLI    openstack server show -f value -c OS-EXT-SRV-ATTR:host ${vm_name}
1206     [Return]    ${output}
1207
1208 Check If Migration Is Complete
1209     [Arguments]    ${vm_name}
1210     [Documentation]    Show server and verify if task_state is not migrating
1211     ${output} =    OpenStackOperations.OpenStack CLI    openstack server show ${vm_name} | grep "OS-EXT-STS:task_state"
1212     BuiltIn.Should Not Contain    ${output}    migrating
1213
1214 Modify OpenStack Configuration File
1215     [Arguments]    ${conn_id}    ${file_name}    ${section}    ${key}    ${value}
1216     [Documentation]    Use crudini to modify any parameter in any Openstack configuration File
1217     SSHLibrary.Switch Connection    ${conn_id}
1218     ${output}    ${rc} =    SSHLibrary.Execute Command    sudo crudini --verbose --set --inplace ${file_name} ${section} ${key} ${value}    return_rc=True    return_stdout=True
1219     BuiltIn.Log    ${output}
1220     BuiltIn.Should Be True    '${rc}' == '0'
1221
1222 Restart DevStack Service
1223     [Arguments]    ${conn_id}    ${service_name}
1224     [Documentation]    Restart the Openstack Service
1225     SSHLibrary.Switch Connection    ${conn_id}
1226     ${output}    ${rc} =    SSHLibrary.Execute Command    sudo systemctl restart devstack@${service_name}.service    return_rc=True    return_stdout=True
1227     BuiltIn.Log    ${output}
1228     BuiltIn.Should Be True    '${rc}' == '0'
1229
1230 Get Network Segmentation Id
1231     [Arguments]    ${network_name}
1232     [Documentation]    Returns network segmentation id for the given network name.
1233     ${output} =    OpenStack CLI    openstack network show ${network_name} | grep segmentation_id | awk '{print $4}'
1234     @{list} =    String.Split String    ${output}
1235     [Return]    @{list}[0]
1236
1237 Verify Services
1238     [Documentation]    Verify if the services are operational
1239     Wait Until Keyword Succeeds    60    2    ClusterManagement.Check Status Of Services Is OPERATIONAL    @{NETVIRT_DIAG_SERVICES}
1240
1241 Verify Expected Default Tunnels
1242     [Documentation]    Verify if the default tunnels are created
1243     ${output} =    ODLTools.Analyze Tunnels    test_name=${SUITE_NAME}.Suite Setup
1244     BuiltIn.Should Contain    ${output}    All tunnels are up
1245
1246 Verify Expected Default Tables On Nodes
1247     [Arguments]    ${node_ips}=@{OS_ALL_IPS}
1248     [Documentation]    Verify if Default Table Entries are programmed on all Nodes
1249     ${resp} =    RequestsLibrary.Get Request    session    ${CONFIG_NODES_API}
1250     Utils.Log Content    ${resp.content}
1251     ${failed_node_list} =    BuiltIn.Create List
1252     : FOR    ${node_ip}    IN    @{node_ips}
1253     \    ${failed_table_list} =    Verify Expected Default Tables    ${node_ip}
1254     \    ${failed_table_list_size} =    BuiltIn.Get Length    ${failed_table_list}
1255     \    BuiltIn.Run Keyword If    ${failed_table_list_size} > 0    Collections.Append To List    ${failed_node_list}    ${node_ip}
1256     Builtin.Should Be Empty    ${failed_node_list}
1257
1258 Verify Expected Default Tables
1259     [Arguments]    ${ovs_ip}
1260     [Documentation]    Verify if Default Table Entries are programmed on specific Node
1261     ${flow_dump} =    Utils.Run Command On Remote System    ${ovs_ip}    sudo ovs-ofctl dump-flows ${INTEGRATION_BRIDGE} -OOpenFlow13
1262     BuiltIn.Log    ${flow_dump}
1263     ${failed_table_list} =    BuiltIn.Create List
1264     : FOR    ${table}    IN    @{DEFAULT_FLOW_TABLES}
1265     \    ${rc} =    Builtin.Run Keyword And Return Status    Builtin.Should Not Match Regexp    ${flow_dump}    .*table=${table}.*priority=0
1266     \    BuiltIn.Run Keyword If    ${rc}    Collections.Append To List    ${failed_table_list}    ${table}
1267     [Return]    ${failed_table_list}
1268
1269 Get Project Id
1270     [Arguments]    ${project_name}
1271     [Documentation]    Returns project ID for the given project name.
1272     ${project_id} =    OpenStack CLI    openstack project show ${project_name} -f value -c id
1273     [Return]    ${project_id}
1274
1275 Set Instance Quota For Project
1276     [Arguments]    ${num_instances}    ${project_id}
1277     [Documentation]    Set quota for the created instances using the specific project id.
1278     ${output} =    OpenStack CLI    openstack quota set --instances ${num_instances} ${project_id}
1279     [Return]    ${output}