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