Add new keywords in BgpOperations robot file.
[integration/test.git] / csit / libraries / BgpOperations.robot
1 *** Settings ***
2 Documentation     This library contains keywords related to the BGP functionality.
3 Library           SSHLibrary
4 Resource          Utils.robot
5 Resource          ../variables/Variables.robot
6 Resource          TemplatedRequests.robot
7 Resource          KillPythonTool.robot
8
9 *** Variables ***
10 ${BGP_BMP_DIR}    ${CURDIR}/../variables/bgpfunctional/bmp_basic/filled_structure
11 ${BGP_BMP_FEAT_DIR}    ${CURDIR}/../variables/bgpfunctional/bmp_basic/empty_structure
12 ${BGP_RIB_URI}    ${OPERATIONAL_API}/bgp-rib:bgp-rib/rib/example-bgp-rib
13 ${BGP_TOPOLOGY_URI}    ${OPERATIONAL_TOPO_API}/topology/example-ipv4-topology
14 ${VAR_BASE_BGP}    ${CURDIR}/../variables/bgpfunctional
15
16 *** Keywords ***
17 Start Quagga Processes On ODL
18     [Arguments]    ${odl_ip}
19     [Documentation]    To start the zrpcd processes on ODL VM
20     ${conn_id}=    Open_Connection_To_ODL_System    ip_address=${odl_ip}
21     Switch Connection    ${conn_id}
22     Write Commands Until Expected Prompt    cd /opt/quagga/etc/    ${DEFAULT_LINUX_PROMPT_STRICT}
23     Write Commands Until Expected Prompt    sudo cp zebra.conf.sample zebra.conf    ${DEFAULT_LINUX_PROMPT_STRICT}
24     Write Commands Until Expected Prompt    sudo /opt/quagga/etc/init.d/zrpcd start    ${DEFAULT_LINUX_PROMPT_STRICT}
25     Write Commands Until Expected Prompt    ps -ef | grep zrpcd    ${DEFAULT_LINUX_PROMPT_STRICT}
26     Write Commands Until Expected Prompt    netstat -nap | grep 7644    ${DEFAULT_LINUX_PROMPT_STRICT}
27     Close Connection
28
29 Restart BGP Processes On ODL
30     [Arguments]    ${odl_ip}
31     [Documentation]    To restart the bgpd , qthriftd processes on ODL VM
32     ${conn_id} =    Open_Connection_To_ODL_System    ip_address=${odl_ip}
33     Switch Connection    ${conn_id}
34     Write Commands Until Expected Prompt    sudo pkill -f bgpd    ${DEFAULT_LINUX_PROMPT_STRICT}
35     Start Quagga Processes On ODL    ${odl_ip}
36
37 Start Quagga Processes On DCGW
38     [Arguments]    ${dcgw_ip}
39     [Documentation]    To start the zrpcd, bgpd,and zebra processes on DCGW
40     ${dcgw_conn_id} =    Open_Connection_To_Tools_System    ip_address=${dcgw_ip}
41     Switch Connection    ${dcgw_conn_id}
42     Write Commands Until Expected Prompt    cd /opt/quagga/etc/    ${DEFAULT_LINUX_PROMPT_STRICT}
43     Write Commands Until Expected Prompt    sudo cp zebra.conf.sample zebra.conf    ${DEFAULT_LINUX_PROMPT_STRICT}
44     Write Commands Until Expected Prompt    sudo /opt/quagga/etc/init.d/zrpcd start    ${DEFAULT_LINUX_PROMPT_STRICT}
45     Write Commands Until Expected Prompt    ps -ef | grep zrpcd    ${DEFAULT_LINUX_PROMPT_STRICT}
46     Write Commands Until Expected Prompt    cd /opt/quagga/sbin/    ${DEFAULT_LINUX_PROMPT_STRICT}
47     ${output} =    Write    sudo ./bgpd &
48     ${output} =    Read Until    pid
49     Log    ${output}
50     ${output} =    Write    sudo ./zebra &
51     ${output} =    Read
52     Log    ${output}
53     Write Commands Until Expected Prompt    ps -ef | grep bgpd    ${DEFAULT_LINUX_PROMPT_STRICT}
54     Write Commands Until Expected Prompt    ps -ef | grep zebra    ${DEFAULT_LINUX_PROMPT_STRICT}
55     Write Commands Until Expected Prompt    netstat -nap | grep 7644    ${DEFAULT_LINUX_PROMPT_STRICT}
56
57 Restart BGP Processes On DCGW
58     [Arguments]    ${dcgw_ip}
59     [Documentation]    To Restart the zrpcd, bgpd,and zebra processes on DCGW
60     ${dcgw_conn_id} =    Open_Connection_To_Tools_System    ip_address=${dcgw_ip}
61     Switch Connection    ${dcgw_conn_id}
62     Write Commands Until Expected Prompt    sudo pkill -f bgpd    ${DEFAULT_LINUX_PROMPT_STRICT}
63     Start Quagga Processes On DCGW    ${dcgw_ip}
64
65 Show Quagga Configuration On ODL
66     [Arguments]    ${odl_ip}    ${rd}
67     [Documentation]    Show quagga config from ODL
68     Create Quagga Telnet Session    ${odl_ip}    bgpd    sdncbgpc
69     Execute Command On Quagga Telnet Session    show running-config
70     Execute Command On Quagga Telnet Session    show bgp neighbors
71     Execute Command On Quagga Telnet Session    show ip bgp vrf ${rd}
72     Execute Command On Quagga Telnet Session    exit
73     Close Connection
74
75 Create Quagga Telnet Session
76     [Arguments]    ${ip}    ${user}    ${password}
77     [Documentation]    Create telnet session for Quagga
78     ${conn_id}=    Open_Connection_To_Tools_System    ip_address=${ip}
79     Switch Connection    ${conn_id}
80     ${output} =    Write    telnet localhost ${user}
81     ${output} =    Read Until    Password:
82     ${output} =    Write    ${password}
83     ${output} =    Read
84     ${output} =    Write    terminal length 512
85     ${output} =    Read
86
87 Execute Command On Quagga Telnet Session
88     [Arguments]    ${command}
89     [Documentation]    Execute command on Quagga telnet session(session should exist) and returns the output.
90     SSHLibrary.Write    ${command}
91     ${output} =    SSHLibrary.Read
92     Log    ${output}
93     [Return]    ${output}
94
95 Configure BGP And Add Neighbor On DCGW
96     [Arguments]    ${dcgw_ip}    ${as_id}    ${router_id}    ${neighbor_ip}    ${vrf_name}    ${rd}
97     ...    ${loopback_ip}
98     [Documentation]    Configure BGP and add neighbor on the dcgw
99     Create Quagga Telnet Session    ${dcgw_ip}    bgpd    sdncbgpc
100     Execute Command On Quagga Telnet Session    configure terminal
101     Execute Command On Quagga Telnet Session    router bgp ${as_id}
102     Execute Command On Quagga Telnet Session    bgp router-id ${router_id}
103     Execute Command On Quagga Telnet Session    redistribute static
104     Execute Command On Quagga Telnet Session    redistribute connected
105     Execute Command On Quagga Telnet Session    neighbor ${neighbor_ip} send-remote-as ${as_id}
106     Execute Command On Quagga Telnet Session    vrf ${vrf_name}
107     Execute Command On Quagga Telnet Session    rd ${rd}
108     Execute Command On Quagga Telnet Session    rt import ${rd}
109     Execute Command On Quagga Telnet Session    rt export ${rd}
110     Execute Command On Quagga Telnet Session    exit
111     Execute Command On Quagga Telnet Session    address-family vpnv4 unicast
112     Execute Command On Quagga Telnet Session    network ${loopback_ip}/32 rd ${rd} tag ${as_id}
113     Execute Command On Quagga Telnet Session    neighbor ${neighbor_ip} activate
114     Execute Command On Quagga Telnet Session    end
115     Execute Command On Quagga Telnet Session    show running-config
116     Execute Command On Quagga Telnet Session    exit
117
118 Add Loopback Interface On DCGW
119     [Arguments]    ${dcgw_ip}    ${loopback_name}    ${loopback_ip}    ${user}=zebra    ${password}=zebra
120     [Documentation]    Add loopback interface on DCGW
121     Create Quagga Telnet Session    ${dcgw_ip}    ${user}    ${password}
122     Execute Command On Quagga Telnet Session    enable
123     Execute Command On Quagga Telnet Session    ${password}
124     Execute Command On Quagga Telnet Session    configure terminal
125     Execute Command On Quagga Telnet Session    interface ${loopback_name}
126     Execute Command On Quagga Telnet Session    ip address ${loopback_ip}/32
127     Execute Command On Quagga Telnet Session    exit
128     Execute Command On Quagga Telnet Session    end
129     Execute Command On Quagga Telnet Session    show running-config
130     Execute Command On Quagga Telnet Session    exit
131
132 Execute Show Command On Quagga
133     [Arguments]    ${dcgw_ip}    ${cmd}    ${user}=bgpd    ${password}=sdncbgpc
134     [Documentation]    Execute command on quagga and returns the ouput.
135     Create Quagga Telnet Session    ${dcgw_ip}    ${user}    ${password}
136     ${output} =    Execute Command On Quagga Telnet Session    ${cmd}
137     Log    ${output}
138     Execute Command On quagga Telnet Session    exit
139     [Return]    ${output}
140
141 Verify BGP Neighbor Status On Quagga
142     [Arguments]    ${dcgw_ip}    ${neighbor_ip}
143     [Documentation]    Verify bgp neighbor status on quagga
144     ${output} =    Execute Show Command On quagga    ${dcgw_ip}    show bgp neighbors ${neighbor_ip}
145     Log    ${output}
146     Should Contain    ${output}    BGP state = Established
147
148 Verify Routes On Quagga
149     [Arguments]    ${dcgw_ip}    ${rd}    ${ip_list}
150     [Documentation]    Verify routes on quagga
151     ${output} =    Execute Show Command On quagga    ${dcgw_ip}    show ip bgp vrf ${rd}
152     Log    ${output}
153     : FOR    ${ip}    IN    @{ip_list}
154     \    Should Contain    ${output}    ${ip}
155
156 Delete BGP Config On Quagga
157     [Arguments]    ${dcgw_ip}    ${bgp_id}    ${user}=bgpd    ${password}=sdncbgpc
158     [Documentation]    Delete BGP Config on Quagga
159     Create Quagga Telnet Session    ${dcgw_ip}    ${user}    ${password}
160     Execute Command On Quagga Telnet Session    configure terminal
161     Execute Command On Quagga Telnet Session    no router bgp ${bgp_id}
162     Execute Command On Quagga Telnet Session    end
163     ${output} =    Execute Command On Quagga Telnet Session    show running-config
164     Execute Command On Quagga Telnet Session    exit
165     [Return]    ${output}
166
167 Create L3VPN on DCGW
168     [Arguments]    ${dcgw_ip}    ${as_id}    ${vpn_name}    ${rd}
169     [Documentation]    Creating L3VPN on DCGW
170     BgpOperations.Create Quagga Telnet Session    ${dcgw_ip}    bgpd    sdncbgpc
171     BgpOperations.Execute Command On Quagga Telnet Session    configure terminal
172     BgpOperations.Execute Command On Quagga Telnet Session    router bgp ${as_id}
173     BgpOperations.Execute Command On Quagga Telnet Session    vrf ${vpn_name}
174     BgpOperations.Execute Command On Quagga Telnet Session    rd ${rd}
175     BgpOperations.Execute Command On Quagga Telnet Session    rt export ${rd}
176     BgpOperations.Execute Command On Quagga Telnet Session    rt import ${rd}
177     BgpOperations.Execute Command On Quagga Telnet Session    end
178
179 Delete L3VPN on DCGW
180     [Arguments]    ${dcgw_ip}    ${as_id}    @{vpns}
181     [Documentation]    Deleting L3VPN on DCGW
182     BgpOperations.Create Quagga Telnet Session    ${dcgw_ip}    bgpd    sdncbgpc
183     BgpOperations.Execute Command On Quagga Telnet Session    configure terminal
184     BgpOperations.Execute Command On Quagga Telnet Session    router bgp ${as_id}
185     : FOR    ${vpn}    IN    @{vpns}
186     \    BgpOperations.Execute Command On Quagga Telnet Session    no vrf ${vpn}
187     BgpOperations.Execute Command On Quagga Telnet Session    end
188
189 Verify L3VPN On DCGW
190     [Arguments]    ${dcgw_ip}    ${vpn_name}    ${rd}
191     [Documentation]    Verify L3VPN vrf name and rd value on DCGW
192     ${output} =    BgpOperations.Execute Show Command On Quagga    ${dcgw_ip}    show running-config
193     BuiltIn.Should Contain    ${output}    vrf ${vpn_name}
194     BuiltIn.Should Contain    ${output}    rd ${rd}
195
196 Add Routes On DCGW
197     [Arguments]    ${dcgw_ip}    ${rd}    ${network_ip}    ${label}
198     [Documentation]    Add routes on DCGW
199     BgpOperations.Create Quagga Telnet Session    ${dcgw_ip}    bgpd    sdncbgpc
200     BgpOperations.Execute Command On Quagga Telnet Session    configure terminal
201     BgpOperations.Execute Command On Quagga Telnet Session    router bgp ${AS_ID}
202     BgpOperations.Execute Command On Quagga Telnet Session    address-family vpnv4 unicast
203     BgpOperations.Execute Command On Quagga Telnet Session    network ${network_ip}/32 rd ${rd} tag ${label}
204     BgpOperations.Execute Command On Quagga Telnet Session    end
205
206 Create BGP Configuration On ODL
207     [Arguments]    &{Kwargs}
208     [Documentation]    Associate the created L3VPN to a network-id received as dictionary argument
209     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE_BGP}/create_bgp    mapping=${Kwargs}    session=session
210
211 AddNeighbor To BGP Configuration On ODL
212     [Arguments]    &{Kwargs}
213     [Documentation]    Associate the created L3VPN to a network-id received as dictionary argument
214     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE_BGP}/addNeighbor_bgp    mapping=${Kwargs}    session=session
215
216 Get BGP Configuration On ODL
217     [Arguments]    ${odl_session}
218     [Documentation]    Get bgp configuration
219     ${resp} =    RequestsLibrary.Get Request    ${odl_session}    ${CONFIG_API}/ebgp:bgp/
220     Log    ${resp.content}
221     [Return]    ${resp.content}
222
223 Delete BGP Configuration On ODL
224     [Arguments]    ${odl_session}
225     [Documentation]    Delete BGP
226     ${resp} =    RequestsLibrary.Delete Request    ${odl_session}    ${CONFIG_API}/ebgp:bgp/
227     Log    ${resp.content}
228     Should Be Equal As Strings    ${resp.status_code}    200
229     [Return]    ${resp.content}
230
231 Create External Tunnel Endpoint Configuration
232     [Arguments]    &{Kwargs}
233     [Documentation]    Create Tunnel End point
234     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE_BGP}/create_etep    mapping=${Kwargs}    session=session
235
236 Delete External Tunnel Endpoint Configuration
237     [Arguments]    &{Kwargs}
238     [Documentation]    Delete Tunnel End point
239     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE_BGP}/delete_etep    mapping=${Kwargs}    session=session
240
241 Get External Tunnel Endpoint Configuration
242     [Arguments]    ${ip}
243     [Documentation]    Get bgp configuration
244     ${resp} =    RequestsLibrary.Get Request    session    ${CONFIG_API}/itm:dc-gateway-ip-list/dc-gateway-ip/${ip}/
245     Log    ${resp.content}
246     [Return]    ${resp.content}
247
248 Teardown_Everything
249     [Documentation]    Create and Log the diff between expected and actual responses, make sure Python tool was killed.
250     ...    Tear down imported Resources.
251     KillPythonTool.Search_And_Kill_Remote_Python    'play\.py'
252     RequestsLibrary.Delete_All_Sessions
253     SSHLibrary.Close_All_Connections
254
255 Check_Example_Bgp_Rib_Content
256     [Arguments]    ${session}    ${substr}    ${error_message}=${JSONKEYSTR} not found, but expected.
257     [Documentation]    Check the example-bgp-rib content for string
258     ${response}=    RequestsLibrary.Get Request    ${session}    ${BGP_RIB_URI}
259     BuiltIn.Log    ${response.status_code}
260     BuiltIn.Log    ${response.text}
261     BuiltIn.Should_Contain    ${response.text}    ${substr}    ${error_message}    values=False
262
263 Check_Example_Bgp_Rib_Does_Not_Contain
264     [Arguments]    ${session}    ${substr}    ${error_message}=${JSONKEYSTR} found, but not expected.
265     [Documentation]    Check the example-bgp-rib does not contain the string
266     ${response}=    RequestsLibrary.Get Request    ${session}    ${BGP_RIB_URI}
267     BuiltIn.Log    ${response.status_code}
268     BuiltIn.Log    ${response.text}
269     BuiltIn.Should_Not_Contain    ${response.text}    ${substr}    ${error_message}    values=False
270
271 Check_Example_IPv4_Topology_Content
272     [Arguments]    ${session}    ${string_to_check}=${EMPTY}
273     [Documentation]    Check the example-ipv4-topology content for string
274     ${response}=    RequestsLibrary.Get Request    ${session}    ${BGP_TOPOLOGY_URI}
275     BuiltIn.Log    ${response.status_code}
276     BuiltIn.Log    ${response.text}
277     BuiltIn.Should_Contain    ${response.text}    ${string_to_check}
278
279 Check_Example_IPv4_Topology_Does_Not_Contain
280     [Arguments]    ${session}    ${string_to_check}
281     [Documentation]    Check the example-ipv4-topology does not contain the string
282     ${response}=    RequestsLibrary.Get Request    ${session}    ${BGP_TOPOLOGY_URI}
283     BuiltIn.Log    ${response.status_code}
284     BuiltIn.Log    ${response.text}
285     BuiltIn.Should_Not_Contain    ${response.text}    ${string_to_check}
286
287 Bmp_Monitor_Precondition
288     [Arguments]    ${session}
289     [Documentation]    Verify example-bmp-monitor presence in bmp-monitors
290     &{mapping}    BuiltIn.Create_Dictionary    TOOL_IP=${TOOLS_SYSTEM_IP}
291     BuiltIn.Wait_Until_Keyword_Succeeds    6x    10s    TemplatedRequests.Get_As_Json_Templated    folder=${BGP_BMP_FEAT_DIR}    mapping=${mapping}    verify=True
292     ...    session=${session}
293
294 Bmp_Monitor_Postcondition
295     [Arguments]    ${session}
296     [Documentation]    Verifies if example-bmp-monitor data contains one peer.
297     &{mapping}    BuiltIn.Create_Dictionary    TOOL_IP=${TOOLS_SYSTEM_IP}
298     ${output}    BuiltIn.Wait_Until_Keyword_Succeeds    10x    5s    TemplatedRequests.Get_As_Json_Templated    folder=${BGP_BMP_DIR}    mapping=${mapping}
299     ...    session=${session}    verify=True
300     BuiltIn.Log    ${output}