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