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