fix Verify VMs Received DHCP Lease func - if dhcp ip is empty change to
[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 Resource          ../variables/Variables.robot
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    ${additional_args}=${EMPTY}
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} ${additional_args}    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 Subnet Id
191     [Arguments]    ${subnet_name}    ${devstack_conn_id}
192     [Documentation]    Retrieve the subnet id for the given subnet name
193     Switch Connection    ${devstack_conn_id}
194     ${output}=    Write Commands Until Prompt    neutron subnet-list | grep "${subnet_name}" | awk '{print $2}'    30s
195     Log    ${output}
196     ${splitted_output}=    Split String    ${output}    ${EMPTY}
197     ${subnet_id}=    Get from List    ${splitted_output}    0
198     Log    ${subnet_id}
199     [Return]    ${subnet_id}
200
201 Get Port Id
202     [Arguments]    ${port_name}    ${devstack_conn_id}
203     [Documentation]    Retrieve the port id for the given port name to attach specific vm instance to a particular port
204     Switch Connection    ${devstack_conn_id}
205     ${output}=    Write Commands Until Prompt    neutron port-list | grep "${port_name}" | awk '{print $2}'    30s
206     Log    ${output}
207     ${splitted_output}=    Split String    ${output}    ${EMPTY}
208     ${port_id}=    Get from List    ${splitted_output}    0
209     Log    ${port_id}
210     [Return]    ${port_id}
211
212 Get Router Id
213     [Arguments]    ${router1}    ${devstack_conn_id}
214     [Documentation]    Retrieve the router id for the given router name
215     Switch Connection    ${devstack_conn_id}
216     ${output}=    Write Commands Until Prompt    neutron router-list | grep "${router1}" | awk '{print $2}'    30s
217     Log    ${output}
218     ${splitted_output}=    Split String    ${output}    ${EMPTY}
219     ${router_id}=    Get from List    ${splitted_output}    0
220     Log    ${router_id}
221     [Return]    ${router_id}
222
223 Create Vm Instances
224     [Arguments]    ${net_name}    ${vm_instance_names}    ${image}=cirros-0.3.4-x86_64-uec    ${flavor}=m1.nano    ${sg}=default
225     [Documentation]    Create X Vm Instance with the net id of the Netowrk.
226     ${devstack_conn_id}=    Get ControlNode Connection
227     Switch Connection    ${devstack_conn_id}
228     ${net_id}=    Get Net Id    ${net_name}    ${devstack_conn_id}
229     : FOR    ${VmElement}    IN    @{vm_instance_names}
230     \    ${output}=    Write Commands Until Prompt    nova boot --image ${image} --flavor ${flavor} --nic net-id=${net_id} ${VmElement} --security-groups ${sg}    30s
231     \    Log    ${output}
232
233 Create Vm Instance With Port On Compute Node
234     [Arguments]    ${port_name}    ${vm_instance_name}    ${compute_node}    ${image}=cirros-0.3.4-x86_64-uec    ${flavor}=m1.nano    ${sg}=default
235     [Documentation]    Create One VM instance using given ${port_name} and for given ${compute_node}
236     ${devstack_conn_id}=    Get ControlNode Connection
237     Switch Connection    ${devstack_conn_id}
238     ${port_id}=    Get Port Id    ${port_name}    ${devstack_conn_id}
239     ${hostname_compute_node}=    Run Command On Remote System    ${compute_node}    hostname
240     ${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
241     Log    ${output}
242
243 Verify VM Is ACTIVE
244     [Arguments]    ${vm_name}
245     [Documentation]    Run these commands to check whether the created vm instance is active or not.
246     ${devstack_conn_id}=    Get ControlNode Connection
247     Switch Connection    ${devstack_conn_id}
248     ${output}=    Write Commands Until Prompt    nova show ${vm_name} | grep OS-EXT-STS:vm_state    30s
249     Log    ${output}
250     Should Contain    ${output}    active
251
252 Verify VMs Received DHCP Lease
253     [Arguments]    @{vm_list}
254     [Documentation]    Using nova console-log on the provided ${vm_list} to search for the string "obtained" which
255     ...    correlates to the instance receiving it's IP address via DHCP. Also retrieved is the ip of the nameserver
256     ...    if available in the console-log output. The keyword will also return a list of the learned ips as it
257     ...    finds them in the console log output, and will have "None" for Vms that no ip was found.
258     ${devstack_conn_id}=    Get ControlNode Connection
259     Switch Connection    ${devstack_conn_id}
260     ${ip_list}    Create List    @{EMPTY}
261     ${dhcp_ip}    Create List    @{EMPTY}
262     : FOR    ${vm}    IN    @{vm_list}
263     \    ${vm_ip_line}=    Write Commands Until Prompt    nova console-log ${vm} | grep -i "obtained"    30s
264     \    Log    ${vm_ip_line}
265     \    @{vm_ip}    Get Regexp Matches    ${vm_ip_line}    [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}
266     \    ${vm_ip_length}    Get Length    ${vm_ip}
267     \    Run Keyword If    ${vm_ip_length}>0    Append To List    ${ip_list}    @{vm_ip}[0]
268     \    ...    ELSE    Append To List    ${ip_list}    None
269     \    ${dhcp_ip_line}=    Write Commands Until Prompt    nova console-log ${vm} | grep "^nameserver"    30s
270     \    Log    ${dhcp_ip_line}
271     \    @{dhcp_ip}    Get Regexp Matches    ${dhcp_ip_line}    [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}
272     \    ${dhcp_ip_length}    Get Length    ${dhcp_ip}
273     \    Run Keyword If    ${dhcp_ip_length}<=0    Append To List    ${dhcp_ip}    None
274     \    Log    ${dhcp_ip}
275     ${dhcp_length}    Get Length    ${dhcp_ip}
276     Return From Keyword If    ${dhcp_length}==0    ${ip_list}    ${EMPTY}
277     [Return]    ${ip_list}    @{dhcp_ip}[0]
278
279 View Vm Console
280     [Arguments]    ${vm_instance_names}
281     [Documentation]    View Console log of the created vm instances using nova show.
282     : FOR    ${VmElement}    IN    @{vm_instance_names}
283     \    ${output}=    Write Commands Until Prompt    nova show ${VmElement}
284     \    Log    ${output}
285     \    ${output}=    Write Commands Until Prompt    nova console-log ${VmElement}
286     \    Log    ${output}
287
288 Ping Vm From DHCP Namespace
289     [Arguments]    ${net_name}    ${vm_ip}
290     [Documentation]    Reach all Vm Instance with the net id of the Netowrk.
291     Log    ${vm_ip}
292     ${devstack_conn_id}=    Get ControlNode Connection
293     Switch Connection    ${devstack_conn_id}
294     ${net_id}=    Get Net Id    ${net_name}    ${devstack_conn_id}
295     Log    ${net_id}
296     ${output}=    Write Commands Until Prompt    sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip}    20s
297     Log    ${output}
298     Close Connection
299     Should Contain    ${output}    64 bytes
300
301 Ping From DHCP Should Not Succeed
302     [Arguments]    ${net_name}    ${vm_ip}
303     [Documentation]    Should Not Reach Vm Instance with the net id of the Netowrk.
304     Log    ${vm_ip}
305     ${devstack_conn_id}=    Get ControlNode Connection
306     Switch Connection    ${devstack_conn_id}
307     ${net_id}=    Get Net Id    ${net_name}    ${devstack_conn_id}
308     Log    ${net_id}
309     ${output}=    Write Commands Until Prompt    sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip}    20s
310     Close Connection
311     Log    ${output}
312     Should Not Contain    ${output}    64 bytes
313
314 Ping Vm From Control Node
315     [Arguments]    ${vm_floating_ip}
316     [Documentation]    Ping VM floating IP from control node
317     Log    ${vm_floating_ip}
318     ${devstack_conn_id}=    Get ControlNode Connection
319     Switch Connection    ${devstack_conn_id}
320     ${output}=    Write Commands Until Prompt    ping -c 3 ${vm_floating_ip}    20s
321     Log    ${output}
322     Close Connection
323     Should Contain    ${output}    64 bytes
324
325 Ping From Instance
326     [Arguments]    ${dest_vm_ip}
327     [Documentation]    Ping to the expected destination ip.
328     ${output}=    Write Commands Until Expected Prompt    ping -c 3 ${dest_vm_ip}    ${OS_SYSTEM_PROMPT}
329     Log    ${output}
330     [Return]    ${output}
331
332 Curl Metadata Server
333     [Documentation]    Ping to the expected destination ip.
334     ${output}=    Write Commands Until Expected Prompt    curl -i http://169.254.169.254    ${OS_SYSTEM_PROMPT}
335     Write Commands Until Prompt    exit
336     Should Contain    ${output}    200
337
338 Close Vm Instance
339     [Documentation]    Exit the vm instance.
340     ${output}=    Write Commands Until Prompt    exit
341     Log    ${output}
342
343 Check If Console Is VmInstance
344     [Arguments]    ${console}=cirros
345     [Documentation]    Check if the session has been able to login to the VM instance
346     ${output}=    Write Commands Until Expected Prompt    id    ${OS_SYSTEM_PROMPT}
347     Should Contain    ${output}    ${console}
348
349 Exit From Vm Console
350     [Documentation]    Check if the session has been able to login to the VM instance and exit the instance
351     ${rcode}=    Run Keyword And Return Status    Check If Console Is VmInstance    cirros
352     Run Keyword If    ${rcode}    Write Commands Until Prompt    exit
353
354 Check Ping
355     [Arguments]    ${ip_address}
356     [Documentation]    Run Ping command on the IP available as argument
357     ${output}=    Write Commands Until Expected Prompt    ping -c 3 ${ip_address}    ${OS_SYSTEM_PROMPT}
358     Should Contain    ${output}    64 bytes
359
360 Check Metadata Access
361     [Documentation]    Try curl on the Metadataurl and check if it is okay
362     ${output}=    Write Commands Until Expected Prompt    curl -i http://169.254.169.254    ${OS_SYSTEM_PROMPT}
363     Should Contain    ${output}    200
364
365 Execute Command on VM Instance
366     [Arguments]    ${net_name}    ${vm_ip}    ${cmd}    ${user}=cirros    ${password}=cubswin:)
367     [Documentation]    Login to the vm instance using ssh in the network, executes a command inside the VM and returns the ouput.
368     ${devstack_conn_id} =    Get ControlNode Connection
369     Switch Connection    ${devstack_conn_id}
370     ${net_id} =    Get Net Id    ${net_name}    ${devstack_conn_id}
371     Log    ${vm_ip}
372     ${output} =    Write Commands Until Expected Prompt    sudo ip netns exec qdhcp-${net_id} ssh ${user}@${vm_ip} -o ConnectTimeout=10 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null    d:
373     Log    ${output}
374     ${output} =    Write Commands Until Expected Prompt    ${password}    ${OS_SYSTEM_PROMPT}
375     Log    ${output}
376     ${rcode} =    Run Keyword And Return Status    Check If Console Is VmInstance
377     ${output} =    Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    ${cmd}    ${OS_SYSTEM_PROMPT}
378     [Teardown]    Exit From Vm Console
379     [Return]    ${output}
380
381 Test Operations From Vm Instance
382     [Arguments]    ${net_name}    ${src_ip}    ${dest_ips}    ${user}=cirros    ${password}=cubswin:)
383     [Documentation]    Login to the vm instance using ssh in the network.
384     ${devstack_conn_id}=    Get ControlNode Connection
385     Switch Connection    ${devstack_conn_id}
386     Log    ${src_ip}
387     ${net_id}=    Get Net Id    ${net_name}    ${devstack_conn_id}
388     ${output}=    Write Commands Until Expected Prompt    sudo ip netns exec qdhcp-${net_id} ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=no ${user}@${src_ip} -o UserKnownHostsFile=/dev/null    d:
389     Log    ${output}
390     ${output}=    Write Commands Until Expected Prompt    ${password}    ${OS_SYSTEM_PROMPT}
391     Log    ${output}
392     ${rcode}=    Run Keyword And Return Status    Check If Console Is VmInstance
393     Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    ifconfig    ${OS_SYSTEM_PROMPT}
394     Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    route    ${OS_SYSTEM_PROMPT}
395     Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    arp -an    ${OS_SYSTEM_PROMPT}
396     : FOR    ${dest_ip}    IN    @{dest_ips}
397     \    Log    ${dest_ip}
398     \    ${string_empty}=    Run Keyword And Return Status    Should Be Empty    ${dest_ip}
399     \    Run Keyword If    ${string_empty}    Continue For Loop
400     \    Run Keyword If    ${rcode}    Check Ping    ${dest_ip}
401     Run Keyword If    ${rcode}    Check Metadata Access
402     [Teardown]    Exit From Vm Console
403
404 Install Netcat On Controller
405     [Documentation]    Installs Netcat on the controller - this probably shouldn't be here
406     ${devstack_conn_id}=    Get ControlNode Connection
407     Switch Connection    ${devstack_conn_id}
408     ${output}=    Write Commands Until Prompt    sudo yum install -y nc
409     Log    ${output}
410     Close Connection
411
412 Test Netcat Operations From Vm Instance
413     [Arguments]    ${net_name}    ${vm_ip}    ${dest_ip}    ${additional_args}=${EMPTY}    ${port}=12345    ${user}=cirros
414     ...    ${password}=cubswin:)
415     [Documentation]    Use Netcat to test TCP/UDP connections to the controller
416     ${client_data}    Set Variable    Test Client Data
417     ${server_data}    Set Variable    Test Server Data
418     ${devstack_conn_id}=    Get ControlNode Connection
419     Switch Connection    ${devstack_conn_id}
420     Log    ${vm_ip}
421     ${output}=    Write Commands Until Prompt    ( ( echo "${server_data}" | sudo timeout 60 nc -l ${additional_args} ${port} ) & )
422     Log    ${output}
423     ${output}=    Write Commands Until Prompt    sudo netstat -nlap | grep ${port}
424     Log    ${output}
425     ${nc_output}=    Execute Command on VM Instance    ${net_name}    ${vm_ip}    sudo echo "${client_data}" | nc -v -w 5 ${additional_args} ${dest_ip} ${port}
426     Log    ${nc_output}
427     ${output}=    Execute Command on VM Instance    ${net_name}    ${vm_ip}    sudo route -n
428     Log    ${output}
429     ${output}=    Execute Command on VM Instance    ${net_name}    ${vm_ip}    sudo arp -an
430     Log    ${output}
431     Should Match Regexp    ${nc_output}    ${server_data}
432
433 Ping Other Instances
434     [Arguments]    ${list_of_external_dst_ips}
435     [Documentation]    Check reachability with other network's instances.
436     ${rcode}=    Run Keyword And Return Status    Check If Console Is VmInstance
437     : FOR    ${dest_ip}    IN    @{list_of_external_dst_ips}
438     \    Log    ${dest_ip}
439     \    Check Ping    ${dest_ip}
440
441 Create Router
442     [Arguments]    ${router_name}
443     [Documentation]    Create Router and Add Interface to the subnets.
444     ${devstack_conn_id}=    Get ControlNode Connection
445     Switch Connection    ${devstack_conn_id}
446     ${output}=    Write Commands Until Prompt    neutron -v router-create ${router_name}    30s
447     Close Connection
448     Should Contain    ${output}    Created a new router
449
450 List Router
451     [Documentation]    List Router and return output with neutron client.
452     ${devstack_conn_id}=    Get ControlNode Connection
453     Switch Connection    ${devstack_conn_id}
454     ${output}=    Write Commands Until Prompt    neutron router-list    30s
455     Close Connection
456     Log    ${output}
457     [Return]    ${output}
458
459 Add Router Interface
460     [Arguments]    ${router_name}    ${interface_name}
461     ${devstack_conn_id}=    Get ControlNode Connection
462     Switch Connection    ${devstack_conn_id}
463     ${output}=    Write Commands Until Prompt    neutron -v router-interface-add ${router_name} ${interface_name}
464     Close Connection
465     Should Contain    ${output}    Added interface
466
467 Show Router Interface
468     [Arguments]    ${router_name}
469     [Documentation]    List Router interface associated with given Router and return output with neutron client.
470     ${devstack_conn_id}=    Get ControlNode Connection
471     Switch Connection    ${devstack_conn_id}
472     ${output}=    Write Commands Until Prompt    neutron router-port-list ${router_name} -f csv    30s
473     Close Connection
474     Log    ${output}
475     [Return]    ${output}
476
477 Add Router Gateway
478     [Arguments]    ${router_name}    ${network_name}
479     ${devstack_conn_id}=    Get ControlNode Connection
480     Switch Connection    ${devstack_conn_id}
481     ${output}=    Write Commands Until Prompt    neutron -v router-gateway-set ${router_name} ${network_name}
482     Close Connection
483     Should Contain    ${output}    Set gateway
484
485 Remove Interface
486     [Arguments]    ${router_name}    ${interface_name}
487     [Documentation]    Remove Interface to the subnets.
488     ${devstack_conn_id}=    Get ControlNode Connection
489     Switch Connection    ${devstack_conn_id}
490     ${output}=    Write Commands Until Prompt    neutron -v router-interface-delete ${router_name} ${interface_name}
491     Close Connection
492     Should Contain    ${output}    Removed interface from router
493
494 Update Router
495     [Arguments]    ${router_name}    ${cmd}
496     [Documentation]    Update the router with the command. Router name and command should be passed as argument.
497     ${devstack_conn_id} =    Get ControlNode Connection
498     Switch Connection    ${devstack_conn_id}
499     ${output} =    Write Commands Until Prompt    neutron router-update ${router_name} ${cmd}    30s
500     Close Connection
501     Should Contain    ${output}    Updated
502
503 Show Router
504     [Arguments]    ${router_name}    ${options}
505     [Documentation]    Show information of a given router. Router name and optional fields should be sent as arguments.
506     ${devstack_conn_id} =    Get ControlNode Connection
507     Switch Connection    ${devstack_conn_id}
508     ${output} =    Write Commands Until Prompt    neutron router-show ${router_name} ${options}    30s
509     Log    ${output}
510     Close Connection
511
512 Delete Router
513     [Arguments]    ${router_name}
514     [Documentation]    Delete Router and Interface to the subnets.
515     ${devstack_conn_id}=    Get ControlNode Connection
516     Switch Connection    ${devstack_conn_id}
517     ${output}=    Write Commands Until Prompt    neutron -v router-delete ${router_name}    60s
518     Close Connection
519     Should Match Regexp    ${output}    Deleted router: ${router_name}|Deleted router\\(s\\): ${router_name}
520
521 Get DumpFlows And Ovsconfig
522     [Arguments]    ${openstack_node_ip}
523     [Documentation]    Get the OvsConfig and Flow entries from OVS from the Openstack Node
524     Log    ${openstack_node_ip}
525     SSHLibrary.Open Connection    ${openstack_node_ip}    prompt=${DEFAULT_LINUX_PROMPT}
526     Utils.Flexible SSH Login    ${OS_USER}    ${DEVSTACK_SYSTEM_PASSWORD}
527     SSHLibrary.Set Client Configuration    timeout=${default_devstack_prompt_timeout}
528     Write Commands Until Expected Prompt    ip -o link    ]>
529     Write Commands Until Expected Prompt    ip -o addr    ]>
530     Write Commands Until Expected Prompt    ip route    ]>
531     Write Commands Until Expected Prompt    arp -an    ]>
532     ${nslist}=    Write Commands Until Expected Prompt    ip netns list | awk '{print $1}'    ]>
533     @{lines}    Split To Lines    ${nslist}
534     : FOR    ${line}    IN    @{lines}
535     \    Write Commands Until Expected Prompt    sudo ip netns exec ${line} ip -o link    ]>
536     \    Write Commands Until Expected Prompt    sudo ip netns exec ${line} ip -o addr    ]>
537     \    Write Commands Until Expected Prompt    sudo ip netns exec ${line} ip route    ]>
538     Write Commands Until Expected Prompt    sudo ovs-vsctl show    ]>
539     Write Commands Until Expected Prompt    sudo ovs-vsctl list Open_vSwitch    ]>
540     Write Commands Until Expected Prompt    sudo ovs-ofctl show br-int -OOpenFlow13    ]>
541     Write Commands Until Expected Prompt    sudo ovs-ofctl dump-ports-desc br-int -OOpenFlow13    ]>
542     Write Commands Until Expected Prompt    sudo ovs-ofctl dump-flows br-int -OOpenFlow13    ]>
543     Write Commands Until Expected Prompt    sudo ovs-ofctl dump-groups br-int -OOpenFlow13    ]>
544     Write Commands Until Expected Prompt    sudo ovs-ofctl dump-group-stats br-int -OOpenFlow13    ]>
545
546 Get Karaf Log Type From Test Start
547     [Arguments]    ${ip}    ${test_name}    ${type}    ${user}=${ODL_SYSTEM_USER}    ${password}=${ODL_SYSTEM_PASSWORD}    ${prompt}=${ODL_SYSTEM_PROMPT}
548     ...    ${log_file}=${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
549     ${cmd}    Set Variable    sed '1,/ROBOT MESSAGE: Starting test ${test_name}/d' ${log_file} | grep '${type}'
550     ${output}    Run Command On Controller    ${ip}    ${cmd}    ${user}    ${password}    ${prompt}
551     Log    ${output}
552
553 Get Karaf Log Types From Test Start
554     [Arguments]    ${ip}    ${test_name}    ${types}    ${user}=${ODL_SYSTEM_USER}    ${password}=${ODL_SYSTEM_PASSWORD}    ${prompt}=${ODL_SYSTEM_PROMPT}
555     ...    ${log_file}=${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
556     : FOR    ${type}    IN    @{types}
557     \    Get Karaf Log Type From Test Start    ${ip}    ${test_name}    ${type}    ${user}    ${password}
558     \    ...    ${prompt}    ${log_file}
559
560 Get Karaf Log Events From Test Start
561     [Arguments]    ${test_name}    ${user}=${ODL_SYSTEM_USER}    ${password}=${ODL_SYSTEM_PASSWORD}    ${prompt}=${ODL_SYSTEM_PROMPT}
562     ${log_types} =    Create List    ERROR    WARN    Exception
563     Run Keyword If    0 < ${NUM_ODL_SYSTEM}    Get Karaf Log Types From Test Start    ${ODL_SYSTEM_IP}    ${test_name}    ${log_types}
564     Run Keyword If    1 < ${NUM_ODL_SYSTEM}    Get Karaf Log Types From Test Start    ${ODL_SYSTEM_2_IP}    ${test_name}    ${log_types}
565     Run Keyword If    2 < ${NUM_ODL_SYSTEM}    Get Karaf Log Types From Test Start    ${ODL_SYSTEM_3_IP}    ${test_name}    ${log_types}
566
567 Get ControlNode Connection
568     ${control_conn_id}=    SSHLibrary.Open Connection    ${OS_CONTROL_NODE_IP}    prompt=${DEFAULT_LINUX_PROMPT_STRICT}
569     Utils.Flexible SSH Login    ${OS_USER}    ${DEVSTACK_SYSTEM_PASSWORD}
570     SSHLibrary.Set Client Configuration    timeout=30s
571     Source Password    force=yes
572     [Return]    ${control_conn_id}
573
574 Get OvsDebugInfo
575     [Documentation]    Get the OvsConfig and Flow entries from all Openstack nodes
576     Run Keyword If    0 < ${NUM_OS_SYSTEM}    Get DumpFlows And Ovsconfig    ${OS_CONTROL_NODE_IP}
577     Run Keyword If    1 < ${NUM_OS_SYSTEM}    Get DumpFlows And Ovsconfig    ${OS_COMPUTE_1_IP}
578     Run Keyword If    2 < ${NUM_OS_SYSTEM}    Get DumpFlows And Ovsconfig    ${OS_COMPUTE_2_IP}
579
580 Get Test Teardown Debugs
581     [Arguments]    ${test_name}=${TEST_NAME}
582     Get OvsDebugInfo
583     Get Model Dump    ${HA_PROXY_IP}
584     Get Karaf Log Events From Test Start    ${test_name}
585
586 Get Test Teardown Debugs Allow Model Dump Failures
587     [Arguments]    ${test_name}=${TEST_NAME}
588     Get OvsDebugInfo
589     Run Keyword And Ignore Error    Get Model Dump    ${HA_PROXY_IP}
590     Get Karaf Log Events From Test Start    ${test_name}
591
592 Get Suite Teardown Debugs
593     Get OvsDebugInfo
594     Get Model Dump    ${HA_PROXY_IP}
595
596 Show Debugs
597     [Arguments]    @{vm_indices}
598     [Documentation]    Run these commands for debugging, it can list state of VM instances and ip information in control node
599     ${devstack_conn_id}=    Get ControlNode Connection
600     Switch Connection    ${devstack_conn_id}
601     ${output}=    Write Commands Until Prompt    sudo ip netns list
602     Log    ${output}
603     : FOR    ${index}    IN    @{vm_indices}
604     \    ${output}=    Write Commands Until Prompt    nova show ${index}    30s
605     \    Log    ${output}
606     Close Connection
607     List Nova VMs
608     List Networks
609     List Subnets
610     List Ports
611
612 Create Security Group
613     [Arguments]    ${sg_name}    ${desc}
614     ${devstack_conn_id}=    Get ControlNode Connection
615     Switch Connection    ${devstack_conn_id}
616     ${output}=    Write Commands Until Prompt    nova secgroup-create ${sg_name} ${desc}    40s
617     Close Connection
618
619 Create Security Rule
620     [Arguments]    ${direction}    ${protocol}    ${min_port}    ${max_port}    ${remote_ip}    ${sg_name}
621     ${devstack_conn_id}=    Get ControlNode Connection
622     Switch Connection    ${devstack_conn_id}
623     ${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}
624     Close Connection
625
626 Neutron Security Group Show
627     [Arguments]    ${SecurityGroupRuleName}    ${additional_args}=${EMPTY}
628     [Documentation]    Displays the neutron security group configurations that belongs to a given neutron security group name
629     ${devstack_conn_id}=    Get ControlNode Connection
630     Switch Connection    ${devstack_conn_id}
631     ${cmd}=    Set Variable    neutron security-group-show ${SecurityGroupRuleName} ${additional_args}
632     Log    ${cmd}
633     ${output}=    Write Commands Until Prompt    ${cmd}    30s
634     Log    ${output}
635     Close Connection
636     [Return]    ${output}
637
638 Neutron Port Show
639     [Arguments]    ${PortName}    ${additional_args}=${EMPTY}
640     [Documentation]    Display the port configuration that belong to a given neutron port
641     ${devstack_conn_id}=    Get ControlNode Connection
642     Switch Connection    ${devstack_conn_id}
643     ${cmd}=    Set Variable    neutron port-show ${PortName} ${additional_args}
644     Log    ${cmd}
645     ${output}=    Write Commands Until Prompt    ${cmd}    30s
646     Log    ${output}
647     Close Connection
648     [Return]    ${output}
649
650 Neutron Security Group Create
651     [Arguments]    ${SecurityGroupName}    ${additional_args}=${EMPTY}
652     [Documentation]    Create a security group with specified name ,description & protocol value according to security group template
653     ${devstack_conn_id}=    Get ControlNode Connection
654     Switch Connection    ${devstack_conn_id}
655     ${cmd}=    Set Variable    neutron security-group-create ${SecurityGroupName} ${additional_args}
656     Log    ${cmd}
657     ${output}=    Write Commands Until Prompt    ${cmd}    30s
658     Log    ${output}
659     Should Contain    ${output}    Created a new security_group
660     ${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}
661     Log    ${sgp_id}
662     Close Connection
663     [Return]    ${output}    ${sgp_id}
664
665 Neutron Security Group Update
666     [Arguments]    ${SecurityGroupName}    ${additional_args}=${EMPTY}
667     [Documentation]    Updating security groups
668     ${devstack_conn_id}=    Get ControlNode Connection
669     Switch Connection    ${devstack_conn_id}
670     ${cmd}=    Set Variable    neutron security-group-update ${SecurityGroupName} ${additional_args}
671     Log    ${cmd}
672     ${output}=    Write Commands Until Prompt    ${cmd}    30s
673     Log    ${output}
674     Close Connection
675     [Return]    ${output}
676
677 Delete SecurityGroup
678     [Arguments]    ${sg_name}
679     [Documentation]    Delete Security group
680     ${devstack_conn_id}=    Get ControlNode Connection
681     Switch Connection    ${devstack_conn_id}
682     ${output}=    Write Commands Until Prompt    neutron security-group-delete ${sg_name}    40s
683     Log    ${output}
684     Should Match Regexp    ${output}    Deleted security_group: ${sg_name}|Deleted security_group\\(s\\): ${sg_name}
685     Close Connection
686
687 Neutron Security Group Rule Create
688     [Arguments]    ${Security_group_name}    &{Kwargs}
689     [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]} ..."
690     ${devstack_conn_id}=    Get ControlNode Connection
691     Switch Connection    ${devstack_conn_id}
692     Run Keyword If    ${Kwargs}    Log    ${Kwargs}
693     ${description}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    description    default=${None}
694     ${direction}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    direction    default=${None}
695     ${ethertype}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    ethertype    default=${None}
696     ${port_range_max}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    port_range_max    default=${None}
697     ${port_range_min}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    port_range_min    default=${None}
698     ${protocol}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    protocol    default=${None}
699     ${remote_group_id}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    remote_group_id    default=${None}
700     ${remote_ip_prefix}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    remote_ip_prefix    default=${None}
701     ${cmd}=    Set Variable    neutron security-group-rule-create ${Security_group_name}
702     ${cmd}=    Run Keyword If    '${description}'!='None'    Catenate    ${cmd}    --description ${description}
703     ...    ELSE    Catenate    ${cmd}
704     ${cmd}=    Run Keyword If    '${direction}'!='None'    Catenate    ${cmd}    --direction ${direction}
705     ...    ELSE    Catenate    ${cmd}
706     ${cmd}=    Run Keyword If    '${ethertype}'!='None'    Catenate    ${cmd}    --ethertype ${ethertype}
707     ...    ELSE    Catenate    ${cmd}
708     ${cmd}=    Run Keyword If    '${port_range_max}'!='None'    Catenate    ${cmd}    --port_range_max ${port_range_max}
709     ...    ELSE    Catenate    ${cmd}
710     ${cmd}=    Run Keyword If    '${port_range_min}'!='None'    Catenate    ${cmd}    --port_range_min ${port_range_min}
711     ...    ELSE    Catenate    ${cmd}
712     ${cmd}=    Run Keyword If    '${protocol}'!='None'    Catenate    ${cmd}    --protocol ${protocol}
713     ...    ELSE    Catenate    ${cmd}
714     ${cmd}=    Run Keyword If    '${remote_group_id}'!='None'    Catenate    ${cmd}    --remote_group_id ${remote_group_id}
715     ...    ELSE    Catenate    ${cmd}
716     ${cmd}=    Run Keyword If    '${remote_ip_prefix}'!='None'    Catenate    ${cmd}    --remote_ip_prefix ${remote_ip_prefix}
717     ...    ELSE    Catenate    ${cmd}
718     ${output}=    Write Commands Until Prompt    ${cmd}    30s
719     ${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}
720     Log    ${rule_id}
721     Should Contain    ${output}    Created a new security_group_rule
722     Close Connection
723     [Return]    ${output}    ${rule_id}
724
725 Create Neutron Port With Additional Params
726     [Arguments]    ${network_name}    ${port_name}    ${additional_args}=${EMPTY}
727     [Documentation]    Create Port With given additional parameters
728     ${devstack_conn_id}=    Get ControlNode Connection
729     Switch Connection    ${devstack_conn_id}
730     ${cmd}=    Set Variable    neutron -v port-create ${network_name} --name ${port_name} ${additional_args}
731     Log    ${cmd}
732     ${OUTPUT}=    Write Commands Until Prompt    ${cmd}    30s
733     Log    ${OUTPUT}
734     Should Contain    ${output}    Created a new port
735     ${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}
736     Log    ${port_id}
737     Close Connection
738     [Return]    ${OUTPUT}    ${port_id}
739
740 Get Ports MacAddr
741     [Arguments]    ${portName_list}
742     [Documentation]    Retrieve the port MacAddr for the given list of port name and return the MAC address list.
743     ${devstack_conn_id}=    Get ControlNode Connection
744     Switch Connection    ${devstack_conn_id}
745     ${MacAddr-list}    Create List
746     : FOR    ${portName}    IN    @{portName_list}
747     \    ${output} =    Write Commands Until Prompt    neutron port-list | grep "${portName}" | awk '{print $6}'    30s
748     \    Log    ${output}
749     \    ${splitted_output}=    Split String    ${output}    ${EMPTY}
750     \    ${macAddr}=    Get from List    ${splitted_output}    0
751     \    Log    ${macAddr}
752     \    Append To List    ${MacAddr-list}    ${macAddr}
753     [Return]    ${MacAddr-list}