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