Update Robot Framework format - step 14
[integration/test.git] / csit / suites / sfc / SFC_Basic / 070__sfc_rendered_service_paths.robot
1 *** Settings ***
2 Documentation       Test suite for SFC Rendered Service Paths, Operates functions from Restconf APIs.
3
4 Library             SSHLibrary
5 Library             Collections
6 Library             OperatingSystem
7 Library             RequestsLibrary
8 Resource            ../../../variables/sfc/Variables.robot
9 Resource            ../../../libraries/SFC/SfcKeywords.robot
10 Resource            ../../../libraries/Utils.robot
11 Resource            ../../../libraries/TemplatedRequests.robot
12
13 Suite Setup         Init Suite
14 Suite Teardown      Delete All Sessions
15
16
17 *** Test Cases ***
18 Basic Environment Setup Tests
19     [Documentation]    Prepare Basic Test Environment
20     Utils.Add Elements To URI From File    ${SERVICE_FORWARDERS_URI}    ${SERVICE_FORWARDERS_FILE}
21     Utils.Add Elements To URI From File    ${SERVICE_NODES_URI}    ${SERVICE_NODES_FILE}
22     Utils.Add Elements To URI From File    ${SERVICE_FUNCTIONS_URI}    ${SERVICE_FUNCTIONS_FILE}
23     BuiltIn.Wait Until Keyword Succeeds
24     ...    60s
25     ...    2s
26     ...    SfcKeywords.Check Service Function Types Added
27     ...    ${SERVICE_FUNCTION_NAMES}
28     Utils.Add Elements To URI From File    ${SERVICE_CHAINS_URI}    ${SERVICE_CHAINS_FILE}
29     # Creates SFPs: SFC1-100, SFC1-200, SFC1-300, SFC2-100, and SFC2-200
30     SfcKeywords.Create Sfp And Wait For Rsp Creation    ${SERVICE_FUNCTION_PATHS_FILE}
31
32 Get Rendered Service Path By Name
33     [Documentation]    Get The Rendered Service Path Created in "Basic Environment Setup Tests" By Name Via RESTConf APIs
34     ${sfp_name} =    BuiltIn.Set Variable    SFC1-100
35     ${rsp_name} =    SfcKeywords.Get Rendered Service Path Name    ${sfp_name}
36     ${resp} =    RequestsLibrary.Get Request    session    ${OPERATIONAL_RSP_URI}/${rsp_name}
37     BuiltIn.Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
38     # The RSP should not be symetric, so only 1 should be created for the SFP
39     Utils.Check For Specific Number Of Elements At URI
40     ...    ${SERVICE_FUNCTION_PATH_STATE_URI}/${sfp_name}
41     ...    "sfp-rendered-service-path"
42     ...    1
43     ${elements} =    BuiltIn.Create List
44     ...    "parent-service-function-path":"SFC1-100"
45     ...    "hop-number":0
46     ...    "service-index":255
47     ...    "hop-number":1
48     ...    "service-index":254
49     ...    "hop-number":2
50     ...    "service-index":253
51     Utils.Check For Elements At URI    ${OPERATIONAL_RSPS_URI}    ${elements}
52
53 Get Rendered Service Path Hop
54     [Documentation]    Check Rendered Service Path Hops Created in "Basic Environment Setup Tests"
55     ${sfp_name} =    BuiltIn.Set Variable    SFC1-100
56     ${rsp_name} =    SfcKeywords.Get Rendered Service Path Name    ${sfp_name}
57     ${resp} =    RequestsLibrary.Get Request
58     ...    session
59     ...    ${OPERATIONAL_RSP_URI}/${rsp_name}/rendered-service-path-hop/0/
60     BuiltIn.Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
61     ${elements} =    BuiltIn.Create List    "hop-number":0    "service-index":255    "service-function-name":"dpi
62     Utils.Check For Elements At URI    ${OPERATIONAL_RSP_URI}/${rsp_name}/rendered-service-path-hop/0/    ${elements}
63     ${elements} =    BuiltIn.Create List    "hop-number":1    "service-index":254    "service-function-name":"napt44
64     Utils.Check For Elements At URI    ${OPERATIONAL_RSP_URI}/${rsp_name}/rendered-service-path-hop/1/    ${elements}
65     ${elements} =    BuiltIn.Create List    "hop-number":2    "service-index":253    "service-function-name":"firewall
66     Utils.Check For Elements At URI    ${OPERATIONAL_RSP_URI}/${rsp_name}/rendered-service-path-hop/2/    ${elements}
67     ${resp} =    RequestsLibrary.Get Request
68     ...    session
69     ...    ${OPERATIONAL_RSP_URI}/${rsp_name}/rendered-service-path-hop/3/
70     BuiltIn.Should Be Equal As Strings    ${resp.status_code}    404
71
72 Delete one Rendered Service Path By Name
73     [Documentation]    Delete One Rendered Service Path By deleting the parent Service Function Path
74     ...    The RSP to be deleted was created in "Basic Environment Setup Tests"
75     ${sfp_name} =    BuiltIn.Set Variable    SFC2-200
76     ${rsp_name} =    SfcKeywords.Get Rendered Service Path Name    ${sfp_name}
77     # First verify that the RSP exists
78     ${resp} =    RequestsLibrary.Get Request    session    ${OPERATIONAL_RSP_URI}/${rsp_name}
79     BuiltIn.Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
80     SfcKeywords.Delete Sfp And Wait For Rsps Deletion    ${sfp_name}
81
82 Generate RSPs with Random Schedule Algorithm type
83     [Documentation]    Generate RSPs with Random Schedule Algorithm type Through RESTConf APIs
84     Utils.Remove All Elements At URI    ${SERVICE_SCHED_TYPES_URI}
85     Utils.Add Elements To URI From File    ${SERVICE_RANDOM_SCHED_TYPE_URI}    ${SERVICE_RANDOM_SCHED_TYPE_FILE}
86     SfcKeywords.Delete All Sfps And Wait For Rsps Deletion
87     # Create the SFPs which will create the RSPs with the Random scheduler
88     SfcKeywords.Create Sfp And Wait For Rsp Creation    ${SERVICE_FUNCTION_PATHS_FILE}
89     ${sfp_name} =    BuiltIn.Set Variable    SFC1-100
90     ${rsp_name} =    SfcKeywords.Get Rendered Service Path Name    ${sfp_name}
91     ${elements} =    BuiltIn.Create List    "hop-number":0    "service-index":255    "service-function-name":"dpi
92     Utils.Check For Elements At URI    ${OPERATIONAL_RSP_URI}/${rsp_name}/rendered-service-path-hop/0/    ${elements}
93     ${elements} =    BuiltIn.Create List    "hop-number":1    "service-index":254    "service-function-name":"napt44
94     Utils.Check For Elements At URI    ${OPERATIONAL_RSP_URI}/${rsp_name}/rendered-service-path-hop/1/    ${elements}
95     ${elements} =    BuiltIn.Create List    "hop-number":2    "service-index":253    "service-function-name":"firewall
96     Utils.Check For Elements At URI    ${OPERATIONAL_RSP_URI}/${rsp_name}/rendered-service-path-hop/2/    ${elements}
97
98 Generate RSPs with Round Robin Schedule Algorithm type
99     [Documentation]    Generate RSPs with Round Robin Schedule Algorithm type
100     [Tags]    exclude
101     Utils.Remove All Elements At URI    ${SERVICE_SCHED_TYPES_URI}
102     Utils.Add Elements To URI From File
103     ...    ${SERVICE_ROUNDROBIN_SCHED_TYPE_URI}
104     ...    ${SERVICE_ROUNDROBIN_SCHED_TYPE_FILE}
105     SfcKeywords.Delete All Sfps And Wait For Rsps Deletion
106     # Create the SFPs which will create the RSPs with the Random scheduler
107     SfcKeywords.Create Sfp And Wait For Rsp Creation    ${SERVICE_FUNCTION_PATHS_FILE}
108     ${rsp1_name} =    SfcKeywords.Get Rendered Service Path Name    SFC1-100
109     ${rsp2_name} =    SfcKeywords.Get Rendered Service Path Name    SFC1-200
110     ${rsp3_name} =    SfcKeywords.Get Rendered Service Path Name    SFC1-300
111     ${rsp4_name} =    SfcKeywords.Get Rendered Service Path Name    SFC2-100
112     ${rsp5_name} =    SfcKeywords.Get Rendered Service Path Name    SFC2-200
113     ${path1_hop0} =    SfcKeywords.Get JSON Elements From URI
114     ...    ${OPERATIONAL_RSP_URI}/${rsp1_name}/rendered-service-path-hop/0/
115     ${path1_hop1} =    SfcKeywords.Get JSON Elements From URI
116     ...    ${OPERATIONAL_RSP_URI}/${rsp1_name}/rendered-service-path-hop/1/
117     ${path1_hop2} =    SfcKeywords.Get JSON Elements From URI
118     ...    ${OPERATIONAL_RSP_URI}/${rsp1_name}/rendered-service-path-hop/2/
119     ${path2_hop0} =    SfcKeywords.Get JSON Elements From URI
120     ...    ${OPERATIONAL_RSP_URI}/${rsp1_name}/rendered-service-path-hop/0/
121     ${path2_hop1} =    SfcKeywords.Get JSON Elements From URI
122     ...    ${OPERATIONAL_RSP_URI}/${rsp1_name}/rendered-service-path-hop/1/
123     ${path2_hop2} =    SfcKeywords.Get JSON Elements From URI
124     ...    ${OPERATIONAL_RSP_URI}/${rsp1_name}/rendered-service-path-hop/2/
125     ${path3_hop0} =    SfcKeywords.Get JSON Elements From URI
126     ...    ${OPERATIONAL_RSP_URI}/${rsp1_name}/rendered-service-path-hop/0/
127     ${path3_hop1} =    SfcKeywords.Get JSON Elements From URI
128     ...    ${OPERATIONAL_RSP_URI}/${rsp1_name}/rendered-service-path-hop/1/
129     ${path3_hop2} =    SfcKeywords.Get JSON Elements From URI
130     ...    ${OPERATIONAL_RSP_URI}/${rsp1_name}/rendered-service-path-hop/2/
131     ${path4_hop0} =    SfcKeywords.Get JSON Elements From URI
132     ...    ${OPERATIONAL_RSP_URI}/${rsp1_name}/rendered-service-path-hop/0/
133     ${path4_hop1} =    SfcKeywords.Get JSON Elements From URI
134     ...    ${OPERATIONAL_RSP_URI}/${rsp1_name}/rendered-service-path-hop/1/
135     ${path4_hop2} =    SfcKeywords.Get JSON Elements From URI
136     ...    ${OPERATIONAL_RSP_URI}/${rsp1_name}/rendered-service-path-hop/2/
137     ${path5_hop0} =    SfcKeywords.Get JSON Elements From URI
138     ...    ${OPERATIONAL_RSP_URI}/${rsp1_name}/rendered-service-path-hop/0/
139     ${path5_hop1} =    SfcKeywords.Get JSON Elements From URI
140     ...    ${OPERATIONAL_RSP_URI}/${rsp1_name}/rendered-service-path-hop/1/
141     ${path5_hop2} =    SfcKeywords.Get JSON Elements From URI
142     ...    ${OPERATIONAL_RSP_URI}/${rsp1_name}/rendered-service-path-hop/2/
143     BuiltIn.Should Be Equal    ${path1_hop0}    ${path4_hop0}
144     BuiltIn.Should Not Be Equal    ${path1_hop0}    ${path2_hop0}
145     BuiltIn.Should Be Equal    ${path1_hop1}    ${path4_hop1}
146     BuiltIn.Should Not Be Equal    ${path1_hop1}    ${path2_hop1}
147     BuiltIn.Should Be Equal    ${path1_hop2}    ${path4_hop2}
148     BuiltIn.Should Not Be Equal    ${path1_hop2}    ${path2_hop2}
149     BuiltIn.Should Be Equal    ${path2_hop0}    ${path5_hop0}
150     BuiltIn.Should Not Be Equal    ${path2_hop0}    ${path3_hop0}
151     BuiltIn.Should Be Equal    ${path2_hop1}    ${path5_hop1}
152     BuiltIn.Should Not Be Equal    ${path2_hop1}    ${path3_hop1}
153     BuiltIn.Should Be Equal    ${path2_hop2}    ${path5_hop2}
154     BuiltIn.Should Not Be Equal    ${path2_hop2}    ${path3_hop2}
155     BuiltIn.Should Be Equal    ${path3_hop0}    ${path1_hop0}
156     BuiltIn.Should Not Be Equal    ${path3_hop0}    ${path1_hop0}
157     BuiltIn.Should Be Equal    ${path3_hop1}    ${path1_hop1}
158     BuiltIn.Should Not Be Equal    ${path3_hop1}    ${path1_hop1}
159     BuiltIn.Should Be Equal    ${path3_hop2}    ${path1_hop2}
160     BuiltIn.Should Not Be Equal    ${path3_hop2}    ${path1_hop2}
161
162 Generate RSPs with Shortest Path Schedule Algorithm type
163     [Documentation]    Generate RSPs with Shortest Path Schedule Algorithm type Through RESTConf APIs
164     Utils.Remove All Elements At URI    ${SERVICE_SCHED_TYPES_URI}
165     Utils.Add Elements To URI From File
166     ...    ${SERVICE_SHORTESTPATH_SCHED_TYPE_URI}
167     ...    ${SERVICE_SHORTESTPATH_SCHED_TYPE_FILE}
168     SfcKeywords.Delete All Sfps And Wait For Rsps Deletion
169     # Create the SFPs which will create the RSPs with the Random scheduler
170     SfcKeywords.Create Sfp And Wait For Rsp Creation    ${SERVICE_FUNCTION_PATHS_FILE}
171     ${rsp1_name} =    SfcKeywords.Get Rendered Service Path Name    SFC1-100
172     ${rsp2_name} =    SfcKeywords.Get Rendered Service Path Name    SFC1-200
173     ${rsp3_name} =    SfcKeywords.Get Rendered Service Path Name    SFC1-300
174     ${rsp4_name} =    SfcKeywords.Get Rendered Service Path Name    SFC2-100
175     ${rsp5_name} =    SfcKeywords.Get Rendered Service Path Name    SFC2-200
176     ${elements} =    BuiltIn.Create List    "hop-number":0    "service-index":255    "service-function-name":"dpi-1
177     Utils.Check For Elements At URI    ${OPERATIONAL_RSP_URI}/${rsp1_name}/rendered-service-path-hop/0/    ${elements}
178     ${elements} =    BuiltIn.Create List    "hop-number":1    "service-index":254    "service-function-name":"napt44
179     Utils.Check For Elements At URI    ${OPERATIONAL_RSP_URI}/${rsp1_name}/rendered-service-path-hop/1/    ${elements}
180     ${elements} =    BuiltIn.Create List    "hop-number":2    "service-index":253    "service-function-name":"firewall
181     Utils.Check For Elements At URI    ${OPERATIONAL_RSP_URI}/${rsp1_name}/rendered-service-path-hop/2/    ${elements}
182     ${resp} =    RequestsLibrary.Get Request
183     ...    session
184     ...    ${OPERATIONAL_RSP_URI}/${rsp1_name}/rendered-service-path-hop/0/
185     BuiltIn.Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
186     ${temp_vars} =    BuiltIn.Set Variable    ['rendered-service-path-hop'][0]['service-function-forwarder']
187     ${fwd_hop1} =    Utils.Extract Value From Content    ${resp.content}    ${temp_vars}
188     ${resp} =    RequestsLibrary.Get Request
189     ...    session
190     ...    ${OPERATIONAL_RSP_URI}/${rsp1_name}/rendered-service-path-hop/1/
191     BuiltIn.Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
192     ${fwd_hop2} =    Utils.Extract Value From Content    ${resp.content}    ${temp_vars}
193     ${resp} =    RequestsLibrary.Get Request
194     ...    session
195     ...    ${OPERATIONAL_RSP_URI}/${rsp1_name}/rendered-service-path-hop/2/
196     BuiltIn.Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
197     ${fwd_hop3} =    Utils.Extract Value From Content    ${resp.content}    ${temp_vars}
198     BuiltIn.Should Be Equal    ${fwd_hop1}    ${fwd_hop2}
199     BuiltIn.Should Be Equal    ${fwd_hop2}    ${fwd_hop3}
200     ${resp} =    RequestsLibrary.Get Request
201     ...    session
202     ...    ${OPERATIONAL_RSP_URI}/${rsp2_name}/rendered-service-path-hop/0/
203     BuiltIn.Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
204     ${fwd_hop1} =    Utils.Extract Value From Content    ${resp.content}    ${temp_vars}
205     ${resp} =    RequestsLibrary.Get Request
206     ...    session
207     ...    ${OPERATIONAL_RSP_URI}/${rsp2_name}/rendered-service-path-hop/1/
208     BuiltIn.Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
209     ${fwd_hop2} =    Utils.Extract Value From Content    ${resp.content}    ${temp_vars}
210     ${resp} =    RequestsLibrary.Get Request
211     ...    session
212     ...    ${OPERATIONAL_RSP_URI}/${rsp2_name}/rendered-service-path-hop/2/
213     BuiltIn.Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
214     ${fwd_hop3} =    Utils.Extract Value From Content    ${resp.content}    ${temp_vars}
215     BuiltIn.Should Be Equal    ${fwd_hop1}    ${fwd_hop2}
216     BuiltIn.Should Be Equal    ${fwd_hop2}    ${fwd_hop3}
217
218 Clean Datastore After Tests
219     [Documentation]    Clean All Items In Datastore After Tests
220     Utils.Remove All Elements At URI    ${SERVICE_FUNCTIONS_URI}
221     BuiltIn.Wait Until Keyword Succeeds
222     ...    60s
223     ...    2s
224     ...    SfcKeywords.Check Service Function Types Removed
225     ...    ${SERVICE_FUNCTION_NAMES}
226     Utils.Remove All Elements At URI    ${SERVICE_FORWARDERS_URI}
227     Utils.Remove All Elements At URI    ${SERVICE_NODES_URI}
228     Utils.Remove All Elements At URI    ${SERVICE_CHAINS_URI}
229     Utils.Remove All Elements At URI    ${SERVICE_SCHED_TYPES_URI}
230     Utils.Remove All Elements If Exist    ${SERVICE_FUNCTION_PATHS_URI}
231     BuiltIn.Wait Until Keyword Succeeds    60s    2s    SfcKeywords.Check Empty Service Function Paths State
232
233
234 *** Keywords ***
235 Init Suite
236     [Documentation]    Create session and initialize ODL version specific variables
237     RequestsLibrary.Create Session
238     ...    session
239     ...    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}
240     ...    auth=${AUTH}
241     ...    headers=${HEADERS}
242     BuiltIn.log    ${ODL_STREAM}
243     BuiltIn.Set Suite Variable    ${VERSION_DIR}    master
244     BuiltIn.Set Suite Variable    ${TEST_DIR}    ${CURDIR}/../../../variables/sfc/${VERSION_DIR}
245     BuiltIn.Set Suite Variable    ${SERVICE_FUNCTIONS_FILE}    ${TEST_DIR}/service-functions.json
246     BuiltIn.Set Suite Variable
247     ...    @{SERVICE_FUNCTION_NAMES}
248     ...    "napt44-103-2"
249     ...    "napt44-103-1"
250     ...    "dpi-102-2"
251     ...    "firewall-101-2"
252     ...    "napt44-104"
253     ...    "dpi-102-1"
254     ...    "firewall-104"
255     ...    "dpi-102-3"
256     ...    "firewall-101-1"
257     BuiltIn.Set Suite Variable    ${SERVICE_FORWARDERS_FILE}    ${TEST_DIR}/service-function-forwarders.json
258     BuiltIn.Set Suite Variable    ${SERVICE_NODES_FILE}    ${TEST_DIR}/service-nodes.json
259     BuiltIn.Set Suite Variable    ${SERVICE_CHAINS_FILE}    ${TEST_DIR}/service-function-chains.json
260     BuiltIn.Set Suite Variable    ${SERVICE_FUNCTION_PATHS_FILE}    ${TEST_DIR}/service-function-paths.json
261     BuiltIn.Set Suite Variable    ${SERVICE_RANDOM_SCHED_TYPE_FILE}    ${TEST_DIR}/service-random-schedule-type.json
262     BuiltIn.Set Suite Variable
263     ...    ${SERVICE_ROUNDROBIN_SCHED_TYPE_FILE}
264     ...    ${TEST_DIR}/service-roundrobin-schedule-type.json
265     BuiltIn.Set Suite Variable
266     ...    ${SERVICE_LOADBALANCE_SCHED_TYPE_FILE}
267     ...    ${TEST_DIR}/service-loadbalance-schedule-type.json
268     BuiltIn.Set Suite Variable
269     ...    ${SERVICE_SHORTESTPATH_SCHED_TYPE_FILE}
270     ...    ${TEST_DIR}/service-shortestpath-schedule-type.json