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