Get compute node hostname from hypervisor list
[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}=${EMPTY}    ${flavor}=m1.nano    ${sg}=default    ${min}=1
256     ...    ${max}=1
257     [Documentation]    Create X Vm Instance with the net id of the Netowrk.
258     ${image}    Set Variable If    "${image}"=="${EMPTY}"    ${CIRROS_${OPENSTACK_BRANCH}}    ${image}
259     ${net_id}=    Get Net Id    ${net_name}    ${devstack_conn_id}
260     : FOR    ${VmElement}    IN    @{vm_instance_names}
261     \    ${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}
262     \    Should Not Be True    ${rc}
263     \    Log    ${output}
264
265 Create Vm Instance With Port
266     [Arguments]    ${port_name}    ${vm_instance_name}    ${image}=${EMPTY}    ${flavor}=m1.nano    ${sg}=default
267     [Documentation]    Create One VM instance using given ${port_name} and for given ${compute_node}
268     ${image}    Set Variable If    "${image}"=="${EMPTY}"    ${CIRROS_${OPENSTACK_BRANCH}}    ${image}
269     ${port_id}=    Get Port Id    ${port_name}    ${devstack_conn_id}
270     ${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}
271     Log    ${output}
272
273 Create Vm Instance With Ports
274     [Arguments]    ${port_name}    ${port2_name}    ${vm_instance_name}    ${image}=${EMPTY}    ${flavor}=m1.nano    ${sg}=default
275     [Documentation]    Create One VM instance using given ${port_name} and for given ${compute_node}
276     ${image}    Set Variable If    "${image}"=="${EMPTY}"    ${CIRROS_${OPENSTACK_BRANCH}}    ${image}
277     ${port_id}=    Get Port Id    ${port_name}    ${devstack_conn_id}
278     ${port2_id}=    Get Port Id    ${port2_name}    ${devstack_conn_id}
279     ${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}
280     Log    ${output}
281     Should Not Be True    ${rc}
282
283 Create Vm Instance With Port On Compute Node
284     [Arguments]    ${port_name}    ${vm_instance_name}    ${compute_node}    ${image}=${EMPTY}    ${flavor}=m1.nano    ${sg}=default
285     [Documentation]    Create One VM instance using given ${port_name} and for given ${compute_node}
286     ${image}    Set Variable If    "${image}"=="${EMPTY}"    ${CIRROS_${OPENSTACK_BRANCH}}    ${image}
287     ${port_id}=    Get Port Id    ${port_name}    ${devstack_conn_id}
288     ${hostname_compute_node}=    Get Hypervisor Hostname From IP    ${compute_node}
289     ${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}
290     Log    ${output}
291     Should Not Be True    ${rc}
292
293 Get Hypervisor Hostname From IP
294     [Arguments]    ${hypervisor_ip}
295     [Documentation]    Returns the hostname found for the given IP address if it's listed in hypervisor list. For debuggability
296     ...    the full listing is logged first, then followed by a grep | cut to focus on the actual hostname to return
297     ${rc}    ${output}    Run And Return Rc And Output    openstack hypervisor list
298     Log    ${output}
299     ${rc}    ${hostname}=    Run And Return Rc And Output    openstack hypervisor list -f value | grep ${hypervisor_ip} | cut -d" " -f 2
300     Log    ${hostname}
301     Should Not Be True    ${rc}
302     [Return]    ${hostname}
303
304 Create Nano Flavor
305     [Documentation]    Create a nano flavor
306     ${rc}    ${output}=    Run And Return Rc And Output    openstack flavor create m1.nano --id auto --ram 64 --disk 0 --vcpus 1
307     Log    ${output}
308     Should Not Be True    ${rc}
309
310 Verify VM Is ACTIVE
311     [Arguments]    ${vm_name}
312     [Documentation]    Run these commands to check whether the created vm instance is active or not.
313     ${rc}    ${output}=    Run And Return Rc And Output    openstack server show ${vm_name} | grep OS-EXT-STS:vm_state
314     Log    ${output}
315     Should Not Be True    ${rc}
316     Should Contain    ${output}    active
317
318 Poll VM Is ACTIVE
319     [Arguments]    ${vm_name}    ${retry}=600s    ${retry_interval}=5s
320     [Documentation]    Run these commands to check whether the created vm instance is active or not.
321     Wait Until Keyword Succeeds    ${retry}    ${retry_interval}    Verify VM Is ACTIVE    ${vm_name}
322
323 Collect VM IP Addresses
324     [Arguments]    ${fail_on_none}    @{vm_list}
325     [Documentation]    Using nova console-log on the provided ${vm_list} to search for the string "obtained" which
326     ...    correlates to the instance receiving it's IP address via DHCP. Also retrieved is the ip of the nameserver
327     ...    if available in the console-log output. The keyword will also return a list of the learned ips as it
328     ...    finds them in the console log output, and will have "None" for Vms that no ip was found.
329     ${ip_list}    Create List    @{EMPTY}
330     : FOR    ${vm}    IN    @{vm_list}
331     \    ${rc}    ${vm_ip_line}=    Run And Return Rc And Output    openstack console log show ${vm} | grep -i "obtained"
332     \    Log    ${vm_ip_line}
333     \    Log    ${rc}
334     \    @{vm_ip}    Get Regexp Matches    ${vm_ip_line}    [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}
335     \    ${vm_ip_length}    Get Length    ${vm_ip}
336     \    Run Keyword If    ${vm_ip_length}>0    Append To List    ${ip_list}    @{vm_ip}[0]
337     \    ...    ELSE    Append To List    ${ip_list}    None
338     \    ${rc}    ${dhcp_ip_line}=    Run And Return Rc And Output    openstack console log show ${vm} | grep "^nameserver"
339     \    Log    ${dhcp_ip_line}
340     \    Log    ${rc}
341     \    ${dhcp_ip}    Get Regexp Matches    ${dhcp_ip_line}    [0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}
342     \    ${dhcp_ip_length}    Get Length    ${dhcp_ip}
343     \    Run Keyword If    ${dhcp_ip_length}<=0    Append To List    ${dhcp_ip}    None
344     \    Log    ${dhcp_ip}
345     \    ${vm_console_output}=    Run    openstack console log show ${vm}
346     \    Log    ${vm_console_output}
347     ${dhcp_length}    Get Length    ${dhcp_ip}
348     Run Keyword If    '${fail_on_none}' == 'true'    Should Not Contain    ${ip_list}    None
349     Run Keyword If    '${fail_on_none}' == 'true'    Should Not Contain    ${dhcp_ip}    None
350     Should Be True    ${dhcp_length} <= 1
351     Return From Keyword If    ${dhcp_length}==0    ${ip_list}    ${EMPTY}
352     [Return]    ${ip_list}    ${dhcp_ip}
353
354 Collect VM IPv6 SLAAC Addresses
355     [Arguments]    ${fail_on_none}    ${prefix}    @{vm_list}
356     [Documentation]    Using nova console-log on the provided ${vm_list} to search for the string "inet6" which
357     ...    correlates to the instance generated IPv6 address, based on the ${prefix} received from ODL (SLAAC mode).
358     ${ip_list}    Create List    @{EMPTY}
359     : FOR    ${vm}    IN    @{vm_list}
360     \    Log    ${vm}
361     \    ${rc}    ${vm_ip_line}=    Run And Return Rc And Output    nova console-log ${vm} | grep -i "inet6"
362     \    Log    ${vm_ip_line}
363     \    Log    ${rc}
364     \    @{vm_ip_list}    Get Regexp Matches    ${vm_ip_line}    ${prefix}
365     \    ${vm_ip_length}    Get Length    ${vm_ip_list}
366     \    Run Keyword If    ${vm_ip_length}>0    Append To List    ${ip_list}    @{vm_ip_list}[0]
367     \    ...    ELSE    Append To List    ${ip_list}    None
368     \    Log    ${ip_list}
369     Run Keyword If    '${fail_on_none}' == 'true'    Should Not Contain    ${ip_list}    None
370     Log    ${ip_list}
371     [Return]    ${ip_list}
372
373 View Vm Console
374     [Arguments]    ${vm_instance_names}
375     [Documentation]    View Console log of the created vm instances using nova show.
376     : FOR    ${VmElement}    IN    @{vm_instance_names}
377     \    ${rc}    ${output}=    Run And Return Rc And Output    nova show ${VmElement}
378     \    Log    ${output}
379     \    Should Not Be True    ${rc}
380     \    ${rc}    ${output}=    Run And Return Rc And Output    openstack console log show ${VmElement}
381     \    Log    ${output}
382     \    Should Not Be True    ${rc}
383
384 Ping Vm From DHCP Namespace
385     [Arguments]    ${net_name}    ${vm_ip}
386     [Documentation]    Reach all Vm Instance with the net id of the Netowrk.
387     Log    ${vm_ip}
388     ${devstack_conn_id}=    Get ControlNode Connection
389     Switch Connection    ${devstack_conn_id}
390     ${net_id}=    Get Net Id    ${net_name}    ${devstack_conn_id}
391     Log    ${net_id}
392     ${output}=    Write Commands Until Prompt    sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip}    20s
393     Log    ${output}
394     Close Connection
395     Should Contain    ${output}    64 bytes
396
397 Ping From DHCP Should Not Succeed
398     [Arguments]    ${net_name}    ${vm_ip}
399     [Documentation]    Should Not Reach Vm Instance with the net id of the Netowrk.
400     Return From Keyword If    "skip_if_${SECURITY_GROUP_MODE}" in @{TEST_TAGS}
401     Log    ${vm_ip}
402     ${devstack_conn_id}=    Get ControlNode Connection
403     Switch Connection    ${devstack_conn_id}
404     ${net_id}=    Get Net Id    ${net_name}    ${devstack_conn_id}
405     Log    ${net_id}
406     ${output}=    Write Commands Until Prompt    sudo ip netns exec qdhcp-${net_id} ping -c 3 ${vm_ip}    20s
407     Close Connection
408     Log    ${output}
409     Should Not Contain    ${output}    64 bytes
410
411 Ping Vm From Control Node
412     [Arguments]    ${vm_floating_ip}    ${additional_args}=${EMPTY}
413     [Documentation]    Ping VM floating IP from control node
414     Log    ${vm_floating_ip}
415     ${devstack_conn_id}=    Get ControlNode Connection
416     Switch Connection    ${devstack_conn_id}
417     ${output}=    Write Commands Until Prompt    ping ${additional_args} -c 3 ${vm_floating_ip}    20s
418     Log    ${output}
419     Close Connection
420     Should Contain    ${output}    64 bytes
421
422 Ping From Instance
423     [Arguments]    ${dest_vm_ip}
424     [Documentation]    Ping to the expected destination ip.
425     ${output}=    Write Commands Until Expected Prompt    ping -c 3 ${dest_vm_ip}    ${OS_SYSTEM_PROMPT}
426     Log    ${output}
427     [Return]    ${output}
428
429 Curl Metadata Server
430     [Documentation]    Ping to the expected destination ip.
431     ${output}=    Write Commands Until Expected Prompt    curl -i http://169.254.169.254    ${OS_SYSTEM_PROMPT}
432     Write Commands Until Prompt    exit
433     Should Contain    ${output}    200
434
435 Close Vm Instance
436     [Documentation]    Exit the vm instance.
437     ${output}=    Write Commands Until Prompt    exit
438     Log    ${output}
439
440 Check If Console Is VmInstance
441     [Arguments]    ${console}=cirros
442     [Documentation]    Check if the session has been able to login to the VM instance
443     ${output}=    Write Commands Until Expected Prompt    id    ${OS_SYSTEM_PROMPT}
444     Should Contain    ${output}    ${console}
445
446 Exit From Vm Console
447     [Documentation]    Check if the session has been able to login to the VM instance and exit the instance
448     ${rcode}=    Run Keyword And Return Status    Check If Console Is VmInstance    cirros
449     Run Keyword If    ${rcode}    Write Commands Until Prompt    exit
450     Close Connection
451
452 Check Ping
453     [Arguments]    ${ip_address}    ${ttl}=64
454     [Documentation]    Run Ping command on the IP available as argument
455     ${ethertype}=    Get Regexp Matches    ${ip_address}    ${IP_REGEX}
456     ${output}=    Run Keyword If    ${ethertype}    Write Commands Until Expected Prompt    ping -t ${ttl} -c 3 ${ip_address}    ${OS_SYSTEM_PROMPT}
457     ...    ELSE    Write Commands Until Expected Prompt    ping6 -t ${ttl} -c 3 ${ip_address}    ${OS_SYSTEM_PROMPT}
458     Should Contain    ${output}    64 bytes
459
460 Check No Ping
461     [Arguments]    ${ip_address}    ${ttl}=64
462     [Documentation]    Run Ping command to the IP given as argument, executing 3 times and expecting NOT to see "64 bytes"
463     ${output}=    Write Commands Until Expected Prompt    ping -t ${ttl} -c 3 ${ip_address}    ${OS_SYSTEM_PROMPT}
464     Should Not Contain    ${output}    64 bytes
465
466 Check Metadata Access
467     [Documentation]    Try curl on the Metadataurl and check if it is okay
468     ${output}=    Write Commands Until Expected Prompt    curl -i http://169.254.169.254    ${OS_SYSTEM_PROMPT}
469     Should Contain    ${output}    200
470
471 Execute Command on VM Instance
472     [Arguments]    ${net_name}    ${vm_ip}    ${cmd}    ${user}=cirros    ${password}=cubswin:)
473     [Documentation]    Login to the vm instance using ssh in the network, executes a command inside the VM and returns the ouput.
474     ${devstack_conn_id} =    Get ControlNode Connection
475     Switch Connection    ${devstack_conn_id}
476     ${net_id} =    Get Net Id    ${net_name}    ${devstack_conn_id}
477     Log    ${vm_ip}
478     ${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:
479     Log    ${output}
480     ${output} =    Write Commands Until Expected Prompt    ${password}    ${OS_SYSTEM_PROMPT}
481     Log    ${output}
482     ${rcode} =    Run Keyword And Return Status    Check If Console Is VmInstance
483     ${output} =    Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    ${cmd}    ${OS_SYSTEM_PROMPT}
484     [Teardown]    Exit From Vm Console
485     [Return]    ${output}
486
487 Test Operations From Vm Instance
488     [Arguments]    ${net_name}    ${src_ip}    ${dest_ips}    ${user}=cirros    ${password}=cubswin:)    ${ttl}=64
489     ...    ${ping_should_succeed}=True    ${check_metadata}=True
490     [Documentation]    Login to the vm instance using ssh in the network.
491     ${devstack_conn_id}=    Get ControlNode Connection
492     Switch Connection    ${devstack_conn_id}
493     Log    ${src_ip}
494     ${net_id}=    Get Net Id    ${net_name}    ${devstack_conn_id}
495     ${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:
496     Log    ${output}
497     ${output}=    Write Commands Until Expected Prompt    ${password}    ${OS_SYSTEM_PROMPT}
498     Log    ${output}
499     ${rcode}=    Run Keyword And Return Status    Check If Console Is VmInstance
500     Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    ifconfig    ${OS_SYSTEM_PROMPT}
501     Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    route -n    ${OS_SYSTEM_PROMPT}
502     Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    route -A inet6    ${OS_SYSTEM_PROMPT}
503     Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    arp -an    ${OS_SYSTEM_PROMPT}
504     Run Keyword If    ${rcode}    Write Commands Until Expected Prompt    ip -6 neigh    ${OS_SYSTEM_PROMPT}
505     : FOR    ${dest_ip}    IN    @{dest_ips}
506     \    Log    ${dest_ip}
507     \    ${string_empty}=    Run Keyword And Return Status    Should Be Empty    ${dest_ip}
508     \    Run Keyword If    ${string_empty}    Continue For Loop
509     \    Run Keyword If    ${rcode} and "${ping_should_succeed}" == "True"    Check Ping    ${dest_ip}    ttl=${ttl}
510     \    ...    ELSE    Check No Ping    ${dest_ip}    ttl=${ttl}
511     ${ethertype}=    Get Regexp Matches    ${src_ip}    ${IP_REGEX}
512     Run Keyword If    ${rcode} and "${check_metadata}" and ${ethertype} == "True"    Check Metadata Access
513     [Teardown]    Exit From Vm Console
514
515 Test Netcat Operations From Vm Instance
516     [Arguments]    ${net_name}    ${vm_ip}    ${dest_ip}    ${additional_args}=${EMPTY}    ${port}=12345    ${user}=cirros
517     ...    ${password}=cubswin:)
518     [Documentation]    Use Netcat to test TCP/UDP connections to the controller
519     ${client_data}    Set Variable    Test Client Data
520     ${server_data}    Set Variable    Test Server Data
521     ${devstack_conn_id}=    Get ControlNode Connection
522     Switch Connection    ${devstack_conn_id}
523     Log    ${vm_ip}
524     ${output}=    Write Commands Until Prompt    ( ( echo "${server_data}" | sudo timeout 60 nc -l ${additional_args} ${port} ) & )
525     Log    ${output}
526     ${output}=    Write Commands Until Prompt    sudo netstat -nlap | grep ${port}
527     Log    ${output}
528     ${nc_output}=    Execute Command on VM Instance    ${net_name}    ${vm_ip}    sudo echo "${client_data}" | nc -v -w 5 ${additional_args} ${dest_ip} ${port}
529     Log    ${nc_output}
530     ${output}=    Execute Command on VM Instance    ${net_name}    ${vm_ip}    sudo route -n
531     Log    ${output}
532     ${output}=    Execute Command on VM Instance    ${net_name}    ${vm_ip}    sudo arp -an
533     Log    ${output}
534     Should Match Regexp    ${nc_output}    ${server_data}
535
536 Ping Other Instances
537     [Arguments]    ${list_of_external_dst_ips}
538     [Documentation]    Check reachability with other network's instances.
539     ${rcode}=    Run Keyword And Return Status    Check If Console Is VmInstance
540     : FOR    ${dest_ip}    IN    @{list_of_external_dst_ips}
541     \    Log    ${dest_ip}
542     \    Check Ping    ${dest_ip}
543
544 Create Router
545     [Arguments]    ${router_name}
546     [Documentation]    Create Router and Add Interface to the subnets.
547     ${rc}    ${output}=    Run And Return Rc And Output    openstack router create ${router_name}
548     Should Not Be True    ${rc}
549
550 List Router
551     [Documentation]    List Router and return output with neutron client.
552     ${rc}    ${output}=    Run And Return Rc And Output    openstack router list -f value
553     Log    ${output}
554     Should Not Be True    ${rc}
555     [Return]    ${output}
556
557 Add Router Interface
558     [Arguments]    ${router_name}    ${interface_name}
559     ${rc}    ${output}=    Run And Return Rc And Output    openstack router add subnet ${router_name} ${interface_name}
560     Should Not Be True    ${rc}
561
562 Show Router Interface
563     [Arguments]    ${router_name}
564     [Documentation]    List Router interface associated with given Router and return output with neutron client.
565     ${rc}    ${output}=    Run And Return Rc And Output    openstack port list --router ${router_name} -f value
566     Log    ${output}
567     Should Not Be True    ${rc}
568     [Return]    ${output}
569
570 Add Router Gateway
571     [Arguments]    ${router_name}    ${external_network_name}
572     ${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}
573     ${rc}    ${output}=    Run And Return Rc And Output    ${cmd}
574     Should Not Be True    ${rc}
575
576 Remove Interface
577     [Arguments]    ${router_name}    ${interface_name}
578     [Documentation]    Remove Interface to the subnets.
579     ${rc}    ${output}=    Run And Return Rc And Output    openstack router remove subnet ${router_name} ${interface_name}
580     Should Not Be True    ${rc}
581
582 Update Router
583     [Arguments]    ${router_name}    ${cmd}
584     [Documentation]    Update the router with the command. Router name and command should be passed as argument.
585     ${rc}    ${output} =    Run And Return Rc And Output    openstack router set ${router_name} ${cmd}
586     Should Not Be True    ${rc}
587
588 Show Router
589     [Arguments]    ${router_name}    ${options}
590     [Documentation]    Show information of a given router. Router name and optional fields should be sent as arguments.
591     ${rc}    ${output} =    Run And Return Rc And Output    openstack router show ${router_name}
592     Log    ${output}
593
594 Delete Router
595     [Arguments]    ${router_name}
596     [Documentation]    Delete Router and Interface to the subnets.
597     ${rc}    ${output}=    Run And Return Rc And Output    openstack router delete ${router_name}
598     Should Not Be True    ${rc}
599
600 Get DumpFlows And Ovsconfig
601     [Arguments]    ${openstack_node_ip}
602     [Documentation]    Get the OvsConfig and Flow entries from OVS from the Openstack Node
603     Log    ${openstack_node_ip}
604     SSHLibrary.Open Connection    ${openstack_node_ip}    prompt=${DEFAULT_LINUX_PROMPT}
605     SSHKeywords.Flexible SSH Login    ${OS_USER}    ${DEVSTACK_SYSTEM_PASSWORD}
606     SSHLibrary.Set Client Configuration    timeout=${default_devstack_prompt_timeout}
607     Write Commands Until Expected Prompt    ip -o link    ${DEFAULT_LINUX_PROMPT_STRICT}
608     Write Commands Until Expected Prompt    ip -o addr    ${DEFAULT_LINUX_PROMPT_STRICT}
609     Write Commands Until Expected Prompt    ip route    ${DEFAULT_LINUX_PROMPT_STRICT}
610     Write Commands Until Expected Prompt    arp -an    ${DEFAULT_LINUX_PROMPT_STRICT}
611     ${nslist}=    Write Commands Until Expected Prompt    ip netns list | awk '{print $1}'    ${DEFAULT_LINUX_PROMPT_STRICT}
612     @{lines}    Split To Lines    ${nslist}
613     : FOR    ${line}    IN    @{lines}
614     \    Write Commands Until Expected Prompt    sudo ip netns exec ${line} ip -o link    ${DEFAULT_LINUX_PROMPT_STRICT}
615     \    Write Commands Until Expected Prompt    sudo ip netns exec ${line} ip -o addr    ${DEFAULT_LINUX_PROMPT_STRICT}
616     \    Write Commands Until Expected Prompt    sudo ip netns exec ${line} ip route    ${DEFAULT_LINUX_PROMPT_STRICT}
617     Write Commands Until Expected Prompt    sudo ovs-vsctl show    ${DEFAULT_LINUX_PROMPT_STRICT}
618     Write Commands Until Expected Prompt    sudo ovs-vsctl list Open_vSwitch    ${DEFAULT_LINUX_PROMPT_STRICT}
619     Write Commands Until Expected Prompt    sudo ovs-ofctl show br-int -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
620     Write Commands Until Expected Prompt    sudo ovs-ofctl dump-flows br-int -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
621     Write Commands Until Expected Prompt    sudo ovs-ofctl dump-groups br-int -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
622     Write Commands Until Expected Prompt    sudo ovs-ofctl dump-group-stats br-int -OOpenFlow13    ${DEFAULT_LINUX_PROMPT_STRICT}
623
624 Get Karaf Log Type From Test Start
625     [Arguments]    ${ip}    ${test_name}    ${type}    ${user}=${ODL_SYSTEM_USER}    ${password}=${ODL_SYSTEM_PASSWORD}    ${prompt}=${ODL_SYSTEM_PROMPT}
626     ...    ${log_file}=${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
627     ${cmd}    Set Variable    sed '1,/ROBOT MESSAGE: Starting test ${test_name}/d' ${log_file} | grep '${type}'
628     ${output}    Run Command On Controller    ${ip}    ${cmd}    ${user}    ${password}    ${prompt}
629     Log    ${output}
630
631 Get Karaf Log Types From Test Start
632     [Arguments]    ${ip}    ${test_name}    ${types}    ${user}=${ODL_SYSTEM_USER}    ${password}=${ODL_SYSTEM_PASSWORD}    ${prompt}=${ODL_SYSTEM_PROMPT}
633     ...    ${log_file}=${WORKSPACE}/${BUNDLEFOLDER}/data/log/karaf.log
634     : FOR    ${type}    IN    @{types}
635     \    Get Karaf Log Type From Test Start    ${ip}    ${test_name}    ${type}    ${user}    ${password}
636     \    ...    ${prompt}    ${log_file}
637
638 Get Karaf Log Events From Test Start
639     [Arguments]    ${test_name}    ${user}=${ODL_SYSTEM_USER}    ${password}=${ODL_SYSTEM_PASSWORD}    ${prompt}=${ODL_SYSTEM_PROMPT}
640     ${log_types} =    Create List    ERROR    WARN    Exception
641     Run Keyword If    0 < ${NUM_ODL_SYSTEM}    Get Karaf Log Types From Test Start    ${ODL_SYSTEM_IP}    ${test_name}    ${log_types}
642     Run Keyword If    1 < ${NUM_ODL_SYSTEM}    Get Karaf Log Types From Test Start    ${ODL_SYSTEM_2_IP}    ${test_name}    ${log_types}
643     Run Keyword If    2 < ${NUM_ODL_SYSTEM}    Get Karaf Log Types From Test Start    ${ODL_SYSTEM_3_IP}    ${test_name}    ${log_types}
644
645 Get ControlNode Connection
646     ${control_conn_id}=    SSHLibrary.Open Connection    ${OS_CONTROL_NODE_IP}    prompt=${DEFAULT_LINUX_PROMPT_STRICT}
647     SSHKeywords.Flexible SSH Login    ${OS_USER}    ${DEVSTACK_SYSTEM_PASSWORD}
648     SSHLibrary.Set Client Configuration    timeout=30s
649     [Return]    ${control_conn_id}
650
651 Get OvsDebugInfo
652     [Documentation]    Get the OvsConfig and Flow entries from all Openstack nodes
653     Run Keyword If    0 < ${NUM_OS_SYSTEM}    Get DumpFlows And Ovsconfig    ${OS_CONTROL_NODE_IP}
654     Run Keyword If    1 < ${NUM_OS_SYSTEM}    Get DumpFlows And Ovsconfig    ${OS_COMPUTE_1_IP}
655     Run Keyword If    2 < ${NUM_OS_SYSTEM}    Get DumpFlows And Ovsconfig    ${OS_COMPUTE_2_IP}
656
657 Get Test Teardown Debugs
658     [Arguments]    ${test_name}=${TEST_NAME}
659     Get OvsDebugInfo
660     Run Keyword And Ignore Error    Get Model Dump    ${HA_PROXY_IP}    ${netvirt_data_models}
661     Get Karaf Log Events From Test Start    ${test_name}
662
663 Show Debugs
664     [Arguments]    @{vm_indices}
665     [Documentation]    Run these commands for debugging, it can list state of VM instances and ip information in control node
666     ${devstack_conn_id}=    Get ControlNode Connection
667     Switch Connection    ${devstack_conn_id}
668     ${output}=    Write Commands Until Prompt    sudo ip netns list
669     Log    ${output}
670     Close Connection
671     : FOR    ${index}    IN    @{vm_indices}
672     \    ${rc}    ${output}=    Run And Return Rc And Output    nova show ${index}
673     \    Log    ${output}
674     \    Log    ${rc}
675     List Nova VMs
676     List Networks
677     List Subnets
678     List Ports
679
680 Neutron Security Group Show
681     [Arguments]    ${SecurityGroupRuleName}
682     [Documentation]    Displays the neutron security group configurations that belongs to a given neutron security group name
683     ${cmd}=    Set Variable    openstack security group show ${SecurityGroupRuleName}
684     Log    ${cmd}
685     ${rc}    ${output}=    Run And Return Rc And Output    ${cmd}
686     Log    ${output}
687     Should Not Be True    ${rc}
688     [Return]    ${output}
689
690 Neutron Port Show
691     [Arguments]    ${PortName}
692     [Documentation]    Display the port configuration that belong to a given neutron port
693     ${cmd}=    Set Variable    openstack port show ${PortName}
694     Log    ${cmd}
695     ${rc}    ${output}=    Run And Return Rc And Output    ${cmd}
696     Log    ${output}
697     Should Not Be True    ${rc}
698     [Return]    ${output}
699
700 Neutron Security Group Create
701     [Arguments]    ${SecurityGroupName}    ${additional_args}=${EMPTY}
702     [Documentation]    Create a security group with specified name ,description & protocol value according to security group template
703     ${devstack_conn_id}=    Get ControlNode Connection
704     Switch Connection    ${devstack_conn_id}
705     ${cmd}=    Set Variable    openstack security group create ${SecurityGroupName} ${additional_args}
706     Log    ${cmd}
707     ${rc}    ${output}=    Run And Return Rc And Output    ${cmd}
708     Log    ${output}
709     Should Not Be True    ${rc}
710     ${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}
711     Log    ${sgp_id}
712     [Return]    ${output}    ${sgp_id}
713
714 Neutron Security Group Update
715     [Arguments]    ${SecurityGroupName}    ${additional_args}=${EMPTY}
716     [Documentation]    Updating security groups
717     ${cmd}=    Set Variable    openstack security group set ${SecurityGroupName} ${additional_args}
718     Log    ${cmd}
719     ${rc}    ${output}=    Run And Return Rc And Output    ${cmd}
720     Log    ${output}
721     Should Not Be True    ${rc}
722     [Return]    ${output}
723
724 Delete SecurityGroup
725     [Arguments]    ${sg_name}
726     [Documentation]    Delete Security group
727     ${rc}    ${output}=    Run And Return Rc And Output    openstack security group delete ${sg_name}
728     Log    ${output}
729     Should Not Be True    ${rc}
730
731 Neutron Security Group Rule Create
732     [Arguments]    ${Security_group_name}    &{Kwargs}
733     [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]} ..."
734     Run Keyword If    ${Kwargs}    Log    ${Kwargs}
735     ${description}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    description    default=${None}
736     ${direction}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    direction    default=${None}
737     ${ethertype}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    ethertype    default=${None}
738     ${port_range_max}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    port_range_max    default=${None}
739     ${port_range_min}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    port_range_min    default=${None}
740     ${protocol}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    protocol    default=${None}
741     ${remote_group_id}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    remote_group_id    default=${None}
742     ${remote_ip_prefix}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    remote_ip_prefix    default=${None}
743     ${cmd}=    Set Variable    openstack security group rule create ${Security_group_name}
744     ${cmd}=    Run Keyword If    '${description}'!='None'    Catenate    ${cmd}    --description ${description}
745     ...    ELSE    Catenate    ${cmd}
746     ${cmd}=    Run Keyword If    '${direction}'!='None'    Catenate    ${cmd}    --${direction}
747     ...    ELSE    Catenate    ${cmd}
748     ${cmd}=    Run Keyword If    '${ethertype}'!='None'    Catenate    ${cmd}    --ethertype ${ethertype}
749     ...    ELSE    Catenate    ${cmd}
750     ${cmd}=    Run Keyword If    '${port_range_min}'!='None' and '${port_range_max}'!='None'    Catenate    ${cmd}    --dst-port ${port_range_min}:${port_range_max}
751     ...    ELSE IF    '${port_range_max}'!='None'    Catenate    ${cmd}    --dst-port ${port_range_max}
752     ...    ELSE IF    '${port_range_min}'!='None'    Catenate    ${cmd}    --dst-port ${port_range_min}
753     ...    ELSE    Catenate    ${cmd}
754     ${cmd}=    Run Keyword If    '${protocol}'!='None'    Catenate    ${cmd}    --protocol ${protocol}
755     ...    ELSE    Catenate    ${cmd}
756     ${cmd}=    Run Keyword If    '${remote_group_id}'!='None'    Catenate    ${cmd}    --remote-group ${remote_group_id}
757     ...    ELSE    Catenate    ${cmd}
758     ${cmd}=    Run Keyword If    '${remote_ip_prefix}'!='None'    Catenate    ${cmd}    --src-ip ${remote_ip_prefix}
759     ...    ELSE    Catenate    ${cmd}
760     ${rc}    ${output}=    Run And Return Rc And Output    ${cmd}
761     ${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}
762     Log    ${rule_id}
763     Should Not Be True    ${rc}
764     [Return]    ${output}    ${rule_id}
765
766 Neutron Security Group Rule Create Legacy Cli
767     [Arguments]    ${Security_group_name}    &{Kwargs}
768     [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]} ..."
769     Run Keyword If    ${Kwargs}    Log    ${Kwargs}
770     ${description}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    description    default=${None}
771     ${direction}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    direction    default=${None}
772     ${ethertype}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    ethertype    default=${None}
773     ${port_range_max}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    port_range_max    default=${None}
774     ${port_range_min}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    port_range_min    default=${None}
775     ${protocol}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    protocol    default=${None}
776     ${remote_group_id}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    remote_group_id    default=${None}
777     ${remote_ip_prefix}    Run Keyword If    ${Kwargs}    Pop From Dictionary    ${Kwargs}    remote_ip_prefix    default=${None}
778     ${cmd}=    Set Variable    neutron security-group-rule-create ${Security_group_name}
779     ${cmd}=    Run Keyword If    '${description}'!='None'    Catenate    ${cmd}    --description ${description}
780     ...    ELSE    Catenate    ${cmd}
781     ${cmd}=    Run Keyword If    '${direction}'!='None'    Catenate    ${cmd}    --direction ${direction}
782     ...    ELSE    Catenate    ${cmd}
783     ${cmd}=    Run Keyword If    '${ethertype}'!='None'    Catenate    ${cmd}    --ethertype ${ethertype}
784     ...    ELSE    Catenate    ${cmd}
785     ${cmd}=    Run Keyword If    '${port_range_max}'!='None'    Catenate    ${cmd}    --port_range_max ${port_range_max}
786     ...    ELSE    Catenate    ${cmd}
787     ${cmd}=    Run Keyword If    '${port_range_min}'!='None'    Catenate    ${cmd}    --port_range_min ${port_range_min}
788     ...    ELSE    Catenate    ${cmd}
789     ${cmd}=    Run Keyword If    '${protocol}'!='None'    Catenate    ${cmd}    --protocol ${protocol}
790     ...    ELSE    Catenate    ${cmd}
791     ${cmd}=    Run Keyword If    '${remote_group_id}'!='None'    Catenate    ${cmd}    --remote_group_id ${remote_group_id}
792     ...    ELSE    Catenate    ${cmd}
793     ${cmd}=    Run Keyword If    '${remote_ip_prefix}'!='None'    Catenate    ${cmd}    --remote_ip_prefix ${remote_ip_prefix}
794     ...    ELSE    Catenate    ${cmd}
795     ${rc}    ${output}=    Run And Return Rc And Output    ${cmd}
796     ${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}
797     Log    ${rule_id}
798     Should Not Be True    ${rc}
799     [Return]    ${output}    ${rule_id}
800
801 Security Group Create Without Default Security Rules
802     [Arguments]    ${sg_name}    ${additional_args}=${EMPTY}
803     [Documentation]    Create Neutron Security Group with no default rules, using specified name and optional arguments.
804     Neutron Security Group Create    ${sg_name}    ${additional_args}
805     Delete All Security Group Rules    ${sg_name}
806
807 Delete All Security Group Rules
808     [Arguments]    ${sg_name}
809     [Documentation]    Delete all security rules from a specified security group
810     ${rc}    ${sg_rules_output}=    Run And Return Rc And Output    openstack security group rule list ${sg_name} -cID -fvalue
811     Log    ${sg_rules_output}
812     Should Not Be True    ${rc}
813     @{sg_rules}=    Split String    ${sg_rules_output}    \n
814     : FOR    ${rule}    IN    @{sg_rules}
815     \    ${rc}    ${output}=    Run And Return Rc And Output    openstack security group rule delete ${rule}
816     \    Log    ${output}
817     \    Should Not Be True    ${rc}
818
819 Create Allow All SecurityGroup
820     [Arguments]    ${sg_name}    ${ether_type}=IPv4
821     [Documentation]    Allow all TCP/UDP/ICMP packets for this suite
822     Neutron Security Group Create    ${sg_name}
823     Neutron Security Group Rule Create    ${sg_name}    direction=ingress    ethertype=${ether_type}    port_range_max=65535    port_range_min=1    protocol=tcp
824     Neutron Security Group Rule Create    ${sg_name}    direction=egress    ethertype=${ether_type}    port_range_max=65535    port_range_min=1    protocol=tcp
825     Neutron Security Group Rule Create    ${sg_name}    direction=ingress    ethertype=${ether_type}    protocol=icmp
826     Neutron Security Group Rule Create    ${sg_name}    direction=egress    ethertype=${ether_type}    protocol=icmp
827     Neutron Security Group Rule Create    ${sg_name}    direction=ingress    ethertype=${ether_type}    port_range_max=65535    port_range_min=1    protocol=udp
828     Neutron Security Group Rule Create    ${sg_name}    direction=egress    ethertype=${ether_type}    port_range_max=65535    port_range_min=1    protocol=udp
829
830 Create Neutron Port With Additional Params
831     [Arguments]    ${network_name}    ${port_name}    ${additional_args}=${EMPTY}
832     [Documentation]    Create Port With given additional parameters
833     ${cmd}=    Set Variable    neutron -v port-create ${network_name} --name ${port_name} ${additional_args}
834     Log    ${cmd}
835     ${rc}    ${output}=    Run And Return Rc And Output    ${cmd}
836     Log    ${output}
837     Should Not Be True    ${rc}
838     ${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}
839     Log    ${port_id}
840     [Return]    ${OUTPUT}    ${port_id}
841
842 Get Ports MacAddr
843     [Arguments]    ${portName_list}
844     [Documentation]    Retrieve the port MacAddr for the given list of port name and return the MAC address list.
845     ${MacAddr-list}    Create List
846     : FOR    ${portName}    IN    @{portName_list}
847     \    ${macAddr}=    OpenStackOperations.Get Port Mac    ${portName}    ${devstack_conn_id}
848     \    Append To List    ${MacAddr-list}    ${macAddr}
849     [Return]    ${MacAddr-list}
850
851 Get Port Ip
852     [Arguments]    ${port_name}
853     [Documentation]    Keyword would return the IP of the ${port_name} received.
854     ${rc}    ${output}=    Run And Return Rc And Output    openstack port list | grep "${port_name}" | awk -F\\' '{print $2}'
855     Log    ${output}
856     ${splitted_output}=    Split String    ${output}    ${EMPTY}
857     ${port_ip}=    Get from List    ${splitted_output}    0
858     Log    ${port_ip}
859     Should Not Be True    ${rc}
860     [Return]    ${port_ip}
861
862 Get Port Mac
863     [Arguments]    ${port_name}    ${conn_id}=${devstack_conn_id}
864     [Documentation]    Keyword would return the MAC ID of the ${port_name} received.
865     ${rc}    ${output}=    Run And Return Rc And Output    openstack port show ${port_name} | grep mac_address | awk '{print $4}'
866     Log    ${output}
867     ${splitted_output}=    Split String    ${output}    ${EMPTY}
868     ${port_mac}=    Get from List    ${splitted_output}    0
869     Log    ${port_mac}
870     Should Not Be True    ${rc}
871     [Return]    ${port_mac}
872
873 Create L2Gateway
874     [Arguments]    ${bridge_name}    ${intf_name}    ${gw_name}
875     [Documentation]    Keyword to create an L2 Gateway ${gw_name} for bridge ${bridge_name} connected to interface ${intf_name} (Using Neutron CLI).
876     ${rc}    ${l2gw_output}=    Run And Return Rc And Output    ${L2GW_CREATE} name=${bridge_name},interface_names=${intf_name} ${gw_name}
877     Log    ${l2gw_output}
878     [Return]    ${l2gw_output}
879
880 Create L2Gateway Connection
881     [Arguments]    ${gw_name}    ${net_name}
882     [Documentation]    Keyword would create a new L2 Gateway Connection for ${gw_name} to ${net_name} (Using Neutron CLI).
883     ${rc}    ${l2gw_output}=    Run And Return Rc And Output    ${L2GW_CONN_CREATE} ${gw_name} ${net_name}
884     Log    ${l2gw_output}
885     Should Not Be True    ${rc}
886     [Return]    ${l2gw_output}
887
888 Get All L2Gateway
889     [Documentation]    Keyword to return all the L2 Gateways available (Using Neutron CLI).
890     ${rc}    ${output}=    Run And Return Rc And Output    ${L2GW_GET_YAML}
891     Should Not Be True    ${rc}
892     [Return]    ${output}
893
894 Get All L2Gateway Connection
895     [Documentation]    Keyword to return all the L2 Gateway connections available (Using Neutron CLI).
896     ${rc}    ${output}=    Run And Return Rc And Output    ${L2GW_GET_CONN_YAML}
897     Should Not Be True    ${rc}
898     [Return]    ${output}
899
900 Get L2Gateway
901     [Arguments]    ${gw_id}
902     [Documentation]    Keyword to check if the ${gw_id} is available in the L2 Gateway list (Using Neutron CLI).
903     ${rc}    ${output}=    Run And Return Rc And Output    ${L2GW_SHOW} ${gw_id}
904     Log    ${output}
905     Should Not Be True    ${rc}
906     [Return]    ${output}
907
908 Get L2gw Id
909     [Arguments]    ${l2gw_name}
910     [Documentation]    Keyword to retrieve the L2 Gateway ID for the ${l2gw_name} (Using Neutron CLI).
911     ${rc}    ${output}=    Run And Return Rc And Output    ${L2GW_GET} | grep "${l2gw_name}" | awk '{print $2}'
912     Log    ${output}
913     Should Not Be True    ${rc}
914     ${splitted_output}=    Split String    ${output}    ${EMPTY}
915     ${l2gw_id}=    Get from List    ${splitted_output}    0
916     Log    ${l2gw_id}
917     [Return]    ${l2gw_id}
918
919 Get L2gw Connection Id
920     [Arguments]    ${l2gw_name}
921     [Documentation]    Keyword to retrieve the L2 Gateway Connection ID for the ${l2gw_name} (Using Neutron CLI).
922     ${l2gw_id}=    OpenStackOperations.Get L2gw Id    ${l2gw_name}
923     ${rc}    ${output}=    Run And Return Rc And Output    ${L2GW_GET_CONN} | grep "${l2gw_id}" | awk '{print $2}'
924     Log    ${output}
925     Should Not Be True    ${rc}
926     ${splitted_output}=    Split String    ${output}    ${EMPTY}
927     ${splitted_output}=    Split String    ${output}    ${EMPTY}
928     ${l2gw_conn_id}=    Get from List    ${splitted_output}    0
929     Log    ${l2gw_conn_id}
930     [Return]    ${l2gw_conn_id}
931
932 Neutron Port List Rest
933     [Documentation]    Keyword to get all ports details in Neutron (Using REST).
934     ${resp} =    RequestsLibrary.Get Request    session    ${PORT_URL}
935     Log    ${resp.content}
936     Should Be Equal As Strings    ${resp.status_code}    200
937     [Return]    ${resp.content}
938
939 Get Neutron Port Rest
940     [Arguments]    ${port_id}
941     [Documentation]    Keyword to get the specific port details in Neutron (Using REST).
942     ${resp} =    RequestsLibrary.Get Request    session    ${CONFIG_API}/${GET_PORT_URL}/${port_id}
943     Log    ${resp.content}
944     Should Be Equal As Strings    ${resp.status_code}    200
945     [Return]    ${resp.content}
946
947 Update Port Rest
948     [Arguments]    ${port_id}    ${json_data}
949     [Documentation]    Keyword to update ${port_id} with json data received in ${json_data} (Using REST).
950     Log    ${json_data}
951     ${resp} =    RequestsLibrary.Put Request    session    ${CONFIG_API}/${GET_PORT_URL}/${port_id}    ${json_data}
952     Log    ${resp.content}
953     Should Be Equal As Strings    ${resp.status_code}    200
954     [Return]    ${resp.content}
955
956 Create And Configure Security Group
957     [Arguments]    ${sg-name}
958     [Documentation]    Create Security Group with given name, and default allow rules for TCP/UDP/ICMP protocols.
959     Neutron Security Group Create    ${sg-name}
960     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
961     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
962     Neutron Security Group Rule Create    ${sg-name}    direction=ingress    protocol=icmp    remote_ip_prefix=0.0.0.0/0
963     Neutron Security Group Rule Create    ${sg-name}    direction=egress    protocol=icmp    remote_ip_prefix=0.0.0.0/0
964     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
965     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
966
967 Add Security Group To VM
968     [Arguments]    ${vm}    ${sg}
969     [Documentation]    Add the security group provided to the given VM.
970     ${rc}    ${output}=    Run And Return Rc And Output    openstack server add security group ${vm} ${sg}
971     Log    ${output}
972     Should Not Be True    ${rc}
973
974 Remove Security Group From VM
975     [Arguments]    ${vm}    ${sg}
976     [Documentation]    Remove the security group provided to the given VM.
977     ${devstack_conn_id}=    Get ControlNode Connection
978     Switch Connection    ${devstack_conn_id}
979     ${output}=    Write Commands Until Prompt    openstack server remove security group ${vm} ${sg}
980     Log    ${output}
981     Close Connection
982
983 Create SFC Flow Classifier
984     [Arguments]    ${name}    ${src_ip}    ${dest_ip}    ${protocol}    ${dest_port}    ${neutron_src_port}
985     [Documentation]    Create a flow classifier for SFC
986     ${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}
987     Log    ${cmd}
988     ${rc}    ${output}=    Run And Return Rc And Output    ${cmd}
989     Log    ${output}
990     Should Not Be True    ${rc}
991     Should Contain    ${output}    Created a new flow_classifier
992     [Return]    ${output}
993
994 Delete SFC Flow Classifier
995     [Arguments]    ${name}
996     [Documentation]    Delete a SFC flow classifier
997     ${devstack_conn_id}=    Get ControlNode Connection
998     Switch Connection    ${devstack_conn_id}
999     ${cmd}=    Set Variable    neutron flow-classifier-delete ${name}
1000     Log    ${cmd}
1001     ${rc}    ${output}=    Run And Return Rc And Output    ${cmd}
1002     Log    ${output}
1003     Should Not Be True    ${rc}
1004     Should Contain    ${output}    Deleted flow_classifier
1005     [Return]    ${output}
1006
1007 Create SFC Port Pair
1008     [Arguments]    ${name}    ${port_in}    ${port_out}
1009     [Documentation]    Creates a neutron port pair for SFC
1010     ${devstack_conn_id}=    Get ControlNode Connection
1011     Switch Connection    ${devstack_conn_id}
1012     ${cmd}=    Set Variable    neutron port-pair-create --ingress=${port_in} --egress=${port_out} ${name}
1013     Log    ${cmd}
1014     ${rc}    ${output}=    Run And Return Rc And Output    ${cmd}
1015     Log    ${output}
1016     Should Not Be True    ${rc}
1017     Should Contain    ${output}    Created a new port_pair
1018     [Return]    ${output}
1019
1020 Delete SFC Port Pair
1021     [Arguments]    ${name}
1022     [Documentation]    Delete a SFC port pair
1023     ${cmd}=    Set Variable    neutron port-pair-delete ${name}
1024     Log    ${cmd}
1025     ${rc}    ${output}=    Run And Return Rc And Output    ${cmd}
1026     Log    ${output}
1027     Should Not Be True    ${rc}
1028     Should Contain    ${output}    Deleted port_pair
1029     [Return]    ${output}
1030
1031 Create SFC Port Pair Group
1032     [Arguments]    ${name}    ${port_pair}
1033     [Documentation]    Creates a port pair group with a single port pair for SFC
1034     ${cmd}=    Set Variable    neutron port-pair-group-create --port-pair ${port_pair} ${name}
1035     Log    ${cmd}
1036     ${rc}    ${output}=    Run And Return Rc And Output    ${cmd}
1037     Log    ${output}
1038     Should Not Be True    ${rc}
1039     Should Contain    ${output}    Created a new port_pair_group
1040     [Return]    ${output}
1041
1042 Create SFC Port Pair Group With Two Pairs
1043     [Arguments]    ${name}    ${port_pair1}    ${port_pair2}
1044     [Documentation]    Creates a port pair group with two port pairs for SFC
1045     ${cmd}=    Set Variable    neutron port-pair-group-create --port-pair ${port_pair1} --port-pair ${port_pair2} ${name}
1046     Log    ${cmd}
1047     ${rc}    ${output}=    Run And Return Rc And Output    ${cmd}
1048     Log    ${output}
1049     Should Not Be True    ${rc}
1050     Should Contain    ${output}    Created a new port_pair_group
1051     [Return]    ${output}
1052
1053 Delete SFC Port Pair Group
1054     [Arguments]    ${name}
1055     [Documentation]    Delete a SFC port pair group
1056     ${devstack_conn_id}=    Get ControlNode Connection
1057     ${cmd}=    Set Variable    neutron port-pair-group-delete ${name}
1058     Log    ${cmd}
1059     ${rc}    ${output}=    Run And Return Rc And Output    ${cmd}
1060     Log    ${output}
1061     Should Not Be True    ${rc}
1062     Should Contain    ${output}    Deleted port_pair_group
1063     [Return]    ${output}
1064
1065 Create SFC Port Chain
1066     [Arguments]    ${name}    ${pg1}    ${pg2}    ${fc}
1067     [Documentation]    Creates a port pair chain with two port groups and a singel classifier.
1068     ${cmd}=    Set Variable    neutron port-chain-create --port-pair-group ${pg1} --port-pair-group ${pg2} --flow-classifier ${fc} ${name}
1069     Log    ${cmd}
1070     ${rc}    ${output}=    Run And Return Rc And Output    ${cmd}
1071     Log    ${output}
1072     Should Not Be True    ${rc}
1073     Should Contain    ${output}    Created a new port_chain
1074     [Return]    ${output}
1075
1076 Delete SFC Port Chain
1077     [Arguments]    ${name}
1078     [Documentation]    Delete a SFC port chain
1079     ${cmd}=    Set Variable    neutron port-chain-delete ${name}
1080     Log    ${cmd}
1081     ${rc}    ${output}=    Run And Return Rc And Output    ${cmd}
1082     Log    ${output}
1083     Should Not Be True    ${rc}
1084     Should Contain    ${output}    Deleted port_chain
1085     [Return]    ${output}
1086
1087 Reboot Nova VM
1088     [Arguments]    ${vm_name}
1089     [Documentation]    Reboot NOVA VM
1090     ${rc}    ${output}=    Run And Return Rc And Output    openstack server reboot --wait ${vm_name}
1091     Log    ${output}
1092     Should Not Be True    ${rc}
1093     Wait Until Keyword Succeeds    35s    10s    Verify VM Is ACTIVE    ${vm_name}
1094
1095 Remove RSA Key From KnowHosts
1096     [Arguments]    ${vm_ip}
1097     [Documentation]    Remove RSA
1098     ${devstack_conn_id}=    Get ControlNode Connection
1099     Switch Connection    ${devstack_conn_id}
1100     ${output}=    Write Commands Until Prompt    sudo cat /root/.ssh/known_hosts    30s
1101     Log    ${output}
1102     ${output}=    Write Commands Until Prompt    sudo ssh-keygen -f "/root/.ssh/known_hosts" -R ${vm_ip}    30s
1103     Log    ${output}
1104     ${output}=    Write Commands Until Prompt    sudo cat "/root/.ssh/known_hosts"    30s
1105
1106 Wait For Routes To Propogate
1107     [Arguments]    ${networks}    ${subnets}
1108     [Documentation]    Check propagated routes
1109     ${devstack_conn_id} =    Get ControlNode Connection
1110     Switch Connection    ${devstack_conn_id}
1111     : FOR    ${INDEX}    IN RANGE    0    1
1112     \    ${net_id}=    Get Net Id    @{networks}[${INDEX}]    ${devstack_conn_id}
1113     \    ${is_ipv6}=    Get Regexp Matches    @{subnets}[${INDEX}]    ${IP6_REGEX}
1114     \    ${length}=    Get Length    ${is_ipv6}
1115     \    ${cmd}=    Set Variable If    ${length} == 0    ip route    ip -6 route
1116     \    ${output}=    Write Commands Until Expected Prompt    sudo ip netns exec qdhcp-${net_id} ${cmd}    ]>
1117     \    Should Contain    ${output}    @{subnets}[${INDEX}]