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