Step 2: Move test folder to root
[integration/test.git] / csit / suites / nic / basic / 010_Restconf_OK.robot
1 *** Settings ***
2 Documentation     Test suite to verify Restconf is OK
3 Suite Setup       Create Session    session    http://${CONTROLLER}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS_XML}
4 Suite Teardown    Delete All Sessions
5 Library           RequestsLibrary
6 Library           Collections
7 Library           HttpLibrary.HTTP
8 Variables         ../../../variables/Variables.py
9 Resource          ../../../libraries/Utils.robot
10
11 *** Variables ***
12 ${REST_CONTEXT}    /restconf/modules
13 ${INTENT_CONTEXT}    /restconf/config/intent:intents
14 @{intent1_correct}    10.0.0.5    10.0.0.2,10.0.0.3    allow
15 @{intent2_correct}    10.0.0.5    10.0.0.2,10.0.0.10    block
16 @{intent3_correct}    10.0.0.1,10.0.0.4    10.0.0.2    allow
17 @{all_intents_correct}    ${intent1_correct}    ${intent2_correct}    ${intent3_correct}
18 @{intent1_bad}    10.0.0.3    10.0.0.22,10.0.0.33    allow
19 @{intent2_bad}    10.0.0.1    10.0.0.12,10.0.0.102    block
20 @{intent3_bad}    10.0.0.2,10.0.0.10    10.0.0.42    allow
21 @{all_intents_bad}    ${intent1_bad}    ${intent2_bad}    ${intent3_bad}
22 @{all_intents_ids}
23
24 *** Test Cases ***
25 Get Controller Modules
26     [Documentation]    Get the controller modules via Restconf
27     ${resp}    RequestsLibrary.Get    session    ${REST_CONTEXT}
28     Log    ${resp.content}
29     Should Be Equal As Strings    ${resp.status_code}    200
30     Should Contain    ${resp.content}    ietf-restconf
31
32 Verify REST Command Add, Update and Remove
33     REST Delete All Intents
34     : FOR    ${intent}    IN    @{all_intents_bad}
35     \    ${intent_id}=    REST Add Intent    @{intent}
36     \    Append To List    ${all_intents_ids}    ${intent_id}
37     ${resp}=    REST Get List of Intents
38     : FOR    ${intent_id}    IN    @{all_intents_ids}
39     \    Should Contain    ${resp}    ${intent_id}
40     ${size}=    Get Length    ${all_intents_correct}
41     : FOR    ${index}    IN RANGE    ${size}
42     \    ${intent}=    Get From List    ${all_intents_correct}    ${index}
43     \    ${intent_id}=    Get From List    ${all_intents_ids}    ${index}
44     \    REST Update Intent By Id    ${intent_id}    @{intent}
45     \    ${intent_from}=    Get From List    ${intent}    0
46     \    ${intent_to}=    Get From List    ${intent}    1
47     \    ${intent_permission}=    Get From List    ${intent}    2
48     \    ${resp}=    REST Get Intent From Id    ${intent_id}
49     \    Should Contain    ${resp}    ${intent_from}
50     \    Should Contain    ${resp}    ${intent_to}
51     \    Should Contain    ${resp}    ${intent_permission}
52     : FOR    ${id}    IN    @{all_intents_ids}
53     \    REST Delete Intent By Id    ${id}
54
55 *** Keywords ***
56 REST Get List of Intents
57     [Documentation]    Get the list of intents configured
58     ${resp}    RequestsLibrary.Get    session    ${INTENT_CONTEXT}
59     Should Be Equal As Strings    ${resp.status_code}    200
60     Should Contain    ${resp.content}    "intents"
61     [Return]    ${resp.content}
62
63 REST Get Intent From Id
64     [Arguments]    ${id}
65     [Documentation]    Get the intent detail from id
66     ${resp}    RequestsLibrary.Get    session    ${INTENT_CONTEXT}/intent/${id}
67     Log Json    ${resp.content}
68     Should Be Equal As Strings    ${resp.status_code}    200
69     Should Contain    ${resp.content}    ${id}
70     [Return]    ${resp.content}
71
72 Generate Random UUID
73     [Documentation]    Generates random UUID for use with creating intents on REST API. Has the format
74     ...    (alphanumeric) 8-4-4-4-12.
75     ${id1}=    Generate Random String    8    [NUMBERS]abcdef
76     ${id2}=    Generate Random String    4    [NUMBERS]abcdef
77     ${id3}=    Generate Random String    4    [NUMBERS]abcdef
78     ${id4}=    Generate Random String    4    [NUMBERS]abcdef
79     ${id5}=    Generate Random String    12    [NUMBERS]abcdef
80     ${id}=    Catenate    SEPARATOR=-    ${id1}    ${id2}    ${id3}    ${id4}
81     ...    ${id5}
82     [Return]    ${id}
83
84 REST Add Intent
85     [Arguments]    ${intent_from}    ${intent_to}    ${intent_permission}
86     [Documentation]    Make an Intent and return the id of the new intent
87     ${headers}=    Create Dictionary    Content-Type=application/json
88     ${id}=    Generate Random UUID
89     ${data}=    Catenate    {"intent":{"id": "${id}","subjects":[{"order": 1,"end-point-group": {"name": "${intent_from}"}},{"order": 2,"end-point-group": { "name": "${intent_to}"}}],"actions": [{"order": 1,"${intent_permission}": {}}]}}
90     ${resp}    RequestsLibrary.Post    session    ${INTENT_CONTEXT}    headers=${headers}    data=${data}
91     Should Be Equal As Strings    ${resp.status_code}    204
92     [Return]    ${id}
93
94 REST Update Intent By Id
95     [Arguments]    ${id}    ${intent_from}    ${intent_to}    ${intent_permission}
96     [Documentation]    Make an Intent and return the id of the new intent
97     ${headers}=    Create Dictionary    Content-Type=application/json
98     ${data}=    Catenate    {"intent":{"id": "${id}","subjects":[{"order": 1,"end-point-group": {"name": "${intent_from}"}},{"order": 2,"end-point-group": { "name": "${intent_to}"}}],"actions": [{"order": 1,"${intent_permission}": {}}]}}
99     ${resp}    RequestsLibrary.Put    session    ${INTENT_CONTEXT}/intent/${id}    headers=${headers}    data=${data}
100     Should Be Equal As Strings    ${resp.status_code}    200
101     [Return]    ${resp}
102
103 REST Delete All Intents
104     [Documentation]    Delete all of the Intents
105     ${headers}=    Create Dictionary    Content-Type=application/json
106     ${resp}    RequestsLibrary.Delete    session    ${INTENT_CONTEXT}    headers=${headers}
107     Log    ${resp}
108     Should Be Equal As Strings    ${resp.status_code}    200
109     [Return]    ${resp.content}
110
111 REST Delete Intent By Id
112     [Arguments]    ${id}
113     [Documentation]    Delete Intent by Id
114     ${headers}=    Create Dictionary    Content-Type=application/json
115     ${resp}    RequestsLibrary.Delete    session    ${INTENT_CONTEXT}/intent/${id}    headers=${headers}
116     Log    ${resp}
117     Should Be Equal As Strings    ${resp.status_code}    200
118     [Return]    ${resp.content}