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