b2a6e40bd461a1de16e3aef78d1c2e8d4ff39b47
[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 Install Netcat On Controller
428     [Documentation]    Installs Netcat on the controller - this probably shouldn't be here
429     ${devstack_conn_id}=    Get ControlNode Connection
430     Switch Connection    ${devstack_conn_id}
431     ${output}=    Write Commands Until Prompt    sudo yum install -y nc
432     Log    ${output}
433     Close Connection
434
435 Test Netcat Operations From Vm Instance
436     [Arguments]    ${net_name}    ${vm_ip}    ${dest_ip}    ${additional_args}=${EMPTY}    ${port}=12345    ${user}=cirros
437     ...    ${password}=cubswin:)
438     [Documentation]    Use Netcat to test TCP/UDP connections to the controller
439     ${client_data}    Set Variable    Test Client Data
440     ${server_data}    Set Variable    Test Server Data
441     ${devstack_conn_id}=    Get ControlNode Connection
442     Switch Connection    ${devstack_conn_id}
443     Log    ${vm_ip}
444     ${output}=    Write Commands Until Prompt    ( ( echo "${server_data}" | sudo timeout 60 nc -l ${additional_args} ${port} ) & )
445     Log    ${output}
446     ${output}=    Write Commands Until Prompt    sudo netstat -nlap | grep ${port}
447     Log    ${output}
448     ${nc_output}=    Execute Command on VM Instance    ${net_name}    ${vm_ip}    sudo echo "${client_data}" | nc -v -w 5 ${additional_args} ${dest_ip} ${port}
449     Log    ${nc_output}
450     ${output}=    Execute Command on VM Instance    ${net_name}    ${vm_ip}    sudo route -n
451     Log    ${output}
452     ${output}=    Execute Command on VM Instance    ${net_name}    ${vm_ip}    sudo arp -an
453     Log    ${output}
454     Should Match Regexp    ${nc_output}    ${server_data}
455
456 Ping Other Instances
457     [Arguments]    ${list_of_external_dst_ips}
458     [Documentation]    Check reachability with other network's instances.
459     ${rcode}=    Run Keyword And Return Status    Check If Console Is VmInstance
460     : FOR    ${dest_ip}    IN    @{list_of_external_dst_ips}
461     \    Log    ${dest_ip}
462     \    Check Ping    ${dest_ip}
463
464 Create Router
465     [Arguments]    ${router_name}
466     [Documentation]    Create Router and Add Interface to the subnets.
467     ${devstack_conn_id}=    Get ControlNode Connection
468     Switch Connection    ${devstack_conn_id}
469     ${output}=    Write Commands Until Prompt    neutron -v router-create ${router_name}    30s
470     Close Connection
471     Should Contain    ${output}    Created a new router
472
473 List Router
474     [Documentation]    List Router and return output with neutron client.
475     ${devstack_conn_id}=    Get ControlNode Connection
476     Switch Connection    ${devstack_conn_id}
477     ${output}=    Write Commands Until Prompt    neutron router-list    30s
478     Close Connection
479     Log    ${output}
480     [Return]    ${output}
481
482 Add Router Interface
483     [Arguments]    ${router_name}    ${interface_name}
484     ${devstack_conn_id}=    Get ControlNode Connection
485     Switch Connection    ${devstack_conn_id}
486     ${output}=    Write Commands Until Prompt    neutron -v router-interface-add ${router_name} ${interface_name}
487     Close Connection
488     Should Contain    ${output}    Added interface
489
490 Show Router Interface
491     [Arguments]    ${router_name}
492     [Documentation]    List Router interface associated with given Router and return output with neutron client.
493     ${devstack_conn_id}=    Get ControlNode Connection
494     Switch Connection    ${devstack_conn_id}
495     ${output}=    Write Commands Until Prompt    neutron router-port-list ${router_name} -f csv    30s
496     Close Connection
497     Log    ${output}
498     [Return]    ${output}
499
500 Add Router Gateway
501     [Arguments]    ${router_name}    ${network_name}
502     ${devstack_conn_id}=    Get ControlNode Connection
503     Switch Connection    ${devstack_conn_id}
504     ${output}=    Write Commands Until Prompt    neutron -v router-gateway-set ${router_name} ${network_name}
505     Close Connection
506     Should Contain    ${output}    Set gateway
507
508 Remove Interface
509     [Arguments]    ${router_name}    ${interface_name}
510     [Documentation]    Remove Interface to the subnets.
511     ${devstack_conn_id}=    Get ControlNode Connection
512     Switch Connection    ${devstack_conn_id}
513     ${output}=    Write Commands Until Prompt    neutron -v router-interface-delete ${router_name} ${interface_name}
514     Close Connection
515     Should Contain    ${output}    Removed interface from router
516
517 Update Router
518     [Arguments]    ${router_name}    ${cmd}
519     [Documentation]    Update the router with the command. Router name and command should be passed as argument.
520     ${devstack_conn_id} =    Get ControlNode Connection
521     Switch Connection    ${devstack_conn_id}
522     ${output} =    Write Commands Until Prompt    neutron router-update ${router_name} ${cmd}    30s
523     Close Connection
524     Should Contain    ${output}    Updated
525
526 Show Router
527     [Arguments]    ${router_name}    ${options}
528     [Documentation]    Show information of a given router. Router name and optional fields should be sent as arguments.
529     ${devstack_conn_id} =    Get ControlNode Connection
530     Switch Connection    ${devstack_conn_id}
531     ${output} =    Write Commands Until Prompt    neutron router-show ${router_name} ${options}    30s
532     Log    ${output}
533     Close Connection
534
535 Delete Router
536     [Arguments]    ${router_name}
537     [Documentation]    Delete Router and Interface to the subnets.
538     ${devstack_conn_id}=    Get ControlNode Connection
539     Switch Connection    ${devstack_conn_id}
540     ${output}=    Write Commands Until Prompt    neutron -v router-delete ${router_name}    60s
541     Close Connection
542     Should Match Regexp    ${output}    Deleted router: ${router_name}|Deleted router\\(s\\): ${router_name}
543
544 Get DumpFlows And Ovsconfig
545     [Arguments]    ${openstack_node_ip}
546     [Documentation]    Get the OvsConfig and Flow entries from OVS from the Openstack Node
547     Log    ${openstack_node_ip}
548     SSHLibrary.Open Connection    ${openstack_node_ip}    prompt=${DEFAULT_LINUX_PROMPT}
549     Utils.Flexible SSH Login    ${OS_USER}    ${DEVSTACK_SYSTEM_PASSWORD}
550     SSHLibrary.Set Client Configuration    timeout=${default_devstack_prompt_timeout}
551     Write Commands Until Expected Prompt    ip -o link    ${DEFAULT_LINUX_PROMPT_STRICT}
552     Write Commands Until Expected Prompt    ip -o addr    ${DEFAULT_LINUX_PROMPT_STRICT}
553     Write Commands Until Expected Prompt    ip route    ${DEFAULT_LINUX_PROMPT_STRICT}
554     Write Commands Until Expected Prompt    arp -an    ${DEFAULT_LINUX_PROMPT_STRICT}
555     ${nslist}=    Write Commands Until Expected Prompt    ip netns list | awk '{print $1}'    ${DEFAULT_LINUX_PROMPT_STRICT}
556     @{lines}    Split To Lines    ${nslist}
557     : FOR    ${line}    IN    @{lines}
558     \    Write Commands Until Expected Prompt    sudo ip netns exec ${line} ip -o link    ${DEFAULT_LINUX_PROMPT_STRICT}
559     \    Write Commands Until Expected Prompt    sudo ip netns exec ${line} ip -o addr    ${DEFAULT_LINUX_PROMPT_STRICT}
560     \    Write Commands Until Expected Prompt    sudo ip netns exec ${line} ip route    ${DEFAULT_LINUX_PROMPT_STRICT}
561     Write Commands Until Expected Prompt    sudo ovs-vsctl show    ${DEFAULT_LINUX_PROMPT_STRICT}
562     Write Commands Until Expected Prompt    sudo ovs-vsctl list Open_vSwitch    ${DEFAULT_LINUX_PROMPT_STRICT}
563     Write Commands Until Expected Prompt    sudo ovs-ofctl show br-int -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
564     Write Commands Until Expected Prompt    sudo ovs-ofctl dump-flows br-int -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
565     Write Commands Until Expected Prompt    sudo ovs-ofctl dump-groups br-int -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
566     Write Commands Until Expected Prompt    sudo ovs-ofctl dump-group-stats br-int -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
567
568 Get Karaf Log Type From Test Start
569     [Arguments]    ${ip}    ${test_name}    ${type}    ${user}=${ODL_SYSTEM_USER}    ${password}=${ODL_SYSTEM_PASSWORD}    ${prompt}=${ODL_SYSTEM_PROMPT}
570     ...    ${log_file}=${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
571     ${cmd}    Set Variable    sed '1,/ROBOT MESSAGE: Starting test ${test_name}/d' ${log_file} | grep '${type}'
572     ${output}    Run Command On Controller    ${ip}    ${cmd}    ${user}    ${password}    ${prompt}
573     Log    ${output}
574
575 Get Karaf Log Types From Test Start
576     [Arguments]    ${ip}    ${test_name}    ${types}    ${user}=${ODL_SYSTEM_USER}    ${password}=${ODL_SYSTEM_PASSWORD}    ${prompt}=${ODL_SYSTEM_PROMPT}
577     ...    ${log_file}=${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
578     : FOR    ${type}    IN    @{types}
579     \    Get Karaf Log Type From Test Start    ${ip}    ${test_name}    ${type}    ${user}    ${password}
580     \    ...    ${prompt}    ${log_file}
581
582 Get Karaf Log Events From Test Start
583     [Arguments]    ${test_name}    ${user}=${ODL_SYSTEM_USER}    ${password}=${ODL_SYSTEM_PASSWORD}    ${prompt}=${ODL_SYSTEM_PROMPT}
584     ${log_types} =    Create List    ERROR    WARN    Exception
585     Run Keyword If    0 < ${NUM_ODL_SYSTEM}    Get Karaf Log Types From Test Start    ${ODL_SYSTEM_IP}    ${test_name}    ${log_types}
586     Run Keyword If    1 < ${NUM_ODL_SYSTEM}    Get Karaf Log Types From Test Start    ${ODL_SYSTEM_2_IP}    ${test_name}    ${log_types}
587     Run Keyword If    2 < ${NUM_ODL_SYSTEM}    Get Karaf Log Types From Test Start    ${ODL_SYSTEM_3_IP}    ${test_name}    ${log_types}
588
589 Get ControlNode Connection
590     ${control_conn_id}=    SSHLibrary.Open Connection    ${OS_CONTROL_NODE_IP}    prompt=${DEFAULT_LINUX_PROMPT_STRICT}
591     Utils.Flexible SSH Login    ${OS_USER}    ${DEVSTACK_SYSTEM_PASSWORD}
592     SSHLibrary.Set Client Configuration    timeout=30s
593     Source Password    force=yes
594     [Return]    ${control_conn_id}
595
596 Get OvsDebugInfo
597     [Documentation]    Get the OvsConfig and Flow entries from all Openstack nodes
598     Run Keyword If    0 < ${NUM_OS_SYSTEM}    Get DumpFlows And Ovsconfig    ${OS_CONTROL_NODE_IP}
599     Run Keyword If    1 < ${NUM_OS_SYSTEM}    Get DumpFlows And Ovsconfig    ${OS_COMPUTE_1_IP}
600     Run Keyword If    2 < ${NUM_OS_SYSTEM}    Get DumpFlows And Ovsconfig    ${OS_COMPUTE_2_IP}
601
602 Get Test Teardown Debugs
603     [Arguments]    ${test_name}=${TEST_NAME}
604     Get OvsDebugInfo
605     Run Keyword And Ignore Error    Get Model Dump    ${HA_PROXY_IP}    ${netvirt_data_models}
606     Get Karaf Log Events From Test Start    ${test_name}
607
608 Get Suite Teardown Debugs
609     Get OvsDebugInfo
610     Get Model Dump    ${HA_PROXY_IP}    ${netvirt_data_models}
611
612 Show Debugs
613     [Arguments]    @{vm_indices}
614     [Documentation]    Run these commands for debugging, it can list state of VM instances and ip information in control node
615     ${devstack_conn_id}=    Get ControlNode Connection
616     Switch Connection    ${devstack_conn_id}
617     ${output}=    Write Commands Until Prompt    sudo ip netns list
618     Log    ${output}
619     : FOR    ${index}    IN    @{vm_indices}
620     \    ${output}=    Write Commands Until Prompt    nova show ${index}    30s
621     \    Log    ${output}
622     Close Connection
623     List Nova VMs
624     List Networks
625     List Subnets
626     List Ports
627
628 Create Security Group
629     [Arguments]    ${sg_name}    ${desc}
630     ${devstack_conn_id}=    Get ControlNode Connection
631     Switch Connection    ${devstack_conn_id}
632     ${output}=    Write Commands Until Prompt    nova secgroup-create ${sg_name} ${desc}    40s
633     Close Connection
634
635 Create Security Rule
636     [Arguments]    ${direction}    ${protocol}    ${min_port}    ${max_port}    ${remote_ip}    ${sg_name}
637     ${devstack_conn_id}=    Get ControlNode Connection
638     Switch Connection    ${devstack_conn_id}
639     ${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}
640     Close Connection
641
642 Neutron Security Group Show
643     [Arguments]    ${SecurityGroupRuleName}    ${additional_args}=${EMPTY}
644     [Documentation]    Displays the neutron security group configurations that belongs to a given neutron security group name
645     ${devstack_conn_id}=    Get ControlNode Connection
646     Switch Connection    ${devstack_conn_id}
647     ${cmd}=    Set Variable    neutron security-group-show ${SecurityGroupRuleName} ${additional_args}
648     Log    ${cmd}
649     ${output}=    Write Commands Until Prompt    ${cmd}    30s
650     Log    ${output}
651     Close Connection
652     [Return]    ${output}
653
654 Neutron Port Show
655     [Arguments]    ${PortName}    ${additional_args}=${EMPTY}
656     [Documentation]    Display the port configuration that belong to a given neutron port
657     ${devstack_conn_id}=    Get ControlNode Connection
658     Switch Connection    ${devstack_conn_id}
659     ${cmd}=    Set Variable    neutron port-show ${PortName} ${additional_args}
660     Log    ${cmd}
661     ${output}=    Write Commands Until Prompt    ${cmd}    30s
662     Log    ${output}
663     Close Connection
664     [Return]    ${output}
665
666 Neutron Security Group Create
667     [Arguments]    ${SecurityGroupName}    ${additional_args}=${EMPTY}
668     [Documentation]    Create a security group with specified name ,description & protocol value according to security group template
669     ${devstack_conn_id}=    Get ControlNode Connection
670     Switch Connection    ${devstack_conn_id}
671     ${cmd}=    Set Variable    neutron security-group-create ${SecurityGroupName} ${additional_args}
672     Log    ${cmd}
673     ${output}=    Write Commands Until Prompt    ${cmd}    30s
674     Log    ${output}
675     Should Contain    ${output}    Created a new security_group
676     ${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}
677     Log    ${sgp_id}
678     Close Connection
679     [Return]    ${output}    ${sgp_id}
680
681 Neutron Security Group Update
682     [Arguments]    ${SecurityGroupName}    ${additional_args}=${EMPTY}
683     [Documentation]    Updating security groups
684     ${devstack_conn_id}=    Get ControlNode Connection
685     Switch Connection    ${devstack_conn_id}
686     ${cmd}=    Set Variable    neutron security-group-update ${SecurityGroupName} ${additional_args}
687     Log    ${cmd}
688     ${output}=    Write Commands Until Prompt    ${cmd}    30s
689     Log    ${output}
690     Close Connection
691     [Return]    ${output}
692
693 Delete SecurityGroup
694     [Arguments]    ${sg_name}
695     [Documentation]    Delete Security group
696     ${devstack_conn_id}=    Get ControlNode Connection
697     Switch Connection    ${devstack_conn_id}
698     ${output}=    Write Commands Until Prompt    neutron security-group-delete ${sg_name}    40s
699     Log    ${output}
700     Should Match Regexp    ${output}    Deleted security_group: ${sg_name}|Deleted security_group\\(s\\): ${sg_name}
701     Close Connection
702
703 Neutron Security Group Rule Create
704     [Arguments]    ${Security_group_name}    &{Kwargs}
705     [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]} ..."
706     ${devstack_conn_id}=    Get ControlNode Connection
707     Switch Connection    ${devstack_conn_id}
708     Run Keyword If    ${Kwargs}    Log    ${Kwargs}
709     ${description}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    description    default=${None}
710     ${direction}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    direction    default=${None}
711     ${ethertype}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    ethertype    default=${None}
712     ${port_range_max}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    port_range_max    default=${None}
713     ${port_range_min}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    port_range_min    default=${None}
714     ${protocol}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    protocol    default=${None}
715     ${remote_group_id}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    remote_group_id    default=${None}
716     ${remote_ip_prefix}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    remote_ip_prefix    default=${None}
717     ${cmd}=    Set Variable    neutron security-group-rule-create ${Security_group_name}
718     ${cmd}=    Run Keyword If    '${description}'!='None'    Catenate    ${cmd}    --description ${description}
719     ...    ELSE    Catenate    ${cmd}
720     ${cmd}=    Run Keyword If    '${direction}'!='None'    Catenate    ${cmd}    --direction ${direction}
721     ...    ELSE    Catenate    ${cmd}
722     ${cmd}=    Run Keyword If    '${ethertype}'!='None'    Catenate    ${cmd}    --ethertype ${ethertype}
723     ...    ELSE    Catenate    ${cmd}
724     ${cmd}=    Run Keyword If    '${port_range_max}'!='None'    Catenate    ${cmd}    --port_range_max ${port_range_max}
725     ...    ELSE    Catenate    ${cmd}
726     ${cmd}=    Run Keyword If    '${port_range_min}'!='None'    Catenate    ${cmd}    --port_range_min ${port_range_min}
727     ...    ELSE    Catenate    ${cmd}
728     ${cmd}=    Run Keyword If    '${protocol}'!='None'    Catenate    ${cmd}    --protocol ${protocol}
729     ...    ELSE    Catenate    ${cmd}
730     ${cmd}=    Run Keyword If    '${remote_group_id}'!='None'    Catenate    ${cmd}    --remote_group_id ${remote_group_id}
731     ...    ELSE    Catenate    ${cmd}
732     ${cmd}=    Run Keyword If    '${remote_ip_prefix}'!='None'    Catenate    ${cmd}    --remote_ip_prefix ${remote_ip_prefix}
733     ...    ELSE    Catenate    ${cmd}
734     ${output}=    Write Commands Until Prompt    ${cmd}    30s
735     ${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}
736     Log    ${rule_id}
737     Should Contain    ${output}    Created a new security_group_rule
738     Close Connection
739     [Return]    ${output}    ${rule_id}
740
741 Create Neutron Port With Additional Params
742     [Arguments]    ${network_name}    ${port_name}    ${additional_args}=${EMPTY}
743     [Documentation]    Create Port With given additional parameters
744     ${devstack_conn_id}=    Get ControlNode Connection
745     Switch Connection    ${devstack_conn_id}
746     ${cmd}=    Set Variable    neutron -v port-create ${network_name} --name ${port_name} ${additional_args}
747     Log    ${cmd}
748     ${OUTPUT}=    Write Commands Until Prompt    ${cmd}    30s
749     Log    ${OUTPUT}
750     Should Contain    ${output}    Created a new port
751     ${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}
752     Log    ${port_id}
753     Close Connection
754     [Return]    ${OUTPUT}    ${port_id}
755
756 Get Ports MacAddr
757     [Arguments]    ${portName_list}
758     [Documentation]    Retrieve the port MacAddr for the given list of port name and return the MAC address list.
759     ${devstack_conn_id}=    Get ControlNode Connection
760     Switch Connection    ${devstack_conn_id}
761     ${MacAddr-list}    Create List
762     : FOR    ${portName}    IN    @{portName_list}
763     \    ${macAddr}=    OpenStackOperations.Get Port Mac    ${portName}    ${devstack_conn_id}
764     \    Append To List    ${MacAddr-list}    ${macAddr}
765     [Return]    ${MacAddr-list}
766
767 Get Port Ip
768     [Arguments]    ${port_name}
769     [Documentation]    Keyword would return the IP of the ${port_name} received.
770     Switch Connection    ${devstack_conn_id}
771     ${output}=    Write Commands Until Prompt    neutron port-list | grep "${port_name}" | awk '{print $11}' | awk -F "\\"" '{print $2}'    30s
772     Log    ${output}
773     ${splitted_output}=    Split String    ${output}    ${EMPTY}
774     ${port_ip}=    Get from List    ${splitted_output}    0
775     Log    ${port_ip}
776     [Return]    ${port_ip}
777
778 Get Port Mac
779     [Arguments]    ${port_name}    ${conn_id}=${devstack_conn_id}
780     [Documentation]    Keyword would return the MAC ID of the ${port_name} received.
781     Switch Connection    ${conn_id}
782     ${output}=    Write Commands Until Prompt    neutron port-list | grep "${port_name}" | awk '{print $6}'    30s
783     Log    ${output}
784     ${splitted_output}=    Split String    ${output}    ${EMPTY}
785     ${port_mac}=    Get from List    ${splitted_output}    0
786     Log    ${port_mac}
787     [Return]    ${port_mac}
788
789 Create L2Gateway
790     [Arguments]    ${bridge_name}    ${intf_name}    ${gw_name}
791     [Documentation]    Keyword to create an L2 Gateway ${gw_name} for bridge ${bridge_name} connected to interface ${intf_name} (Using Neutron CLI).
792     Switch Connection    ${devstack_conn_id}
793     ${l2gw_output}=    Write Commands Until Prompt    ${L2GW_CREATE} name=${bridge_name},interface_names=${intf_name} ${gw_name}    30s
794     Log    ${l2gw_output}
795     [Return]    ${l2gw_output}
796
797 Create L2Gateway Connection
798     [Arguments]    ${gw_name}    ${net_name}
799     [Documentation]    Keyword would create a new L2 Gateway Connection for ${gw_name} to ${net_name} (Using Neutron CLI).
800     Switch Connection    ${devstack_conn_id}
801     ${l2gw_output}=    Write Commands Until Prompt    ${L2GW_CONN_CREATE} ${gw_name} ${net_name}    30s
802     Log    ${l2gw_output}
803     [Return]    ${l2gw_output}
804
805 Get All L2Gateway
806     [Documentation]    Keyword to return all the L2 Gateways available (Using Neutron CLI).
807     Switch Connection    ${devstack_conn_id}
808     ${output}=    Write Commands Until Prompt    ${L2GW_GET_YAML}    30s
809     [Return]    ${output}
810
811 Get All L2Gateway Connection
812     [Documentation]    Keyword to return all the L2 Gateway connections available (Using Neutron CLI).
813     Switch Connection    ${devstack_conn_id}
814     ${output}=    Write Commands Until Prompt    ${L2GW_GET_CONN_YAML}    30s
815     [Return]    ${output}
816
817 Get L2Gateway
818     [Arguments]    ${gw_id}
819     [Documentation]    Keyword to check if the ${gw_id} is available in the L2 Gateway list (Using Neutron CLI).
820     Switch Connection    ${devstack_conn_id}
821     ${output}=    Write Commands Until Prompt    ${L2GW_SHOW} ${gw_id}    30s
822     Log    ${output}
823     [Return]    ${output}
824
825 Get L2gw Id
826     [Arguments]    ${l2gw_name}
827     [Documentation]    Keyword to retrieve the L2 Gateway ID for the ${l2gw_name} (Using Neutron CLI).
828     Switch Connection    ${devstack_conn_id}
829     ${output}=    Write Commands Until Prompt    ${L2GW_GET} | grep "${l2gw_name}" | awk '{print $2}'    30s
830     Log    ${output}
831     ${splitted_output}=    Split String    ${output}    ${EMPTY}
832     ${l2gw_id}=    Get from List    ${splitted_output}    0
833     Log    ${l2gw_id}
834     [Return]    ${l2gw_id}
835
836 Get L2gw Connection Id
837     [Arguments]    ${l2gw_name}
838     [Documentation]    Keyword to retrieve the L2 Gateway Connection ID for the ${l2gw_name} (Using Neutron CLI).
839     Switch Connection    ${devstack_conn_id}
840     ${l2gw_id}=    OpenStackOperations.Get L2gw Id    ${l2gw_name}
841     ${output}=    Write Commands Until Prompt    ${L2GW_GET_CONN} | grep "${l2gw_id}" | awk '{print $2}'    30s
842     Log    ${output}
843     ${splitted_output}=    Split String    ${output}    ${EMPTY}
844     ${l2gw_conn_id}=    Get from List    ${splitted_output}    0
845     Log    ${l2gw_conn_id}
846     [Return]    ${l2gw_conn_id}
847
848 Neutron Port List Rest
849     [Documentation]    Keyword to get all ports details in Neutron (Using REST).
850     ${resp} =    RequestsLibrary.Get Request    session    ${PORT_URL}
851     Log    ${resp.content}
852     Should Be Equal As Strings    ${resp.status_code}    200
853     [Return]    ${resp.content}
854
855 Get Neutron Port Rest
856     [Arguments]    ${port_id}
857     [Documentation]    Keyword to get the specific port details in Neutron (Using REST).
858     ${resp} =    RequestsLibrary.Get Request    session    ${CONFIG_API}/${GET_PORT_URL}/${port_id}
859     Log    ${resp.content}
860     Should Be Equal As Strings    ${resp.status_code}    200
861     [Return]    ${resp.content}
862
863 Update Port Rest
864     [Arguments]    ${port_id}    ${json_data}
865     [Documentation]    Keyword to update ${port_id} with json data received in ${json_data} (Using REST).
866     Log    ${json_data}
867     ${resp} =    RequestsLibrary.Put Request    session    ${CONFIG_API}/${GET_PORT_URL}/${port_id}    ${json_data}
868     Log    ${resp.content}
869     Should Be Equal As Strings    ${resp.status_code}    200
870     [Return]    ${resp.content}
871
872 Create And Configure Security Group
873     [Arguments]    ${sg-name}
874     Neutron Security Group Create    ${sg-name}
875     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
876     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
877     Neutron Security Group Rule Create    ${sg-name}    direction=ingress    protocol=icmp    remote_ip_prefix=0.0.0.0/0
878     Neutron Security Group Rule Create    ${sg-name}    direction=egress    protocol=icmp    remote_ip_prefix=0.0.0.0/0
879     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
880     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
881
882 Create SFC Flow Classifier
883     [Arguments]    ${name}    ${src_ip}    ${dest_ip}    ${protocol}    ${dest_port}    ${neutron_src_port}
884     [Documentation]    Create a flow classifier for SFC
885     ${devstack_conn_id}=    Get ControlNode Connection
886     Switch Connection    ${devstack_conn_id}
887     ${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}
888     Log    ${cmd}
889     ${output}=    Write Commands Until Prompt    ${cmd}    30s
890     Log    ${output}
891     Close Connection
892     Should Contain    ${output}    Created a new flow_classifier
893     [Return]    ${output}
894
895 Delete SFC Flow Classifier
896     [Arguments]    ${name}
897     [Documentation]    Delete a SFC flow classifier
898     ${devstack_conn_id}=    Get ControlNode Connection
899     Switch Connection    ${devstack_conn_id}
900     ${cmd}=    Set Variable    neutron flow-classifier-delete ${name}
901     Log    ${cmd}
902     ${output}=    Write Commands Until Prompt    ${cmd}    30s
903     Log    ${output}
904     Close Connection
905     Should Contain    ${output}    Deleted flow_classifier
906     [Return]    ${output}
907
908 Create SFC Port Pair
909     [Arguments]    ${name}    ${port_in}    ${port_out}
910     [Documentation]    Creates a neutron port pair for SFC
911     ${devstack_conn_id}=    Get ControlNode Connection
912     Switch Connection    ${devstack_conn_id}
913     ${cmd}=    Set Variable    neutron port-pair-create --ingress=${port_in} --egress=${port_out} ${name}
914     Log    ${cmd}
915     ${output}=    Write Commands Until Prompt    ${cmd}    30s
916     Log    ${output}
917     Close Connection
918     Should Contain    ${output}    Created a new port_pair
919     [Return]    ${output}
920
921 Delete SFC Port Pair
922     [Arguments]    ${name}
923     [Documentation]    Delete a SFC port pair
924     ${devstack_conn_id}=    Get ControlNode Connection
925     Switch Connection    ${devstack_conn_id}
926     ${cmd}=    Set Variable    neutron port-pair-delete ${name}
927     Log    ${cmd}
928     ${output}=    Write Commands Until Prompt    ${cmd}    30s
929     Log    ${output}
930     Close Connection
931     Should Contain    ${output}    Deleted port_pair
932     [Return]    ${output}
933
934 Create SFC Port Pair Group
935     [Arguments]    ${name}    ${port_pair}
936     [Documentation]    Creates a port pair group with a single port pair for SFC
937     ${devstack_conn_id}=    Get ControlNode Connection
938     Switch Connection    ${devstack_conn_id}
939     ${cmd}=    Set Variable    neutron port-pair-group-create --port-pair ${port_pair} ${name}
940     Log    ${cmd}
941     ${output}=    Write Commands Until Prompt    ${cmd}    30s
942     Log    ${output}
943     Close Connection
944     Should Contain    ${output}    Created a new port_pair_group
945     [Return]    ${output}
946
947 Create SFC Port Pair Group With Two Pairs
948     [Arguments]    ${name}    ${port_pair1}    ${port_pair2}
949     [Documentation]    Creates a port pair group with two port pairs for SFC
950     ${devstack_conn_id}=    Get ControlNode Connection
951     Switch Connection    ${devstack_conn_id}
952     ${cmd}=    Set Variable    neutron port-pair-group-create --port-pair ${port_pair1} --port-pair ${port_pair2} ${name}
953     Log    ${cmd}
954     ${output}=    Write Commands Until Prompt    ${cmd}    30s
955     Log    ${output}
956     Close Connection
957     Should Contain    ${output}    Created a new port_pair_group
958     [Return]    ${output}
959
960 Delete SFC Port Pair Group
961     [Arguments]    ${name}
962     [Documentation]    Delete a SFC port pair group
963     ${devstack_conn_id}=    Get ControlNode Connection
964     Switch Connection    ${devstack_conn_id}
965     ${cmd}=    Set Variable    neutron port-pair-group-delete ${name}
966     Log    ${cmd}
967     ${output}=    Write Commands Until Prompt    ${cmd}    30s
968     Log    ${output}
969     Close Connection
970     Should Contain    ${output}    Deleted port_pair_group
971     [Return]    ${output}
972
973 Create SFC Port Chain
974     [Arguments]    ${name}    ${pg1}    ${pg2}    ${fc}
975     [Documentation]    Creates a port pair chain with two port groups and a singel classifier.
976     ${devstack_conn_id}=    Get ControlNode Connection
977     Switch Connection    ${devstack_conn_id}
978     ${cmd}=    Set Variable    neutron port-chain-create --port-pair-group ${pg1} --port-pair-group ${pg2} --flow-classifier ${fc} ${name}
979     Log    ${cmd}
980     ${output}=    Write Commands Until Prompt    ${cmd}    30s
981     Log    ${output}
982     Close Connection
983     Should Contain    ${output}    Created a new port_chain
984     [Return]    ${output}
985
986 Delete SFC Port Chain
987     [Arguments]    ${name}
988     [Documentation]    Delete a SFC port chain
989     ${devstack_conn_id}=    Get ControlNode Connection
990     Switch Connection    ${devstack_conn_id}
991     ${cmd}=    Set Variable    neutron port-chain-delete ${name}
992     Log    ${cmd}
993     ${output}=    Write Commands Until Prompt    ${cmd}    30s
994     Log    ${output}
995     Close Connection
996     Should Contain    ${output}    Deleted port_chain
997     [Return]    ${output}