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