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