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