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