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