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