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