6116f377288d276e76e45fb6c2beed2e5f648064
[integration/test.git] / csit / libraries / L2GatewayOperations.robot
1 *** Settings ***
2 Documentation     L2Gateway Operations Library. This library has useful keywords for various actions on Hwvtep and Ovs connectivity. Most of the keywords expects that ovs_conn_id, hwvtep_conn_id and devstack_conn_id are available.
3 Library           SSHLibrary
4 Library           Collections
5 Library           RequestsLibrary
6 Resource          OVSDB.robot
7 Resource          Utils.robot
8 Resource          MininetKeywords.robot
9 Resource          VpnOperations.robot
10 Resource          OpenStackOperations.robot
11 Resource          DevstackUtils.robot
12 Resource          ../variables/l2gw/Variables.robot
13 Resource          ../variables/netvirt/Variables.robot
14
15 *** Variables ***
16 ${L2GW_VAR_BASE}    ${CURDIR}/../variables/l2gw
17
18 *** Keywords ***
19 Add Ovs Bridge Manager Controller And Verify
20     [Documentation]    Keyword to set OVS manager and controller to ${ODL_IP} for the OVS IP connected in ${ovs_conn_id} and verify the entries in OVSDB NETWORK TOPOLOGY and NETSTAT results.
21     ${output}=    Exec Command    ${ovs_conn_id}    ${OVS_RESTART}
22     ${output}=    Exec Command    ${ovs_conn_id}    ${OVS_DEL_MGR}
23     ${output}=    Exec Command    ${ovs_conn_id}    ${OVS_DEL_CTRLR} ${OVS_BRIDGE}
24     ${output}=    Exec Command    ${ovs_conn_id}    ${DEL_OVS_BRIDGE} ${OVS_BRIDGE}
25     ${output}=    Exec Command    ${ovs_conn_id}    ${OVS_SHOW}
26     Should Not Contain    ${output}    Manager
27     Should Not Contain    ${output}    Controller
28     ${output}=    Exec Command    ${ovs_conn_id}    ${CREATE_OVS_BRIDGE} ${OVS_BRIDGE}
29     ${output}=    Exec Command    ${ovs_conn_id}    ${SET_FAIL_MODE} ${OVS_BRIDGE} secure
30     ${output}=    Exec Command    ${ovs_conn_id}    ${OVS_SET_MGR}:${ODL_IP}:${OVSDBPORT}
31     ${output}=    Exec Command    ${ovs_conn_id}    ${OVS_SET_CTRLR} ${OVS_BRIDGE} tcp:${ODL_IP}:${ODL_OF_PORT}
32     Wait Until Keyword Succeeds    60s    2s    Verify Strings In Command Output    ${ovs_conn_id}    ${OVS_SHOW}    Manager "tcp:${ODL_IP}:${OVSDBPORT}"
33     ...    Controller "tcp:${ODL_IP}:${ODL_OF_PORT}"
34     ${output}=    Exec Command    ${ovs_conn_id}    ${NETSTAT}
35     Wait Until Keyword Succeeds    30s    2s    Validate Regexp In String    ${output}    ${NETSTAT_OVSDB_REGEX}
36     Wait Until Keyword Succeeds    30s    2s    Validate Regexp In String    ${output}    ${NETSTAT_OF_REGEX}
37     @{list_to_check}=    Create List    bridge/${OVS_BRIDGE}    bridge/${HWVTEP_BRIDGE}
38     Wait Until Keyword Succeeds    30s    2s    Check For Elements At URI    ${OVSDB_NETWORK_TOPOLOGY}    ${list_to_check}    session
39
40 Create Itm Tunnel Between Hwvtep and Ovs
41     [Arguments]    ${ovs_ip}
42     [Documentation]    Keyword to create ITM Tunnel Between HWVTEP and OVS connection in ${ovs_conn_id}.
43     ${dpn_id}=    Get Dpnid Decimal    ${ovs_conn_id}
44     ${first_two_octets}    ${third_octet}    ${last_octet}=    Split String From Right    ${ovs_ip}    .    2
45     ${prefix} =    Set Variable    ${first_two_octets}.0.0/24
46     TemplatedRequests.Post_As_Json_Templated    folder=${L2GW_VAR_BASE}/itm_create    mapping={"dpnid":"${dpn_id}","ip":"${ovs_ip}","prefix":"${prefix}"}    session=session
47     ${output}=    ITM Get Tunnels
48     Log    ${output}
49
50 Add Vtep Manager And Verify
51     [Arguments]    ${odl_ip}
52     [Documentation]    Keyword to add vtep manager for HWVTEP connected in ${hwvtep_conn_id} as ${odl_ip} received in argument and verify the entries in NETSTAT and HWVTEP NETWORK TOPOLOGY.
53     ${set_manager_command}=    Set Variable    ${VTEP_ADD_MGR}:${odl_ip}:${OVSDBPORT}
54     ${output}=    Exec Command    ${hwvtep_conn_id}    ${set_manager_command}
55     Log    ${output}
56     @{list_to_verify}=    Create List    ${odl_ip}    state=ACTIVE
57     Wait Until Keyword Succeeds    60s    2s    Verify Vtep List    ${MANAGER_TABLE}    @{list_to_verify}
58     ${output}=    Exec Command    ${hwvtep_conn_id}    ${NETSTAT}
59     Should Contain    ${output}    ${OVSDBPORT}
60     @{list_to_check}=    Create List    ${odl_ip}
61     Utils.Check For Elements At URI    ${HWVTEP_NETWORK_TOPOLOGY}    ${list_to_check}    session
62
63 Create Verify L2Gateway
64     [Arguments]    ${bridge_name}    ${intf_name}    ${gw_name}
65     [Documentation]    Keyword to create an L2 Gateway ${gw_name} for bridge ${bridge_name} connected to interface ${intf_name} (Using Neutron CLI).
66     ${l2gw_output}=    OpenStackOperations.Create L2Gateway    ${bridge_name}    ${intf_name}    ${gw_name}
67     Log    ${l2gw_output}
68     ${output}=    OpenStackOperations.Get All L2Gateway
69     Log    ${output}
70     Should Contain    ${output}    ${gw_name}
71     @{list_to_check}=    Create List    ${gw_name}
72     Utils.Check For Elements At URI    ${L2GW_LIST_REST_URL}    ${list_to_check}    session
73     [Return]    ${l2gw_output}
74
75 Delete L2Gateway
76     [Arguments]    ${gw_name}
77     [Documentation]    Keyword to delete the L2 Gateway ${gw_name} received in argument.
78     ${output}=    Exec Command    ${devstack_conn_id}    ${L2GW_DELETE} ${gw_name}
79     @{list_to_check}=    Create List    ${gw_name}
80     Utils.Check For Elements Not At URI    ${L2GW_LIST_REST_URL}    ${list_to_check}    session
81     Log    ${output}
82
83 Create Verify L2Gateway Connection
84     [Arguments]    ${gw_name}    ${net_name}
85     [Documentation]    Keyword to create a new L2 Gateway Connection for ${gw_name} to ${net_name} (Using Neutron CLI).
86     ${l2gw_output}=    OpenStackOperations.Create L2Gateway Connection    ${gw_name}    ${net_name}
87     Log    ${l2gw_output}
88     ${l2gw_id}=    OpenStackOperations.Get L2gw Id    ${gw_name}
89     ${output}=    OpenStackOperations.Get All L2Gateway Connection
90     Log    ${output}
91     Should Contain    ${output}    ${l2gw_id}
92     @{list_to_check}=    Create List    ${l2gw_id}
93     Utils.Check For Elements At URI    ${L2GW_CONN_LIST_REST_URL}    ${list_to_check}    session
94     [Return]    ${l2gw_output}
95
96 Delete L2Gateway Connection
97     [Arguments]    ${gw_name}
98     [Documentation]    Delete the L2 Gateway connection existing for Gateway ${gw_name} received in argument (Using Neutron CLI).
99     ${l2gw_conn_id}=    OpenStackOperations.Get L2gw Connection Id    ${gw_name}
100     ${output}=    Exec Command    ${devstack_conn_id}    ${L2GW_CONN_DELETE} ${l2gw_conn_id}
101     @{list_to_check}=    Create List    ${l2gw_conn_id}
102     Utils.Check For Elements Not At URI    ${L2GW_CONN_LIST_REST_URL}    ${list_to_check}    session
103     Log    ${output}
104
105 Update Port For Hwvtep
106     [Arguments]    ${port_name}
107     [Documentation]    Keyword to update the Neutron Ports for specific configuration required to connect to HWVTEP (Using REST).
108     ${port_id}=    Get Port Id    ${port_name}    ${devstack_conn_id}
109     Log    ${port_id}
110     ${json_data}=    Get Neutron Port Rest    ${port_id}
111     Should Contain    ${json_data}    ${STR_VIF_TYPE}
112     Should Contain    ${json_data}    ${STR_VNIC_TYPE}
113     ${json_data}=    Replace String    ${json_data}    ${STR_VIF_TYPE}    ${STR_VIF_REPLACE}
114     ${json_data}=    Replace String    ${json_data}    ${STR_VNIC_TYPE}    ${STR_VNIC_REPLACE}
115     ${return}=    OpenStackOperations.Update Port Rest    ${port_id}    ${json_data}
116     ${output}=    OpenStackOperations.Get Neutron Port Rest    ${port_id}
117     Log    ${output}
118     Should Contain    ${output}    ${STR_VIF_REPLACE}
119     Should Contain    ${output}    ${STR_VNIC_REPLACE}
120     Should Not Contain    ${output}    ${STR_VIF_TYPE}
121     Should Not Contain    ${output}    ${STR_VNIC_TYPE}
122     [Return]    ${return}
123
124 Attach Port To Hwvtep Namespace
125     [Arguments]    ${port_mac}    ${ns_name}    ${tap_name}
126     [Documentation]    Keyword to assign the ${port_mac} to the tap port ${tap_name} in namespace ${ns_name}
127     Exec Command    ${hwvtep_conn_id}    ${NETNS_EXEC} ${ns_name} ${IFCONF} ${tap_name} ${HW_ETHER} ${port_mac}
128     ${output}=    Exec Command    ${hwvtep_conn_id}    ${NETNS_EXEC} ${ns_name} ${IFCONF}
129     Should Contain    ${output}    ${port_mac}
130
131 Namespace Dhclient Verify
132     [Arguments]    ${ns_name}    ${ns_tap}    ${ns_port_ip}
133     [Documentation]    Keyword to run dhclient for the tap port ${ns_tap} and verify if it has got assigned with ${ns_port_ip}.
134     Start Command In Hwvtep    ${NETNS_EXEC} ${ns_name} dhclient ${ns_tap}
135     Wait Until Keyword Succeeds    60s    2s    Verify Strings In Command Output    ${hwvtep_conn_id}    ${NETNS_EXEC} ${ns_name} ${IFCONF}    ${ns_port_ip}
136
137 Namespace Static Ip Assign
138     [Arguments]    ${ns_name}    ${ns_tap}    ${ns_port_ip}
139     [Documentation]    Keyword to assign IP address to TAP port manually
140     ${output}=    Exec Command    ${hwvtep_conn_id}    ${NETNS_EXEC} ${ns_name} ${IFCONF} ${ns_tap} ${ns_port_ip}/24 UP
141     Log    ${output}
142
143 Verify Strings In Command Output
144     [Arguments]    ${conn_id}    ${command}    @{string_list}
145     [Documentation]    Keyword to run the ${command} in ${conn_id} and verify if the output contains the list @{string_list}.
146     ${output}=    Exec Command    ${conn_id}    ${command}
147     : FOR    ${item}    IN    @{string_list}
148     \    Should Contain    ${output}    ${item}
149
150 Verify Ping In Namespace Background
151     [Arguments]    ${ns_name}    ${ns_port_mac}    ${vm_ip}
152     [Documentation]    Keyword to ping the IP ${vm_ip} from ${ns_name} and verify MCAS Local Table contains ${ns_port_mac}.
153     ${output}=    Exec Command    ${hwvtep_conn_id}    ${NETNS_EXEC} ${ns_name} ${IFCONF}
154     Log    ${output}
155     Start Command In Hwvtep    ${NETNS_EXEC} ${ns_name} ping ${vm_ip}
156     Wait Until Keyword Succeeds    30s    2s    Verify Mcas Local Table While Ping    ${ns_port_mac}
157
158 Verify Ping In Namespace Extra Timeout
159     [Arguments]    ${ns_name}    ${ns_port_mac}    ${vm_ip}
160     [Documentation]    Keyword to ping the IP ${vm_ip} from ${ns_name} and verify MCAS Local Table contains ${ns_port_mac}.
161     ${output}=    Exec Command    ${hwvtep_conn_id}    ${NETNS_EXEC} ${ns_name} ${IFCONF}
162     Log    ${output}
163     ${output}=    Exec Command    ${hwvtep_conn_id}    ${NETNS_EXEC} ${ns_name} ping -c3 ${vm_ip}    30s
164     Log    ${output}
165     Should Not Contain    ${output}    ${PACKET_LOSS}
166     Wait Until Keyword Succeeds    30s    2s    Verify Mcas Local Table While Ping    ${ns_port_mac}
167
168 Verify Mcas Local Table While Ping
169     [Arguments]    ${mac}
170     [Documentation]    Keyword to check if ${mac} is available under UCAST_MACS_LOCALE_TABLE of HWVTEP dump table.
171     Verify Vtep List    ${UCAST_MACS_LOCALE_TABLE}    ${mac}
172
173 Verify Nova VM IP
174     [Arguments]    ${vm_name}
175     [Documentation]    Keyword to verify if the VM has received IP, and to vefiry it is not null.
176     ${vm_ip}    ${dhcp_ip}    Verify VMs Received DHCP Lease    ${vm_name}
177     Log    ${vm_ip}
178     Should Not Contain    ${vm_ip}    None
179     [Return]    ${vm_ip}
180
181 Get L2gw Debug Info
182     [Documentation]    Keyword to collect the general debug information required for HWVTEP Test Suite.
183     Exec Command    ${hwvtep_conn_id}    ${OVSDB_CLIENT_DUMP}
184     Exec Command    ${devstack_conn_id}    cat /etc/neutron/neutron.conf
185     Exec Command    ${devstack_conn_id}    cat /etc/neutron/l2gw_plugin.ini
186     Exec Command    ${devstack_conn_id}    ps -ef | grep neutron-server
187     OpenStackOperations.Get Test Teardown Debugs
188     ${resp} =    RequestsLibrary.Get Request    session    ${CONFIG_API}/itm-state:external-tunnel-list/
189     Log    ${resp.content}
190     ${resp} =    RequestsLibrary.Get Request    session    ${CONFIG_API}/network-topology:network-topology/topology/hwvtep:1
191     Log    ${resp.content}
192     ${resp} =    RequestsLibrary.Get Request    session    ${OPERATIONAL_API}/network-topology:network-topology/topology/hwvtep:1
193     Log    ${resp.content}
194
195 Start Command In Hwvtep
196     [Arguments]    ${command}
197     [Documentation]    Keyword to execute Start Command in HWVTEP IP.
198     ${conn_id}=    SSHLibrary.Open Connection    ${HWVTEP_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=30s
199     Log    ${conn_id}
200     Flexible SSH Login    ${DEFAULT_USER}    ${DEFAULT_PASSWORD}
201     Start Command    ${command}
202     ${output}=    Exec Command    ${conn_id}    sudo ovs-ofctl dump-flows br-int -O Openflow13
203     Log    ${output}
204     close connection
205
206 Verify Vtep List
207     [Arguments]    ${table_name}    @{list}
208     [Documentation]    Keyword to run vtep-ctl list for the table ${table_name} and verify the list @{list} contents exists in output.
209     ${output}=    Exec Command    ${hwvtep_conn_id}    ${VTEP LIST} ${table_name}
210     : FOR    ${item}    IN    @{list}
211     \    Should Contain    ${output}    ${item}
212
213 Get Vtep List
214     [Arguments]    ${table_name}
215     [Documentation]    Keyword to return the contents of vtep-ctl list for table ${table_name}.
216     ${output}=    Exec Command    ${hwvtep_conn_id}    ${VTEP LIST} ${table_name}
217     [Return]    ${output}
218
219 Get Dpnid Decimal
220     [Arguments]    ${conn_id}
221     [Documentation]    Keyword to return DPN ID in decimal for the br-int in IP connected via ${conn_id}.
222     ${output}=    Exec Command    ${conn_id}    ${GET_DPNID}
223     Log    ${output}
224     ${splitted_output}=    Split String    ${output}    ${EMPTY}
225     ${dpn_id}=    Get from List    ${splitted_output}    0
226     Log    ${dpn_id}
227     [Return]    ${dpn_id}
228
229 Verify Ovs Tunnel
230     [Arguments]    ${hwvtep_ip}    ${ovs_ip}    ${seg_id}=${NET_1_SEGID}
231     [Documentation]    Keyword to verify that the OVS tunnel entries are configured for OVS and HWVTEP.
232     ${output}=    Exec Command    ${hwvtep_conn_id}    ${OVS_SHOW}
233     Log    ${output}
234     Should Contain    ${output}    key="${seg_id}", remote_ip="${ovs_ip}"
235     ${output}=    Exec Command    ${ovs_conn_id}    ${OVS_SHOW}
236     Log    ${output}
237     Should Contain    ${output}    key=flow, local_ip="${ovs_ip}", remote_ip="${hwvtep_ip}"
238
239 Get Vtep Field Values From Table
240     [Arguments]    ${table_name}    ${column_name}
241     [Documentation]    Keyword to return specific field value received in ${column_name} from the vtep-ctl list for ${table_name}.
242     ${output}=    Exec Command    ${hwvtep_conn_id}    ${VTEP_LIST_COLUMN}${column_name} list ${table_name} | awk '{print $3}'
243     Log    ${output}
244     @{keys}=    Split String    ${output}
245     Log    ${keys}
246     [Return]    ${keys}
247
248 Validate Regexp In String
249     [Arguments]    ${string}    ${regexp}    ${verify_count}=1
250     @{occr}=    Get Regexp Matches    ${string}    ${regexp}
251     ${count}=    Get Length    ${occr}
252     Should Be Equal As Integers    ${count}    ${verify_count}
253
254 Exec Command
255     [Arguments]    ${conn_id}    ${command}    ${timeout}=10s
256     Switch Connection    ${conn_id}
257     ${output}=    DevstackUtils.Write Commands Until Prompt    ${command}    ${timeout}
258     Log    ${output}
259     [Return]    ${output}
260
261 Verify Elan Flow Entries
262     [Arguments]    ${ip}    ${srcMacAddrs}    ${destMacAddrs}
263     [Documentation]    Verify Flows Are Present For ELAN service
264     ${flow_output} =    Run Command On Remote System    ${ip}    sudo ovs-ofctl -O OpenFlow13 dump-flows br-int
265     Log    ${flow_output}
266     Should Contain    ${flow_output}    table=50
267     ${sMac_output} =    Get Lines Containing String    ${flow_output}    table=50
268     Log    ${sMac_output}
269     : FOR    ${sMacAddr}    IN    @{srcMacAddrs}
270     \    ${resp}=    Should Contain    ${sMac_output}    dl_src=${sMacAddr}
271     Should Contain    ${flow_output}    table=51
272     ${dMac_output} =    Get Lines Containing String    ${flow_output}    table=51
273     Log    ${dMac_output}
274     : FOR    ${dMacAddr}    IN    @{destMacAddrs}
275     \    ${resp}=    Should Contain    ${dMac_output}    dl_dst=${dMacAddr}
276     Should Contain    ${flow_output}    table=52
277     ${sMac_output} =    Get Lines Containing String    ${flow_output}    table=52
278     Log    ${sMac_output}