Add suite for extensive SG testing
[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          DataModels.robot
5 Resource          Utils.robot
6 Resource          L2GatewayOperations.robot
7 Resource          ../variables/Variables.robot
8 Variables         ../variables/netvirt/Modules.py
9
10 *** Keywords ***
11 Source Password
12     [Arguments]    ${force}=no    ${source_pwd}=yes
13     [Documentation]    Sourcing the Openstack PAsswords for neutron configurations
14     Run Keyword If    '${source_pwd}' == 'yes' or '${force}' == 'yes'    Write Commands Until Prompt    cd ${DEVSTACK_DEPLOY_PATH}; source openrc admin admin
15
16 Get Tenant ID From Security Group
17     [Documentation]    Returns tenant ID by reading it from existing default security-group.
18     ${devstack_conn_id}=    Get ControlNode Connection
19     Switch Connection    ${devstack_conn_id}
20     ${output}=    Write Commands Until Prompt    neutron security-group-show default | grep "| tenant_id" | awk '{print $4}'
21     Log    ${output}
22     [Return]    ${output}
23
24 Get Tenant ID From Network
25     [Arguments]    ${network_uuid}
26     [Documentation]    Returns tenant ID by reading it from existing network.
27     ${resp}=    Get_From_Uri    uri=${CONFIG_API}/neutron:neutron/networks/network/${network_uuid}/    accept=${ACCEPT_EMPTY}    session=session
28     ${tenant_id}=    Utils.Extract Value From Content    ${resp}    /network/0/tenant-id    strip
29     [Return]    ${tenant_id}
30
31 Create Network
32     [Arguments]    ${network_name}    ${additional_args}=${EMPTY}    ${verbose}=TRUE
33     [Documentation]    Create Network with neutron request.
34     ${devstack_conn_id}=    Get ControlNode Connection
35     Switch Connection    ${devstack_conn_id}
36     ${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}'
37     ${output}=    Write Commands Until Prompt    ${command}    30s
38     Log    ${output}
39     [Return]    ${output}
40
41 Update Network
42     [Arguments]    ${network_name}    ${additional_args}=${EMPTY}
43     [Documentation]    Update Network with neutron request.
44     ${devstack_conn_id}=    Get ControlNode Connection
45     Switch Connection    ${devstack_conn_id}
46     ${output}=    Write Commands Until Prompt    neutron -v net-update ${network_name} ${additional_args}    30s
47     Log    ${output}
48     Close Connection
49     [Return]    ${output}
50
51 Show Network
52     [Arguments]    ${network_name}
53     [Documentation]    Show Network with neutron request.
54     ${devstack_conn_id}=    Get ControlNode Connection
55     Switch Connection    ${devstack_conn_id}
56     ${output}=    Write Commands Until Prompt    neutron -v net-show ${network_name}    30s
57     Log    ${output}
58     Close Connection
59     [Return]    ${output}
60
61 List Networks
62     [Documentation]    List networks and return output with neutron client.
63     ${devstack_conn_id}=    Get ControlNode Connection
64     Switch Connection    ${devstack_conn_id}
65     ${output}=    Write Commands Until Prompt    neutron net-list    30s
66     Close Connection
67     Log    ${output}
68     [Return]    ${output}
69
70 List Subnets
71     [Documentation]    List subnets and return output with neutron client.
72     ${devstack_conn_id}=    Get ControlNode Connection
73     Switch Connection    ${devstack_conn_id}
74     ${output}=    Write Commands Until Prompt    neutron subnet-list    30s
75     Close Connection
76     Log    ${output}
77     [Return]    ${output}
78
79 Delete Network
80     [Arguments]    ${network_name}
81     [Documentation]    Delete Network with neutron request.
82     ${devstack_conn_id}=    Get ControlNode Connection
83     Switch Connection    ${devstack_conn_id}
84     ${output}=    Write Commands Until Prompt    neutron -v net-delete ${network_name}    30s
85     Close Connection
86     Log    ${output}
87     Should Match Regexp    ${output}    Deleted network: ${network_name}|Deleted network\\(s\\): ${network_name}
88
89 Create SubNet
90     [Arguments]    ${network_name}    ${subnet}    ${range_ip}    ${additional_args}=${EMPTY}
91     [Documentation]    Create SubNet for the Network with neutron request.
92     ${devstack_conn_id}=    Get ControlNode Connection
93     Switch Connection    ${devstack_conn_id}
94     ${output}=    Write Commands Until Prompt    neutron -v subnet-create ${network_name} ${range_ip} --name ${subnet} ${additional_args}    30s
95     Close Connection
96     Log    ${output}
97     Should Contain    ${output}    Created a new subnet
98
99 Update SubNet
100     [Arguments]    ${subnet_name}    ${additional_args}=${EMPTY}
101     [Documentation]    Update subnet with neutron request.
102     ${devstack_conn_id}=    Get ControlNode Connection
103     Switch Connection    ${devstack_conn_id}
104     ${output}=    Write Commands Until Prompt    neutron -v subnet-update ${subnet_name} ${additional_args}    30s
105     Log    ${output}
106     Close Connection
107     [Return]    ${output}
108
109 Show SubNet
110     [Arguments]    ${subnet_name}
111     [Documentation]    Show subnet with neutron request.
112     ${devstack_conn_id}=    Get ControlNode Connection
113     Switch Connection    ${devstack_conn_id}
114     ${output}=    Write Commands Until Prompt    neutron -v subnet-show ${subnet_name}    30s
115     Log    ${output}
116     Close Connection
117     [Return]    ${output}
118
119 Create Port
120     [Arguments]    ${network_name}    ${port_name}    ${sg}=default    ${additional_args}=${EMPTY}
121     [Documentation]    Create Port with neutron request.
122     ${devstack_conn_id}=    Get ControlNode Connection
123     Switch Connection    ${devstack_conn_id}
124     ${output}=    Write Commands Until Prompt    neutron -v port-create ${network_name} --name ${port_name} --security-group ${sg} ${additional_args}    30s
125     Close Connection
126     Log    ${output}
127     Should Contain    ${output}    Created a new port
128
129 Update Port
130     [Arguments]    ${port_name}    ${additional_args}=${EMPTY}
131     [Documentation]    Update port with neutron request.
132     ${devstack_conn_id}=    Get ControlNode Connection
133     Switch Connection    ${devstack_conn_id}
134     ${output}=    Write Commands Until Prompt    neutron -v port-update ${port_name} ${additional_args}    30s
135     Log    ${output}
136     Close Connection
137     [Return]    ${output}
138
139 Show Port
140     [Arguments]    ${port_name}
141     [Documentation]    Show port with neutron request.
142     ${devstack_conn_id}=    Get ControlNode Connection
143     Switch Connection    ${devstack_conn_id}
144     ${output}=    Write Commands Until Prompt    neutron -v port-show ${port_name}    30s
145     Log    ${output}
146     Close Connection
147     [Return]    ${output}
148
149 Delete Port
150     [Arguments]    ${port_name}
151     [Documentation]    Delete Port with neutron request.
152     ${devstack_conn_id}=    Get ControlNode Connection
153     Switch Connection    ${devstack_conn_id}
154     ${output}=    Write Commands Until Prompt    neutron -v port-delete ${port_name}    30s
155     Close Connection
156     Log    ${output}
157     Should Match Regexp    ${output}    Deleted port: ${port_name}|Deleted port\\(s\\): ${port_name}
158
159 List Ports
160     [Documentation]    List ports and return output with neutron client.
161     ${devstack_conn_id}=    Get ControlNode Connection
162     Switch Connection    ${devstack_conn_id}
163     ${output}=    Write Commands Until Prompt    neutron port-list    30s
164     Close Connection
165     Log    ${output}
166     [Return]    ${output}
167
168 List Nova VMs
169     [Documentation]    List VMs and return output with nova client.
170     ${devstack_conn_id}=    Get ControlNode Connection
171     Switch Connection    ${devstack_conn_id}
172     ${output}=    Write Commands Until Prompt    nova list    30s
173     Close Connection
174     Log    ${output}
175     [Return]    ${output}
176
177 Create And Associate Floating IPs
178     [Arguments]    ${external_net}    @{vm_list}
179     [Documentation]    Create and associate floating IPs to VMs with nova request
180     ${devstack_conn_id}=    Get ControlNode Connection
181     Switch Connection    ${devstack_conn_id}
182     ${ip_list}=    Create List    @{EMPTY}
183     : FOR    ${vm}    IN    @{vm_list}
184     \    ${output}=    Write Commands Until Prompt    neutron floatingip-create ${external_net}    30s
185     \    Log    ${output}
186     \    @{ip}    Get Regexp Matches    ${output}    [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}
187     \    ${ip_length}    Get Length    ${ip}
188     \    Run Keyword If    ${ip_length}>0    Append To List    ${ip_list}    @{ip}[0]
189     \    ...    ELSE    Append To List    ${ip_list}    None
190     \    ${output}=    Write Commands Until Prompt    nova floating-ip-associate ${vm} @{ip}[0]    30s
191     \    Log    ${output}
192     [Return]    ${ip_list}
193
194 Verify Gateway Ips
195     [Documentation]    Verifies the Gateway Ips with dump flow.
196     ${output}=    Write Commands Until Prompt    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
197     Log    ${output}
198     : FOR    ${GatewayIpElement}    IN    @{GATEWAY_IPS}
199     \    Should Contain    ${output}    ${GatewayIpElement}
200
201 Verify Dhcp Ips
202     [Documentation]    Verifies the Dhcp Ips with dump flow.
203     ${output}=    Write Commands Until Prompt    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
204     Log    ${output}
205     : FOR    ${DhcpIpElement}    IN    @{DHCP_IPS}
206     \    Should Contain    ${output}    ${DhcpIpElement}
207
208 Verify No Dhcp Ips
209     [Documentation]    Verifies the Dhcp Ips with dump flow.
210     ${output}=    Write Commands Until Prompt    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
211     Log    ${output}
212     : FOR    ${DhcpIpElement}    IN    @{DHCP_IPS}
213     \    Should Not Contain    ${output}    ${DhcpIpElement}
214
215 Delete SubNet
216     [Arguments]    ${subnet}
217     [Documentation]    Delete SubNet for the Network with neutron request.
218     Log    ${subnet}
219     ${devstack_conn_id}=    Get ControlNode Connection
220     Switch Connection    ${devstack_conn_id}
221     ${output}=    Write Commands Until Prompt    neutron -v subnet-delete ${subnet}
222     Close Connection
223     Log    ${output}
224     Should Match Regexp    ${output}    Deleted subnet: ${subnet}|Deleted subnet\\(s\\): ${subnet}
225
226 Verify No Gateway Ips
227     [Documentation]    Verifies the Gateway Ips removed with dump flow.
228     ${output}=    Write Commands Until Prompt    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
229     Log    ${output}
230     : FOR    ${GatewayIpElement}    IN    @{GATEWAY_IPS}
231     \    Should Not Contain    ${output}    ${GatewayIpElement}
232
233 Delete Vm Instance
234     [Arguments]    ${vm_name}
235     [Documentation]    Delete Vm instances using instance names.
236     ${devstack_conn_id}=    Get ControlNode Connection
237     Switch Connection    ${devstack_conn_id}
238     ${output}=    Write Commands Until Prompt    nova force-delete ${vm_name}    40s
239     Close Connection
240
241 Get Net Id
242     [Arguments]    ${network_name}    ${devstack_conn_id}
243     [Documentation]    Retrieve the net id for the given network name to create specific vm instance
244     Switch Connection    ${devstack_conn_id}
245     ${output}=    Write Commands Until Prompt    neutron net-list | grep "${network_name}" | awk '{print $2}'    30s
246     Log    ${output}
247     ${splitted_output}=    Split String    ${output}    ${EMPTY}
248     ${net_id}=    Get from List    ${splitted_output}    0
249     Log    ${net_id}
250     [Return]    ${net_id}
251
252 Get Subnet Id
253     [Arguments]    ${subnet_name}    ${devstack_conn_id}
254     [Documentation]    Retrieve the subnet id for the given subnet name
255     Switch Connection    ${devstack_conn_id}
256     ${output}=    Write Commands Until Prompt    neutron subnet-list | grep "${subnet_name}" | awk '{print $2}'    30s
257     Log    ${output}
258     ${splitted_output}=    Split String    ${output}    ${EMPTY}
259     ${subnet_id}=    Get from List    ${splitted_output}    0
260     Log    ${subnet_id}
261     [Return]    ${subnet_id}
262
263 Get Port Id
264     [Arguments]    ${port_name}    ${devstack_conn_id}
265     [Documentation]    Retrieve the port id for the given port name to attach specific vm instance to a particular port
266     Switch Connection    ${devstack_conn_id}
267     ${output}=    Write Commands Until Prompt    neutron port-list | grep "${port_name}" | awk '{print $2}'    30s
268     Log    ${output}
269     ${splitted_output}=    Split String    ${output}    ${EMPTY}
270     ${port_id}=    Get from List    ${splitted_output}    0
271     Log    ${port_id}
272     [Return]    ${port_id}
273
274 Get Router Id
275     [Arguments]    ${router1}    ${devstack_conn_id}
276     [Documentation]    Retrieve the router id for the given router name
277     Switch Connection    ${devstack_conn_id}
278     ${output}=    Write Commands Until Prompt    neutron router-list | grep "${router1}" | awk '{print $2}'    30s
279     Log    ${output}
280     ${splitted_output}=    Split String    ${output}    ${EMPTY}
281     ${router_id}=    Get from List    ${splitted_output}    0
282     Log    ${router_id}
283     [Return]    ${router_id}
284
285 Create Vm Instances
286     [Arguments]    ${net_name}    ${vm_instance_names}    ${image}=cirros-0.3.4-x86_64-uec    ${flavor}=m1.nano    ${sg}=default
287     [Documentation]    Create X Vm Instance with the net id of the Netowrk.
288     ${devstack_conn_id}=    Get ControlNode Connection
289     Switch Connection    ${devstack_conn_id}
290     ${net_id}=    Get Net Id    ${net_name}    ${devstack_conn_id}
291     : FOR    ${VmElement}    IN    @{vm_instance_names}
292     \    ${output}=    Write Commands Until Prompt    nova boot --image ${image} --flavor ${flavor} --nic net-id=${net_id} ${VmElement} --security-groups ${sg}    30s
293     \    Log    ${output}
294
295 Create Vm Instance With Port
296     [Arguments]    ${port_name}    ${vm_instance_name}    ${image}=cirros-0.3.4-x86_64-uec    ${flavor}=m1.nano    ${sg}=default
297     [Documentation]    Create One VM instance using given ${port_name} and for given ${compute_node}
298     ${devstack_conn_id}=    Get ControlNode Connection
299     Switch Connection    ${devstack_conn_id}
300     ${port_id}=    Get Port Id    ${port_name}    ${devstack_conn_id}
301     ${output}=    Write Commands Until Prompt    nova boot --image ${image} --flavor ${flavor} --nic port-id=${port_id} ${vm_instance_name} --security-groups ${sg}    30s
302     Log    ${output}
303
304 Create Vm Instance With Ports
305     [Arguments]    ${port_name}    ${port2_name}    ${vm_instance_name}    ${image}=cirros-0.3.4-x86_64-uec    ${flavor}=m1.nano    ${sg}=default
306     [Documentation]    Create One VM instance using given ${port_name} and for given ${compute_node}
307     ${devstack_conn_id}=    Get ControlNode Connection
308     Switch Connection    ${devstack_conn_id}
309     ${port_id}=    Get Port Id    ${port_name}    ${devstack_conn_id}
310     ${port2_id}=    Get Port Id    ${port2_name}    ${devstack_conn_id}
311     ${output}=    Write Commands Until Prompt    nova boot --image ${image} --flavor ${flavor} --nic port-id=${port_id} --nic port-id=${port2_id} ${vm_instance_name} --security-groups ${sg}    30s
312     Log    ${output}
313
314 Create Vm Instance With Port On Compute Node
315     [Arguments]    ${port_name}    ${vm_instance_name}    ${compute_node}    ${image}=cirros-0.3.4-x86_64-uec    ${flavor}=m1.nano    ${sg}=default
316     [Documentation]    Create One VM instance using given ${port_name} and for given ${compute_node}
317     ${devstack_conn_id}=    Get ControlNode Connection
318     Switch Connection    ${devstack_conn_id}
319     ${port_id}=    Get Port Id    ${port_name}    ${devstack_conn_id}
320     ${hostname_compute_node}=    Run Command On Remote System    ${compute_node}    hostname
321     ${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
322     Log    ${output}
323
324 Verify VM Is ACTIVE
325     [Arguments]    ${vm_name}
326     [Documentation]    Run these commands to check whether the created vm instance is active or not.
327     ${devstack_conn_id}=    Get ControlNode Connection
328     Switch Connection    ${devstack_conn_id}
329     ${output}=    Write Commands Until Prompt    nova show ${vm_name} | grep OS-EXT-STS:vm_state    30s
330     Log    ${output}
331     Should Contain    ${output}    active
332
333 Collect VM IP Addresses
334     [Arguments]    ${fail_on_none}    @{vm_list}
335     [Documentation]    Using nova console-log on the provided ${vm_list} to search for the string "obtained" which
336     ...    correlates to the instance receiving it's IP address via DHCP. Also retrieved is the ip of the nameserver
337     ...    if available in the console-log output. The keyword will also return a list of the learned ips as it
338     ...    finds them in the console log output, and will have "None" for Vms that no ip was found.
339     ${devstack_conn_id}=    Get ControlNode Connection
340     Switch Connection    ${devstack_conn_id}
341     ${ip_list}    Create List    @{EMPTY}
342     : FOR    ${vm}    IN    @{vm_list}
343     \    ${vm_ip_line}=    Write Commands Until Prompt    nova console-log ${vm} | grep -i "obtained"    30s
344     \    Log    ${vm_ip_line}
345     \    @{vm_ip}    Get Regexp Matches    ${vm_ip_line}    [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}
346     \    ${vm_ip_length}    Get Length    ${vm_ip}
347     \    Run Keyword If    ${vm_ip_length}>0    Append To List    ${ip_list}    @{vm_ip}[0]
348     \    ...    ELSE    Append To List    ${ip_list}    None
349     \    ${dhcp_ip_line}=    Write Commands Until Prompt    nova console-log ${vm} | grep "^nameserver"    30s
350     \    Log    ${dhcp_ip_line}
351     \    ${dhcp_ip}    Get Regexp Matches    ${dhcp_ip_line}    [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}
352     \    ${dhcp_ip_length}    Get Length    ${dhcp_ip}
353     \    Run Keyword If    ${dhcp_ip_length}<=0    Append To List    ${dhcp_ip}    None
354     \    Log    ${dhcp_ip}
355     ${dhcp_length}    Get Length    ${dhcp_ip}
356     Run Keyword If    '${fail_on_none}' == 'true'    Should Not Contain    ${ip_list}    None
357     Run Keyword If    '${fail_on_none}' == 'true'    Should Not Contain    ${dhcp_ip}    None
358     Should Be True    ${dhcp_length} <= 1
359     Return From Keyword If    ${dhcp_length}==0    ${ip_list}    ${EMPTY}
360     [Return]    ${ip_list}    ${dhcp_ip}
361
362 Collect VM IPv6 SLAAC Addresses
363     [Arguments]    ${fail_on_none}    ${prefix}    @{vm_list}
364     [Documentation]    Using nova console-log on the provided ${vm_list} to search for the string "inet6" which
365     ...    correlates to the instance generated IPv6 address, based on the ${prefix} received from ODL (SLAAC mode).
366     ${devstack_conn_id}=    Get ControlNode Connection
367     Switch Connection    ${devstack_conn_id}
368     ${ip_list}    Create List    @{EMPTY}
369     : FOR    ${vm}    IN    @{vm_list}
370     \    Log    ${vm}
371     \    ${vm_ip_line}=    Write Commands Until Prompt    nova console-log ${vm} | grep -i "inet6"    30s
372     \    Log    ${vm_ip_line}
373     \    @{vm_ip_list}    Get Regexp Matches    ${vm_ip_line}    ${prefix}
374     \    ${vm_ip_length}    Get Length    ${vm_ip_list}
375     \    Run Keyword If    ${vm_ip_length}>0    Append To List    ${ip_list}    @{vm_ip_list}[0]
376     \    ...    ELSE    Append To List    ${ip_list}    None
377     \    Log    ${ip_list}
378     Run Keyword If    '${fail_on_none}' == 'true'    Should Not Contain    ${ip_list}    None
379     Log    ${ip_list}
380     [Return]    ${ip_list}
381
382 View Vm Console
383     [Arguments]    ${vm_instance_names}
384     [Documentation]    View Console log of the created vm instances using nova show.
385     : FOR    ${VmElement}    IN    @{vm_instance_names}
386     \    ${output}=    Write Commands Until Prompt    nova show ${VmElement}
387     \    Log    ${output}
388     \    ${output}=    Write Commands Until Prompt    nova console-log ${VmElement}
389     \    Log    ${output}
390
391 Ping Vm From DHCP Namespace
392     [Arguments]    ${net_name}    ${vm_ip}
393     [Documentation]    Reach all Vm Instance with the net id of the Netowrk.
394     Log    ${vm_ip}
395     ${devstack_conn_id}=    Get ControlNode Connection
396     Switch Connection    ${devstack_conn_id}
397     ${net_id}=    Get Net Id    ${net_name}    ${devstack_conn_id}
398     Log    ${net_id}
399     ${output}=    Write Commands Until Prompt    sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip}    20s
400     Log    ${output}
401     Close Connection
402     Should Contain    ${output}    64 bytes
403
404 Ping From DHCP Should Not Succeed
405     [Arguments]    ${net_name}    ${vm_ip}
406     [Documentation]    Should Not Reach Vm Instance with the net id of the Netowrk.
407     Return From Keyword If    "skip_if_${SECURITY_GROUP_MODE}" in @{TEST_TAGS}
408     Log    ${vm_ip}
409     ${devstack_conn_id}=    Get ControlNode Connection
410     Switch Connection    ${devstack_conn_id}
411     ${net_id}=    Get Net Id    ${net_name}    ${devstack_conn_id}
412     Log    ${net_id}
413     ${output}=    Write Commands Until Prompt    sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip}    20s
414     Close Connection
415     Log    ${output}
416     Should Not Contain    ${output}    64 bytes
417
418 Ping Vm From Control Node
419     [Arguments]    ${vm_floating_ip}    ${additional_args}=${EMPTY}
420     [Documentation]    Ping VM floating IP from control node
421     Log    ${vm_floating_ip}
422     ${devstack_conn_id}=    Get ControlNode Connection
423     Switch Connection    ${devstack_conn_id}
424     ${output}=    Write Commands Until Prompt    ping ${additional_args} -c 3 ${vm_floating_ip}    20s
425     Log    ${output}
426     Close Connection
427     Should Contain    ${output}    64 bytes
428
429 Ping From Instance
430     [Arguments]    ${dest_vm_ip}
431     [Documentation]    Ping to the expected destination ip.
432     ${output}=    Write Commands Until Expected Prompt    ping -c 3 ${dest_vm_ip}    ${OS_SYSTEM_PROMPT}
433     Log    ${output}
434     [Return]    ${output}
435
436 Curl Metadata Server
437     [Documentation]    Ping to the expected destination ip.
438     ${output}=    Write Commands Until Expected Prompt    curl -i http://169.254.169.254    ${OS_SYSTEM_PROMPT}
439     Write Commands Until Prompt    exit
440     Should Contain    ${output}    200
441
442 Close Vm Instance
443     [Documentation]    Exit the vm instance.
444     ${output}=    Write Commands Until Prompt    exit
445     Log    ${output}
446
447 Check If Console Is VmInstance
448     [Arguments]    ${console}=cirros
449     [Documentation]    Check if the session has been able to login to the VM instance
450     ${output}=    Write Commands Until Expected Prompt    id    ${OS_SYSTEM_PROMPT}
451     Should Contain    ${output}    ${console}
452
453 Exit From Vm Console
454     [Documentation]    Check if the session has been able to login to the VM instance and exit the instance
455     ${rcode}=    Run Keyword And Return Status    Check If Console Is VmInstance    cirros
456     Run Keyword If    ${rcode}    Write Commands Until Prompt    exit
457
458 Check Ping
459     [Arguments]    ${ip_address}    ${ttl}=64
460     [Documentation]    Run Ping command on the IP available as argument
461     ${ethertype}=    Get Regexp Matches    ${ip_address}    ${IP_REGEX}
462     ${output}=    Run Keyword If    ${ethertype}    Write Commands Until Expected Prompt    ping -t ${ttl} -c 3 ${ip_address}    ${OS_SYSTEM_PROMPT}
463     ...    ELSE    Write Commands Until Expected Prompt    ping6 -t ${ttl} -c 3 ${ip_address}    ${OS_SYSTEM_PROMPT}
464     Should Contain    ${output}    64 bytes
465
466 Check No Ping
467     [Arguments]    ${ip_address}    ${ttl}=64
468     [Documentation]    Run Ping command to the IP given as argument, executing 3 times and expecting NOT to see "64 bytes"
469     ${output}=    Write Commands Until Expected Prompt    ping -t ${ttl} -c 3 ${ip_address}    ${OS_SYSTEM_PROMPT}
470     Should Not Contain    ${output}    64 bytes
471
472 Check Metadata Access
473     [Documentation]    Try curl on the Metadataurl and check if it is okay
474     ${output}=    Write Commands Until Expected Prompt    curl -i http://169.254.169.254    ${OS_SYSTEM_PROMPT}
475     Should Contain    ${output}    200
476
477 Execute Command on VM Instance
478     [Arguments]    ${net_name}    ${vm_ip}    ${cmd}    ${user}=cirros    ${password}=cubswin:)
479     [Documentation]    Login to the vm instance using ssh in the network, executes a command inside the VM and returns the ouput.
480     ${devstack_conn_id} =    Get ControlNode Connection
481     Switch Connection    ${devstack_conn_id}
482     ${net_id} =    Get Net Id    ${net_name}    ${devstack_conn_id}
483     Log    ${vm_ip}
484     ${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:
485     Log    ${output}
486     ${output} =    Write Commands Until Expected Prompt    ${password}    ${OS_SYSTEM_PROMPT}
487     Log    ${output}
488     ${rcode} =    Run Keyword And Return Status    Check If Console Is VmInstance
489     ${output} =    Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    ${cmd}    ${OS_SYSTEM_PROMPT}
490     [Teardown]    Exit From Vm Console
491     [Return]    ${output}
492
493 Test Operations From Vm Instance
494     [Arguments]    ${net_name}    ${src_ip}    ${dest_ips}    ${user}=cirros    ${password}=cubswin:)    ${ttl}=64
495     ...    ${ping_should_succeed}=True    ${check_metadata}=True
496     [Documentation]    Login to the vm instance using ssh in the network.
497     ${devstack_conn_id}=    Get ControlNode Connection
498     Switch Connection    ${devstack_conn_id}
499     Log    ${src_ip}
500     ${net_id}=    Get Net Id    ${net_name}    ${devstack_conn_id}
501     ${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:
502     Log    ${output}
503     ${output}=    Write Commands Until Expected Prompt    ${password}    ${OS_SYSTEM_PROMPT}
504     Log    ${output}
505     ${rcode}=    Run Keyword And Return Status    Check If Console Is VmInstance
506     Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    ifconfig    ${OS_SYSTEM_PROMPT}
507     Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    route -n    ${OS_SYSTEM_PROMPT}
508     Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    route -A inet6    ${OS_SYSTEM_PROMPT}
509     Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    arp -an    ${OS_SYSTEM_PROMPT}
510     : FOR    ${dest_ip}    IN    @{dest_ips}
511     \    Log    ${dest_ip}
512     \    ${string_empty}=    Run Keyword And Return Status    Should Be Empty    ${dest_ip}
513     \    Run Keyword If    ${string_empty}    Continue For Loop
514     \    Run Keyword If    ${rcode} and "${ping_should_succeed}" == "True"    Check Ping    ${dest_ip}    ttl=${ttl}
515     \    ...    ELSE    Check No Ping    ${dest_ip}    ttl=${ttl}
516     ${ethertype}=    Get Regexp Matches    ${src_ip}    ${IP_REGEX}
517     Run Keyword If    ${rcode} and "${check_metadata}" and ${ethertype} == "True"    Check Metadata Access
518     [Teardown]    Exit From Vm Console
519
520 Test Netcat Operations From Vm Instance
521     [Arguments]    ${net_name}    ${vm_ip}    ${dest_ip}    ${additional_args}=${EMPTY}    ${port}=12345    ${user}=cirros
522     ...    ${password}=cubswin:)
523     [Documentation]    Use Netcat to test TCP/UDP connections to the controller
524     ${client_data}    Set Variable    Test Client Data
525     ${server_data}    Set Variable    Test Server Data
526     ${devstack_conn_id}=    Get ControlNode Connection
527     Switch Connection    ${devstack_conn_id}
528     Log    ${vm_ip}
529     ${output}=    Write Commands Until Prompt    ( ( echo "${server_data}" | sudo timeout 60 nc -l ${additional_args} ${port} ) & )
530     Log    ${output}
531     ${output}=    Write Commands Until Prompt    sudo netstat -nlap | grep ${port}
532     Log    ${output}
533     ${nc_output}=    Execute Command on VM Instance    ${net_name}    ${vm_ip}    sudo echo "${client_data}" | nc -v -w 5 ${additional_args} ${dest_ip} ${port}
534     Log    ${nc_output}
535     ${output}=    Execute Command on VM Instance    ${net_name}    ${vm_ip}    sudo route -n
536     Log    ${output}
537     ${output}=    Execute Command on VM Instance    ${net_name}    ${vm_ip}    sudo arp -an
538     Log    ${output}
539     Should Match Regexp    ${nc_output}    ${server_data}
540
541 Ping Other Instances
542     [Arguments]    ${list_of_external_dst_ips}
543     [Documentation]    Check reachability with other network's instances.
544     ${rcode}=    Run Keyword And Return Status    Check If Console Is VmInstance
545     : FOR    ${dest_ip}    IN    @{list_of_external_dst_ips}
546     \    Log    ${dest_ip}
547     \    Check Ping    ${dest_ip}
548
549 Create Router
550     [Arguments]    ${router_name}
551     [Documentation]    Create Router and Add Interface to the subnets.
552     ${devstack_conn_id}=    Get ControlNode Connection
553     Switch Connection    ${devstack_conn_id}
554     ${output}=    Write Commands Until Prompt    neutron -v router-create ${router_name}    30s
555     Close Connection
556     Should Contain    ${output}    Created a new router
557
558 List Router
559     [Documentation]    List Router and return output with neutron client.
560     ${devstack_conn_id}=    Get ControlNode Connection
561     Switch Connection    ${devstack_conn_id}
562     ${output}=    Write Commands Until Prompt    neutron router-list    30s
563     Close Connection
564     Log    ${output}
565     [Return]    ${output}
566
567 Add Router Interface
568     [Arguments]    ${router_name}    ${interface_name}
569     ${devstack_conn_id}=    Get ControlNode Connection
570     Switch Connection    ${devstack_conn_id}
571     ${output}=    Write Commands Until Prompt    neutron -v router-interface-add ${router_name} ${interface_name}
572     Close Connection
573     Should Contain    ${output}    Added interface
574
575 Show Router Interface
576     [Arguments]    ${router_name}
577     [Documentation]    List Router interface associated with given Router and return output with neutron client.
578     ${devstack_conn_id}=    Get ControlNode Connection
579     Switch Connection    ${devstack_conn_id}
580     ${output}=    Write Commands Until Prompt    neutron router-port-list ${router_name} -f csv    30s
581     Close Connection
582     Log    ${output}
583     [Return]    ${output}
584
585 Add Router Gateway
586     [Arguments]    ${router_name}    ${network_name}
587     ${devstack_conn_id}=    Get ControlNode Connection
588     Switch Connection    ${devstack_conn_id}
589     ${output}=    Write Commands Until Prompt    neutron -v router-gateway-set ${router_name} ${network_name}
590     Close Connection
591     Should Contain    ${output}    Set gateway
592
593 Remove Interface
594     [Arguments]    ${router_name}    ${interface_name}
595     [Documentation]    Remove Interface to the subnets.
596     ${devstack_conn_id}=    Get ControlNode Connection
597     Switch Connection    ${devstack_conn_id}
598     ${output}=    Write Commands Until Prompt    neutron -v router-interface-delete ${router_name} ${interface_name}
599     Close Connection
600     Should Contain    ${output}    Removed interface from router
601
602 Update Router
603     [Arguments]    ${router_name}    ${cmd}
604     [Documentation]    Update the router with the command. Router name and command should be passed as argument.
605     ${devstack_conn_id} =    Get ControlNode Connection
606     Switch Connection    ${devstack_conn_id}
607     ${output} =    Write Commands Until Prompt    neutron router-update ${router_name} ${cmd}    30s
608     Close Connection
609     Should Contain    ${output}    Updated
610
611 Show Router
612     [Arguments]    ${router_name}    ${options}
613     [Documentation]    Show information of a given router. Router name and optional fields should be sent as arguments.
614     ${devstack_conn_id} =    Get ControlNode Connection
615     Switch Connection    ${devstack_conn_id}
616     ${output} =    Write Commands Until Prompt    neutron router-show ${router_name} ${options}    30s
617     Log    ${output}
618     Close Connection
619
620 Delete Router
621     [Arguments]    ${router_name}
622     [Documentation]    Delete Router and Interface to the subnets.
623     ${devstack_conn_id}=    Get ControlNode Connection
624     Switch Connection    ${devstack_conn_id}
625     ${output}=    Write Commands Until Prompt    neutron -v router-delete ${router_name}    60s
626     Close Connection
627     Should Match Regexp    ${output}    Deleted router: ${router_name}|Deleted router\\(s\\): ${router_name}
628
629 Get DumpFlows And Ovsconfig
630     [Arguments]    ${openstack_node_ip}
631     [Documentation]    Get the OvsConfig and Flow entries from OVS from the Openstack Node
632     Log    ${openstack_node_ip}
633     SSHLibrary.Open Connection    ${openstack_node_ip}    prompt=${DEFAULT_LINUX_PROMPT}
634     Utils.Flexible SSH Login    ${OS_USER}    ${DEVSTACK_SYSTEM_PASSWORD}
635     SSHLibrary.Set Client Configuration    timeout=${default_devstack_prompt_timeout}
636     Write Commands Until Expected Prompt    ip -o link    ${DEFAULT_LINUX_PROMPT_STRICT}
637     Write Commands Until Expected Prompt    ip -o addr    ${DEFAULT_LINUX_PROMPT_STRICT}
638     Write Commands Until Expected Prompt    ip route    ${DEFAULT_LINUX_PROMPT_STRICT}
639     Write Commands Until Expected Prompt    arp -an    ${DEFAULT_LINUX_PROMPT_STRICT}
640     ${nslist}=    Write Commands Until Expected Prompt    ip netns list | awk '{print $1}'    ${DEFAULT_LINUX_PROMPT_STRICT}
641     @{lines}    Split To Lines    ${nslist}
642     : FOR    ${line}    IN    @{lines}
643     \    Write Commands Until Expected Prompt    sudo ip netns exec ${line} ip -o link    ${DEFAULT_LINUX_PROMPT_STRICT}
644     \    Write Commands Until Expected Prompt    sudo ip netns exec ${line} ip -o addr    ${DEFAULT_LINUX_PROMPT_STRICT}
645     \    Write Commands Until Expected Prompt    sudo ip netns exec ${line} ip route    ${DEFAULT_LINUX_PROMPT_STRICT}
646     Write Commands Until Expected Prompt    sudo ovs-vsctl show    ${DEFAULT_LINUX_PROMPT_STRICT}
647     Write Commands Until Expected Prompt    sudo ovs-vsctl list Open_vSwitch    ${DEFAULT_LINUX_PROMPT_STRICT}
648     Write Commands Until Expected Prompt    sudo ovs-ofctl show br-int -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
649     Write Commands Until Expected Prompt    sudo ovs-ofctl dump-flows br-int -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
650     Write Commands Until Expected Prompt    sudo ovs-ofctl dump-groups br-int -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
651     Write Commands Until Expected Prompt    sudo ovs-ofctl dump-group-stats br-int -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
652
653 Get Karaf Log Type From Test Start
654     [Arguments]    ${ip}    ${test_name}    ${type}    ${user}=${ODL_SYSTEM_USER}    ${password}=${ODL_SYSTEM_PASSWORD}    ${prompt}=${ODL_SYSTEM_PROMPT}
655     ...    ${log_file}=${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
656     ${cmd}    Set Variable    sed '1,/ROBOT MESSAGE: Starting test ${test_name}/d' ${log_file} | grep '${type}'
657     ${output}    Run Command On Controller    ${ip}    ${cmd}    ${user}    ${password}    ${prompt}
658     Log    ${output}
659
660 Get Karaf Log Types From Test Start
661     [Arguments]    ${ip}    ${test_name}    ${types}    ${user}=${ODL_SYSTEM_USER}    ${password}=${ODL_SYSTEM_PASSWORD}    ${prompt}=${ODL_SYSTEM_PROMPT}
662     ...    ${log_file}=${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
663     : FOR    ${type}    IN    @{types}
664     \    Get Karaf Log Type From Test Start    ${ip}    ${test_name}    ${type}    ${user}    ${password}
665     \    ...    ${prompt}    ${log_file}
666
667 Get Karaf Log Events From Test Start
668     [Arguments]    ${test_name}    ${user}=${ODL_SYSTEM_USER}    ${password}=${ODL_SYSTEM_PASSWORD}    ${prompt}=${ODL_SYSTEM_PROMPT}
669     ${log_types} =    Create List    ERROR    WARN    Exception
670     Run Keyword If    0 < ${NUM_ODL_SYSTEM}    Get Karaf Log Types From Test Start    ${ODL_SYSTEM_IP}    ${test_name}    ${log_types}
671     Run Keyword If    1 < ${NUM_ODL_SYSTEM}    Get Karaf Log Types From Test Start    ${ODL_SYSTEM_2_IP}    ${test_name}    ${log_types}
672     Run Keyword If    2 < ${NUM_ODL_SYSTEM}    Get Karaf Log Types From Test Start    ${ODL_SYSTEM_3_IP}    ${test_name}    ${log_types}
673
674 Get ControlNode Connection
675     ${control_conn_id}=    SSHLibrary.Open Connection    ${OS_CONTROL_NODE_IP}    prompt=${DEFAULT_LINUX_PROMPT_STRICT}
676     Utils.Flexible SSH Login    ${OS_USER}    ${DEVSTACK_SYSTEM_PASSWORD}
677     SSHLibrary.Set Client Configuration    timeout=30s
678     Source Password    force=yes
679     [Return]    ${control_conn_id}
680
681 Get OvsDebugInfo
682     [Documentation]    Get the OvsConfig and Flow entries from all Openstack nodes
683     Run Keyword If    0 < ${NUM_OS_SYSTEM}    Get DumpFlows And Ovsconfig    ${OS_CONTROL_NODE_IP}
684     Run Keyword If    1 < ${NUM_OS_SYSTEM}    Get DumpFlows And Ovsconfig    ${OS_COMPUTE_1_IP}
685     Run Keyword If    2 < ${NUM_OS_SYSTEM}    Get DumpFlows And Ovsconfig    ${OS_COMPUTE_2_IP}
686
687 Get Test Teardown Debugs
688     [Arguments]    ${test_name}=${TEST_NAME}
689     Get OvsDebugInfo
690     Run Keyword And Ignore Error    Get Model Dump    ${HA_PROXY_IP}    ${netvirt_data_models}
691     Get Karaf Log Events From Test Start    ${test_name}
692
693 Get Suite Teardown Debugs
694     Get OvsDebugInfo
695     Get Model Dump    ${HA_PROXY_IP}    ${netvirt_data_models}
696
697 Show Debugs
698     [Arguments]    @{vm_indices}
699     [Documentation]    Run these commands for debugging, it can list state of VM instances and ip information in control node
700     ${devstack_conn_id}=    Get ControlNode Connection
701     Switch Connection    ${devstack_conn_id}
702     ${output}=    Write Commands Until Prompt    sudo ip netns list
703     Log    ${output}
704     : FOR    ${index}    IN    @{vm_indices}
705     \    ${output}=    Write Commands Until Prompt    nova show ${index}    30s
706     \    Log    ${output}
707     Close Connection
708     List Nova VMs
709     List Networks
710     List Subnets
711     List Ports
712
713 Create Security Group
714     [Arguments]    ${sg_name}    ${desc}
715     ${devstack_conn_id}=    Get ControlNode Connection
716     Switch Connection    ${devstack_conn_id}
717     ${output}=    Write Commands Until Prompt    nova secgroup-create ${sg_name} ${desc}    40s
718     Close Connection
719
720 Create Security Rule
721     [Arguments]    ${direction}    ${protocol}    ${min_port}    ${max_port}    ${remote_ip}    ${sg_name}
722     ${devstack_conn_id}=    Get ControlNode Connection
723     Switch Connection    ${devstack_conn_id}
724     ${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}
725     Close Connection
726
727 Neutron Security Group Show
728     [Arguments]    ${SecurityGroupRuleName}    ${additional_args}=${EMPTY}
729     [Documentation]    Displays the neutron security group configurations that belongs to a given neutron security group name
730     ${devstack_conn_id}=    Get ControlNode Connection
731     Switch Connection    ${devstack_conn_id}
732     ${cmd}=    Set Variable    neutron security-group-show ${SecurityGroupRuleName} ${additional_args}
733     Log    ${cmd}
734     ${output}=    Write Commands Until Prompt    ${cmd}    30s
735     Log    ${output}
736     Close Connection
737     [Return]    ${output}
738
739 Neutron Port Show
740     [Arguments]    ${PortName}    ${additional_args}=${EMPTY}
741     [Documentation]    Display the port configuration that belong to a given neutron port
742     ${devstack_conn_id}=    Get ControlNode Connection
743     Switch Connection    ${devstack_conn_id}
744     ${cmd}=    Set Variable    neutron port-show ${PortName} ${additional_args}
745     Log    ${cmd}
746     ${output}=    Write Commands Until Prompt    ${cmd}    30s
747     Log    ${output}
748     Close Connection
749     [Return]    ${output}
750
751 Neutron Security Group Create
752     [Arguments]    ${SecurityGroupName}    ${additional_args}=${EMPTY}
753     [Documentation]    Create a security group with specified name ,description & protocol value according to security group template
754     ${devstack_conn_id}=    Get ControlNode Connection
755     Switch Connection    ${devstack_conn_id}
756     ${cmd}=    Set Variable    neutron security-group-create ${SecurityGroupName} ${additional_args}
757     Log    ${cmd}
758     ${output}=    Write Commands Until Prompt    ${cmd}    30s
759     Log    ${output}
760     Should Contain    ${output}    Created a new security_group
761     ${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}
762     Log    ${sgp_id}
763     Close Connection
764     [Return]    ${output}    ${sgp_id}
765
766 Neutron Security Group Update
767     [Arguments]    ${SecurityGroupName}    ${additional_args}=${EMPTY}
768     [Documentation]    Updating security groups
769     ${devstack_conn_id}=    Get ControlNode Connection
770     Switch Connection    ${devstack_conn_id}
771     ${cmd}=    Set Variable    neutron security-group-update ${SecurityGroupName} ${additional_args}
772     Log    ${cmd}
773     ${output}=    Write Commands Until Prompt    ${cmd}    30s
774     Log    ${output}
775     Close Connection
776     [Return]    ${output}
777
778 Delete SecurityGroup
779     [Arguments]    ${sg_name}
780     [Documentation]    Delete Security group
781     ${devstack_conn_id}=    Get ControlNode Connection
782     Switch Connection    ${devstack_conn_id}
783     ${output}=    Write Commands Until Prompt    neutron security-group-delete ${sg_name}    40s
784     Log    ${output}
785     Should Match Regexp    ${output}    Deleted security_group: ${sg_name}|Deleted security_group\\(s\\): ${sg_name}
786     Close Connection
787
788 Neutron Security Group Rule Create
789     [Arguments]    ${Security_group_name}    &{Kwargs}
790     [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]} ..."
791     ${devstack_conn_id}=    Get ControlNode Connection
792     Switch Connection    ${devstack_conn_id}
793     Run Keyword If    ${Kwargs}    Log    ${Kwargs}
794     ${description}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    description    default=${None}
795     ${direction}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    direction    default=${None}
796     ${ethertype}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    ethertype    default=${None}
797     ${port_range_max}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    port_range_max    default=${None}
798     ${port_range_min}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    port_range_min    default=${None}
799     ${protocol}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    protocol    default=${None}
800     ${remote_group_id}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    remote_group_id    default=${None}
801     ${remote_ip_prefix}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    remote_ip_prefix    default=${None}
802     ${cmd}=    Set Variable    neutron security-group-rule-create ${Security_group_name}
803     ${cmd}=    Run Keyword If    '${description}'!='None'    Catenate    ${cmd}    --description ${description}
804     ...    ELSE    Catenate    ${cmd}
805     ${cmd}=    Run Keyword If    '${direction}'!='None'    Catenate    ${cmd}    --direction ${direction}
806     ...    ELSE    Catenate    ${cmd}
807     ${cmd}=    Run Keyword If    '${ethertype}'!='None'    Catenate    ${cmd}    --ethertype ${ethertype}
808     ...    ELSE    Catenate    ${cmd}
809     ${cmd}=    Run Keyword If    '${port_range_max}'!='None'    Catenate    ${cmd}    --port_range_max ${port_range_max}
810     ...    ELSE    Catenate    ${cmd}
811     ${cmd}=    Run Keyword If    '${port_range_min}'!='None'    Catenate    ${cmd}    --port_range_min ${port_range_min}
812     ...    ELSE    Catenate    ${cmd}
813     ${cmd}=    Run Keyword If    '${protocol}'!='None'    Catenate    ${cmd}    --protocol ${protocol}
814     ...    ELSE    Catenate    ${cmd}
815     ${cmd}=    Run Keyword If    '${remote_group_id}'!='None'    Catenate    ${cmd}    --remote_group_id ${remote_group_id}
816     ...    ELSE    Catenate    ${cmd}
817     ${cmd}=    Run Keyword If    '${remote_ip_prefix}'!='None'    Catenate    ${cmd}    --remote_ip_prefix ${remote_ip_prefix}
818     ...    ELSE    Catenate    ${cmd}
819     ${output}=    Write Commands Until Prompt    ${cmd}    30s
820     ${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}
821     Log    ${rule_id}
822     Should Contain    ${output}    Created a new security_group_rule
823     Close Connection
824     [Return]    ${output}    ${rule_id}
825
826 Security Group Create Without Default Security Rules
827     [Arguments]    ${sg_name}    ${additional_args}=${EMPTY}
828     [Documentation]    Create Neutron Security Group with no default rules, using specified name and optional arguments.
829     Neutron Security Group Create    ${sg_name}    ${additional_args}
830     Delete All Security Group Rules    ${sg_name}
831
832 Delete All Security Group Rules
833     [Arguments]    ${sg_name}
834     [Documentation]    Delete all security rules from a specified security group
835     ${devstack_conn_id}=    Get ControlNode Connection
836     Switch Connection    ${devstack_conn_id}
837     ${sg_rules_output}=    Write Commands Until Prompt    openstack security group rule list ${sg_name} -cID -fvalue
838     Log    ${sg_rules_output}
839     @{sg_rules}=    Split String    ${sg_rules_output}    \n
840     : FOR    ${rule}    IN    @{sg_rules}
841     \    ${output}=    Write Commands Until Prompt    openstack security group rule delete ${rule}
842     \    Log    ${output}
843     Close Connection
844
845 Create Neutron Port With Additional Params
846     [Arguments]    ${network_name}    ${port_name}    ${additional_args}=${EMPTY}
847     [Documentation]    Create Port With given additional parameters
848     ${devstack_conn_id}=    Get ControlNode Connection
849     Switch Connection    ${devstack_conn_id}
850     ${cmd}=    Set Variable    neutron -v port-create ${network_name} --name ${port_name} ${additional_args}
851     Log    ${cmd}
852     ${OUTPUT}=    Write Commands Until Prompt    ${cmd}    30s
853     Log    ${OUTPUT}
854     Should Contain    ${output}    Created a new port
855     ${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}
856     Log    ${port_id}
857     Close Connection
858     [Return]    ${OUTPUT}    ${port_id}
859
860 Get Ports MacAddr
861     [Arguments]    ${portName_list}
862     [Documentation]    Retrieve the port MacAddr for the given list of port name and return the MAC address list.
863     ${devstack_conn_id}=    Get ControlNode Connection
864     Switch Connection    ${devstack_conn_id}
865     ${MacAddr-list}    Create List
866     : FOR    ${portName}    IN    @{portName_list}
867     \    ${macAddr}=    OpenStackOperations.Get Port Mac    ${portName}    ${devstack_conn_id}
868     \    Append To List    ${MacAddr-list}    ${macAddr}
869     [Return]    ${MacAddr-list}
870
871 Get Port Ip
872     [Arguments]    ${port_name}
873     [Documentation]    Keyword would return the IP of the ${port_name} received.
874     Switch Connection    ${devstack_conn_id}
875     ${output}=    Write Commands Until Prompt    neutron port-list | grep "${port_name}" | awk '{print $11}' | awk -F "\\"" '{print $2}'    30s
876     Log    ${output}
877     ${splitted_output}=    Split String    ${output}    ${EMPTY}
878     ${port_ip}=    Get from List    ${splitted_output}    0
879     Log    ${port_ip}
880     [Return]    ${port_ip}
881
882 Get Port Mac
883     [Arguments]    ${port_name}    ${conn_id}=${devstack_conn_id}
884     [Documentation]    Keyword would return the MAC ID of the ${port_name} received.
885     Switch Connection    ${conn_id}
886     ${output}=    Write Commands Until Prompt    neutron port-list | grep "${port_name}" | awk '{print $6}'    30s
887     Log    ${output}
888     ${splitted_output}=    Split String    ${output}    ${EMPTY}
889     ${port_mac}=    Get from List    ${splitted_output}    0
890     Log    ${port_mac}
891     [Return]    ${port_mac}
892
893 Create L2Gateway
894     [Arguments]    ${bridge_name}    ${intf_name}    ${gw_name}
895     [Documentation]    Keyword to create an L2 Gateway ${gw_name} for bridge ${bridge_name} connected to interface ${intf_name} (Using Neutron CLI).
896     Switch Connection    ${devstack_conn_id}
897     ${l2gw_output}=    Write Commands Until Prompt    ${L2GW_CREATE} name=${bridge_name},interface_names=${intf_name} ${gw_name}    30s
898     Log    ${l2gw_output}
899     [Return]    ${l2gw_output}
900
901 Create L2Gateway Connection
902     [Arguments]    ${gw_name}    ${net_name}
903     [Documentation]    Keyword would create a new L2 Gateway Connection for ${gw_name} to ${net_name} (Using Neutron CLI).
904     Switch Connection    ${devstack_conn_id}
905     ${l2gw_output}=    Write Commands Until Prompt    ${L2GW_CONN_CREATE} ${gw_name} ${net_name}    30s
906     Log    ${l2gw_output}
907     [Return]    ${l2gw_output}
908
909 Get All L2Gateway
910     [Documentation]    Keyword to return all the L2 Gateways available (Using Neutron CLI).
911     Switch Connection    ${devstack_conn_id}
912     ${output}=    Write Commands Until Prompt    ${L2GW_GET_YAML}    30s
913     [Return]    ${output}
914
915 Get All L2Gateway Connection
916     [Documentation]    Keyword to return all the L2 Gateway connections available (Using Neutron CLI).
917     Switch Connection    ${devstack_conn_id}
918     ${output}=    Write Commands Until Prompt    ${L2GW_GET_CONN_YAML}    30s
919     [Return]    ${output}
920
921 Get L2Gateway
922     [Arguments]    ${gw_id}
923     [Documentation]    Keyword to check if the ${gw_id} is available in the L2 Gateway list (Using Neutron CLI).
924     Switch Connection    ${devstack_conn_id}
925     ${output}=    Write Commands Until Prompt    ${L2GW_SHOW} ${gw_id}    30s
926     Log    ${output}
927     [Return]    ${output}
928
929 Get L2gw Id
930     [Arguments]    ${l2gw_name}
931     [Documentation]    Keyword to retrieve the L2 Gateway ID for the ${l2gw_name} (Using Neutron CLI).
932     Switch Connection    ${devstack_conn_id}
933     ${output}=    Write Commands Until Prompt    ${L2GW_GET} | grep "${l2gw_name}" | awk '{print $2}'    30s
934     Log    ${output}
935     ${splitted_output}=    Split String    ${output}    ${EMPTY}
936     ${l2gw_id}=    Get from List    ${splitted_output}    0
937     Log    ${l2gw_id}
938     [Return]    ${l2gw_id}
939
940 Get L2gw Connection Id
941     [Arguments]    ${l2gw_name}
942     [Documentation]    Keyword to retrieve the L2 Gateway Connection ID for the ${l2gw_name} (Using Neutron CLI).
943     Switch Connection    ${devstack_conn_id}
944     ${l2gw_id}=    OpenStackOperations.Get L2gw Id    ${l2gw_name}
945     ${output}=    Write Commands Until Prompt    ${L2GW_GET_CONN} | grep "${l2gw_id}" | awk '{print $2}'    30s
946     Log    ${output}
947     ${splitted_output}=    Split String    ${output}    ${EMPTY}
948     ${l2gw_conn_id}=    Get from List    ${splitted_output}    0
949     Log    ${l2gw_conn_id}
950     [Return]    ${l2gw_conn_id}
951
952 Neutron Port List Rest
953     [Documentation]    Keyword to get all ports details in Neutron (Using REST).
954     ${resp} =    RequestsLibrary.Get Request    session    ${PORT_URL}
955     Log    ${resp.content}
956     Should Be Equal As Strings    ${resp.status_code}    200
957     [Return]    ${resp.content}
958
959 Get Neutron Port Rest
960     [Arguments]    ${port_id}
961     [Documentation]    Keyword to get the specific port details in Neutron (Using REST).
962     ${resp} =    RequestsLibrary.Get Request    session    ${CONFIG_API}/${GET_PORT_URL}/${port_id}
963     Log    ${resp.content}
964     Should Be Equal As Strings    ${resp.status_code}    200
965     [Return]    ${resp.content}
966
967 Update Port Rest
968     [Arguments]    ${port_id}    ${json_data}
969     [Documentation]    Keyword to update ${port_id} with json data received in ${json_data} (Using REST).
970     Log    ${json_data}
971     ${resp} =    RequestsLibrary.Put Request    session    ${CONFIG_API}/${GET_PORT_URL}/${port_id}    ${json_data}
972     Log    ${resp.content}
973     Should Be Equal As Strings    ${resp.status_code}    200
974     [Return]    ${resp.content}
975
976 Create And Configure Security Group
977     [Arguments]    ${sg-name}
978     [Documentation]    Create Security Group with given name, and default allow rules for TCP/UDP/ICMP protocols.
979     Neutron Security Group Create    ${sg-name}
980     Neutron Security Group Rule Create    ${sg-name}    direction=ingress    port_range_max=65535    port_range_min=1    protocol=tcp    remote_ip_prefix=0.0.0.0/0
981     Neutron Security Group Rule Create    ${sg-name}    direction=egress    port_range_max=65535    port_range_min=1    protocol=tcp    remote_ip_prefix=0.0.0.0/0
982     Neutron Security Group Rule Create    ${sg-name}    direction=ingress    protocol=icmp    remote_ip_prefix=0.0.0.0/0
983     Neutron Security Group Rule Create    ${sg-name}    direction=egress    protocol=icmp    remote_ip_prefix=0.0.0.0/0
984     Neutron Security Group Rule Create    ${sg-name}    direction=ingress    port_range_max=65535    port_range_min=1    protocol=udp    remote_ip_prefix=0.0.0.0/0
985     Neutron Security Group Rule Create    ${sg-name}    direction=egress    port_range_max=65535    port_range_min=1    protocol=udp    remote_ip_prefix=0.0.0.0/0
986
987 Add Security Group To VM
988     [Arguments]    ${vm}    ${sg}
989     [Documentation]    Add the security group provided to the given VM.
990     ${devstack_conn_id}=    Get ControlNode Connection
991     Switch Connection    ${devstack_conn_id}
992     ${output}=    Write Commands Until Prompt    openstack server add security group ${vm} ${sg}
993     Log    ${output}
994     Close Connection
995
996 Create SFC Flow Classifier
997     [Arguments]    ${name}    ${src_ip}    ${dest_ip}    ${protocol}    ${dest_port}    ${neutron_src_port}
998     [Documentation]    Create a flow classifier for SFC
999     ${devstack_conn_id}=    Get ControlNode Connection
1000     Switch Connection    ${devstack_conn_id}
1001     ${cmd}=    Set Variable    neutron flow-classifier-create --ethertype IPv4 --source-ip-prefix ${src_ip}/32 --destination-ip-prefix ${dest_ip}/32 --protocol ${protocol} --destination-port ${dest_port}:${dest_port} --logical-source-port ${neutron_src_port} ${name}
1002     Log    ${cmd}
1003     ${output}=    Write Commands Until Prompt    ${cmd}    30s
1004     Log    ${output}
1005     Close Connection
1006     Should Contain    ${output}    Created a new flow_classifier
1007     [Return]    ${output}
1008
1009 Delete SFC Flow Classifier
1010     [Arguments]    ${name}
1011     [Documentation]    Delete a SFC flow classifier
1012     ${devstack_conn_id}=    Get ControlNode Connection
1013     Switch Connection    ${devstack_conn_id}
1014     ${cmd}=    Set Variable    neutron flow-classifier-delete ${name}
1015     Log    ${cmd}
1016     ${output}=    Write Commands Until Prompt    ${cmd}    30s
1017     Log    ${output}
1018     Close Connection
1019     Should Contain    ${output}    Deleted flow_classifier
1020     [Return]    ${output}
1021
1022 Create SFC Port Pair
1023     [Arguments]    ${name}    ${port_in}    ${port_out}
1024     [Documentation]    Creates a neutron port pair for SFC
1025     ${devstack_conn_id}=    Get ControlNode Connection
1026     Switch Connection    ${devstack_conn_id}
1027     ${cmd}=    Set Variable    neutron port-pair-create --ingress=${port_in} --egress=${port_out} ${name}
1028     Log    ${cmd}
1029     ${output}=    Write Commands Until Prompt    ${cmd}    30s
1030     Log    ${output}
1031     Close Connection
1032     Should Contain    ${output}    Created a new port_pair
1033     [Return]    ${output}
1034
1035 Delete SFC Port Pair
1036     [Arguments]    ${name}
1037     [Documentation]    Delete a SFC port pair
1038     ${devstack_conn_id}=    Get ControlNode Connection
1039     Switch Connection    ${devstack_conn_id}
1040     ${cmd}=    Set Variable    neutron port-pair-delete ${name}
1041     Log    ${cmd}
1042     ${output}=    Write Commands Until Prompt    ${cmd}    30s
1043     Log    ${output}
1044     Close Connection
1045     Should Contain    ${output}    Deleted port_pair
1046     [Return]    ${output}
1047
1048 Create SFC Port Pair Group
1049     [Arguments]    ${name}    ${port_pair}
1050     [Documentation]    Creates a port pair group with a single port pair for SFC
1051     ${devstack_conn_id}=    Get ControlNode Connection
1052     Switch Connection    ${devstack_conn_id}
1053     ${cmd}=    Set Variable    neutron port-pair-group-create --port-pair ${port_pair} ${name}
1054     Log    ${cmd}
1055     ${output}=    Write Commands Until Prompt    ${cmd}    30s
1056     Log    ${output}
1057     Close Connection
1058     Should Contain    ${output}    Created a new port_pair_group
1059     [Return]    ${output}
1060
1061 Create SFC Port Pair Group With Two Pairs
1062     [Arguments]    ${name}    ${port_pair1}    ${port_pair2}
1063     [Documentation]    Creates a port pair group with two port pairs for SFC
1064     ${devstack_conn_id}=    Get ControlNode Connection
1065     Switch Connection    ${devstack_conn_id}
1066     ${cmd}=    Set Variable    neutron port-pair-group-create --port-pair ${port_pair1} --port-pair ${port_pair2} ${name}
1067     Log    ${cmd}
1068     ${output}=    Write Commands Until Prompt    ${cmd}    30s
1069     Log    ${output}
1070     Close Connection
1071     Should Contain    ${output}    Created a new port_pair_group
1072     [Return]    ${output}
1073
1074 Delete SFC Port Pair Group
1075     [Arguments]    ${name}
1076     [Documentation]    Delete a SFC port pair group
1077     ${devstack_conn_id}=    Get ControlNode Connection
1078     Switch Connection    ${devstack_conn_id}
1079     ${cmd}=    Set Variable    neutron port-pair-group-delete ${name}
1080     Log    ${cmd}
1081     ${output}=    Write Commands Until Prompt    ${cmd}    30s
1082     Log    ${output}
1083     Close Connection
1084     Should Contain    ${output}    Deleted port_pair_group
1085     [Return]    ${output}
1086
1087 Create SFC Port Chain
1088     [Arguments]    ${name}    ${pg1}    ${pg2}    ${fc}
1089     [Documentation]    Creates a port pair chain with two port groups and a singel classifier.
1090     ${devstack_conn_id}=    Get ControlNode Connection
1091     Switch Connection    ${devstack_conn_id}
1092     ${cmd}=    Set Variable    neutron port-chain-create --port-pair-group ${pg1} --port-pair-group ${pg2} --flow-classifier ${fc} ${name}
1093     Log    ${cmd}
1094     ${output}=    Write Commands Until Prompt    ${cmd}    30s
1095     Log    ${output}
1096     Close Connection
1097     Should Contain    ${output}    Created a new port_chain
1098     [Return]    ${output}
1099
1100 Delete SFC Port Chain
1101     [Arguments]    ${name}
1102     [Documentation]    Delete a SFC port chain
1103     ${devstack_conn_id}=    Get ControlNode Connection
1104     Switch Connection    ${devstack_conn_id}
1105     ${cmd}=    Set Variable    neutron port-chain-delete ${name}
1106     Log    ${cmd}
1107     ${output}=    Write Commands Until Prompt    ${cmd}    30s
1108     Log    ${output}
1109     Close Connection
1110     Should Contain    ${output}    Deleted port_chain
1111     [Return]    ${output}
1112
1113 Reboot Nova VM
1114     [Arguments]    ${vm_name}
1115     [Documentation]    Reboot NOVA VM
1116     ${devstack_conn_id}=    Get ControlNode Connection
1117     Switch Connection    ${devstack_conn_id}
1118     ${output}=    Write Commands Until Prompt    nova reboot --poll ${vm_name}    30s
1119     Log    ${output}
1120     Wait Until Keyword Succeeds    35s    10s    Verify VM Is ACTIVE    ${vm_name}
1121     Close Connection
1122
1123 Remove RSA Key From KnowHosts
1124     [Arguments]    ${vm_ip}
1125     [Documentation]    Remove RSA
1126     ${devstack_conn_id}=    Get ControlNode Connection
1127     Switch Connection    ${devstack_conn_id}
1128     ${output}=    Write Commands Until Prompt    sudo cat /root/.ssh/known_hosts    30s
1129     Log    ${output}
1130     ${output}=    Write Commands Until Prompt    sudo ssh-keygen -f "/root/.ssh/known_hosts" -R ${vm_ip}    30s
1131     Log    ${output}
1132     ${output}=    Write Commands Until Prompt    sudo cat "/root/.ssh/known_hosts"    30s