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