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