Disable stale marking feature test
[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
7 *** Variables ***
8 ${VAR_BASE_BGP}    ${CURDIR}/../variables/bgpfunctional
9
10 *** Keywords ***
11 Start Quagga Processes On ODL
12     [Arguments]    ${odl_ip}
13     [Documentation]    To start the zrpcd processes on ODL VM
14     ${conn_id}=    Open_Connection_To_ODL_System    ip_address=${odl_ip}
15     Switch Connection    ${conn_id}
16     Write Commands Until Expected Prompt    cd /opt/quagga/etc/    ${DEFAULT_LINUX_PROMPT_STRICT}
17     Write Commands Until Expected Prompt    sudo cp zebra.conf.sample zebra.conf    ${DEFAULT_LINUX_PROMPT_STRICT}
18     Write Commands Until Expected Prompt    sudo /opt/quagga/etc/init.d/zrpcd start    ${DEFAULT_LINUX_PROMPT_STRICT}
19     Write Commands Until Expected Prompt    ps -ef | grep zrpcd    ${DEFAULT_LINUX_PROMPT_STRICT}
20     Write Commands Until Expected Prompt    netstat -nap | grep 7644    ${DEFAULT_LINUX_PROMPT_STRICT}
21     Close Connection
22
23 Start Quagga Processes On DCGW
24     [Arguments]    ${dcgw_ip}
25     [Documentation]    To start the zrpcd, bgpd,and zebra processes on DCGW
26     ${dcgw_conn_id} =    Open_Connection_To_Tools_System    ip_address=${dcgw_ip}
27     Switch Connection    ${dcgw_conn_id}
28     Write Commands Until Expected Prompt    cd /opt/quagga/etc/    ${DEFAULT_LINUX_PROMPT_STRICT}
29     Write Commands Until Expected Prompt    sudo cp zebra.conf.sample zebra.conf    ${DEFAULT_LINUX_PROMPT_STRICT}
30     Write Commands Until Expected Prompt    sudo /opt/quagga/etc/init.d/zrpcd start    ${DEFAULT_LINUX_PROMPT_STRICT}
31     Write Commands Until Expected Prompt    ps -ef | grep zrpcd    ${DEFAULT_LINUX_PROMPT_STRICT}
32     Write Commands Until Expected Prompt    cd /opt/quagga/sbin/    ${DEFAULT_LINUX_PROMPT_STRICT}
33     ${output} =    Write    sudo ./bgpd &
34     ${output} =    Read Until    pid
35     Log    ${output}
36     ${output} =    Write    sudo ./zebra &
37     ${output} =    Read
38     Log    ${output}
39     Write Commands Until Expected Prompt    ps -ef | grep bgpd    ${DEFAULT_LINUX_PROMPT_STRICT}
40     Write Commands Until Expected Prompt    ps -ef | grep zebra    ${DEFAULT_LINUX_PROMPT_STRICT}
41     Write Commands Until Expected Prompt    netstat -nap | grep 7644    ${DEFAULT_LINUX_PROMPT_STRICT}
42
43 Show Quagga Configuration On ODL
44     [Arguments]    ${odl_ip}    ${rd}
45     [Documentation]    Show quagga config from ODL
46     Create Quagga Telnet Session    ${odl_ip}    bgpd    sdncbgpc
47     Execute Command On Quagga Telnet Session    show running-config
48     Execute Command On Quagga Telnet Session    show bgp neighbors
49     Execute Command On Quagga Telnet Session    show ip bgp vrf ${rd}
50     Execute Command On Quagga Telnet Session    exit
51     Close Connection
52
53 Create Quagga Telnet Session
54     [Arguments]    ${ip}    ${user}    ${password}
55     [Documentation]    Create telnet session for Quagga
56     ${conn_id}=    Open_Connection_To_Tools_System    ip_address=${ip}
57     Switch Connection    ${conn_id}
58     ${output} =    Write    telnet localhost ${user}
59     ${output} =    Read Until    Password:
60     ${output} =    Write    ${password}
61     ${output} =    Read
62     ${output} =    Write    terminal length 512
63     ${output} =    Read
64
65 Execute Command On Quagga Telnet Session
66     [Arguments]    ${command}
67     [Documentation]    Execute command on Quagga telnet session(session should exist) and returns the output.
68     SSHLibrary.Write    ${command}
69     ${output} =    SSHLibrary.Read
70     Log    ${output}
71     [Return]    ${output}
72
73 Configure BGP And Add Neighbor On DCGW
74     [Arguments]    ${dcgw_ip}    ${as_id}    ${router_id}    ${neighbor_ip}    ${vrf_name}    ${rd}
75     ...    ${loopback_ip}
76     [Documentation]    Configure BGP and add neighbor on the dcgw
77     Create Quagga Telnet Session    ${dcgw_ip}    bgpd    sdncbgpc
78     Execute Command On Quagga Telnet Session    configure terminal
79     Execute Command On Quagga Telnet Session    router bgp ${as_id}
80     Execute Command On Quagga Telnet Session    bgp router-id ${router_id}
81     Execute Command On Quagga Telnet Session    redistribute static
82     Execute Command On Quagga Telnet Session    redistribute connected
83     Execute Command On Quagga Telnet Session    neighbor ${neighbor_ip} send-remote-as ${as_id}
84     Execute Command On Quagga Telnet Session    vrf ${vrf_name}
85     Execute Command On Quagga Telnet Session    rd ${rd}
86     Execute Command On Quagga Telnet Session    rt import ${rd}
87     Execute Command On Quagga Telnet Session    rt export ${rd}
88     Execute Command On Quagga Telnet Session    exit
89     Execute Command On Quagga Telnet Session    address-family vpnv4 unicast
90     Execute Command On Quagga Telnet Session    network ${loopback_ip}/32 rd ${rd} tag ${as_id}
91     Execute Command On Quagga Telnet Session    neighbor ${neighbor_ip} activate
92     Execute Command On Quagga Telnet Session    end
93     Execute Command On Quagga Telnet Session    show running-config
94     Execute Command On Quagga Telnet Session    exit
95
96 Add Loopback Interface On DCGW
97     [Arguments]    ${dcgw_ip}    ${loopback_name}    ${loopback_ip}    ${user}=zebra    ${password}=zebra
98     [Documentation]    Add loopback interface on DCGW
99     Create Quagga Telnet Session    ${dcgw_ip}    ${user}    ${password}
100     Execute Command On Quagga Telnet Session    enable
101     Execute Command On Quagga Telnet Session    ${password}
102     Execute Command On Quagga Telnet Session    configure terminal
103     Execute Command On Quagga Telnet Session    interface ${loopback_name}
104     Execute Command On Quagga Telnet Session    ip address ${loopback_ip}/32
105     Execute Command On Quagga Telnet Session    exit
106     Execute Command On Quagga Telnet Session    end
107     Execute Command On Quagga Telnet Session    show running-config
108     Execute Command On Quagga Telnet Session    exit
109
110 Execute Show Command On Quagga
111     [Arguments]    ${dcgw_ip}    ${cmd}    ${user}=bgpd    ${password}=sdncbgpc
112     [Documentation]    Execute command on quagga and returns the ouput.
113     Create Quagga Telnet Session    ${dcgw_ip}    ${user}    ${password}
114     ${output} =    Execute Command On Quagga Telnet Session    ${cmd}
115     Log    ${output}
116     Execute Command On quagga Telnet Session    exit
117     [Return]    ${output}
118
119 Verify BGP Neighbor Status On Quagga
120     [Arguments]    ${dcgw_ip}    ${neighbor_ip}
121     [Documentation]    Verify bgp neighbor status on quagga
122     ${output} =    Execute Show Command On quagga    ${dcgw_ip}    show bgp neighbors ${neighbor_ip}
123     Log    ${output}
124     Should Contain    ${output}    BGP state = Established
125
126 Verify Routes On Quagga
127     [Arguments]    ${dcgw_ip}    ${rd}    ${ip_list}
128     [Documentation]    Verify routes on quagga
129     ${output} =    Execute Show Command On quagga    ${dcgw_ip}    show ip bgp vrf ${rd}
130     Log    ${output}
131     : FOR    ${ip}    IN    @{ip_list}
132     \    Should Contain    ${output}    ${ip}
133
134 Delete BGP Config On Quagga
135     [Arguments]    ${dcgw_ip}    ${bgp_id}    ${user}=bgpd    ${password}=sdncbgpc
136     [Documentation]    Delete BGP Config on Quagga
137     Create Quagga Telnet Session    ${dcgw_ip}    ${user}    ${password}
138     Execute Command On Quagga Telnet Session    configure terminal
139     Execute Command On Quagga Telnet Session    no router bgp ${bgp_id}
140     Execute Command On Quagga Telnet Session    end
141     ${output} =    Execute Command On Quagga Telnet Session    show running-config
142     Execute Command On Quagga Telnet Session    exit
143     [Return]    ${output}
144
145 Create BGP Configuration On ODL
146     [Arguments]    &{Kwargs}
147     [Documentation]    Associate the created L3VPN to a network-id received as dictionary argument
148     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE_BGP}/create_bgp    mapping=${Kwargs}    session=session
149
150 AddNeighbor To BGP Configuration On ODL
151     [Arguments]    &{Kwargs}
152     [Documentation]    Associate the created L3VPN to a network-id received as dictionary argument
153     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE_BGP}/addNeighbor_bgp    mapping=${Kwargs}    session=session
154
155 Get BGP Configuration On ODL
156     [Arguments]    ${odl_session}
157     [Documentation]    Get bgp configuration
158     ${resp} =    RequestsLibrary.Get Request    ${odl_session}    ${CONFIG_API}/ebgp:bgp/
159     Log    ${resp.content}
160     [Return]    ${resp.content}
161
162 Delete BGP Configuration On ODL
163     [Arguments]    ${odl_session}
164     [Documentation]    Delete BGP
165     ${resp} =    RequestsLibrary.Delete Request    ${odl_session}    ${CONFIG_API}/ebgp:bgp/
166     Log    ${resp.content}
167     Should Be Equal As Strings    ${resp.status_code}    200
168     [Return]    ${resp.content}
169
170 Create External Tunnel Endpoint Configuration
171     [Arguments]    &{Kwargs}
172     [Documentation]    Create Tunnel End point
173     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE_BGP}/create_etep    mapping=${Kwargs}    session=session
174
175 Delete External Tunnel Endpoint Configuration
176     [Arguments]    &{Kwargs}
177     [Documentation]    Delete Tunnel End point
178     TemplatedRequests.Post_As_Json_Templated    folder=${VAR_BASE_BGP}/delete_etep    mapping=${Kwargs}    session=session
179
180 Get External Tunnel Endpoint Configuration
181     [Arguments]    ${ip}
182     [Documentation]    Get bgp configuration
183     ${resp} =    RequestsLibrary.Get Request    session    ${CONFIG_API}/itm:dc-gateway-ip-list/dc-gateway-ip/${ip}/
184     Log    ${resp.content}
185     [Return]    ${resp.content}
186
187 Teardown_Everything
188     [Documentation]    Create and Log the diff between expected and actual responses, make sure Python tool was killed.
189     ...    Tear down imported Resources.
190     KillPythonTool.Search_And_Kill_Remote_Python    'play\.py'
191     RequestsLibrary.Delete_All_Sessions
192     SSHLibrary.Close_All_Connections
193
194 Check_Example_Bgp_Rib_Content
195     [Arguments]    ${substr}    ${error_message}=${JSONKEYSTR} not found, but expected.
196     [Documentation]    Check the example-bgp-rib content for string
197     ${response}=    RequestsLibrary.Get Request    operational    bgp-rib:bgp-rib/rib/example-bgp-rib
198     BuiltIn.Log    ${response.status_code}
199     BuiltIn.Log    ${response.text}
200     BuiltIn.Should_Contain    ${response.text}    ${substr}    ${error_message}    values=False
201
202 Check_Example_Bgp_Rib_Does_Not_Contain
203     [Arguments]    ${substr}    ${error_message}=${JSONKEYSTR} found, but not expected.
204     [Documentation]    Check the example-bgp-rib does not contain the string
205     ${response}=    RequestsLibrary.Get Request    operational    bgp-rib:bgp-rib/rib/example-bgp-rib
206     BuiltIn.Log    ${response.status_code}
207     BuiltIn.Log    ${response.text}
208     BuiltIn.Should_Not_Contain    ${response.text}    ${substr}    ${error_message}    values=False
209
210 Check_Example_IPv4_Topology_Content
211     [Arguments]    ${string_to_check}=${EMPTY}
212     [Documentation]    Check the example-ipv4-topology content for string
213     ${response}=    RequestsLibrary.Get Request    operational    topology/example-ipv4-topology
214     BuiltIn.Log    ${response.status_code}
215     BuiltIn.Log    ${response.text}
216     BuiltIn.Should_Contain    ${response.text}    ${string_to_check}
217
218 Check_Example_IPv4_Topology_Does_Not_Contain
219     [Arguments]    ${string_to_check}
220     [Documentation]    Check the example-ipv4-topology does not contain the string
221     ${response}=    RequestsLibrary.Get Request    operational    topology/example-ipv4-topology
222     BuiltIn.Log    ${response.status_code}
223     BuiltIn.Log    ${response.text}
224     BuiltIn.Should_Not_Contain    ${response.text}    ${string_to_check}