refactor dhcp function
[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           SSHLibrary
4 Resource          Netvirt.robot
5 Resource          Utils.robot
6 Resource          L2GatewayOperations.robot
7 Resource          ../variables/Variables.robot
8
9 *** Keywords ***
10 Source Password
11     [Arguments]    ${force}=no    ${source_pwd}=yes
12     [Documentation]    Sourcing the Openstack PAsswords for neutron configurations
13     Run Keyword If    '${source_pwd}' == 'yes' or '${force}' == 'yes'    Write Commands Until Prompt    cd ${DEVSTACK_DEPLOY_PATH}; source openrc admin admin
14
15 Get Tenant ID From Security Group
16     [Documentation]    Returns tenant ID by reading it from existing default security-group.
17     ${devstack_conn_id}=    Get ControlNode Connection
18     Switch Connection    ${devstack_conn_id}
19     ${output}=    Write Commands Until Prompt    neutron security-group-show default | grep "| tenant_id" | awk '{print $4}'
20     Log    ${output}
21     [Return]    ${output}
22
23 Get Tenant ID From Network
24     [Arguments]    ${network_uuid}
25     [Documentation]    Returns tenant ID by reading it from existing network.
26     ${resp}=    Get_From_Uri    uri=${CONFIG_API}/neutron:neutron/networks/network/${network_uuid}/    accept=${ACCEPT_EMPTY}    session=session
27     ${tenant_id}=    Utils.Extract Value From Content    ${resp}    /network/0/tenant-id    strip
28     [Return]    ${tenant_id}
29
30 Create Network
31     [Arguments]    ${network_name}    ${additional_args}=${EMPTY}    ${verbose}=TRUE
32     [Documentation]    Create Network with neutron request.
33     ${devstack_conn_id}=    Get ControlNode Connection
34     Switch Connection    ${devstack_conn_id}
35     ${command}    Set Variable If    "${verbose}" == "TRUE"    neutron -v net-create ${network_name} ${additional_args}    neutron net-create ${network_name} ${additional_args} | grep -w id | awk '{print $4}'
36     ${output}=    Write Commands Until Prompt    ${command}    30s
37     Log    ${output}
38     [Return]    ${output}
39
40 List Networks
41     [Documentation]    List networks and return output with neutron client.
42     ${devstack_conn_id}=    Get ControlNode Connection
43     Switch Connection    ${devstack_conn_id}
44     ${output}=    Write Commands Until Prompt    neutron net-list    30s
45     Close Connection
46     Log    ${output}
47     [Return]    ${output}
48
49 List Subnets
50     [Documentation]    List subnets and return output with neutron client.
51     ${devstack_conn_id}=    Get ControlNode Connection
52     Switch Connection    ${devstack_conn_id}
53     ${output}=    Write Commands Until Prompt    neutron subnet-list    30s
54     Close Connection
55     Log    ${output}
56     [Return]    ${output}
57
58 Delete Network
59     [Arguments]    ${network_name}
60     [Documentation]    Delete Network with neutron request.
61     ${devstack_conn_id}=    Get ControlNode Connection
62     Switch Connection    ${devstack_conn_id}
63     ${output}=    Write Commands Until Prompt    neutron -v net-delete ${network_name}    30s
64     Close Connection
65     Log    ${output}
66     Should Match Regexp    ${output}    Deleted network: ${network_name}|Deleted network\\(s\\): ${network_name}
67
68 Create SubNet
69     [Arguments]    ${network_name}    ${subnet}    ${range_ip}    ${additional_args}=${EMPTY}
70     [Documentation]    Create SubNet for the Network with neutron request.
71     ${devstack_conn_id}=    Get ControlNode Connection
72     Switch Connection    ${devstack_conn_id}
73     ${output}=    Write Commands Until Prompt    neutron -v subnet-create ${network_name} ${range_ip} --name ${subnet} ${additional_args}    30s
74     Close Connection
75     Log    ${output}
76     Should Contain    ${output}    Created a new subnet
77
78 Create Port
79     [Arguments]    ${network_name}    ${port_name}    ${sg}=default    ${additional_args}=${EMPTY}
80     [Documentation]    Create Port with neutron request.
81     ${devstack_conn_id}=    Get ControlNode Connection
82     Switch Connection    ${devstack_conn_id}
83     ${output}=    Write Commands Until Prompt    neutron -v port-create ${network_name} --name ${port_name} --security-group ${sg} ${additional_args}    30s
84     Close Connection
85     Log    ${output}
86     Should Contain    ${output}    Created a new port
87
88 Delete Port
89     [Arguments]    ${port_name}
90     [Documentation]    Delete Port with neutron request.
91     ${devstack_conn_id}=    Get ControlNode Connection
92     Switch Connection    ${devstack_conn_id}
93     ${output}=    Write Commands Until Prompt    neutron -v port-delete ${port_name}    30s
94     Close Connection
95     Log    ${output}
96     Should Match Regexp    ${output}    Deleted port: ${port_name}|Deleted port\\(s\\): ${port_name}
97
98 List Ports
99     [Documentation]    List ports and return output with neutron client.
100     ${devstack_conn_id}=    Get ControlNode Connection
101     Switch Connection    ${devstack_conn_id}
102     ${output}=    Write Commands Until Prompt    neutron port-list    30s
103     Close Connection
104     Log    ${output}
105     [Return]    ${output}
106
107 List Nova VMs
108     [Documentation]    List VMs and return output with nova client.
109     ${devstack_conn_id}=    Get ControlNode Connection
110     Switch Connection    ${devstack_conn_id}
111     ${output}=    Write Commands Until Prompt    nova list    30s
112     Close Connection
113     Log    ${output}
114     [Return]    ${output}
115
116 Create And Associate Floating IPs
117     [Arguments]    ${external_net}    @{vm_list}
118     [Documentation]    Create and associate floating IPs to VMs with nova request
119     ${devstack_conn_id}=    Get ControlNode Connection
120     Switch Connection    ${devstack_conn_id}
121     ${ip_list}=    Create List    @{EMPTY}
122     : FOR    ${vm}    IN    @{vm_list}
123     \    ${output}=    Write Commands Until Prompt    neutron floatingip-create ${external_net}    30s
124     \    Log    ${output}
125     \    @{ip}    Get Regexp Matches    ${output}    [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}
126     \    ${ip_length}    Get Length    ${ip}
127     \    Run Keyword If    ${ip_length}>0    Append To List    ${ip_list}    @{ip}[0]
128     \    ...    ELSE    Append To List    ${ip_list}    None
129     \    ${output}=    Write Commands Until Prompt    nova floating-ip-associate ${vm} @{ip}[0]    30s
130     \    Log    ${output}
131     [Return]    ${ip_list}
132
133 Verify Gateway Ips
134     [Documentation]    Verifies the Gateway Ips with dump flow.
135     ${output}=    Write Commands Until Prompt    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
136     Log    ${output}
137     : FOR    ${GatewayIpElement}    IN    @{GATEWAY_IPS}
138     \    Should Contain    ${output}    ${GatewayIpElement}
139
140 Verify Dhcp Ips
141     [Documentation]    Verifies the Dhcp Ips with dump flow.
142     ${output}=    Write Commands Until Prompt    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
143     Log    ${output}
144     : FOR    ${DhcpIpElement}    IN    @{DHCP_IPS}
145     \    Should Contain    ${output}    ${DhcpIpElement}
146
147 Verify No Dhcp Ips
148     [Documentation]    Verifies the Dhcp Ips with dump flow.
149     ${output}=    Write Commands Until Prompt    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
150     Log    ${output}
151     : FOR    ${DhcpIpElement}    IN    @{DHCP_IPS}
152     \    Should Not Contain    ${output}    ${DhcpIpElement}
153
154 Delete SubNet
155     [Arguments]    ${subnet}
156     [Documentation]    Delete SubNet for the Network with neutron request.
157     Log    ${subnet}
158     ${devstack_conn_id}=    Get ControlNode Connection
159     Switch Connection    ${devstack_conn_id}
160     ${output}=    Write Commands Until Prompt    neutron -v subnet-delete ${subnet}
161     Close Connection
162     Log    ${output}
163     Should Match Regexp    ${output}    Deleted subnet: ${subnet}|Deleted subnet\\(s\\): ${subnet}
164
165 Verify No Gateway Ips
166     [Documentation]    Verifies the Gateway Ips removed with dump flow.
167     ${output}=    Write Commands Until Prompt    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
168     Log    ${output}
169     : FOR    ${GatewayIpElement}    IN    @{GATEWAY_IPS}
170     \    Should Not Contain    ${output}    ${GatewayIpElement}
171
172 Delete Vm Instance
173     [Arguments]    ${vm_name}
174     [Documentation]    Delete Vm instances using instance names.
175     ${devstack_conn_id}=    Get ControlNode Connection
176     Switch Connection    ${devstack_conn_id}
177     ${output}=    Write Commands Until Prompt    nova force-delete ${vm_name}    40s
178     Close Connection
179
180 Get Net Id
181     [Arguments]    ${network_name}    ${devstack_conn_id}
182     [Documentation]    Retrieve the net id for the given network name to create specific vm instance
183     Switch Connection    ${devstack_conn_id}
184     ${output}=    Write Commands Until Prompt    neutron net-list | grep "${network_name}" | awk '{print $2}'    30s
185     Log    ${output}
186     ${splitted_output}=    Split String    ${output}    ${EMPTY}
187     ${net_id}=    Get from List    ${splitted_output}    0
188     Log    ${net_id}
189     [Return]    ${net_id}
190
191 Get Subnet Id
192     [Arguments]    ${subnet_name}    ${devstack_conn_id}
193     [Documentation]    Retrieve the subnet id for the given subnet name
194     Switch Connection    ${devstack_conn_id}
195     ${output}=    Write Commands Until Prompt    neutron subnet-list | grep "${subnet_name}" | awk '{print $2}'    30s
196     Log    ${output}
197     ${splitted_output}=    Split String    ${output}    ${EMPTY}
198     ${subnet_id}=    Get from List    ${splitted_output}    0
199     Log    ${subnet_id}
200     [Return]    ${subnet_id}
201
202 Get Port Id
203     [Arguments]    ${port_name}    ${devstack_conn_id}
204     [Documentation]    Retrieve the port id for the given port name to attach specific vm instance to a particular port
205     Switch Connection    ${devstack_conn_id}
206     ${output}=    Write Commands Until Prompt    neutron port-list | grep "${port_name}" | awk '{print $2}'    30s
207     Log    ${output}
208     ${splitted_output}=    Split String    ${output}    ${EMPTY}
209     ${port_id}=    Get from List    ${splitted_output}    0
210     Log    ${port_id}
211     [Return]    ${port_id}
212
213 Get Router Id
214     [Arguments]    ${router1}    ${devstack_conn_id}
215     [Documentation]    Retrieve the router id for the given router name
216     Switch Connection    ${devstack_conn_id}
217     ${output}=    Write Commands Until Prompt    neutron router-list | grep "${router1}" | awk '{print $2}'    30s
218     Log    ${output}
219     ${splitted_output}=    Split String    ${output}    ${EMPTY}
220     ${router_id}=    Get from List    ${splitted_output}    0
221     Log    ${router_id}
222     [Return]    ${router_id}
223
224 Create Vm Instances
225     [Arguments]    ${net_name}    ${vm_instance_names}    ${image}=cirros-0.3.4-x86_64-uec    ${flavor}=m1.nano    ${sg}=default
226     [Documentation]    Create X Vm Instance with the net id of the Netowrk.
227     ${devstack_conn_id}=    Get ControlNode Connection
228     Switch Connection    ${devstack_conn_id}
229     ${net_id}=    Get Net Id    ${net_name}    ${devstack_conn_id}
230     : FOR    ${VmElement}    IN    @{vm_instance_names}
231     \    ${output}=    Write Commands Until Prompt    nova boot --image ${image} --flavor ${flavor} --nic net-id=${net_id} ${VmElement} --security-groups ${sg}    30s
232     \    Log    ${output}
233
234 Create Vm Instance With Port On Compute Node
235     [Arguments]    ${port_name}    ${vm_instance_name}    ${compute_node}    ${image}=cirros-0.3.4-x86_64-uec    ${flavor}=m1.nano    ${sg}=default
236     [Documentation]    Create One VM instance using given ${port_name} and for given ${compute_node}
237     ${devstack_conn_id}=    Get ControlNode Connection
238     Switch Connection    ${devstack_conn_id}
239     ${port_id}=    Get Port Id    ${port_name}    ${devstack_conn_id}
240     ${hostname_compute_node}=    Run Command On Remote System    ${compute_node}    hostname
241     ${output}=    Write Commands Until Prompt    nova boot --image ${image} --flavor ${flavor} --nic port-id=${port_id} ${vm_instance_name} --security-groups ${sg} --availability-zone nova:${hostname_compute_node}    30s
242     Log    ${output}
243
244 Verify VM Is ACTIVE
245     [Arguments]    ${vm_name}
246     [Documentation]    Run these commands to check whether the created vm instance is active or not.
247     ${devstack_conn_id}=    Get ControlNode Connection
248     Switch Connection    ${devstack_conn_id}
249     ${output}=    Write Commands Until Prompt    nova show ${vm_name} | grep OS-EXT-STS:vm_state    30s
250     Log    ${output}
251     Should Contain    ${output}    active
252
253 Collect VM IP Addresses
254     [Arguments]    ${fail_on_none}    @{vm_list}
255     [Documentation]    Using nova console-log on the provided ${vm_list} to search for the string "obtained" which
256     ...    correlates to the instance receiving it's IP address via DHCP. Also retrieved is the ip of the nameserver
257     ...    if available in the console-log output. The keyword will also return a list of the learned ips as it
258     ...    finds them in the console log output, and will have "None" for Vms that no ip was found.
259     ${devstack_conn_id}=    Get ControlNode Connection
260     Switch Connection    ${devstack_conn_id}
261     ${ip_list}    Create List    @{EMPTY}
262     : FOR    ${vm}    IN    @{vm_list}
263     \    ${vm_ip_line}=    Write Commands Until Prompt    nova console-log ${vm} | grep -i "obtained"    30s
264     \    Log    ${vm_ip_line}
265     \    @{vm_ip}    Get Regexp Matches    ${vm_ip_line}    [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}
266     \    ${vm_ip_length}    Get Length    ${vm_ip}
267     \    Run Keyword If    ${vm_ip_length}>0    Append To List    ${ip_list}    @{vm_ip}[0]
268     \    ...    ELSE    Append To List    ${ip_list}    None
269     \    ${dhcp_ip_line}=    Write Commands Until Prompt    nova console-log ${vm} | grep "^nameserver"    30s
270     \    Log    ${dhcp_ip_line}
271     \    ${dhcp_ip}    Get Regexp Matches    ${dhcp_ip_line}    [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}
272     \    ${dhcp_ip_length}    Get Length    ${dhcp_ip}
273     \    Run Keyword If    ${dhcp_ip_length}<=0    Append To List    ${dhcp_ip}    None
274     \    Log    ${dhcp_ip}
275     ${dhcp_length}    Get Length    ${dhcp_ip}
276     Run Keyword If    '${fail_on_none}' == 'true'    Should Not Contain    ${ip_list}    None
277     Run Keyword If    '${fail_on_none}' == 'true'    Should Not Contain    ${dhcp_ip}    None
278     Should Be True    ${dhcp_length} <= 1
279     Return From Keyword If    ${dhcp_length}==0    ${ip_list}    ${EMPTY}
280     [Return]    ${ip_list}    ${dhcp_ip}
281
282 View Vm Console
283     [Arguments]    ${vm_instance_names}
284     [Documentation]    View Console log of the created vm instances using nova show.
285     : FOR    ${VmElement}    IN    @{vm_instance_names}
286     \    ${output}=    Write Commands Until Prompt    nova show ${VmElement}
287     \    Log    ${output}
288     \    ${output}=    Write Commands Until Prompt    nova console-log ${VmElement}
289     \    Log    ${output}
290
291 Ping Vm From DHCP Namespace
292     [Arguments]    ${net_name}    ${vm_ip}
293     [Documentation]    Reach all Vm Instance with the net id of the Netowrk.
294     Log    ${vm_ip}
295     ${devstack_conn_id}=    Get ControlNode Connection
296     Switch Connection    ${devstack_conn_id}
297     ${net_id}=    Get Net Id    ${net_name}    ${devstack_conn_id}
298     Log    ${net_id}
299     ${output}=    Write Commands Until Prompt    sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip}    20s
300     Log    ${output}
301     Close Connection
302     Should Contain    ${output}    64 bytes
303
304 Ping From DHCP Should Not Succeed
305     [Arguments]    ${net_name}    ${vm_ip}
306     [Documentation]    Should Not Reach Vm Instance with the net id of the Netowrk.
307     Log    ${vm_ip}
308     ${devstack_conn_id}=    Get ControlNode Connection
309     Switch Connection    ${devstack_conn_id}
310     ${net_id}=    Get Net Id    ${net_name}    ${devstack_conn_id}
311     Log    ${net_id}
312     ${output}=    Write Commands Until Prompt    sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip}    20s
313     Close Connection
314     Log    ${output}
315     Should Not Contain    ${output}    64 bytes
316
317 Ping Vm From Control Node
318     [Arguments]    ${vm_floating_ip}
319     [Documentation]    Ping VM floating IP from control node
320     Log    ${vm_floating_ip}
321     ${devstack_conn_id}=    Get ControlNode Connection
322     Switch Connection    ${devstack_conn_id}
323     ${output}=    Write Commands Until Prompt    ping -c 3 ${vm_floating_ip}    20s
324     Log    ${output}
325     Close Connection
326     Should Contain    ${output}    64 bytes
327
328 Ping From Instance
329     [Arguments]    ${dest_vm_ip}
330     [Documentation]    Ping to the expected destination ip.
331     ${output}=    Write Commands Until Expected Prompt    ping -c 3 ${dest_vm_ip}    ${OS_SYSTEM_PROMPT}
332     Log    ${output}
333     [Return]    ${output}
334
335 Curl Metadata Server
336     [Documentation]    Ping to the expected destination ip.
337     ${output}=    Write Commands Until Expected Prompt    curl -i http://169.254.169.254    ${OS_SYSTEM_PROMPT}
338     Write Commands Until Prompt    exit
339     Should Contain    ${output}    200
340
341 Close Vm Instance
342     [Documentation]    Exit the vm instance.
343     ${output}=    Write Commands Until Prompt    exit
344     Log    ${output}
345
346 Check If Console Is VmInstance
347     [Arguments]    ${console}=cirros
348     [Documentation]    Check if the session has been able to login to the VM instance
349     ${output}=    Write Commands Until Expected Prompt    id    ${OS_SYSTEM_PROMPT}
350     Should Contain    ${output}    ${console}
351
352 Exit From Vm Console
353     [Documentation]    Check if the session has been able to login to the VM instance and exit the instance
354     ${rcode}=    Run Keyword And Return Status    Check If Console Is VmInstance    cirros
355     Run Keyword If    ${rcode}    Write Commands Until Prompt    exit
356
357 Check Ping
358     [Arguments]    ${ip_address}
359     [Documentation]    Run Ping command on the IP available as argument
360     ${output}=    Write Commands Until Expected Prompt    ping -c 3 ${ip_address}    ${OS_SYSTEM_PROMPT}
361     Should Contain    ${output}    64 bytes
362
363 Check Metadata Access
364     [Documentation]    Try curl on the Metadataurl and check if it is okay
365     ${output}=    Write Commands Until Expected Prompt    curl -i http://169.254.169.254    ${OS_SYSTEM_PROMPT}
366     Should Contain    ${output}    200
367
368 Execute Command on VM Instance
369     [Arguments]    ${net_name}    ${vm_ip}    ${cmd}    ${user}=cirros    ${password}=cubswin:)
370     [Documentation]    Login to the vm instance using ssh in the network, executes a command inside the VM and returns the ouput.
371     ${devstack_conn_id} =    Get ControlNode Connection
372     Switch Connection    ${devstack_conn_id}
373     ${net_id} =    Get Net Id    ${net_name}    ${devstack_conn_id}
374     Log    ${vm_ip}
375     ${output} =    Write Commands Until Expected Prompt    sudo ip netns exec qdhcp-${net_id} ssh ${user}@${vm_ip} -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null    d:
376     Log    ${output}
377     ${output} =    Write Commands Until Expected Prompt    ${password}    ${OS_SYSTEM_PROMPT}
378     Log    ${output}
379     ${rcode} =    Run Keyword And Return Status    Check If Console Is VmInstance
380     ${output} =    Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    ${cmd}    ${OS_SYSTEM_PROMPT}
381     [Teardown]    Exit From Vm Console
382     [Return]    ${output}
383
384 Test Operations From Vm Instance
385     [Arguments]    ${net_name}    ${src_ip}    ${dest_ips}    ${user}=cirros    ${password}=cubswin:)
386     [Documentation]    Login to the vm instance using ssh in the network.
387     ${devstack_conn_id}=    Get ControlNode Connection
388     Switch Connection    ${devstack_conn_id}
389     Log    ${src_ip}
390     ${net_id}=    Get Net Id    ${net_name}    ${devstack_conn_id}
391     ${output}=    Write Commands Until Expected Prompt    sudo ip netns exec qdhcp-${net_id} ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no ${user}@${src_ip} -o UserKnownHostsFile=/dev/null    d:
392     Log    ${output}
393     ${output}=    Write Commands Until Expected Prompt    ${password}    ${OS_SYSTEM_PROMPT}
394     Log    ${output}
395     ${rcode}=    Run Keyword And Return Status    Check If Console Is VmInstance
396     Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    ifconfig    ${OS_SYSTEM_PROMPT}
397     Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    route    ${OS_SYSTEM_PROMPT}
398     Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    arp -an    ${OS_SYSTEM_PROMPT}
399     : FOR    ${dest_ip}    IN    @{dest_ips}
400     \    Log    ${dest_ip}
401     \    ${string_empty}=    Run Keyword And Return Status    Should Be Empty    ${dest_ip}
402     \    Run Keyword If    ${string_empty}    Continue For Loop
403     \    Run Keyword If    ${rcode}    Check Ping    ${dest_ip}
404     Run Keyword If    ${rcode}    Check Metadata Access
405     [Teardown]    Exit From Vm Console
406
407 Install Netcat On Controller
408     [Documentation]    Installs Netcat on the controller - this probably shouldn't be here
409     ${devstack_conn_id}=    Get ControlNode Connection
410     Switch Connection    ${devstack_conn_id}
411     ${output}=    Write Commands Until Prompt    sudo yum install -y nc
412     Log    ${output}
413     Close Connection
414
415 Test Netcat Operations From Vm Instance
416     [Arguments]    ${net_name}    ${vm_ip}    ${dest_ip}    ${additional_args}=${EMPTY}    ${port}=12345    ${user}=cirros
417     ...    ${password}=cubswin:)
418     [Documentation]    Use Netcat to test TCP/UDP connections to the controller
419     ${client_data}    Set Variable    Test Client Data
420     ${server_data}    Set Variable    Test Server Data
421     ${devstack_conn_id}=    Get ControlNode Connection
422     Switch Connection    ${devstack_conn_id}
423     Log    ${vm_ip}
424     ${output}=    Write Commands Until Prompt    ( ( echo "${server_data}" | sudo timeout 60 nc -l ${additional_args} ${port} ) & )
425     Log    ${output}
426     ${output}=    Write Commands Until Prompt    sudo netstat -nlap | grep ${port}
427     Log    ${output}
428     ${nc_output}=    Execute Command on VM Instance    ${net_name}    ${vm_ip}    sudo echo "${client_data}" | nc -v -w 5 ${additional_args} ${dest_ip} ${port}
429     Log    ${nc_output}
430     ${output}=    Execute Command on VM Instance    ${net_name}    ${vm_ip}    sudo route -n
431     Log    ${output}
432     ${output}=    Execute Command on VM Instance    ${net_name}    ${vm_ip}    sudo arp -an
433     Log    ${output}
434     Should Match Regexp    ${nc_output}    ${server_data}
435
436 Ping Other Instances
437     [Arguments]    ${list_of_external_dst_ips}
438     [Documentation]    Check reachability with other network's instances.
439     ${rcode}=    Run Keyword And Return Status    Check If Console Is VmInstance
440     : FOR    ${dest_ip}    IN    @{list_of_external_dst_ips}
441     \    Log    ${dest_ip}
442     \    Check Ping    ${dest_ip}
443
444 Create Router
445     [Arguments]    ${router_name}
446     [Documentation]    Create Router and Add Interface to the subnets.
447     ${devstack_conn_id}=    Get ControlNode Connection
448     Switch Connection    ${devstack_conn_id}
449     ${output}=    Write Commands Until Prompt    neutron -v router-create ${router_name}    30s
450     Close Connection
451     Should Contain    ${output}    Created a new router
452
453 List Router
454     [Documentation]    List Router and return output with neutron client.
455     ${devstack_conn_id}=    Get ControlNode Connection
456     Switch Connection    ${devstack_conn_id}
457     ${output}=    Write Commands Until Prompt    neutron router-list    30s
458     Close Connection
459     Log    ${output}
460     [Return]    ${output}
461
462 Add Router Interface
463     [Arguments]    ${router_name}    ${interface_name}
464     ${devstack_conn_id}=    Get ControlNode Connection
465     Switch Connection    ${devstack_conn_id}
466     ${output}=    Write Commands Until Prompt    neutron -v router-interface-add ${router_name} ${interface_name}
467     Close Connection
468     Should Contain    ${output}    Added interface
469
470 Show Router Interface
471     [Arguments]    ${router_name}
472     [Documentation]    List Router interface associated with given Router and return output with neutron client.
473     ${devstack_conn_id}=    Get ControlNode Connection
474     Switch Connection    ${devstack_conn_id}
475     ${output}=    Write Commands Until Prompt    neutron router-port-list ${router_name} -f csv    30s
476     Close Connection
477     Log    ${output}
478     [Return]    ${output}
479
480 Add Router Gateway
481     [Arguments]    ${router_name}    ${network_name}
482     ${devstack_conn_id}=    Get ControlNode Connection
483     Switch Connection    ${devstack_conn_id}
484     ${output}=    Write Commands Until Prompt    neutron -v router-gateway-set ${router_name} ${network_name}
485     Close Connection
486     Should Contain    ${output}    Set gateway
487
488 Remove Interface
489     [Arguments]    ${router_name}    ${interface_name}
490     [Documentation]    Remove Interface to the subnets.
491     ${devstack_conn_id}=    Get ControlNode Connection
492     Switch Connection    ${devstack_conn_id}
493     ${output}=    Write Commands Until Prompt    neutron -v router-interface-delete ${router_name} ${interface_name}
494     Close Connection
495     Should Contain    ${output}    Removed interface from router
496
497 Update Router
498     [Arguments]    ${router_name}    ${cmd}
499     [Documentation]    Update the router with the command. Router name and command should be passed as argument.
500     ${devstack_conn_id} =    Get ControlNode Connection
501     Switch Connection    ${devstack_conn_id}
502     ${output} =    Write Commands Until Prompt    neutron router-update ${router_name} ${cmd}    30s
503     Close Connection
504     Should Contain    ${output}    Updated
505
506 Show Router
507     [Arguments]    ${router_name}    ${options}
508     [Documentation]    Show information of a given router. Router name and optional fields should be sent as arguments.
509     ${devstack_conn_id} =    Get ControlNode Connection
510     Switch Connection    ${devstack_conn_id}
511     ${output} =    Write Commands Until Prompt    neutron router-show ${router_name} ${options}    30s
512     Log    ${output}
513     Close Connection
514
515 Delete Router
516     [Arguments]    ${router_name}
517     [Documentation]    Delete Router and Interface to the subnets.
518     ${devstack_conn_id}=    Get ControlNode Connection
519     Switch Connection    ${devstack_conn_id}
520     ${output}=    Write Commands Until Prompt    neutron -v router-delete ${router_name}    60s
521     Close Connection
522     Should Match Regexp    ${output}    Deleted router: ${router_name}|Deleted router\\(s\\): ${router_name}
523
524 Get DumpFlows And Ovsconfig
525     [Arguments]    ${openstack_node_ip}
526     [Documentation]    Get the OvsConfig and Flow entries from OVS from the Openstack Node
527     Log    ${openstack_node_ip}
528     SSHLibrary.Open Connection    ${openstack_node_ip}    prompt=${DEFAULT_LINUX_PROMPT}
529     Utils.Flexible SSH Login    ${OS_USER}    ${DEVSTACK_SYSTEM_PASSWORD}
530     SSHLibrary.Set Client Configuration    timeout=${default_devstack_prompt_timeout}
531     Write Commands Until Expected Prompt    ip -o link    ${DEFAULT_LINUX_PROMPT_STRICT}
532     Write Commands Until Expected Prompt    ip -o addr    ${DEFAULT_LINUX_PROMPT_STRICT}
533     Write Commands Until Expected Prompt    ip route    ${DEFAULT_LINUX_PROMPT_STRICT}
534     Write Commands Until Expected Prompt    arp -an    ${DEFAULT_LINUX_PROMPT_STRICT}
535     ${nslist}=    Write Commands Until Expected Prompt    ip netns list | awk '{print $1}'    ${DEFAULT_LINUX_PROMPT_STRICT}
536     @{lines}    Split To Lines    ${nslist}
537     : FOR    ${line}    IN    @{lines}
538     \    Write Commands Until Expected Prompt    sudo ip netns exec ${line} ip -o link    ${DEFAULT_LINUX_PROMPT_STRICT}
539     \    Write Commands Until Expected Prompt    sudo ip netns exec ${line} ip -o addr    ${DEFAULT_LINUX_PROMPT_STRICT}
540     \    Write Commands Until Expected Prompt    sudo ip netns exec ${line} ip route    ${DEFAULT_LINUX_PROMPT_STRICT}
541     Write Commands Until Expected Prompt    sudo ovs-vsctl show    ${DEFAULT_LINUX_PROMPT_STRICT}
542     Write Commands Until Expected Prompt    sudo ovs-vsctl list Open_vSwitch    ${DEFAULT_LINUX_PROMPT_STRICT}
543     Write Commands Until Expected Prompt    sudo ovs-ofctl show br-int -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
544     Write Commands Until Expected Prompt    sudo ovs-ofctl dump-flows br-int -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
545     Write Commands Until Expected Prompt    sudo ovs-ofctl dump-groups br-int -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
546     Write Commands Until Expected Prompt    sudo ovs-ofctl dump-group-stats br-int -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
547
548 Get Karaf Log Type From Test Start
549     [Arguments]    ${ip}    ${test_name}    ${type}    ${user}=${ODL_SYSTEM_USER}    ${password}=${ODL_SYSTEM_PASSWORD}    ${prompt}=${ODL_SYSTEM_PROMPT}
550     ...    ${log_file}=${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
551     ${cmd}    Set Variable    sed '1,/ROBOT MESSAGE: Starting test ${test_name}/d' ${log_file} | grep '${type}'
552     ${output}    Run Command On Controller    ${ip}    ${cmd}    ${user}    ${password}    ${prompt}
553     Log    ${output}
554
555 Get Karaf Log Types From Test Start
556     [Arguments]    ${ip}    ${test_name}    ${types}    ${user}=${ODL_SYSTEM_USER}    ${password}=${ODL_SYSTEM_PASSWORD}    ${prompt}=${ODL_SYSTEM_PROMPT}
557     ...    ${log_file}=${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
558     : FOR    ${type}    IN    @{types}
559     \    Get Karaf Log Type From Test Start    ${ip}    ${test_name}    ${type}    ${user}    ${password}
560     \    ...    ${prompt}    ${log_file}
561
562 Get Karaf Log Events From Test Start
563     [Arguments]    ${test_name}    ${user}=${ODL_SYSTEM_USER}    ${password}=${ODL_SYSTEM_PASSWORD}    ${prompt}=${ODL_SYSTEM_PROMPT}
564     ${log_types} =    Create List    ERROR    WARN    Exception
565     Run Keyword If    0 < ${NUM_ODL_SYSTEM}    Get Karaf Log Types From Test Start    ${ODL_SYSTEM_IP}    ${test_name}    ${log_types}
566     Run Keyword If    1 < ${NUM_ODL_SYSTEM}    Get Karaf Log Types From Test Start    ${ODL_SYSTEM_2_IP}    ${test_name}    ${log_types}
567     Run Keyword If    2 < ${NUM_ODL_SYSTEM}    Get Karaf Log Types From Test Start    ${ODL_SYSTEM_3_IP}    ${test_name}    ${log_types}
568
569 Get ControlNode Connection
570     ${control_conn_id}=    SSHLibrary.Open Connection    ${OS_CONTROL_NODE_IP}    prompt=${DEFAULT_LINUX_PROMPT_STRICT}
571     Utils.Flexible SSH Login    ${OS_USER}    ${DEVSTACK_SYSTEM_PASSWORD}
572     SSHLibrary.Set Client Configuration    timeout=30s
573     Source Password    force=yes
574     [Return]    ${control_conn_id}
575
576 Get OvsDebugInfo
577     [Documentation]    Get the OvsConfig and Flow entries from all Openstack nodes
578     Run Keyword If    0 < ${NUM_OS_SYSTEM}    Get DumpFlows And Ovsconfig    ${OS_CONTROL_NODE_IP}
579     Run Keyword If    1 < ${NUM_OS_SYSTEM}    Get DumpFlows And Ovsconfig    ${OS_COMPUTE_1_IP}
580     Run Keyword If    2 < ${NUM_OS_SYSTEM}    Get DumpFlows And Ovsconfig    ${OS_COMPUTE_2_IP}
581
582 Get Test Teardown Debugs
583     [Arguments]    ${test_name}=${TEST_NAME}
584     Get OvsDebugInfo
585     Run Keyword And Ignore Error    Get Model Dump    ${HA_PROXY_IP}
586     Get Karaf Log Events From Test Start    ${test_name}
587
588 Get Suite Teardown Debugs
589     Get OvsDebugInfo
590     Get Model Dump    ${HA_PROXY_IP}
591
592 Show Debugs
593     [Arguments]    @{vm_indices}
594     [Documentation]    Run these commands for debugging, it can list state of VM instances and ip information in control node
595     ${devstack_conn_id}=    Get ControlNode Connection
596     Switch Connection    ${devstack_conn_id}
597     ${output}=    Write Commands Until Prompt    sudo ip netns list
598     Log    ${output}
599     : FOR    ${index}    IN    @{vm_indices}
600     \    ${output}=    Write Commands Until Prompt    nova show ${index}    30s
601     \    Log    ${output}
602     Close Connection
603     List Nova VMs
604     List Networks
605     List Subnets
606     List Ports
607
608 Create Security Group
609     [Arguments]    ${sg_name}    ${desc}
610     ${devstack_conn_id}=    Get ControlNode Connection
611     Switch Connection    ${devstack_conn_id}
612     ${output}=    Write Commands Until Prompt    nova secgroup-create ${sg_name} ${desc}    40s
613     Close Connection
614
615 Create Security Rule
616     [Arguments]    ${direction}    ${protocol}    ${min_port}    ${max_port}    ${remote_ip}    ${sg_name}
617     ${devstack_conn_id}=    Get ControlNode Connection
618     Switch Connection    ${devstack_conn_id}
619     ${output}=    Write Commands Until Prompt    neutron security-group-rule-create --direction ${direction} --protocol ${protocol} --port-range-min ${min_port} --port-range-max ${max_port} --remote-ip-prefix ${remote_ip} ${sg_name}
620     Close Connection
621
622 Neutron Security Group Show
623     [Arguments]    ${SecurityGroupRuleName}    ${additional_args}=${EMPTY}
624     [Documentation]    Displays the neutron security group configurations that belongs to a given neutron security group name
625     ${devstack_conn_id}=    Get ControlNode Connection
626     Switch Connection    ${devstack_conn_id}
627     ${cmd}=    Set Variable    neutron security-group-show ${SecurityGroupRuleName} ${additional_args}
628     Log    ${cmd}
629     ${output}=    Write Commands Until Prompt    ${cmd}    30s
630     Log    ${output}
631     Close Connection
632     [Return]    ${output}
633
634 Neutron Port Show
635     [Arguments]    ${PortName}    ${additional_args}=${EMPTY}
636     [Documentation]    Display the port configuration that belong to a given neutron port
637     ${devstack_conn_id}=    Get ControlNode Connection
638     Switch Connection    ${devstack_conn_id}
639     ${cmd}=    Set Variable    neutron port-show ${PortName} ${additional_args}
640     Log    ${cmd}
641     ${output}=    Write Commands Until Prompt    ${cmd}    30s
642     Log    ${output}
643     Close Connection
644     [Return]    ${output}
645
646 Neutron Security Group Create
647     [Arguments]    ${SecurityGroupName}    ${additional_args}=${EMPTY}
648     [Documentation]    Create a security group with specified name ,description & protocol value according to security group template
649     ${devstack_conn_id}=    Get ControlNode Connection
650     Switch Connection    ${devstack_conn_id}
651     ${cmd}=    Set Variable    neutron security-group-create ${SecurityGroupName} ${additional_args}
652     Log    ${cmd}
653     ${output}=    Write Commands Until Prompt    ${cmd}    30s
654     Log    ${output}
655     Should Contain    ${output}    Created a new security_group
656     ${sgp_id}=    Should Match Regexp    ${output}    [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}
657     Log    ${sgp_id}
658     Close Connection
659     [Return]    ${output}    ${sgp_id}
660
661 Neutron Security Group Update
662     [Arguments]    ${SecurityGroupName}    ${additional_args}=${EMPTY}
663     [Documentation]    Updating security groups
664     ${devstack_conn_id}=    Get ControlNode Connection
665     Switch Connection    ${devstack_conn_id}
666     ${cmd}=    Set Variable    neutron security-group-update ${SecurityGroupName} ${additional_args}
667     Log    ${cmd}
668     ${output}=    Write Commands Until Prompt    ${cmd}    30s
669     Log    ${output}
670     Close Connection
671     [Return]    ${output}
672
673 Delete SecurityGroup
674     [Arguments]    ${sg_name}
675     [Documentation]    Delete Security group
676     ${devstack_conn_id}=    Get ControlNode Connection
677     Switch Connection    ${devstack_conn_id}
678     ${output}=    Write Commands Until Prompt    neutron security-group-delete ${sg_name}    40s
679     Log    ${output}
680     Should Match Regexp    ${output}    Deleted security_group: ${sg_name}|Deleted security_group\\(s\\): ${sg_name}
681     Close Connection
682
683 Neutron Security Group Rule Create
684     [Arguments]    ${Security_group_name}    &{Kwargs}
685     [Documentation]    Creates neutron security rule with neutron request with or without optional params, here security group name is mandatory args, rule with optional params can be created by passing the optional args values ex: direction=${INGRESS_EGRESS}, Then these optional params are catenated with mandatory args, example of usage: "Neutron Security Group Rule Create ${SGP_SSH} direction=${RULE_PARAMS[0]} ethertype=${RULE_PARAMS[1]} ..."
686     ${devstack_conn_id}=    Get ControlNode Connection
687     Switch Connection    ${devstack_conn_id}
688     Run Keyword If    ${Kwargs}    Log    ${Kwargs}
689     ${description}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    description    default=${None}
690     ${direction}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    direction    default=${None}
691     ${ethertype}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    ethertype    default=${None}
692     ${port_range_max}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    port_range_max    default=${None}
693     ${port_range_min}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    port_range_min    default=${None}
694     ${protocol}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    protocol    default=${None}
695     ${remote_group_id}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    remote_group_id    default=${None}
696     ${remote_ip_prefix}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    remote_ip_prefix    default=${None}
697     ${cmd}=    Set Variable    neutron security-group-rule-create ${Security_group_name}
698     ${cmd}=    Run Keyword If    '${description}'!='None'    Catenate    ${cmd}    --description ${description}
699     ...    ELSE    Catenate    ${cmd}
700     ${cmd}=    Run Keyword If    '${direction}'!='None'    Catenate    ${cmd}    --direction ${direction}
701     ...    ELSE    Catenate    ${cmd}
702     ${cmd}=    Run Keyword If    '${ethertype}'!='None'    Catenate    ${cmd}    --ethertype ${ethertype}
703     ...    ELSE    Catenate    ${cmd}
704     ${cmd}=    Run Keyword If    '${port_range_max}'!='None'    Catenate    ${cmd}    --port_range_max ${port_range_max}
705     ...    ELSE    Catenate    ${cmd}
706     ${cmd}=    Run Keyword If    '${port_range_min}'!='None'    Catenate    ${cmd}    --port_range_min ${port_range_min}
707     ...    ELSE    Catenate    ${cmd}
708     ${cmd}=    Run Keyword If    '${protocol}'!='None'    Catenate    ${cmd}    --protocol ${protocol}
709     ...    ELSE    Catenate    ${cmd}
710     ${cmd}=    Run Keyword If    '${remote_group_id}'!='None'    Catenate    ${cmd}    --remote_group_id ${remote_group_id}
711     ...    ELSE    Catenate    ${cmd}
712     ${cmd}=    Run Keyword If    '${remote_ip_prefix}'!='None'    Catenate    ${cmd}    --remote_ip_prefix ${remote_ip_prefix}
713     ...    ELSE    Catenate    ${cmd}
714     ${output}=    Write Commands Until Prompt    ${cmd}    30s
715     ${rule_id}=    Should Match Regexp    ${output}    [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}
716     Log    ${rule_id}
717     Should Contain    ${output}    Created a new security_group_rule
718     Close Connection
719     [Return]    ${output}    ${rule_id}
720
721 Create Neutron Port With Additional Params
722     [Arguments]    ${network_name}    ${port_name}    ${additional_args}=${EMPTY}
723     [Documentation]    Create Port With given additional parameters
724     ${devstack_conn_id}=    Get ControlNode Connection
725     Switch Connection    ${devstack_conn_id}
726     ${cmd}=    Set Variable    neutron -v port-create ${network_name} --name ${port_name} ${additional_args}
727     Log    ${cmd}
728     ${OUTPUT}=    Write Commands Until Prompt    ${cmd}    30s
729     Log    ${OUTPUT}
730     Should Contain    ${output}    Created a new port
731     ${port_id}=    Should Match Regexp    ${OUTPUT}    [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}
732     Log    ${port_id}
733     Close Connection
734     [Return]    ${OUTPUT}    ${port_id}
735
736 Get Ports MacAddr
737     [Arguments]    ${portName_list}
738     [Documentation]    Retrieve the port MacAddr for the given list of port name and return the MAC address list.
739     ${devstack_conn_id}=    Get ControlNode Connection
740     Switch Connection    ${devstack_conn_id}
741     ${MacAddr-list}    Create List
742     : FOR    ${portName}    IN    @{portName_list}
743     \    ${macAddr}=    OpenStackOperations.Get Port Mac    ${portName}    ${devstack_conn_id}
744     \    Append To List    ${MacAddr-list}    ${macAddr}
745     [Return]    ${MacAddr-list}
746
747 Get Port Ip
748     [Arguments]    ${port_name}
749     [Documentation]    Keyword would return the IP of the ${port_name} received.
750     Switch Connection    ${devstack_conn_id}
751     ${output}=    Write Commands Until Prompt    neutron port-list | grep "${port_name}" | awk '{print $11}' | awk -F "\\"" '{print $2}'    30s
752     Log    ${output}
753     ${splitted_output}=    Split String    ${output}    ${EMPTY}
754     ${port_ip}=    Get from List    ${splitted_output}    0
755     Log    ${port_ip}
756     [Return]    ${port_ip}
757
758 Get Port Mac
759     [Arguments]    ${port_name}    ${conn_id}=${devstack_conn_id}
760     [Documentation]    Keyword would return the MAC ID of the ${port_name} received.
761     Switch Connection    ${conn_id}
762     ${output}=    Write Commands Until Prompt    neutron port-list | grep "${port_name}" | awk '{print $6}'    30s
763     Log    ${output}
764     ${splitted_output}=    Split String    ${output}    ${EMPTY}
765     ${port_mac}=    Get from List    ${splitted_output}    0
766     Log    ${port_mac}
767     [Return]    ${port_mac}
768
769 Create L2Gateway
770     [Arguments]    ${bridge_name}    ${intf_name}    ${gw_name}
771     [Documentation]    Keyword to create an L2 Gateway ${gw_name} for bridge ${bridge_name} connected to interface ${intf_name} (Using Neutron CLI).
772     Switch Connection    ${devstack_conn_id}
773     ${l2gw_output}=    Write Commands Until Prompt    ${L2GW_CREATE} name=${bridge_name},interface_names=${intf_name} ${gw_name}    30s
774     Log    ${l2gw_output}
775     [Return]    ${l2gw_output}
776
777 Create L2Gateway Connection
778     [Arguments]    ${gw_name}    ${net_name}
779     [Documentation]    Keyword would create a new L2 Gateway Connection for ${gw_name} to ${net_name} (Using Neutron CLI).
780     Switch Connection    ${devstack_conn_id}
781     ${l2gw_output}=    Write Commands Until Prompt    ${L2GW_CONN_CREATE} ${gw_name} ${net_name}    30s
782     Log    ${l2gw_output}
783     [Return]    ${l2gw_output}
784
785 Get All L2Gateway
786     [Documentation]    Keyword to return all the L2 Gateways available (Using Neutron CLI).
787     Switch Connection    ${devstack_conn_id}
788     ${output}=    Write Commands Until Prompt    ${L2GW_GET_YAML}    30s
789     [Return]    ${output}
790
791 Get All L2Gateway Connection
792     [Documentation]    Keyword to return all the L2 Gateway connections available (Using Neutron CLI).
793     Switch Connection    ${devstack_conn_id}
794     ${output}=    Write Commands Until Prompt    ${L2GW_GET_CONN_YAML}    30s
795     [Return]    ${output}
796
797 Get L2Gateway
798     [Arguments]    ${gw_id}
799     [Documentation]    Keyword to check if the ${gw_id} is available in the L2 Gateway list (Using Neutron CLI).
800     Switch Connection    ${devstack_conn_id}
801     ${output}=    Write Commands Until Prompt    ${L2GW_SHOW} ${gw_id}    30s
802     Log    ${output}
803     [Return]    ${output}
804
805 Get L2gw Id
806     [Arguments]    ${l2gw_name}
807     [Documentation]    Keyword to retrieve the L2 Gateway ID for the ${l2gw_name} (Using Neutron CLI).
808     Switch Connection    ${devstack_conn_id}
809     ${output}=    Write Commands Until Prompt    ${L2GW_GET} | grep "${l2gw_name}" | awk '{print $2}'    30s
810     Log    ${output}
811     ${splitted_output}=    Split String    ${output}    ${EMPTY}
812     ${l2gw_id}=    Get from List    ${splitted_output}    0
813     Log    ${l2gw_id}
814     [Return]    ${l2gw_id}
815
816 Get L2gw Connection Id
817     [Arguments]    ${l2gw_name}
818     [Documentation]    Keyword to retrieve the L2 Gateway Connection ID for the ${l2gw_name} (Using Neutron CLI).
819     Switch Connection    ${devstack_conn_id}
820     ${l2gw_id}=    OpenStackOperations.Get L2gw Id    ${l2gw_name}
821     ${output}=    Write Commands Until Prompt    ${L2GW_GET_CONN} | grep "${l2gw_id}" | awk '{print $2}'    30s
822     Log    ${output}
823     ${splitted_output}=    Split String    ${output}    ${EMPTY}
824     ${l2gw_conn_id}=    Get from List    ${splitted_output}    0
825     Log    ${l2gw_conn_id}
826     [Return]    ${l2gw_conn_id}
827
828 Neutron Port List Rest
829     [Documentation]    Keyword to get all ports details in Neutron (Using REST).
830     ${resp} =    RequestsLibrary.Get Request    session    ${PORT_URL}
831     Log    ${resp.content}
832     Should Be Equal As Strings    ${resp.status_code}    200
833     [Return]    ${resp.content}
834
835 Get Neutron Port Rest
836     [Arguments]    ${port_id}
837     [Documentation]    Keyword to get the specific port details in Neutron (Using REST).
838     ${resp} =    RequestsLibrary.Get Request    session    ${CONFIG_API}/${GET_PORT_URL}/${port_id}
839     Log    ${resp.content}
840     Should Be Equal As Strings    ${resp.status_code}    200
841     [Return]    ${resp.content}
842
843 Update Port Rest
844     [Arguments]    ${port_id}    ${json_data}
845     [Documentation]    Keyword to update ${port_id} with json data received in ${json_data} (Using REST).
846     Log    ${json_data}
847     ${resp} =    RequestsLibrary.Put Request    session    ${CONFIG_API}/${GET_PORT_URL}/${port_id}    ${json_data}
848     Log    ${resp.content}
849     Should Be Equal As Strings    ${resp.status_code}    200
850     [Return]    ${resp.content}
851
852 Create And Configure Security Group
853     [Arguments]    ${sg-name}
854     Neutron Security Group Create    ${sg-name}
855     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
856     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
857     Neutron Security Group Rule Create    ${sg-name}    direction=ingress    protocol=icmp    remote_ip_prefix=0.0.0.0/0
858     Neutron Security Group Rule Create    ${sg-name}    direction=egress    protocol=icmp    remote_ip_prefix=0.0.0.0/0
859     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
860     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