Adapt 404 response when delete non-existent element
[integration/test.git] / csit / suites / sfc / SFC_Basic / 010__sfc_service_functions.robot
1 *** Settings ***
2 Documentation     Test suite for SFC Service Functions, Operates functions from Restconf APIs.
3 Suite Setup       Init Suite
4 Suite Teardown    Delete All Sessions
5 Test Setup        Remove All Elements If Exist    ${SERVICE_FUNCTIONS_URI}
6 Library           SSHLibrary
7 Library           Collections
8 Library           OperatingSystem
9 Library           RequestsLibrary
10 Variables         ../../../variables/Variables.py
11 Resource          ../../../libraries/Utils.robot
12 Resource          ../../../libraries/TemplatedRequests.robot
13
14 *** Test Cases ***
15 Add Service Functions
16     [Documentation]    Add Service Functions from JSON file
17     Add Elements To URI From File    ${SERVICE_FUNCTIONS_URI}    ${SERVICE_FUNCTIONS_FILE}
18     ${body}    OperatingSystem.Get File    ${SERVICE_FUNCTIONS_FILE}
19     ${jsonbody}    To Json    ${body}
20     ${functions}    Get From Dictionary    ${jsonbody}    service-functions
21     ${resp}    RequestsLibrary.Get Request    session    ${SERVICE_FUNCTIONS_URI}
22     Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
23     ${result}    To JSON    ${resp.content}
24     ${function}    Get From Dictionary    ${result}    service-functions
25     Lists Should be Equal    ${function}    ${functions}
26
27 Delete All Service Functions
28     [Documentation]    Delete all Service Functions
29     ${body}    OperatingSystem.Get File    ${SERVICE_FUNCTIONS_FILE}
30     Add Elements To URI From File    ${SERVICE_FUNCTIONS_URI}    ${SERVICE_FUNCTIONS_FILE}
31     ${resp}    RequestsLibrary.Get Request    session    ${SERVICE_FUNCTIONS_URI}
32     Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
33     Remove All Elements At URI    ${SERVICE_FUNCTIONS_URI}
34     ${resp}    RequestsLibrary.Get Request    session    ${SERVICE_FUNCTIONS_URI}
35     Should Be Equal As Strings    ${resp.status_code}    404
36
37 Get one Service Function
38     [Documentation]    Get one Service Function
39     Add Elements To URI From File    ${SERVICE_FUNCTIONS_URI}    ${SERVICE_FUNCTIONS_FILE}
40     ${elements}=    Create List    dpi-102-1    dpi
41     Check For Elements At URI    ${SERVICE_FUNCTIONS_URI}service-function/dpi-102-1    ${elements}
42
43 Get A Non-existing Service Function
44     [Documentation]    Get A Non-existing Service Function
45     Add Elements To URI From File    ${SERVICE_FUNCTIONS_URI}    ${SERVICE_FUNCTIONS_FILE}
46     ${resp}    RequestsLibrary.Get Request    session    ${SERVICE_FUNCTIONS_URI}service-function/non-existing-sf
47     Should Be Equal As Strings    ${resp.status_code}    404
48
49 Delete A Service Function
50     [Documentation]    Delete A Service Function
51     Add Elements To URI From File    ${SERVICE_FUNCTIONS_URI}    ${SERVICE_FUNCTIONS_FILE}
52     Remove All Elements At URI    ${SERVICE_FUNCTIONS_URI}service-function/dpi-102-1
53     ${resp}    RequestsLibrary.Get Request    session    ${SERVICE_FUNCTIONS_URI}
54     Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
55     Should Not Contain    ${resp.content}    dpi-102-1
56
57 Delete A Non-existing Empty Service Function
58     [Documentation]    Delete A Non existing Service Function
59     Add Elements To URI From File    ${SERVICE_FUNCTIONS_URI}    ${SERVICE_FUNCTIONS_FILE}
60     ${body}    OperatingSystem.Get File    ${SERVICE_FUNCTIONS_FILE}
61     ${jsonbody}    To Json    ${body}
62     ${functions}    Get From Dictionary    ${jsonbody}    service-functions
63     ${resp}    RequestsLibrary.Delete Request    session    ${SERVICE_FUNCTIONS_URI}service-function/non-existing-sf
64     Should Be Equal As Strings    ${resp.status_code}    404
65     ${resp}    RequestsLibrary.Get Request    session    ${SERVICE_FUNCTIONS_URI}
66     Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
67     ${result}    To JSON    ${resp.content}
68     ${function}    Get From Dictionary    ${result}    service-functions
69     Lists Should be Equal    ${function}    ${functions}
70
71 Put one Service Function
72     [Documentation]    Put one Service Function
73     Add Elements To URI From File    ${SF_DPI102100_URI}    ${SF_DPI102100_FILE}
74     ${elements}=    Create List    dpi-102-100    dpi
75     Check For Elements At URI    ${SF_DPI102100_URI}    ${elements}
76     Check For Elements At URI    ${SERVICE_FUNCTIONS_URI}    ${elements}
77
78 Get Service Function DPL
79     [Documentation]    Get Service Function Data Plane Locator
80     Add Elements To URI From File    ${SF_DPI102100_URI}    ${SF_DPI102100_FILE}
81     ${elements}=    Create List    100    10100
82     Check For Elements At URI    ${SF_DPI102100_URI}sf-data-plane-locator/dpl-100    ${elements}
83
84 Put Service Function DPL
85     [Documentation]    Put Service Function Data Plane Locator
86     Add Elements To URI From File    ${SF_DPI102100_URI}    ${SF_DPI102100_FILE}
87     Add Elements To URI From File    ${SF_DPI102100_URI}sf-data-plane-locator/dpl-101    ${SF_DPL101_FILE}
88     ${elements}=    Create List    dpl-101    10101
89     Check For Elements At URI    ${SF_DPI102100_URI}sf-data-plane-locator/dpl-101    ${elements}
90     Check For Elements At URI    ${SF_DPI102100_URI}    ${elements}
91
92 Put Service Function DPL to a Non-existing Service Function
93     [Documentation]    Put Service Function DPL to a Non-existing Service Function
94     [Tags]    exclude
95     Add Elements To URI From File    ${SF_DPI102100_URI}sf-data-plane-locator/dpl-101    ${SF_DPL101_FILE}
96     ${resp}    RequestsLibrary.Get Request    session    ${SERVICE_FUNCTIONS_URI}
97     Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
98     Should Contain    ${resp.content}    dpi-102-100
99     ${elements}=    Create List    dpl-101    10101
100     Check For Elements At URI    ${SF_DPI102100_URI}sf-data-plane-locator/dpl-101    ${elements}
101     Check For Elements At URI    ${SF_DPI102100_URI}    ${elements}
102
103 Delete Service Function DPL
104     [Documentation]    Delete Service Function Data Plane Locator
105     Add Elements To URI From File    ${SF_DPI102100_URI}    ${SF_DPI102100_FILE}
106     Remove All Elements At URI    ${SF_DPI102100_URI}sf-data-plane-locator/dpl-100
107     ${resp}    RequestsLibrary.Get Request    session    ${SF_DPI102100_URI}
108     Should Contain    ${ALLOWED_STATUS_CODES}    ${resp.status_code}
109     Should Not Contain    ${resp.content}    dpl-100
110
111 *** Keywords ***
112 Init Suite
113     [Documentation]    Initialize session and ODL version specific variables
114     Create Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS}
115     log    ${ODL_STREAM}
116     Run Keyword If    '${ODL_STREAM}' == 'stable-lithium'    Set Suite Variable    ${VERSION_DIR}    lithium
117     ...    ELSE    Set Suite Variable    ${VERSION_DIR}    master
118     Set Suite Variable    ${SERVICE_FUNCTIONS_URI}    /restconf/config/service-function:service-functions/
119     Set Suite Variable    ${SERVICE_FUNCTIONS_FILE}    ${CURDIR}/../../../variables/sfc/${VERSION_DIR}/service-functions.json
120     Set Suite Variable    ${SF_DPI102100_URI}    /restconf/config/service-function:service-functions/service-function/dpi-102-100/
121     Set Suite Variable    ${SF_DPI102100_FILE}    ${CURDIR}/../../../variables/sfc/${VERSION_DIR}/sf_dpi_102_100.json
122     Set Suite Variable    ${SF_DPL101_FILE}    ${CURDIR}/../../../variables/sfc/${VERSION_DIR}/sf_dpl_101.json