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