Adapt netconf device configuration in daexim CSIT
[integration/test.git] / csit / suites / bgpcep / bgpfunct / bgp_policies_default.robot
1 *** Settings ***
2 Documentation       Functional test for bgp routing policies
3 ...
4 ...                 Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
5 ...
6 ...                 This program and the accompanying materials are made available under the
7 ...                 terms of the Eclipse Public License v1.0 which accompanies this distribution,
8 ...                 and is available at http://www.eclipse.org/legal/epl-v10.html
9 ...
10 ...                 This suite uses 7 peers: app peer, 2x rr-client, 2x ebgp, 2x ibgp
11 ...                 Tests results on effective-rib-in dependant on their respective configurations.
12 ...                 Peers 1,2,4,5 are testing multiple ipv4 routes with additional arguments.
13 ...                 Peers 3,6 have ipv4 and ipv6 mpls-labeled routes.
14
15 Library             RequestsLibrary
16 Library             SSHLibrary
17 Resource            ../../../variables/Variables.robot
18 Resource            ../../../libraries/CompareStream.robot
19 Resource            ../../../libraries/ExaBgpLib.robot
20 Resource            ../../../libraries/SetupUtils.robot
21 Resource            ../../../libraries/TemplatedRequests.robot
22 Resource            ../../../libraries/SSHKeywords.robot
23
24 Suite Setup         Start_Suite
25 Suite Teardown      Stop_Suite
26 Test Setup          SetupUtils.Setup_Test_With_Logging_And_Without_Fast_Failing
27
28
29 *** Variables ***
30 ${POLICIES_VAR}         ${CURDIR}/../../../variables/bgpfunctional/bgppolicies
31 ${CMD}                  env exabgp.tcp.port=1790 exabgp --debug
32 @{PEER_TYPES}           ibgp_peer    ibgp_peer    ebgp_peer    ebgp_peer    rr_client_peer    rr_client_peer
33 @{NUMBERS}              1    2    3    4    5    6
34 ${HOLDTIME}             180
35 ${RIB_INSTANCE}         example-bgp-rib
36 ${CONFIG_SESSION}       config-session
37
38
39 *** Test Cases ***
40 Verify_Rib_Empty
41     [Documentation]    Checks empty example-ipv4-topology ready.
42     Verify_Rib_Status_Empty
43
44 Configure_App_Peer
45     [Documentation]    Configures bgp application peer, and configures it's routes.
46     &{mapping}    BuiltIn.Create_Dictionary
47     ...    RIB_INSTANCE_NAME=${RIB_INSTANCE}
48     ...    APP_PEER_ID=${ODL_SYSTEM_IP}
49     ...    BGP_RIB_OPENCONFIG=${RIB_INSTANCE}
50     ...    IP=${ODL_SYSTEM_IP}
51     TemplatedRequests.Post_As_Xml_Templated
52     ...    ${POLICIES_VAR}/app_peer
53     ...    mapping=${mapping}
54     ...    session=${CONFIG_SESSION}
55     TemplatedRequests.Post_As_Xml_Templated
56     ...    ${POLICIES_VAR}/app_peer_route
57     ...    mapping=${mapping}
58     ...    session=${CONFIG_SESSION}
59
60 Reconfigure_ODL_To_Accept_Connections
61     [Documentation]    Configure BGP peer modules with initiate-connection set to false.
62     ...    Configures 6 different peers, two internal, two external and two route-reflectors.
63     FOR    ${index}    ${peer_type}    IN ZIP    ${NUMBERS}    ${PEER_TYPES}
64         &{mapping}    Create Dictionary
65         ...    IP=127.0.0.${index}
66         ...    HOLDTIME=${HOLDTIME}
67         ...    PASSIVE_MODE=true
68         ...    BGP_RIB_OPENCONFIG=${RIB_INSTANCE}
69         ...    RIB_INSTANCE_NAME=${RIB_INSTANCE}
70         TemplatedRequests.Put_As_Xml_Templated
71         ...    ${POLICIES_VAR}${/}${peer_type}
72         ...    mapping=${mapping}
73         ...    session=${CONFIG_SESSION}
74     END
75
76 Start_Exabgps
77     [Documentation]    Start 6 exabgps as processes in background, each with it's own configuration.
78     SSHKeywords.Virtual_Env_Activate_On_Current_Session    log_output=${True}
79     FOR    ${index}    IN    @{NUMBERS}
80         ${start_cmd}    BuiltIn.Set_Variable    ${CMD} exabgp${index}.cfg > exa${index}.log &
81         BuiltIn.Log    ${start_cmd}
82         ${output}    SSHLibrary.Write    ${start_cmd}
83         BuiltIn.Log    ${output}
84     END
85
86 Verify_Rib_Filled
87     [Documentation]    Verifies that sent routes are present in particular ribs.
88     [Tags]    critical
89     Verify_Rib_Status
90
91 Stop_All_Peers
92     [Documentation]    Send command to kill all exabgp processes running on controller
93     ExaBgpLib.Stop_All_ExaBgps
94     FOR    ${index}    IN    @{NUMBERS}
95         BGPcliKeywords.Store_File_To_Workspace    exa${index}.log    exa${index}.log
96     END
97
98 Delete_Bgp_Peer_Configuration
99     [Documentation]    Revert the BGP configuration to the original state: without any configured peers.
100     FOR    ${index}    ${peer_type}    IN ZIP    ${NUMBERS}    ${PEER_TYPES}
101         &{mapping}    Create Dictionary
102         ...    IP=127.0.0.${index}
103         ...    HOLDTIME=${HOLDTIME}
104         ...    PASSIVE_MODE=true
105         ...    BGP_RIB_OPENCONFIG=${RIB_INSTANCE}
106         ...    RIB_INSTANCE_NAME=${RIB_INSTANCE}
107         TemplatedRequests.Delete_Templated
108         ...    ${POLICIES_VAR}/${peer_type}
109         ...    mapping=${mapping}
110         ...    session=${CONFIG_SESSION}
111     END
112
113 Deconfigure_App_Peer
114     [Documentation]    Revert the BGP configuration to the original state: without application peer
115     &{mapping}    BuiltIn.Create_Dictionary    IP=${ODL_SYSTEM_IP}    BGP_RIB_OPENCONFIG=${RIB_INSTANCE}
116     TemplatedRequests.Delete_Templated    ${POLICIES_VAR}/app_peer    mapping=${mapping}    session=${CONFIG_SESSION}
117     TemplatedRequests.Delete_Templated
118     ...    ${POLICIES_VAR}/app_peer_route
119     ...    mapping=${mapping}
120     ...    session=${CONFIG_SESSION}
121
122
123 *** Keywords ***
124 Start_Suite
125     [Documentation]    Suite setup keyword.
126     SetupUtils.Setup_Utils_For_Setup_And_Teardown
127     ${conn_id}    SSHLibrary.Open Connection    ${ODL_SYSTEM_IP}    prompt=${DEFAULT_LINUX_PROMPT}    timeout=10s
128     Builtin.Set_Suite_Variable    ${conn_id}
129     SSHKeywords.Flexible_Controller_Login
130     SSHKeywords.Virtual_Env_Create    upgrade_pip=False
131     SSHKeywords.Virtual_Env_Install_Package    exabgp==4.0.5
132     RequestsLibrary.Create_Session    ${CONFIG_SESSION}    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}
133     Upload_Config_Files
134
135 Stop_Suite
136     [Documentation]    Suite teardown keyword
137     SSHKeywords.Virtual_Env_Delete
138     SSHLibrary.Close_All_Connections
139     RequestsLibrary.Delete_All_Sessions
140
141 Verify_Rib_Status
142     [Documentation]    Verify output from effective-rib-in for each of the 6 exabgp peers and app peer.
143     ...    First request is for full example-bgp-rib and it's output is logged for debug purposes.
144     ...    Each of the peers have different output which is stored in folder by their respective
145     ...    numbers as peer_${index} (peer_1, peer_2 ...)
146     # gets and outputs full rib output for debug purposes if one of the peers reports faulty data.
147     ${output}    TemplatedRequests.Get_As_Json_Templated    ${POLICIES_VAR}/rib_state    session=${CONFIG_SESSION}
148     BuiltIn.Log    ${output}
149     FOR    ${index}    IN    @{NUMBERS}
150         &{mapping}    BuiltIn.Create_Dictionary    IP=127.0.0.${index}
151         BuiltIn.Wait_Until_Keyword_Succeeds
152         ...    5x
153         ...    3s
154         ...    TemplatedRequests.Get_As_Json_Templated
155         ...    ${POLICIES_VAR}/effective_rib_in/peer_${index}
156         ...    mapping=${mapping}
157         ...    session=${CONFIG_SESSION}
158         ...    verify=True
159     END
160     &{mapping}    BuiltIn.Create_Dictionary    IP=${ODL_SYSTEM_IP}
161     # application peer verification
162     BuiltIn.Wait_Until_Keyword_Succeeds
163     ...    5x
164     ...    3s
165     ...    TemplatedRequests.Get_As_Json_Templated
166     ...    ${POLICIES_VAR}/app_peer_rib
167     ...    mapping=${mapping}
168     ...    session=${CONFIG_SESSION}
169     ...    verify=True
170
171 Verify_Rib_Status_Empty
172     [Documentation]    Checks that example-ipv4-topology is ready, and therefore full rib is ready to be configured.
173     BuiltIn.Wait_Until_Keyword_Succeeds
174     ...    60s
175     ...    3s
176     ...    TemplatedRequests.Get_As_Json_Templated
177     ...    ${POLICIES_VAR}/topology_state
178     ...    session=${CONFIG_SESSION}
179     ...    verify=True
180
181 Upload_Config_Files
182     [Documentation]    Uploads exabgp config files and replaces variables within those
183     ...    config files with desired values.
184     FOR    ${index}    IN    @{NUMBERS}
185         SSHLibrary.Put_File    ${POLICIES_VAR}/exabgp_configs/exabgp${index}.cfg    .
186     END
187     @{cfgfiles}    SSHLibrary.List_Files_In_Directory    .    *.cfg
188     FOR    ${cfgfile}    IN    @{cfgfiles}
189         SSHLibrary.Execute_Command    sed -i -e 's/ODLIP/${ODL_SYSTEM_IP}/g' ${cfgfile}
190         SSHLibrary.Execute_Command    sed -i -e 's/ROUTEREFRESH/disable/g' ${cfgfile}
191         SSHLibrary.Execute_Command    sed -i -e 's/ADDPATH/disable/g' ${cfgfile}
192         ${stdout}    SSHLibrary.Execute_Command    cat ${cfgfile}
193         Log    ${stdout}
194     END