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