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