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