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