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