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