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