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