netvirt: add floating IP connectivity test
[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          Utils.robot
5 Variables         ../variables/Variables.py
6
7 *** Keywords ***
8 Source Password
9     [Arguments]    ${force}=no    ${source_pwd}=yes
10     [Documentation]    Sourcing the Openstack PAsswords for neutron configurations
11     Run Keyword If    '${source_pwd}' == 'yes' or '${force}' == 'yes'    Write Commands Until Prompt    cd ${DEVSTACK_DEPLOY_PATH}; source openrc admin admin
12
13 Get Tenant ID From Security Group
14     [Documentation]    Returns tenant ID by reading it from existing default security-group.
15     ${devstack_conn_id}=    Get ControlNode Connection
16     Switch Connection    ${devstack_conn_id}
17     ${output}=    Write Commands Until Prompt    neutron security-group-show default | grep "| tenant_id" | awk '{print $4}'
18     Log    ${output}
19     [Return]    ${output}
20
21 Get Tenant ID From Network
22     [Arguments]    ${network_uuid}
23     [Documentation]    Returns tenant ID by reading it from existing network.
24     ${resp} =    RequestsLibrary.Get Request    session    ${CONFIG_API}/neutron:neutron/networks/network/${network_uuid}/
25     Log    ${resp.content}
26     ${matches} =    Get Lines Containing String    ${resp.content}    tenant-id
27     ${matches}=    Fetch From Right    ${matches}    :
28     ${tenant_id}=    Strip String    ${matches}    characters=}]"
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
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}    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 Contain    ${output}    Deleted port: ${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 Create And Associate Floating IPs
109     [Arguments]    ${external_net}    @{vm_list}
110     [Documentation]    Create and associate floating IPs to VMs with nova request
111     ${devstack_conn_id}=    Get ControlNode Connection
112     Switch Connection    ${devstack_conn_id}
113     ${ip_list}=    Create List    @{EMPTY}
114     : FOR    ${vm}    IN    @{vm_list}
115     \    ${output}=    Write Commands Until Prompt    nova floating-ip-create ${external_net} | grep "${external_net}"    30s
116     \    Log    ${output}
117     \    @{output_words}    Split String    ${output}
118     \    Append To List    ${ip_list}    @{output_words}[3]
119     \    ${output}=    Write Commands Until Prompt    nova floating-ip-associate ${vm} @{output_words}[3]    30s
120     \    Log    ${output}
121     [Return]    ${ip_list}
122
123 Verify Gateway Ips
124     [Documentation]    Verifies the Gateway Ips with dump flow.
125     ${output}=    Write Commands Until Prompt    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
126     Log    ${output}
127     : FOR    ${GatewayIpElement}    IN    @{GATEWAY_IPS}
128     \    Should Contain    ${output}    ${GatewayIpElement}
129
130 Verify Dhcp Ips
131     [Documentation]    Verifies the Dhcp Ips with dump flow.
132     ${output}=    Write Commands Until Prompt    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
133     Log    ${output}
134     : FOR    ${DhcpIpElement}    IN    @{DHCP_IPS}
135     \    Should Contain    ${output}    ${DhcpIpElement}
136
137 Verify No Dhcp Ips
138     [Documentation]    Verifies the Dhcp Ips with dump flow.
139     ${output}=    Write Commands Until Prompt    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
140     Log    ${output}
141     : FOR    ${DhcpIpElement}    IN    @{DHCP_IPS}
142     \    Should Not Contain    ${output}    ${DhcpIpElement}
143
144 Delete SubNet
145     [Arguments]    ${subnet}
146     [Documentation]    Delete SubNet for the Network with neutron request.
147     Log    ${subnet}
148     ${devstack_conn_id}=    Get ControlNode Connection
149     Switch Connection    ${devstack_conn_id}
150     ${output}=    Write Commands Until Prompt    neutron -v subnet-delete ${subnet}
151     Close Connection
152     Log    ${output}
153     Should Match Regexp    ${output}    Deleted subnet: ${subnet}|Deleted subnet\\(s\\): ${subnet}
154
155 Verify No Gateway Ips
156     [Documentation]    Verifies the Gateway Ips removed with dump flow.
157     ${output}=    Write Commands Until Prompt    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
158     Log    ${output}
159     : FOR    ${GatewayIpElement}    IN    @{GATEWAY_IPS}
160     \    Should Not Contain    ${output}    ${GatewayIpElement}
161
162 Delete Vm Instance
163     [Arguments]    ${vm_name}
164     [Documentation]    Delete Vm instances using instance names.
165     ${devstack_conn_id}=    Get ControlNode Connection
166     Switch Connection    ${devstack_conn_id}
167     ${output}=    Write Commands Until Prompt    nova force-delete ${vm_name}    40s
168     Close Connection
169
170 Get Net Id
171     [Arguments]    ${network_name}    ${devstack_conn_id}
172     [Documentation]    Retrieve the net id for the given network name to create specific vm instance
173     Switch Connection    ${devstack_conn_id}
174     ${output}=    Write Commands Until Prompt    neutron net-list | grep "${network_name}" | awk '{print $2}'    30s
175     Log    ${output}
176     ${splitted_output}=    Split String    ${output}    ${EMPTY}
177     ${net_id}=    Get from List    ${splitted_output}    0
178     Log    ${net_id}
179     [Return]    ${net_id}
180
181 Get Port Id
182     [Arguments]    ${port_name}    ${devstack_conn_id}
183     [Documentation]    Retrieve the port id for the given port name to attach specific vm instance to a particular port
184     Switch Connection    ${devstack_conn_id}
185     ${output}=    Write Commands Until Prompt    neutron port-list | grep "${port_name}" | awk '{print $2}'    30s
186     Log    ${output}
187     ${splitted_output}=    Split String    ${output}    ${EMPTY}
188     ${port_id}=    Get from List    ${splitted_output}    0
189     Log    ${port_id}
190     [Return]    ${port_id}
191
192 Get Router Id
193     [Arguments]    ${router1}    ${devstack_conn_id}
194     [Documentation]    Retrieve the net id for the given network name to create specific vm instance
195     Switch Connection    ${devstack_conn_id}
196     ${output}=    Write Commands Until Prompt    neutron router-list | grep "${router1}" | awk '{print $2}'    30s
197     Log    ${output}
198     ${splitted_output}=    Split String    ${output}    ${EMPTY}
199     ${router_id}=    Get from List    ${splitted_output}    0
200     Log    ${router_id}
201     [Return]    ${router_id}
202
203 Create Vm Instances
204     [Arguments]    ${net_name}    ${vm_instance_names}    ${image}=cirros-0.3.4-x86_64-uec    ${flavor}=m1.nano    ${sg}=default
205     [Documentation]    Create X Vm Instance with the net id of the Netowrk.
206     ${devstack_conn_id}=    Get ControlNode Connection
207     Switch Connection    ${devstack_conn_id}
208     ${net_id}=    Get Net Id    ${net_name}    ${devstack_conn_id}
209     : FOR    ${VmElement}    IN    @{vm_instance_names}
210     \    ${output}=    Write Commands Until Prompt    nova boot --image ${image} --flavor ${flavor} --nic net-id=${net_id} ${VmElement} --security-groups ${sg}    30s
211     \    Log    ${output}
212
213 Create Vm Instance With Port On Compute Node
214     [Arguments]    ${port_name}    ${vm_instance_name}    ${compute_node}    ${image}=cirros-0.3.4-x86_64-uec    ${flavor}=m1.nano    ${sg}=default
215     [Documentation]    Create One VM instance using given ${port_name} and for given ${compute_node}
216     ${devstack_conn_id}=    Get ControlNode Connection
217     Switch Connection    ${devstack_conn_id}
218     ${port_id}=    Get Port Id    ${port_name}    ${devstack_conn_id}
219     ${hostname_compute_node}=    Run Command On Remote System    ${compute_node}    hostname
220     ${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
221     Log    ${output}
222     Wait Until Keyword Succeeds    25s    5s    Verify VM Is ACTIVE    ${vm_instance_name}
223
224 Verify VM Is ACTIVE
225     [Arguments]    ${vm_name}
226     [Documentation]    Run these commands to check whether the created vm instance is active or not.
227     ${devstack_conn_id}=    Get ControlNode Connection
228     Switch Connection    ${devstack_conn_id}
229     ${output}=    Write Commands Until Prompt    nova show ${vm_name} | grep OS-EXT-STS:vm_state    30s
230     Log    ${output}
231     Should Contain    ${output}    active
232
233 Verify VMs Received DHCP Lease
234     [Arguments]    @{vm_list}
235     [Documentation]    Using nova console-log on the provided ${vm_list} to search for the string "obtained" which
236     ...    correlates to the instance receiving it's IP address via DHCP. This should provide a good indication
237     ...    that the instance is fully up and ready.
238     ${devstack_conn_id}=    Get ControlNode Connection
239     Switch Connection    ${devstack_conn_id}
240     ${ip_list}    Create List
241     : FOR    ${vm}    IN    @{vm_list}
242     \    ${output}=    Write Commands Until Prompt    nova console-log ${vm} | grep -i "obtained"    30s
243     \    ${dhcp_ip_line}=    Write Commands Until Prompt    nova console-log ${vm} | grep "^nameserver"    30s
244     \    Log    ${output}
245     \    @{output_words}    Split String    ${output}
246     \    @{dhcp_output_words}    Split String    ${dhcp_ip_line}
247     \    Should Contain    ${output}    obtained
248     \    Append To List    ${ip_list}    @{output_words}[2]
249     [Return]    ${ip_list}    @{dhcp_output_words}[1]
250
251 View Vm Console
252     [Arguments]    ${vm_instance_names}
253     [Documentation]    View Console log of the created vm instances using nova show.
254     : FOR    ${VmElement}    IN    @{vm_instance_names}
255     \    ${output}=    Write Commands Until Prompt    nova show ${VmElement}
256     \    Log    ${output}
257     \    ${output}=    Write Commands Until Prompt    nova console-log ${VmElement}
258     \    Log    ${output}
259
260 Ping Vm From DHCP Namespace
261     [Arguments]    ${net_name}    ${vm_ip}
262     [Documentation]    Reach all Vm Instance with the net id of the Netowrk.
263     Log    ${vm_ip}
264     ${devstack_conn_id}=    Get ControlNode Connection
265     Switch Connection    ${devstack_conn_id}
266     ${net_id}=    Get Net Id    ${net_name}    ${devstack_conn_id}
267     Log    ${net_id}
268     ${output}=    Write Commands Until Prompt    sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip}    20s
269     Log    ${output}
270     Close Connection
271     Should Contain    ${output}    64 bytes
272
273 Ping From DHCP Should Not Succeed
274     [Arguments]    ${net_name}    ${vm_ip}
275     [Documentation]    Should Not Reach Vm Instance with the net id of the Netowrk.
276     Log    ${vm_ip}
277     ${devstack_conn_id}=    Get ControlNode Connection
278     Switch Connection    ${devstack_conn_id}
279     ${net_id}=    Get Net Id    ${net_name}    ${devstack_conn_id}
280     Log    ${net_id}
281     ${output}=    Write Commands Until Prompt    sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip}    20s
282     Close Connection
283     Log    ${output}
284     Should Not Contain    ${output}    64 bytes
285
286 Ping Vm From Control Node
287     [Arguments]    ${vm_floating_ip}
288     [Documentation]    Ping VM floating IP from control node
289     Log    ${vm_floating_ip}
290     ${devstack_conn_id}=    Get ControlNode Connection
291     Switch Connection    ${devstack_conn_id}
292     ${output}=    Write Commands Until Prompt    ping -c 3 ${vm_floating_ip}    20s
293     Log    ${output}
294     Close Connection
295     Should Contain    ${output}    64 bytes
296
297 Ping From Instance
298     [Arguments]    ${dest_vm_ip}
299     [Documentation]    Ping to the expected destination ip.
300     ${output}=    Write Commands Until Expected Prompt    ping -c 3 ${dest_vm_ip}    ${OS_SYSTEM_PROMPT}
301     Log    ${output}
302     [Return]    ${output}
303
304 Curl Metadata Server
305     [Documentation]    Ping to the expected destination ip.
306     ${output}=    Write Commands Until Expected Prompt    curl -i http://169.254.169.254    ${OS_SYSTEM_PROMPT}
307     Write Commands Until Prompt    exit
308     Should Contain    ${output}    200
309
310 Close Vm Instance
311     [Documentation]    Exit the vm instance.
312     ${output}=    Write Commands Until Prompt    exit
313     Log    ${output}
314
315 Check If Console Is VmInstance
316     [Arguments]    ${console}=cirros
317     [Documentation]    Check if the session has been able to login to the VM instance
318     ${output}=    Write Commands Until Expected Prompt    id    ${OS_SYSTEM_PROMPT}
319     Should Contain    ${output}    ${console}
320
321 Exit From Vm Console
322     [Documentation]    Check if the session has been able to login to the VM instance and exit the instance
323     ${rcode}=    Run Keyword And Return Status    Check If Console Is VmInstance    cirros
324     Run Keyword If    ${rcode}    Write Commands Until Prompt    exit
325     Get OvsDebugInfo
326
327 Check Ping
328     [Arguments]    ${ip_address}
329     [Documentation]    Run Ping command on the IP available as argument
330     ${output}=    Write Commands Until Expected Prompt    ping -c 3 ${ip_address}    ${OS_SYSTEM_PROMPT}
331     Should Contain    ${output}    64 bytes
332
333 Check Metadata Access
334     [Documentation]    Try curl on the Metadataurl and check if it is okay
335     ${output}=    Write Commands Until Expected Prompt    curl -i http://169.254.169.254    ${OS_SYSTEM_PROMPT}
336     Should Contain    ${output}    200
337
338 Execute Command on VM Instance
339     [Arguments]    ${net_name}    ${vm_ip}    ${cmd}    ${user}=cirros    ${password}=cubswin:)
340     [Documentation]    Login to the vm instance using ssh in the network, executes a command inside the VM and returns the ouput.
341     ${devstack_conn_id} =    Get ControlNode Connection
342     Switch Connection    ${devstack_conn_id}
343     ${net_id} =    Get Net Id    ${net_name}    ${devstack_conn_id}
344     Log    ${vm_ip}
345     ${output} =    Write Commands Until Expected Prompt    sudo ip netns exec qdhcp-${net_id} ssh ${user}@${vm_ip} -o ConnectTimeout=10 -o StrictHostKeyChecking=no    d:
346     Log    ${output}
347     ${output} =    Write Commands Until Expected Prompt    ${password}    ${OS_SYSTEM_PROMPT}
348     Log    ${output}
349     ${rcode} =    Run Keyword And Return Status    Check If Console Is VmInstance
350     ${output} =    Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    ${cmd}    ${OS_SYSTEM_PROMPT}
351     [Teardown]    Exit From Vm Console
352     [Return]    ${output}
353
354 Test Operations From Vm Instance
355     [Arguments]    ${net_name}    ${src_ip}    ${dest_ips}    ${user}=cirros    ${password}=cubswin:)
356     [Documentation]    Login to the vm instance using ssh in the network.
357     ${devstack_conn_id}=    Get ControlNode Connection
358     Switch Connection    ${devstack_conn_id}
359     Log    ${src_ip}
360     ${net_id}=    Get Net Id    ${net_name}    ${devstack_conn_id}
361     ${output}=    Write Commands Until Expected Prompt    sudo ip netns exec qdhcp-${net_id} ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no ${user}@${src_ip}    d:
362     Log    ${output}
363     ${output}=    Write Commands Until Expected Prompt    ${password}    ${OS_SYSTEM_PROMPT}
364     Log    ${output}
365     ${rcode}=    Run Keyword And Return Status    Check If Console Is VmInstance
366     Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    ifconfig    ${OS_SYSTEM_PROMPT}
367     Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    route    ${OS_SYSTEM_PROMPT}
368     Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    arp -an    ${OS_SYSTEM_PROMPT}
369     : FOR    ${dest_ip}    IN    @{dest_ips}
370     \    Log    ${dest_ip}
371     \    ${string_empty}=    Run Keyword And Return Status    Should Be Empty    ${dest_ip}
372     \    Run Keyword If    ${string_empty}    Continue For Loop
373     \    Run Keyword If    ${rcode}    Check Ping    ${dest_ip}
374     Run Keyword If    ${rcode}    Check Metadata Access
375     [Teardown]    Exit From Vm Console
376
377 Ping Other Instances
378     [Arguments]    ${list_of_external_dst_ips}
379     [Documentation]    Check reachability with other network's instances.
380     ${rcode}=    Run Keyword And Return Status    Check If Console Is VmInstance
381     : FOR    ${dest_ip}    IN    @{list_of_external_dst_ips}
382     \    Log    ${dest_ip}
383     \    Check Ping    ${dest_ip}
384
385 Create Router
386     [Arguments]    ${router_name}
387     [Documentation]    Create Router and Add Interface to the subnets.
388     ${devstack_conn_id}=    Get ControlNode Connection
389     Switch Connection    ${devstack_conn_id}
390     ${output}=    Write Commands Until Prompt    neutron -v router-create ${router_name}    30s
391     Close Connection
392     Should Contain    ${output}    Created a new router
393
394 Add Router Interface
395     [Arguments]    ${router_name}    ${interface_name}
396     ${devstack_conn_id}=    Get ControlNode Connection
397     Switch Connection    ${devstack_conn_id}
398     ${output}=    Write Commands Until Prompt    neutron -v router-interface-add ${router_name} ${interface_name}
399     Close Connection
400     Should Contain    ${output}    Added interface
401
402 Add Router Gateway
403     [Arguments]    ${router_name}    ${network_name}
404     ${devstack_conn_id}=    Get ControlNode Connection
405     Switch Connection    ${devstack_conn_id}
406     ${output}=    Write Commands Until Prompt    neutron -v router-gateway-set ${router_name} ${network_name}
407     Close Connection
408     Should Contain    ${output}    Set gateway
409
410 Remove Interface
411     [Arguments]    ${router_name}    ${interface_name}
412     [Documentation]    Remove Interface to the subnets.
413     ${devstack_conn_id}=    Get ControlNode Connection
414     Switch Connection    ${devstack_conn_id}
415     ${output}=    Write Commands Until Prompt    neutron -v router-interface-delete ${router_name} ${interface_name}
416     Close Connection
417     Should Contain    ${output}    Removed interface from router
418
419 Update Router
420     [Arguments]    ${router_name}    ${cmd}
421     [Documentation]    Update the router with the command. Router name and command should be passed as argument.
422     ${devstack_conn_id} =    Get ControlNode Connection
423     Switch Connection    ${devstack_conn_id}
424     ${output} =    Write Commands Until Prompt    neutron router-update ${router_name} ${cmd}    30s
425     Close Connection
426     Should Contain    ${output}    Updated
427
428 Show Router
429     [Arguments]    ${router_name}    ${options}
430     [Documentation]    Show information of a given router. Router name and optional fields should be sent as arguments.
431     ${devstack_conn_id} =    Get ControlNode Connection
432     Switch Connection    ${devstack_conn_id}
433     ${output} =    Write Commands Until Prompt    neutron router-show ${router_name} ${options}    30s
434     Log    ${output}
435     Close Connection
436
437 Delete Router
438     [Arguments]    ${router_name}
439     [Documentation]    Delete Router and Interface to the subnets.
440     ${devstack_conn_id}=    Get ControlNode Connection
441     Switch Connection    ${devstack_conn_id}
442     ${output}=    Write Commands Until Prompt    neutron -v router-delete ${router_name}    60s
443     Close Connection
444     Should Match Regexp    ${output}    Deleted router: ${router_name}|Deleted router\\(s\\): ${router_name}
445
446 Get DumpFlows And Ovsconfig
447     [Arguments]    ${openstack_node_ip}
448     [Documentation]    Get the OvsConfig and Flow entries from OVS from the Openstack Node
449     Log    ${openstack_node_ip}
450     SSHLibrary.Open Connection    ${openstack_node_ip}    prompt=${DEFAULT_LINUX_PROMPT}
451     Utils.Flexible SSH Login    ${OS_USER}    ${DEVSTACK_SYSTEM_PASSWORD}
452     SSHLibrary.Set Client Configuration    timeout=${default_devstack_prompt_timeout}
453     Write Commands Until Expected Prompt    ip -o link    ]>
454     Write Commands Until Expected Prompt    ip -o addr    ]>
455     Write Commands Until Expected Prompt    ip route    ]>
456     Write Commands Until Expected Prompt    arp -an    ]>
457     ${nslist}=    Write Commands Until Expected Prompt    ip netns list | awk '{print $1}'    ]>
458     @{lines}    Split To Lines    ${nslist}
459     : FOR    ${line}    IN    @{lines}
460     \    Write Commands Until Expected Prompt    sudo ip netns exec ${line} ip -o link    ]>
461     \    Write Commands Until Expected Prompt    sudo ip netns exec ${line} ip -o addr    ]>
462     \    Write Commands Until Expected Prompt    sudo ip netns exec ${line} ip route    ]>
463     Write Commands Until Expected Prompt    sudo ovs-vsctl show    ]>
464     Write Commands Until Expected Prompt    sudo ovs-vsctl list Open_vSwitch    ]>
465     Write Commands Until Expected Prompt    sudo ovs-ofctl show br-int -OOpenFlow13    ]>
466     Write Commands Until Expected Prompt    sudo ovs-ofctl dump-flows br-int -OOpenFlow13    ]>
467     Write Commands Until Expected Prompt    sudo ovs-ofctl dump-groups br-int -OOpenFlow13    ]>
468     Write Commands Until Expected Prompt    sudo ovs-ofctl dump-group-stats br-int -OOpenFlow13    ]>
469
470 Get ControlNode Connection
471     ${control_conn_id}=    SSHLibrary.Open Connection    ${OS_CONTROL_NODE_IP}    prompt=${DEFAULT_LINUX_PROMPT_STRICT}
472     Utils.Flexible SSH Login    ${OS_USER}    ${DEVSTACK_SYSTEM_PASSWORD}
473     SSHLibrary.Set Client Configuration    timeout=30s
474     Source Password    force=yes
475     [Return]    ${control_conn_id}
476
477 Get OvsDebugInfo
478     [Documentation]    Get the OvsConfig and Flow entries from all Openstack nodes
479     Run Keyword If    0 < ${NUM_OS_SYSTEM}    Get DumpFlows And Ovsconfig    ${OS_CONTROL_NODE_IP}
480     Run Keyword If    1 < ${NUM_OS_SYSTEM}    Get DumpFlows And Ovsconfig    ${OS_COMPUTE_1_IP}
481     Run Keyword If    2 < ${NUM_OS_SYSTEM}    Get DumpFlows And Ovsconfig    ${OS_COMPUTE_2_IP}
482
483 Show Debugs
484     [Arguments]    ${vm_indices}
485     [Documentation]    Run these commands for debugging, it can list state of VM instances and ip information in control node
486     ${devstack_conn_id}=    Get ControlNode Connection
487     Switch Connection    ${devstack_conn_id}
488     ${output}=    Write Commands Until Prompt    sudo ip netns list
489     Log    ${output}
490     : FOR    ${index}    IN    @{vm_indices}
491     \    ${output}=    Write Commands Until Prompt    nova show ${index}    30s
492     \    Log    ${output}
493     Close Connection
494     List Networks
495     List Subnets
496     List Ports
497
498 Create Security Group
499     [Arguments]    ${sg_name}    ${desc}
500     ${devstack_conn_id}=    Get ControlNode Connection
501     Switch Connection    ${devstack_conn_id}
502     ${output}=    Write Commands Until Prompt    nova secgroup-create ${sg_name} ${desc}    40s
503     Close Connection
504
505 Create Security Rule
506     [Arguments]    ${direction}    ${protocol}    ${min_port}    ${max_port}    ${remote_ip}    ${sg_name}
507     ${devstack_conn_id}=    Get ControlNode Connection
508     Switch Connection    ${devstack_conn_id}
509     ${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}
510     Close Connection
511
512 Neutron Security Group Show
513     [Arguments]    ${SecurityGroupRuleName}    ${additional_args}=${EMPTY}
514     [Documentation]    Displays the neutron security group configurations that belongs to a given neutron security group name
515     ${devstack_conn_id}=    Get ControlNode Connection
516     Switch Connection    ${devstack_conn_id}
517     ${cmd}=    Set Variable    neutron security-group-show ${SecurityGroupRuleName} ${additional_args}
518     Log    ${cmd}
519     ${output}=    Write Commands Until Prompt    ${cmd}    30s
520     Log    ${output}
521     Close Connection
522     [Return]    ${output}
523
524 Neutron Port Show
525     [Arguments]    ${PortName}    ${additional_args}=${EMPTY}
526     [Documentation]    Display the port configuration that belong to a given neutron port
527     ${devstack_conn_id}=    Get ControlNode Connection
528     Switch Connection    ${devstack_conn_id}
529     ${cmd}=    Set Variable    neutron port-show ${PortName} ${additional_args}
530     Log    ${cmd}
531     ${output}=    Write Commands Until Prompt    ${cmd}    30s
532     Log    ${output}
533     Close Connection
534     [Return]    ${output}
535
536 Neutron Security Group Create
537     [Arguments]    ${SecurityGroupName}    ${additional_args}=${EMPTY}
538     [Documentation]    Create a security group with specified name ,description & protocol value according to security group template
539     ${devstack_conn_id}=    Get ControlNode Connection
540     Switch Connection    ${devstack_conn_id}
541     ${cmd}=    Set Variable    neutron security-group-create ${SecurityGroupName} ${additional_args}
542     Log    ${cmd}
543     ${output}=    Write Commands Until Prompt    ${cmd}    30s
544     Log    ${output}
545     Should Contain    ${output}    Created a new security_group
546     ${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}
547     Log    ${sgp_id}
548     Close Connection
549     [Return]    ${output}    ${sgp_id}
550
551 Neutron Security Group Update
552     [Arguments]    ${SecurityGroupName}    ${additional_args}=${EMPTY}
553     [Documentation]    Updating security groups
554     ${devstack_conn_id}=    Get ControlNode Connection
555     Switch Connection    ${devstack_conn_id}
556     ${cmd}=    Set Variable    neutron security-group-update ${SecurityGroupName} ${additional_args}
557     Log    ${cmd}
558     ${output}=    Write Commands Until Prompt    ${cmd}    30s
559     Log    ${output}
560     Close Connection
561     [Return]    ${output}
562
563 Neutron Security Group Rule Create
564     [Arguments]    ${Security_group_name}    &{Kwargs}
565     [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]} ..."
566     ${devstack_conn_id}=    Get ControlNode Connection
567     Switch Connection    ${devstack_conn_id}
568     Run Keyword If    ${Kwargs}    Log    ${Kwargs}
569     ${description}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    description    default=${None}
570     ${direction}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    direction    default=${None}
571     ${ethertype}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    ethertype    default=${None}
572     ${port_range_max}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    port_range_max    default=${None}
573     ${port_range_min}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    port_range_min    default=${None}
574     ${protocol}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    protocol    default=${None}
575     ${remote_group_id}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    remote_group_id    default=${None}
576     ${remote_ip_prefix}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    remote_ip_prefix    default=${None}
577     ${cmd}=    Set Variable    neutron security-group-rule-create ${Security_group_name}
578     ${cmd}=    Run Keyword If    '${description}'!='None'    Catenate    ${cmd}    --description ${description}
579     ...    ELSE    Catenate    ${cmd}
580     ${cmd}=    Run Keyword If    '${direction}'!='None'    Catenate    ${cmd}    --direction ${direction}
581     ...    ELSE    Catenate    ${cmd}
582     ${cmd}=    Run Keyword If    '${ethertype}'!='None'    Catenate    ${cmd}    --ethertype ${ethertype}
583     ...    ELSE    Catenate    ${cmd}
584     ${cmd}=    Run Keyword If    '${port_range_max}'!='None'    Catenate    ${cmd}    --port_range_max ${port_range_max}
585     ...    ELSE    Catenate    ${cmd}
586     ${cmd}=    Run Keyword If    '${port_range_min}'!='None'    Catenate    ${cmd}    --port_range_min ${port_range_min}
587     ...    ELSE    Catenate    ${cmd}
588     ${cmd}=    Run Keyword If    '${protocol}'!='None'    Catenate    ${cmd}    --protocol ${protocol}
589     ...    ELSE    Catenate    ${cmd}
590     ${cmd}=    Run Keyword If    '${remote_group_id}'!='None'    Catenate    ${cmd}    --remote_group_id ${remote_group_id}
591     ...    ELSE    Catenate    ${cmd}
592     ${cmd}=    Run Keyword If    '${remote_ip_prefix}'!='None'    Catenate    ${cmd}    --remote_ip_prefix ${remote_ip_prefix}
593     ...    ELSE    Catenate    ${cmd}
594     ${output}=    Write Commands Until Prompt    ${cmd}    30s
595     ${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}
596     Log    ${rule_id}
597     Should Contain    ${output}    Created a new security_group_rule
598     Close Connection
599     [Return]    ${output}    ${rule_id}
600
601 Create Neutron Port With Additional Params
602     [Arguments]    ${network_name}    ${port_name}    ${additional_args}=${EMPTY}
603     [Documentation]    Create Port With given additional parameters
604     ${devstack_conn_id}=    Get ControlNode Connection
605     Switch Connection    ${devstack_conn_id}
606     ${cmd}=    Set Variable    neutron -v port-create ${network_name} --name ${port_name} ${additional_args}
607     Log    ${cmd}
608     ${OUTPUT}=    Write Commands Until Prompt    ${cmd}    30s
609     Log    ${OUTPUT}
610     Should Contain    ${output}    Created a new port
611     ${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}
612     Log    ${port_id}
613     Close Connection
614     [Return]    ${OUTPUT}    ${port_id}