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