18928012aa062fcf400c9142f4a5a79a17fe1750
[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          L2GatewayOperations.robot
11 Resource          OVSDB.robot
12 Resource          SetupUtils.robot
13 Resource          SSHKeywords.robot
14 Resource          Tcpdump.robot
15 Resource          Utils.robot
16 Resource          ../variables/Variables.robot
17 Resource          ../variables/netvirt/Variables.robot
18 Variables         ../variables/netvirt/Modules.py
19
20 *** Keywords ***
21 Get Tenant ID From Security Group
22     [Documentation]    Returns tenant ID by reading it from existing default security-group.
23     ${output} =    OpenStack CLI    openstack security group show default | grep "| tenant_id" | awk '{print $4}'
24     [Return]    ${output}
25
26 Get Tenant ID From Network
27     [Arguments]    ${network_uuid}
28     [Documentation]    Returns tenant ID by reading it from existing network.
29     ${resp} =    TemplatedRequests.Get_From_Uri    uri=${CONFIG_API}/neutron:neutron/networks/network/${network_uuid}/    accept=${ACCEPT_EMPTY}    session=session
30     ${tenant_id} =    Utils.Extract Value From Content    ${resp}    /network/0/tenant-id    strip
31     [Return]    ${tenant_id}
32
33 Create Network
34     [Arguments]    ${network_name}    ${additional_args}=${EMPTY}    ${verbose}=TRUE
35     [Documentation]    Create Network with neutron request.
36     ${output} =    OpenStack CLI    openstack network create ${network_name} ${additional_args}
37     [Return]    ${output}
38
39 Update Network
40     [Arguments]    ${network_name}    ${additional_args}=${EMPTY}
41     [Documentation]    Update Network with neutron request.
42     ${cmd} =    BuiltIn.Set Variable If    '${OPENSTACK_BRANCH}'=='stable/newton'    neutron -v net-update ${network_name} ${additional_args}    openstack network set ${network_name} ${additional_args}
43     ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    ${cmd}
44     BuiltIn.Log    ${output}
45     BuiltIn.Should Be True    '${rc}' == '0'
46     [Return]    ${output}
47
48 Show Network
49     [Arguments]    ${network_name}
50     [Documentation]    Show Network with neutron request.
51     ${output} =    OpenStack CLI    openstack network show ${network_name}
52     [Return]    ${output}
53
54 List Networks
55     [Documentation]    List networks and return output with neutron client.
56     ${output} =    OpenStack CLI    openstack network list
57     [Return]    ${output}
58
59 List Subnets
60     [Documentation]    List subnets and return output with neutron client.
61     ${output} =    OpenStack CLI    openstack subnet list
62     [Return]    ${output}
63
64 Delete Network
65     [Arguments]    ${network_name}
66     [Documentation]    Delete Network with neutron request.
67     ${output} =    OpenStack CLI    openstack network delete ${network_name}
68
69 Create SubNet
70     [Arguments]    ${network_name}    ${subnet_name}    ${range_ip}    ${additional_args}=${EMPTY}
71     [Documentation]    Create SubNet for the Network with neutron request.
72     ${output} =    OpenStack CLI    openstack subnet create --network ${network_name} --subnet-range ${range_ip} ${subnet_name} ${additional_args}
73
74 Update SubNet
75     [Arguments]    ${subnet_name}    ${additional_args}=${EMPTY}
76     [Documentation]    Update subnet with neutron request.
77     ${cmd} =    BuiltIn.Set Variable If    '${OPENSTACK_BRANCH}'=='stable/newton'    neutron -v subnet-update ${subnet_name} ${additional_args}    openstack subnet set ${subnet_name} ${additional_args}
78     ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    ${cmd}
79     BuiltIn.Log    ${output}
80     BuiltIn.Should Be True    '${rc}' == '0'
81     [Return]    ${output}
82
83 Show SubNet
84     [Arguments]    ${subnet_name}
85     [Documentation]    Show subnet with neutron request.
86     ${output} =    OpenStack CLI    openstack subnet show ${subnet_name}
87     [Return]    ${output}
88
89 Create Port
90     [Arguments]    ${network_name}    ${port_name}    ${sg}=default    ${additional_args}=${EMPTY}    ${allowed_address_pairs}=${EMPTY}
91     [Documentation]    Create Port with neutron request.
92     # if allowed_address_pairs is not empty we need to create the arguments to pass to the port create command. They are
93     # in a different format with the neutron vs openstack cli.
94     ${address_pair_length} =    BuiltIn.Get Length    ${allowed_address_pairs}
95     ${allowed_pairs_argv} =    BuiltIn.Set Variable If    '${OPENSTACK_BRANCH}'=='stable/newton' and '${address_pair_length}'=='2'    --allowed-address-pairs type=dict list=true ip_address=@{allowed_address_pairs}[0] ip_address=@{allowed_address_pairs}[1]
96     ${allowed_pairs_argv} =    BuiltIn.Set Variable If    '${OPENSTACK_BRANCH}'!='stable/newton' and '${address_pair_length}'=='2'    --allowed-address ip-address=@{allowed_address_pairs}[0] --allowed-address ip-address=@{allowed_address_pairs}[1]    ${allowed_pairs_argv}
97     ${allowed_pairs_argv} =    BuiltIn.Set Variable If    '${address_pair_length}'=='0'    ${EMPTY}    ${allowed_pairs_argv}
98     ${cmd} =    BuiltIn.Set Variable If    '${OPENSTACK_BRANCH}'=='stable/newton'    neutron -v port-create ${network_name} --name ${port_name} --security-group ${sg} ${additional_args} ${allowed_pairs_argv}    openstack port create --network ${network_name} ${port_name} --security-group ${sg} ${additional_args} ${allowed_pairs_argv}
99     ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    ${cmd}
100     BuiltIn.Log    ${output}
101     BuiltIn.Should Be True    '${rc}' == '0'
102
103 Update Port
104     [Arguments]    ${port_name}    ${additional_args}=${EMPTY}
105     [Documentation]    Update port with neutron request.
106     ${output} =    OpenStack CLI    openstack port set ${port_name} ${additional_args}
107     [Return]    ${output}
108
109 Show Port
110     [Arguments]    ${port_name}
111     [Documentation]    Show port with neutron request.
112     ${output} =    OpenStack CLI    openstack port show ${port_name}
113     [Return]    ${output}
114
115 Delete Port
116     [Arguments]    ${port_name}
117     [Documentation]    Delete Port with neutron request.
118     ${output} =    OpenStack CLI    openstack port delete ${port_name}
119
120 List Ports
121     [Documentation]    List ports and return output with neutron client.
122     ${output} =    OpenStack CLI    openstack port list
123     [Return]    ${output}
124
125 List Nova VMs
126     [Documentation]    List VMs and return output with nova client.
127     ${output} =    OpenStack CLI    openstack server list --all-projects
128     [Return]    ${output}
129
130 Create And Associate Floating IPs
131     [Arguments]    ${external_net}    @{vm_list}
132     [Documentation]    Create and associate floating IPs to VMs with nova request
133     ${ip_list} =    BuiltIn.Create List    @{EMPTY}
134     : FOR    ${vm}    IN    @{vm_list}
135     \    ${output} =    OpenStack CLI    openstack floating ip create ${external_net}
136     \    BuiltIn.Log    ${output}
137     \    BuiltIn.Should Be True    '${rc}' == '0'
138     \    @{ip} =    String.Get Regexp Matches    ${output}    [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}
139     \    ${ip_length} =    BuiltIn.Get Length    ${ip}
140     \    BuiltIn.Run Keyword If    ${ip_length}>0    Collections.Append To List    ${ip_list}    @{ip}[0]
141     \    ...    ELSE    Collections.Append To List    ${ip_list}    None
142     \    ${output} =    OpenStack CLI    openstack server add floating ip ${vm} @{ip}[0]
143     [Return]    ${ip_list}
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 Collect VM IPv6 SLAAC Addresses
303     [Arguments]    ${fail_on_none}    ${vm_list}    ${network}    ${subnet}
304     [Documentation]    For each VM parse output of "openstack server show" to get its IPv6 address from Neutron DB.
305     ...    Then try to connect to each VM by SSH and execute there "ip -6 a" command. This double-check allows to
306     ...    obtain and compare IP info (Neutron DB vs dnsmasque/ODL DHCP) and to test L2 connectivity as well.
307     ...    Returns an empty list if no IPv6 addresses found or if SSH connection fails.
308     ...    Otherwise, returns a list of IPv6 addresses.
309     ${ipv6_list} =    BuiltIn.Create List    @{EMPTY}
310     : FOR    ${vm}    IN    @{vm_list}
311     \    ${output} =    OpenStack CLI    openstack server show ${vm} -f shell
312     \    ${pattern} =    String.Replace String    ${subnet}    ::/64    (:[a-f0-9]{,4}){,4}
313     \    @{vm_ipv6} =    String.Get Regexp Matches    ${output}    ${pattern}
314     \    ${vm_ip_length} =    BuiltIn.Get Length    ${vm_ipv6}[0]
315     \    ${ipv6_data_from_vm} =    BuiltIn.Run Keyword If    ${vm_ip_length}>0    OpenStackOperations.Execute Command on VM Instance    ${network}    ${vm_ipv6[0]}
316     \    ...    ip -6 a
317     \    @{ipv6} =    String.Get Regexp Matches    ${ipv6_data_from_vm}    ${pattern}
318     \    ${ipv6_addr_list_length}    BuiltIn.Get Length    @{ipv6}
319     \    BuiltIn.Run Keyword If    ${ipv6_addr_list_length}>0    Collections.Append To List    ${ipv6_list}    ${ipv6[0]}
320     \    ...    ELSE    Collections.Append To List    ${ipv6_list}    None
321     [Return]    ${ipv6_list}
322
323 View Vm Console
324     [Arguments]    ${vm_instance_names}
325     [Documentation]    View Console log of the created vm instances using nova show.
326     : FOR    ${vm}    IN    @{vm_instance_names}
327     \    ${output} =    OpenStack CLI    openstack server show ${vm}
328     \    ${output} =    OpenStack CLI    openstack console log show ${vm}
329
330 Ping Vm From DHCP Namespace
331     [Arguments]    ${net_name}    ${vm_ip}
332     [Documentation]    Reach all Vm Instance with the net id of the Netowrk.
333     OpenStackOperations.Get ControlNode Connection
334     ${net_id} =    OpenStackOperations.Get Net Id    ${net_name}
335     ${output} =    DevstackUtils.Write Commands Until Prompt And Log    sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip}    20s
336     BuiltIn.Should Contain    ${output}    64 bytes
337
338 Ping From DHCP Should Not Succeed
339     [Arguments]    ${net_name}    ${vm_ip}
340     [Documentation]    Should Not Reach Vm Instance with the net id of the Netowrk.
341     Return From Keyword If    "skip_if_${SECURITY_GROUP_MODE}" in @{TEST_TAGS}
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 Not Contain    ${output}    64 bytes
346
347 Ping Vm From Control Node
348     [Arguments]    ${vm_floating_ip}    ${additional_args}=${EMPTY}
349     [Documentation]    Ping VM floating IP from control node
350     OpenStackOperations.Get ControlNode Connection
351     ${output} =    DevstackUtils.Write Commands Until Prompt And Log    ping ${additional_args} -c 3 ${vm_floating_ip}    20s
352     BuiltIn.Should Contain    ${output}    64 bytes
353
354 Curl Metadata Server
355     [Documentation]    Ping to the expected destination ip.
356     ${output} =    Utils.Write Commands Until Expected Prompt    curl -i http://169.254.169.254    ${OS_SYSTEM_PROMPT}
357     DevstackUtils.Write Commands Until Prompt    exit
358     BuiltIn.Should Contain    ${output}    200
359
360 Close Vm Instance
361     [Documentation]    Exit the vm instance.
362     ${output} =    DevstackUtils.Write Commands Until Prompt And Log    exit
363
364 Check If Console Is VmInstance
365     [Arguments]    ${console}=cirros
366     [Documentation]    Check if the session has been able to login to the VM instance
367     ${output} =    Utils.Write Commands Until Expected Prompt    id    ${OS_SYSTEM_PROMPT}
368     BuiltIn.Should Contain    ${output}    ${console}
369
370 Exit From Vm Console
371     [Documentation]    Check if the session has been able to login to the VM instance and exit the instance
372     ${rcode} =    BuiltIn.Run Keyword And Return Status    OpenStackOperations.Check If Console Is VmInstance    cirros
373     BuiltIn.Run Keyword If    ${rcode}    DevstackUtils.Write Commands Until Prompt    exit
374
375 Check Ping
376     [Arguments]    ${ip_address}    ${ttl}=64
377     [Documentation]    Run Ping command on the IP available as argument
378     ${ethertype} =    String.Get Regexp Matches    ${ip_address}    ${IP_REGEX}
379     ${output} =    BuiltIn.Run Keyword If    ${ethertype}    Utils.Write Commands Until Expected Prompt    ping -t ${ttl} -c 3 ${ip_address}    ${OS_SYSTEM_PROMPT}
380     ...    ELSE    Utils.Write Commands Until Expected Prompt    ping6 -t ${ttl} -c 3 ${ip_address}    ${OS_SYSTEM_PROMPT}
381     BuiltIn.Should Contain    ${output}    64 bytes
382
383 Check No Ping
384     [Arguments]    ${ip_address}    ${ttl}=64
385     [Documentation]    Run Ping command to the IP given as argument, executing 3 times and expecting NOT to see "64 bytes"
386     ${output} =    Utils.Write Commands Until Expected Prompt    ping -t ${ttl} -c 3 ${ip_address}    ${OS_SYSTEM_PROMPT}
387     BuiltIn.Should Not Contain    ${output}    64 bytes
388
389 Check Metadata Access
390     [Documentation]    Try curl on the Metadataurl and check if it is okay
391     ${output} =    Utils.Write Commands Until Expected Prompt    curl -i http://169.254.169.254    ${OS_SYSTEM_PROMPT}
392     BuiltIn.Should Contain    ${output}    200
393
394 Execute Command on VM Instance
395     [Arguments]    ${net_name}    ${vm_ip}    ${cmd}    ${user}=cirros    ${password}=cubswin:)
396     [Documentation]    Login to the vm instance using ssh in the network, executes a command inside the VM and returns the ouput.
397     OpenStackOperations.Get ControlNode Connection
398     ${net_id} =    OpenStackOperations.Get Net Id    ${net_name}
399     ${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:
400     ${output} =    Utils.Write Commands Until Expected Prompt    ${password}    ${OS_SYSTEM_PROMPT}
401     ${rcode} =    BuiltIn.Run Keyword And Return Status    OpenStackOperations.Check If Console Is VmInstance
402     ${output} =    BuiltIn.Run Keyword If    ${rcode}    Utils.Write Commands Until Expected Prompt    ${cmd}    ${OS_SYSTEM_PROMPT}
403     [Teardown]    Exit From Vm Console
404     [Return]    ${output}
405
406 Test Operations From Vm Instance
407     [Arguments]    ${net_name}    ${src_ip}    ${dest_ips}    ${user}=cirros    ${password}=cubswin:)    ${ttl}=64
408     ...    ${ping_should_succeed}=True    ${check_metadata}=True
409     [Documentation]    Login to the vm instance using ssh in the network.
410     OpenStackOperations.Get ControlNode Connection
411     ${net_id} =    OpenStackOperations.Get Net Id    ${net_name}
412     ${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:
413     ${output} =    Utils.Write Commands Until Expected Prompt    ${password}    ${OS_SYSTEM_PROMPT}
414     ${rcode} =    BuiltIn.Run Keyword And Return Status    OpenStackOperations.Check If Console Is VmInstance
415     BuiltIn.Run Keyword If    ${rcode}    Utils.Write Commands Until Expected Prompt    ifconfig    ${OS_SYSTEM_PROMPT}
416     BuiltIn.Run Keyword If    ${rcode}    Utils.Write Commands Until Expected Prompt    route -n    ${OS_SYSTEM_PROMPT}
417     BuiltIn.Run Keyword If    ${rcode}    Utils.Write Commands Until Expected Prompt    route -A inet6    ${OS_SYSTEM_PROMPT}
418     BuiltIn.Run Keyword If    ${rcode}    Utils.Write Commands Until Expected Prompt    arp -an    ${OS_SYSTEM_PROMPT}
419     BuiltIn.Run Keyword If    ${rcode}    Utils.Write Commands Until Expected Prompt    ip -f inet6 neigh show    ${OS_SYSTEM_PROMPT}
420     : FOR    ${dest_ip}    IN    @{dest_ips}
421     \    ${string_empty} =    BuiltIn.Run Keyword And Return Status    Should Be Empty    ${dest_ip}
422     \    BuiltIn.Run Keyword If    ${string_empty}    Continue For Loop
423     \    BuiltIn.Run Keyword If    ${rcode} and "${ping_should_succeed}" == "True"    OpenStackOperations.Check Ping    ${dest_ip}    ttl=${ttl}
424     \    ...    ELSE    OpenStackOperations.Check No Ping    ${dest_ip}    ttl=${ttl}
425     ${ethertype} =    String.Get Regexp Matches    ${src_ip}    ${IP_REGEX}
426     BuiltIn.Run Keyword If    ${rcode} and "${check_metadata}" and ${ethertype} == "True"    OpenStackOperations.Check Metadata Access
427     [Teardown]    Exit From Vm Console
428
429 Test Netcat Operations From Vm Instance
430     [Arguments]    ${net_name}    ${vm_ip}    ${dest_ip}    ${additional_args}=${EMPTY}    ${port}=12345    ${user}=cirros
431     ...    ${password}=cubswin:)
432     [Documentation]    Use Netcat to test TCP/UDP connections to the controller
433     ${client_data}    BuiltIn.Set Variable    Test Client Data
434     ${server_data}    BuiltIn.Set Variable    Test Server Data
435     OpenStackOperations.Get ControlNode Connection
436     ${output} =    DevstackUtils.Write Commands Until Prompt And Log    ( ( echo "${server_data}" | sudo timeout 60 nc -l ${additional_args} ${port} ) & )
437     ${output} =    DevstackUtils.Write Commands Until Prompt And Log    sudo netstat -nlap | grep ${port}
438     ${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}
439     BuiltIn.Log    ${output}
440     ${output} =    OpenStackOperations.Execute Command on VM Instance    ${net_name}    ${vm_ip}    sudo route -n
441     BuiltIn.Log    ${output}
442     ${output} =    OpenStackOperations.Execute Command on VM Instance    ${net_name}    ${vm_ip}    sudo arp -an
443     BuiltIn.Log    ${output}
444     BuiltIn.Should Match Regexp    ${nc_output}    ${server_data}
445
446 Ping Other Instances
447     [Arguments]    ${list_of_external_dst_ips}
448     [Documentation]    Check reachability with other network's instances.
449     ${rcode} =    BuiltIn.Run Keyword And Return Status    OpenStackOperations.Check If Console Is VmInstance
450     : FOR    ${dest_ip}    IN    @{list_of_external_dst_ips}
451     \    OpenStackOperations.Check Ping    ${dest_ip}
452
453 Create Router
454     [Arguments]    ${router_name}
455     [Documentation]    Create Router and Add Interface to the subnets.
456     ${output} =    OpenStack CLI    openstack router create ${router_name}
457
458 List Routers
459     [Documentation]    List Routers and return output with neutron client.
460     ${output} =    OpenStack CLI    openstack router list -f value
461     [Return]    ${output}
462
463 Add Router Interface
464     [Arguments]    ${router_name}    ${interface_name}
465     ${output} =    OpenStack CLI    openstack router add subnet ${router_name} ${interface_name}
466
467 Show Router Interface
468     [Arguments]    ${router_name}
469     [Documentation]    List Routers interface associated with given Router and return output with neutron client.
470     ${output} =    OpenStack CLI    openstack port list --router ${router_name} -f value
471     [Return]    ${output}
472
473 Add Router Gateway
474     [Arguments]    ${router_name}    ${external_network_name}
475     ${cmd} =    BuiltIn.Set Variable If    '${OPENSTACK_BRANCH}'=='stable/newton'    neutron -v router-gateway-set ${router_name} ${external_network_name}    openstack router set ${router_name} --external-gateway ${external_network_name}
476     ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    ${cmd}
477     BuiltIn.Should Be True    '${rc}' == '0'
478
479 Remove Interface
480     [Arguments]    ${router_name}    ${interface_name}
481     [Documentation]    Remove Interface to the subnets.
482     ${output} =    OpenStack CLI    openstack router remove subnet ${router_name} ${interface_name}
483
484 Remove Gateway
485     [Arguments]    ${router_name}
486     [Documentation]    Remove external gateway from the router.
487     BuiltIn.Log    openstack router unset ${router_name} --external-gateway
488
489 Update Router
490     [Arguments]    ${router_name}    ${cmd}
491     [Documentation]    Update the router with the command. Router name and command should be passed as argument.
492     ${output} =    OpenStack CLI    openstack router set ${router_name} ${cmd}
493
494 Show Router
495     [Arguments]    ${router_name}    ${options}
496     [Documentation]    Show information of a given router. Router name and optional fields should be sent as arguments.
497     ${output} =    OpenStack CLI    openstack router show ${router_name}
498
499 Delete Router
500     [Arguments]    ${router_name}
501     [Documentation]    Delete Router and Interface to the subnets.
502     ${output} =    OpenStack CLI    openstack router delete ${router_name}
503
504 Get DumpFlows And Ovsconfig
505     [Arguments]    ${conn_id}
506     [Documentation]    Get the OvsConfig and Flow entries from OVS from the Openstack Node
507     SSHLibrary.Switch Connection    ${conn_id}
508     Utils.Write Commands Until Expected Prompt    ip -o link    ${DEFAULT_LINUX_PROMPT_STRICT}
509     Utils.Write Commands Until Expected Prompt    ip -o addr    ${DEFAULT_LINUX_PROMPT_STRICT}
510     Utils.Write Commands Until Expected Prompt    ip route    ${DEFAULT_LINUX_PROMPT_STRICT}
511     Utils.Write Commands Until Expected Prompt    arp -an    ${DEFAULT_LINUX_PROMPT_STRICT}
512     ${nslist} =    Utils.Write Commands Until Expected Prompt    ip netns list | awk '{print $1}'    ${DEFAULT_LINUX_PROMPT_STRICT}
513     @{lines}    Split To Lines    ${nslist}    end=-1
514     : FOR    ${line}    IN    @{lines}
515     \    Utils.Write Commands Until Expected Prompt    sudo ip netns exec ${line} ip -o link    ${DEFAULT_LINUX_PROMPT_STRICT}
516     \    Utils.Write Commands Until Expected Prompt    sudo ip netns exec ${line} ip -o addr    ${DEFAULT_LINUX_PROMPT_STRICT}
517     \    Utils.Write Commands Until Expected Prompt    sudo ip netns exec ${line} ip route    ${DEFAULT_LINUX_PROMPT_STRICT}
518     Utils.Write Commands Until Expected Prompt    sudo ovs-vsctl show    ${DEFAULT_LINUX_PROMPT_STRICT}
519     Utils.Write Commands Until Expected Prompt    sudo ovs-vsctl list Open_vSwitch    ${DEFAULT_LINUX_PROMPT_STRICT}
520     Utils.Write Commands Until Expected Prompt    sudo ovs-ofctl show br-int -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
521     Utils.Write Commands Until Expected Prompt    sudo ovs-ofctl dump-flows br-int -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
522     Utils.Write Commands Until Expected Prompt    sudo ovs-ofctl dump-groups br-int -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
523     Utils.Write Commands Until Expected Prompt    sudo ovs-ofctl dump-group-stats br-int -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
524
525 Get Karaf Log Type From Test Start
526     [Arguments]    ${ip}    ${test_name}    ${type}    ${user}=${ODL_SYSTEM_USER}    ${password}=${ODL_SYSTEM_PASSWORD}    ${prompt}=${ODL_SYSTEM_PROMPT}
527     ...    ${log_file}=${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
528     ${cmd} =    BuiltIn.Set Variable    sed '1,/ROBOT MESSAGE: Starting test ${test_name}/d' ${log_file} | grep '${type}'
529     ${output} =    Utils.Run Command On Controller    ${ip}    ${cmd}    ${user}    ${password}    ${prompt}
530     [Return]    ${output}
531
532 Get Karaf Log Types From Test Start
533     [Arguments]    ${ip}    ${test_name}    ${types}    ${user}=${ODL_SYSTEM_USER}    ${password}=${ODL_SYSTEM_PASSWORD}    ${prompt}=${ODL_SYSTEM_PROMPT}
534     ...    ${log_file}=${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
535     : FOR    ${type}    IN    @{types}
536     \    OpenStackOperations.Get Karaf Log Type From Test Start    ${ip}    ${test_name}    ${type}    ${user}    ${password}
537     \    ...    ${prompt}    ${log_file}
538
539 Get Karaf Log Events From Test Start
540     [Arguments]    ${test_name}    ${user}=${ODL_SYSTEM_USER}    ${password}=${ODL_SYSTEM_PASSWORD}    ${prompt}=${ODL_SYSTEM_PROMPT}
541     ${log_types} =    BuiltIn.Create List    ERROR    WARN    Exception
542     BuiltIn.Run Keyword If    0 < ${NUM_ODL_SYSTEM}    OpenStackOperations.Get Karaf Log Types From Test Start    ${ODL_SYSTEM_IP}    ${test_name}    ${log_types}
543     BuiltIn.Run Keyword If    1 < ${NUM_ODL_SYSTEM}    OpenStackOperations.Get Karaf Log Types From Test Start    ${ODL_SYSTEM_2_IP}    ${test_name}    ${log_types}
544     BuiltIn.Run Keyword If    2 < ${NUM_ODL_SYSTEM}    OpenStackOperations.Get Karaf Log Types From Test Start    ${ODL_SYSTEM_3_IP}    ${test_name}    ${log_types}
545
546 Get ControlNode Connection
547     SSHLibrary.Switch Connection    ${OS_CNTL_CONN_ID}
548     [Return]    ${OS_CNTL_CONN_ID}
549
550 Get OvsDebugInfo
551     [Documentation]    Get the OvsConfig and Flow entries from all Openstack nodes
552     BuiltIn.Run Keyword If    0 < ${NUM_OS_SYSTEM}    OpenStackOperations.Get DumpFlows And Ovsconfig    ${OS_CNTL_CONN_ID}
553     BuiltIn.Run Keyword If    1 < ${NUM_OS_SYSTEM}    OpenStackOperations.Get DumpFlows And Ovsconfig    ${OS_CMP1_CONN_ID}
554     BuiltIn.Run Keyword If    2 < ${NUM_OS_SYSTEM}    OpenStackOperations.Get DumpFlows And Ovsconfig    ${OS_CMP2_CONN_ID}
555
556 Get Test Teardown Debugs
557     [Arguments]    ${test_name}=${TEST_NAME}
558     OpenStackOperations.Get OvsDebugInfo
559     BuiltIn.Run Keyword And Ignore Error    DataModels.Get Model Dump    ${HA_PROXY_IP}    ${netvirt_data_models}
560     OpenStackOperations.Get Karaf Log Events From Test Start    ${test_name}
561
562 Get Test Teardown Debugs For SFC
563     [Arguments]    ${test_name}=${TEST_NAME}
564     BuiltIn.Run Keyword And Ignore Error    DataModels.Get Model Dump    ${HA_PROXY_IP}    ${netvirt_sfc_data_models}
565
566 Show Debugs
567     [Arguments]    @{vm_indices}
568     [Documentation]    Run these commands for debugging, it can list state of VM instances and ip information in control node
569     OpenStackOperations.Get ControlNode Connection
570     ${output} =    DevstackUtils.Write Commands Until Prompt And Log    sudo ip netns list
571     : FOR    ${index}    IN    @{vm_indices}
572     \    ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    nova show ${index}
573     \    BuiltIn.Log    ${output}
574     OpenStackOperations.List Nova VMs
575     OpenStackOperations.List Routers
576     OpenStackOperations.List Networks
577     OpenStackOperations.List Subnets
578     OpenStackOperations.List Ports
579     OpenStackOperations.List Security Groups
580
581 List Security Groups
582     [Documentation]    Logging keyword to display all security groups using the openstack cli. Assumes openstack
583     ...    credentials are already sourced
584     ${output} =    OpenStack CLI    openstack security group list
585     [Return]    ${output}
586
587 Neutron Security Group Show
588     [Arguments]    ${SecurityGroupRuleName}
589     [Documentation]    Displays the neutron security group configurations that belongs to a given neutron security group name
590     ${output} =    OpenStack CLI    openstack security group show ${SecurityGroupRuleName}
591     [Return]    ${output}
592
593 Neutron Port Show
594     [Arguments]    ${PortName}
595     [Documentation]    Display the port configuration that belong to a given neutron port
596     ${output} =    OpenStack CLI    openstack port show ${PortName}
597     [Return]    ${output}
598
599 Neutron Security Group Create
600     [Arguments]    ${SecurityGroupName}    ${additional_args}=${EMPTY}
601     [Documentation]    Create a security group with specified name ,description & protocol value according to security group template
602     OpenStackOperations.Get ControlNode Connection
603     ${output} =    OpenStack CLI    openstack security group create ${SecurityGroupName} ${additional_args}
604     ${sgp_id} =    BuiltIn.Should Match Regexp    ${output}    ${REGEX_UUID}
605     [Return]    ${output}    ${sgp_id}
606
607 Neutron Security Group Update
608     [Arguments]    ${SecurityGroupName}    ${additional_args}=${EMPTY}
609     [Documentation]    Updating security groups
610     ${output} =    OpenStack CLI    openstack security group set ${SecurityGroupName} ${additional_args}
611     [Return]    ${output}
612
613 Delete SecurityGroup
614     [Arguments]    ${sg_name}
615     [Documentation]    Delete Security group
616     ${output} =    OpenStack CLI    openstack security group delete ${sg_name}
617
618 Neutron Security Group Rule Create
619     [Arguments]    ${Security_group_name}    &{Kwargs}
620     [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]} ..."
621     BuiltIn.Run Keyword If    ${Kwargs}    BuiltIn.Log    ${Kwargs}
622     ${description}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    description    default=${None}
623     ${direction}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    direction    default=${None}
624     ${ethertype}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    ethertype    default=${None}
625     ${port_range_max}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    port_range_max    default=${None}
626     ${port_range_min}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    port_range_min    default=${None}
627     ${protocol}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    protocol    default=${None}
628     ${remote_group_id}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    remote_group_id    default=${None}
629     ${remote_ip_prefix}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    remote_ip_prefix    default=${None}
630     ${cmd} =    BuiltIn.Set Variable    openstack security group rule create ${Security_group_name}
631     ${cmd} =    BuiltIn.Run Keyword If    '${description}'!='None'    BuiltIn.Catenate    ${cmd}    --description ${description}
632     ...    ELSE    BuiltIn.Catenate    ${cmd}
633     ${cmd} =    BuiltIn.Run Keyword If    '${direction}'!='None'    BuiltIn.Catenate    ${cmd}    --${direction}
634     ...    ELSE    BuiltIn.Catenate    ${cmd}
635     ${cmd} =    BuiltIn.Run Keyword If    '${ethertype}'!='None'    BuiltIn.Catenate    ${cmd}    --ethertype ${ethertype}
636     ...    ELSE    BuiltIn.Catenate    ${cmd}
637     ${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}
638     ...    ELSE IF    '${port_range_max}'!='None'    BuiltIn.Catenate    ${cmd}    --dst-port ${port_range_max}
639     ...    ELSE IF    '${port_range_min}'!='None'    BuiltIn.Catenate    ${cmd}    --dst-port ${port_range_min}
640     ...    ELSE    BuiltIn.Catenate    ${cmd}
641     ${cmd} =    BuiltIn.Run Keyword If    '${protocol}'!='None'    BuiltIn.Catenate    ${cmd}    --protocol ${protocol}
642     ...    ELSE    BuiltIn.Catenate    ${cmd}
643     ${cmd} =    BuiltIn.Run Keyword If    '${remote_group_id}'!='None'    BuiltIn.Catenate    ${cmd}    --remote-group ${remote_group_id}
644     ...    ELSE    BuiltIn.Catenate    ${cmd}
645     ${cmd} =    BuiltIn.Run Keyword If    '${remote_ip_prefix}'!='None'    BuiltIn.Catenate    ${cmd}    --src-ip ${remote_ip_prefix}
646     ...    ELSE    BuiltIn.Catenate    ${cmd}
647     ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    ${cmd}
648     ${rule_id} =    BuiltIn.Should Match Regexp    ${output}    ${REGEX_UUID}
649     BuiltIn.Log    ${rule_id}
650     BuiltIn.Should Be True    '${rc}' == '0'
651     [Return]    ${output}    ${rule_id}
652
653 Neutron Security Group Rule Create Legacy Cli
654     [Arguments]    ${Security_group_name}    &{Kwargs}
655     [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]} ..."
656     BuiltIn.Run Keyword If    ${Kwargs}    BuiltIn.Log    ${Kwargs}
657     ${description}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    description    default=${None}
658     ${direction}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    direction    default=${None}
659     ${ethertype}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    ethertype    default=${None}
660     ${port_range_max}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    port_range_max    default=${None}
661     ${port_range_min}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    port_range_min    default=${None}
662     ${protocol}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    protocol    default=${None}
663     ${remote_group_id}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    remote_group_id    default=${None}
664     ${remote_ip_prefix}    BuiltIn.Run Keyword If    ${Kwargs}    Collections.Pop From Dictionary    ${Kwargs}    remote_ip_prefix    default=${None}
665     ${cmd} =    BuiltIn.Set Variable    neutron security-group-rule-create ${Security_group_name}
666     ${cmd} =    BuiltIn.Run Keyword If    '${description}'!='None'    BuiltIn.Catenate    ${cmd}    --description ${description}
667     ...    ELSE    BuiltIn.Catenate    ${cmd}
668     ${cmd} =    BuiltIn.Run Keyword If    '${direction}'!='None'    BuiltIn.Catenate    ${cmd}    --direction ${direction}
669     ...    ELSE    BuiltIn.Catenate    ${cmd}
670     ${cmd} =    BuiltIn.Run Keyword If    '${ethertype}'!='None'    BuiltIn.Catenate    ${cmd}    --ethertype ${ethertype}
671     ...    ELSE    BuiltIn.Catenate    ${cmd}
672     ${cmd} =    BuiltIn.Run Keyword If    '${port_range_max}'!='None'    BuiltIn.Catenate    ${cmd}    --port_range_max ${port_range_max}
673     ...    ELSE    BuiltIn.Catenate    ${cmd}
674     ${cmd} =    BuiltIn.Run Keyword If    '${port_range_min}'!='None'    BuiltIn.Catenate    ${cmd}    --port_range_min ${port_range_min}
675     ...    ELSE    BuiltIn.Catenate    ${cmd}
676     ${cmd} =    BuiltIn.Run Keyword If    '${protocol}'!='None'    BuiltIn.Catenate    ${cmd}    --protocol ${protocol}
677     ...    ELSE    BuiltIn.Catenate    ${cmd}
678     ${cmd} =    BuiltIn.Run Keyword If    '${remote_group_id}'!='None'    BuiltIn.Catenate    ${cmd}    --remote_group_id ${remote_group_id}
679     ...    ELSE    BuiltIn.Catenate    ${cmd}
680     ${cmd} =    BuiltIn.Run Keyword If    '${remote_ip_prefix}'!='None'    BuiltIn.Catenate    ${cmd}    --remote_ip_prefix ${remote_ip_prefix}
681     ...    ELSE    BuiltIn.Catenate    ${cmd}
682     ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    ${cmd}
683     ${rule_id} =    BuiltIn.Should Match Regexp    ${output}    ${REGEX_UUID}
684     BuiltIn.Log    ${rule_id}
685     BuiltIn.Should Be True    '${rc}' == '0'
686     [Return]    ${output}    ${rule_id}
687
688 Security Group Create Without Default Security Rules
689     [Arguments]    ${sg_name}    ${additional_args}=${EMPTY}
690     [Documentation]    Create Neutron Security Group with no default rules, using specified name and optional arguments.
691     OpenStackOperations.Neutron Security Group Create    ${sg_name}    ${additional_args}
692     Delete All Security Group Rules    ${sg_name}
693
694 Delete All Security Group Rules
695     [Arguments]    ${sg_name}
696     [Documentation]    Delete all security rules from a specified security group
697     ${sg_rules_output} =    OpenStack CLI    openstack security group rule list ${sg_name} -cID -fvalue
698     @{sg_rules} =    String.Split String    ${sg_rules_output}    \n
699     : FOR    ${rule}    IN    @{sg_rules}
700     \    ${output} =    OpenStack CLI    openstack security group rule delete ${rule}
701
702 Create Allow All SecurityGroup
703     [Arguments]    ${sg_name}    ${ether_type}=IPv4
704     [Documentation]    Allow all TCP/UDP/ICMP packets for this suite
705     OpenStackOperations.Neutron Security Group Create    ${sg_name}
706     OpenStackOperations.Neutron Security Group Rule Create    ${sg_name}    direction=ingress    ethertype=${ether_type}    port_range_max=65535    port_range_min=1    protocol=tcp
707     OpenStackOperations.Neutron Security Group Rule Create    ${sg_name}    direction=egress    ethertype=${ether_type}    port_range_max=65535    port_range_min=1    protocol=tcp
708     OpenStackOperations.Neutron Security Group Rule Create    ${sg_name}    direction=ingress    ethertype=${ether_type}    protocol=icmp
709     OpenStackOperations.Neutron Security Group Rule Create    ${sg_name}    direction=egress    ethertype=${ether_type}    protocol=icmp
710     OpenStackOperations.Neutron Security Group Rule Create    ${sg_name}    direction=ingress    ethertype=${ether_type}    port_range_max=65535    port_range_min=1    protocol=udp
711     OpenStackOperations.Neutron Security Group Rule Create    ${sg_name}    direction=egress    ethertype=${ether_type}    port_range_max=65535    port_range_min=1    protocol=udp
712
713 Create Neutron Port With Additional Params
714     [Arguments]    ${network_name}    ${port_name}    ${additional_args}=${EMPTY}
715     [Documentation]    Create Port With given additional parameters
716     ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    neutron -v port-create ${network_name} --name ${port_name} ${additional_args}
717     BuiltIn.Log    ${output}
718     BuiltIn.Should Be True    '${rc}' == '0'
719     ${port_id} =    BuiltIn.Should Match Regexp    ${OUTPUT}    ${REGEX_UUID}
720     [Return]    ${OUTPUT}    ${port_id}
721
722 Get Ports MacAddr
723     [Arguments]    ${ports}
724     [Documentation]    Retrieve the port MacAddr for the given list of port name and return the MAC address list.
725     ${macs}    BuiltIn.Create List
726     : FOR    ${port}    IN    @{ports}
727     \    ${mac} =    OpenStackOperations.Get Port Mac    ${port}
728     \    Collections.Append To List    ${macs}    ${mac}
729     [Return]    ${macs}
730
731 Get Port Ip
732     [Arguments]    ${port_name}
733     [Documentation]    Keyword would return the IP of the ${port_name} received.
734     ${output} =    OpenStack CLI    openstack port list | grep "${port_name}" | awk -F\\' '{print $2}'
735     ${splitted_output} =    String.Split String    ${output}    ${EMPTY}
736     ${port_ip} =    Collections.Get from List    ${splitted_output}    0
737     [Return]    ${port_ip}
738
739 Get Port Mac
740     [Arguments]    ${port_name}
741     [Documentation]    Keyword would return the MAC ID of the ${port_name} received.
742     ${output} =    OpenStack CLI    openstack port show ${port_name} | grep mac_address | awk '{print $4}'
743     ${splitted_output} =    String.Split String    ${output}    ${EMPTY}
744     ${port_mac} =    Collections.Get from List    ${splitted_output}    0
745     [Return]    ${port_mac}
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 Create L2Gateway Connection
755     [Arguments]    ${gw_name}    ${net_name}
756     [Documentation]    Keyword would create a new L2 Gateway Connection for ${gw_name} to ${net_name} (Using Neutron CLI).
757     ${rc}    ${l2gw_output} =    OperatingSystem.Run And Return Rc And Output    ${L2GW_CONN_CREATE} ${gw_name} ${net_name}
758     BuiltIn.Log    ${l2gw_output}
759     BuiltIn.Should Be True    '${rc}' == '0'
760     [Return]    ${l2gw_output}
761
762 Get All L2Gateway
763     [Documentation]    Keyword to return all the L2 Gateways available (Using Neutron CLI).
764     ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    ${L2GW_GET_YAML}
765     BuiltIn.Should Be True    '${rc}' == '0'
766     [Return]    ${output}
767
768 Get All L2Gateway Connection
769     [Documentation]    Keyword to return all the L2 Gateway connections available (Using Neutron CLI).
770     ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    ${L2GW_GET_CONN_YAML}
771     BuiltIn.Should Be True    '${rc}' == '0'
772     [Return]    ${output}
773
774 Get L2Gateway
775     [Arguments]    ${gw_id}
776     [Documentation]    Keyword to check if the ${gw_id} is available in the L2 Gateway list (Using Neutron CLI).
777     ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    ${L2GW_SHOW} ${gw_id}
778     BuiltIn.Log    ${output}
779     BuiltIn.Should Be True    '${rc}' == '0'
780     [Return]    ${output}
781
782 Get L2gw Id
783     [Arguments]    ${l2gw_name}
784     [Documentation]    Keyword to retrieve the L2 Gateway ID for the ${l2gw_name} (Using Neutron CLI).
785     ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    ${L2GW_GET} | grep "${l2gw_name}" | awk '{print $2}'
786     BuiltIn.Log    ${output}
787     BuiltIn.Should Be True    '${rc}' == '0'
788     ${splitted_output} =    String.Split String    ${output}    ${EMPTY}
789     ${l2gw_id} =    Collections.Get from List    ${splitted_output}    0
790     [Return]    ${l2gw_id}
791
792 Get L2gw Connection Id
793     [Arguments]    ${l2gw_name}
794     [Documentation]    Keyword to retrieve the L2 Gateway Connection ID for the ${l2gw_name} (Using Neutron CLI).
795     ${l2gw_id} =    OpenStackOperations.Get L2gw Id    ${l2gw_name}
796     ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    ${L2GW_GET_CONN} | grep "${l2gw_id}" | awk '{print $2}'
797     BuiltIn.Should Be True    '${rc}' == '0'
798     ${splitted_output} =    String.Split String    ${output}    ${EMPTY}
799     ${splitted_output} =    String.Split String    ${output}    ${EMPTY}
800     ${l2gw_conn_id} =    Collections.Get from List    ${splitted_output}    0
801     [Return]    ${l2gw_conn_id}
802
803 Neutron Port List Rest
804     [Documentation]    Keyword to get all ports details in Neutron (Using REST).
805     ${resp} =    RequestsLibrary.Get Request    session    ${PORT_URL}
806     BuiltIn.Log    ${resp.content}
807     BuiltIn.Should Be Equal As Strings    ${resp.status_code}    200
808     [Return]    ${resp.content}
809
810 Get Neutron Port Rest
811     [Arguments]    ${port_id}
812     [Documentation]    Keyword to get the specific port details in Neutron (Using REST).
813     ${resp} =    RequestsLibrary.Get Request    session    ${CONFIG_API}/${GET_PORT_URL}/${port_id}
814     BuiltIn.Log    ${resp.content}
815     BuiltIn.Should Be Equal As Strings    ${resp.status_code}    200
816     [Return]    ${resp.content}
817
818 Update Port Rest
819     [Arguments]    ${port_id}    ${json_data}
820     [Documentation]    Keyword to update ${port_id} with json data received in ${json_data} (Using REST).
821     BuiltIn.Log    ${json_data}
822     ${resp} =    RequestsLibrary.Put Request    session    ${CONFIG_API}/${GET_PORT_URL}/${port_id}    ${json_data}
823     BuiltIn.Log    ${resp.content}
824     BuiltIn.Should Be Equal As Strings    ${resp.status_code}    200
825     [Return]    ${resp.content}
826
827 Create And Configure Security Group
828     [Arguments]    ${sg-name}
829     [Documentation]    Create Security Group with given name, and default allow rules for TCP/UDP/ICMP protocols.
830     OpenStackOperations.Neutron Security Group Create    ${sg-name}
831     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
832     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
833     OpenStackOperations.Neutron Security Group Rule Create    ${sg-name}    direction=ingress    protocol=icmp    remote_ip_prefix=0.0.0.0/0
834     OpenStackOperations.Neutron Security Group Rule Create    ${sg-name}    direction=egress    protocol=icmp    remote_ip_prefix=0.0.0.0/0
835     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
836     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
837
838 Add Security Group To VM
839     [Arguments]    ${vm}    ${sg}
840     [Documentation]    Add the security group provided to the given VM.
841     ${output} =    OpenStack CLI    openstack server add security group ${vm} ${sg}
842
843 Remove Security Group From VM
844     [Arguments]    ${vm}    ${sg}
845     [Documentation]    Remove the security group provided to the given VM.
846     OpenStackOperations.Get ControlNode Connection
847     ${output} =    OpenStack CLI    openstack server remove security group ${vm} ${sg}
848
849 Create SFC Flow Classifier
850     [Arguments]    ${name}    ${src_ip}    ${dest_ip}    ${protocol}    ${dest_port}    ${neutron_src_port}
851     [Documentation]    Create a flow classifier for SFC
852     ${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}
853     BuiltIn.Should Contain    ${output}    ${name}
854     [Return]    ${output}
855
856 Delete SFC Flow Classifier
857     [Arguments]    ${name}
858     [Documentation]    Delete a SFC flow classifier
859     OpenStackOperations.Get ControlNode Connection
860     ${output} =    OpenStack CLI    openstack sfc flow classifier delete ${name}
861     [Return]    ${output}
862
863 Create SFC Port Pair
864     [Arguments]    ${name}    ${port_in}    ${port_out}
865     [Documentation]    Creates a neutron port pair for SFC
866     OpenStackOperations.Get ControlNode Connection
867     ${output} =    OpenStack CLI    openstack sfc port pair create --ingress=${port_in} --egress=${port_out} ${name}
868     BuiltIn.Should Contain    ${output}    ${name}
869     [Return]    ${output}
870
871 Delete SFC Port Pair
872     [Arguments]    ${name}
873     [Documentation]    Delete a SFC port pair
874     ${output} =    OpenStack CLI    openstack sfc port pair delete ${name}
875     [Return]    ${output}
876
877 Create SFC Port Pair Group
878     [Arguments]    ${name}    ${port_pair}
879     [Documentation]    Creates a port pair group with a single port pair for SFC
880     ${output} =    OpenStack CLI    openstack sfc port pair group create --port-pair ${port_pair} ${name}
881     BuiltIn.Should Contain    ${output}    ${name}
882     [Return]    ${output}
883
884 Create SFC Port Pair Group With Two Pairs
885     [Arguments]    ${name}    ${port_pair1}    ${port_pair2}
886     [Documentation]    Creates a port pair group with two port pairs for SFC
887     ${output} =    OpenStack CLI    openstack sfc port pair group create --port-pair ${port_pair1} --port-pair ${port_pair2} ${name}
888     BuiltIn.Should Contain    ${output}    ${name}
889     [Return]    ${output}
890
891 Delete SFC Port Pair Group
892     [Arguments]    ${name}
893     [Documentation]    Delete a SFC port pair group
894     OpenStackOperations.Get ControlNode Connection
895     ${output} =    OpenStack CLI    openstack sfc port pair group delete ${name}
896     [Return]    ${output}
897
898 Create SFC Port Chain
899     [Arguments]    ${name}    ${pg1}    ${pg2}    ${fc}
900     [Documentation]    Creates a port pair chain with two port groups and a singel classifier.
901     ${output} =    OpenStack CLI    openstack sfc port chain create --port-pair-group ${pg1} --port-pair-group ${pg2} --flow-classifier ${fc} ${name}
902     BuiltIn.Should Contain    ${output}    ${name}
903     [Return]    ${output}
904
905 Delete SFC Port Chain
906     [Arguments]    ${name}
907     [Documentation]    Delete a SFC port chain
908     ${output} =    OpenStack CLI    openstack sfc port chain delete ${name}
909     [Return]    ${output}
910
911 Reboot Nova VM
912     [Arguments]    ${vm_name}
913     [Documentation]    Reboot NOVA VM
914     ${output} =    OpenStack CLI    openstack server reboot --wait ${vm_name}
915     BuiltIn.Wait Until Keyword Succeeds    35s    10s    OpenStackOperations.Verify VM Is ACTIVE    ${vm_name}
916
917 Remove RSA Key From KnownHosts
918     [Arguments]    ${vm_ip}
919     [Documentation]    Remove RSA
920     OpenStackOperations.Get ControlNode Connection
921     ${output} =    DevstackUtils.Write Commands Until Prompt And Log    sudo cat /root/.ssh/known_hosts    30s
922     ${output} =    DevstackUtils.Write Commands Until Prompt And Log    sudo ssh-keygen -f "/root/.ssh/known_hosts" -R ${vm_ip}    30s
923     ${output} =    DevstackUtils.Write Commands Until Prompt    sudo cat "/root/.ssh/known_hosts"    30s
924
925 Wait For Routes To Propogate
926     [Arguments]    ${networks}    ${subnets}
927     [Documentation]    Check propagated routes
928     OpenStackOperations.Get ControlNode Connection
929     : FOR    ${INDEX}    IN RANGE    0    1
930     \    ${net_id} =    OpenStackOperations.Get Net Id    @{networks}[${INDEX}]
931     \    ${is_ipv6} =    String.Get Regexp Matches    @{subnets}[${INDEX}]    ${IP6_REGEX}
932     \    ${length} =    BuiltIn.Get Length    ${is_ipv6}
933     \    ${cmd} =    BuiltIn.Set Variable If    ${length} == 0    ip route    ip -6 route
934     \    ${output} =    Utils.Write Commands Until Expected Prompt    sudo ip netns exec qdhcp-${net_id} ${cmd}    ]>
935     \    BuiltIn.Should Contain    ${output}    @{subnets}[${INDEX}]
936
937 Neutron Cleanup
938     [Arguments]    ${vms}=@{EMPTY}    ${networks}=@{EMPTY}    ${subnets}=@{EMPTY}    ${ports}=@{EMPTY}    ${sgs}=@{EMPTY}
939     : FOR    ${vm}    IN    @{vms}
940     \    BuiltIn.Run Keyword And Ignore Error    Delete Vm Instance    ${vm}
941     : FOR    ${port}    IN    @{ports}
942     \    BuiltIn.Run Keyword And Ignore Error    Delete Port    ${port}
943     : FOR    ${subnet}    IN    @{subnets}
944     \    BuiltIn.Run Keyword And Ignore Error    Delete SubNet    ${subnet}
945     : FOR    ${network}    IN    @{networks}
946     \    BuiltIn.Run Keyword And Ignore Error    Delete Network    ${network}
947     : FOR    ${sg}    IN    @{sgs}
948     \    BuiltIn.Run Keyword And Ignore Error    Delete SecurityGroup    ${sg}
949
950 OpenStack List All
951     [Documentation]    Get a list of different OpenStack resources that might be in use.
952     @{modules} =    BuiltIn.Create List    server    port    network    subnet    security group
953     ...    security group rule
954     BuiltIn.Run Keyword If    "${ODL_ENABLE_L3_FWD}"=="yes"    Collections.Append To List    ${modules}    floating ip    router
955     : FOR    ${module}    IN    @{modules}
956     \    ${output} =    OpenStack CLI    openstack ${module} list
957
958 OpenStack CLI Get List
959     [Arguments]    ${cmd}
960     [Documentation]    Return a json list from the output of an OpenStack command.
961     @{list} =    BuiltIn.Create List
962     ${json} =    OpenStack CLI    ${cmd}
963     @{list} =    RequestsLibrary.To Json    ${json}
964     BuiltIn.Log    ${list}
965     [Return]    @{list}
966
967 OpenStack CLI
968     [Arguments]    ${cmd}
969     [Documentation]    Run the given OpenStack ${cmd} and log the output.
970     ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    ${cmd}
971     BuiltIn.Log    ${output}
972     BuiltIn.Should Be True    '${rc}' == '0'
973     [Return]    ${output}
974
975 OpenStack CLI With No Log
976     [Arguments]    ${cmd}
977     [Documentation]    Run the given OpenStack ${cmd} and do not log the output.
978     ${rc}    ${output} =    OperatingSystem.Run And Return Rc And Output    ${cmd}
979     BuiltIn.Should Be True    '${rc}' == '0'
980     [Return]    ${output}
981
982 OpenStack Cleanup All
983     [Documentation]    Cleanup all Openstack resources with best effort. The keyword will query for all resources
984     ...    in use and then attempt to delete them. Errors are ignored to allow the cleanup to continue.
985     @{fips} =    BuiltIn.Run Keyword If    "${ODL_ENABLE_L3_FWD}"=="yes"    OpenStack CLI Get List    openstack floating ip list -f json
986     ...    ELSE    BuiltIn.Create List    @{EMPTY}
987     : FOR    ${fip}    IN    @{fips}
988     \    BuiltIn.Run Keyword And Ignore Error    Delete Floating IP    ${fip['ID']}
989     @{vms} =    OpenStack CLI Get List    openstack server list -f json
990     : FOR    ${vm}    IN    @{vms}
991     \    BuiltIn.Run Keyword And Ignore Error    Delete Vm Instance    ${vm['ID']}
992     @{routers} =    BuiltIn.Run Keyword If    "${ODL_ENABLE_L3_FWD}"=="yes"    OpenStack CLI Get List    openstack router list -f json
993     ...    ELSE    BuiltIn.Create List    @{EMPTY}
994     : FOR    ${router}    IN    @{routers}
995     \    BuiltIn.Run Keyword And Ignore Error    Cleanup Router    ${router['ID']}
996     @{ports} =    OpenStack CLI Get List    openstack port list -f json
997     : FOR    ${port}    IN    @{ports}
998     \    BuiltIn.Run Keyword And Ignore Error    Delete Port    ${port['ID']}
999     @{networks} =    OpenStack CLI Get List    openstack network list -f json
1000     : FOR    ${network}    IN    @{networks}
1001     \    BuiltIn.Run Keyword And Ignore Error    Delete Subnet    ${network['Subnets']}
1002     \    BuiltIn.Run Keyword And Ignore Error    Delete Network    ${network['ID']}
1003     @{security_groups} =    OpenStack CLI Get List    openstack security group list -f json
1004     : FOR    ${security_group}    IN    @{security_groups}
1005     \    BuiltIn.Run Keyword If    "${security_group['Name']}" != "default"    BuiltIn.Run Keyword And Ignore Error    Delete SecurityGroup    ${security_group['ID']}
1006     OpenStack List All
1007
1008 Cleanup Router
1009     [Arguments]    ${id}
1010     [Documentation]    Delete a router, but first remove any interfaces or gateways so that the delete will be successful.
1011     @{ports} =    OpenStack CLI Get List    openstack port list --router ${id} -f json --long
1012     : FOR    ${port}    IN    @{ports}
1013     \    ${subnet_id} =    OpenStackOperations.Get Match    ${port['Fixed IP Addresses']}    ${REGEX_UUID}    0
1014     \    BuiltIn.Run Keyword If    "${port['Device Owner']}" == "network:router_gateway"    BuiltIn.Run Keyword And Ignore Error    Remove Gateway    ${id}
1015     \    BuiltIn.Run Keyword If    "${port['Device Owner']}" == "network:router_interface"    BuiltIn.Run Keyword And Ignore Error    Remove Interface    ${id}    ${subnet_id}
1016     BuiltIn.Run Keyword And Ignore Error    Delete Router    ${id}
1017
1018 OpenStack Suite Setup
1019     [Documentation]    Wrapper teardown keyword that can be used in any suite running in an openstack environement
1020     SetupUtils.Setup_Utils_For_Setup_And_Teardown
1021     @{tcpdump_port_6653_conn_ids} =    OpenStackOperations.Start Packet Capture On Nodes    tcpdump_port_6653    port 6653    ${OS_CONTROL_NODE_IP}    ${OS_COMPUTE_1_IP}    ${OS_COMPUTE_2_IP}
1022     BuiltIn.Set Suite Variable    @{tcpdump_port_6653_conn_ids}
1023     BuiltIn.Run Keyword If    "${PRE_CLEAN_OPENSTACK_ALL}"=="True"    OpenStack Cleanup All
1024     DevstackUtils.Devstack Suite Setup
1025     OpenStackOperations.Add OVS Logging On All OpenStack Nodes
1026
1027 OpenStack Suite Teardown
1028     [Documentation]    Wrapper teardown keyword that can be used in any suite running in an openstack environement
1029     ...    to clean up all openstack resources. For example, all instances, networks, ports, etc will be listed and
1030     ...    and deleted. As other global cleanup tasks are needed, they can be added here and the suites will all
1031     ...    benefit automatically.
1032     OpenStack Cleanup All
1033     OpenStackOperations.Stop Packet Capture On Nodes    ${tcpdump_port_6653_conn_ids}
1034     SSHLibrary.Close All Connections
1035
1036 Copy DHCP Files From Control Node
1037     [Documentation]    Copy the current DHCP files to the robot vm. The keyword must be called
1038     ...    after the subnet(s) are created and before the subnet(s) are deleted.
1039     ${suite_} =    BuiltIn.Evaluate    """${SUITE_NAME}""".replace(" ","_").replace("/","_").replace(".","_")
1040     ${dstdir} =    BuiltIn.Set Variable    /tmp/qdhcp/${suite_}
1041     OperatingSystem.Create Directory    ${dstdir}
1042     OpenStackOperations.Get ControlNode Connection
1043     BuiltIn.Run Keyword And Ignore Error    SSHLibrary.Get Directory    /opt/stack/data/neutron/dhcp    ${dstdir}    recursive=True
1044
1045 Is Feature Installed
1046     [Arguments]    ${features}=none
1047     : FOR    ${feature}    IN    @{features}
1048     \    ${status}    ${output}    BuiltIn.Run Keyword And Ignore Error    BuiltIn.Should Contain    ${CONTROLLERFEATURES}    ${feature}
1049     \    Return From Keyword If    "${status}" == "PASS"    True
1050     [Return]    False
1051
1052 Add OVS Logging On All OpenStack Nodes
1053     [Documentation]    Add higher levels of OVS logging to all the OpenStack nodes
1054     BuiltIn.Run Keyword If    0 < ${NUM_OS_SYSTEM}    OVSDB.Add OVS Logging    ${OS_CNTL_CONN_ID}
1055     BuiltIn.Run Keyword If    1 < ${NUM_OS_SYSTEM}    OVSDB.Add OVS Logging    ${OS_CMP1_CONN_ID}
1056     BuiltIn.Run Keyword If    2 < ${NUM_OS_SYSTEM}    OVSDB.Add OVS Logging    ${OS_CMP2_CONN_ID}
1057
1058 Reset OVS Logging On All OpenStack Nodes
1059     [Documentation]    Reset the OVS logging to all the OpenStack nodes
1060     BuiltIn.Run Keyword If    0 < ${NUM_OS_SYSTEM}    OVSDB.Reset OVS Logging    ${OS_CNTL_CONN_ID}
1061     BuiltIn.Run Keyword If    1 < ${NUM_OS_SYSTEM}    OVSDB.Reset OVS Logging    ${OS_CMP1_CONN_ID}
1062     BuiltIn.Run Keyword If    2 < ${NUM_OS_SYSTEM}    OVSDB.Reset OVS Logging    ${OS_CMP2_CONN_ID}
1063
1064 Start Packet Capture On Nodes
1065     [Arguments]    ${tag}    ${filter}    @{ips}
1066     [Documentation]    Wrapper keyword around the TcpDump packet capture that is catered to the Openstack setup.
1067     ...    The caller must pass the three arguments with a variable number of ips at the end,
1068     ...    but ${EMPTY} can be used for the tag and filter.
1069     ${suite_} =    BuiltIn.Evaluate    """${SUITE_NAME}""".replace(" ","_").replace("/","_").replace(".","_")
1070     ${tag_} =    BuiltIn.Catenate    SEPARATOR=__    ${tag}    ${suite_}
1071     @{conn_ids} =    Tcpdump.Start Packet Capture on Nodes    tag=${tag_}    filter=${filter}    ips=${ips}
1072     [Return]    @{conn_ids}
1073
1074 Stop Packet Capture On Nodes
1075     [Arguments]    ${conn_ids}=@{EMPTY}
1076     Tcpdump.Stop Packet Capture on Nodes    ${conn_ids}