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