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