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