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