Fix NIC basic test.
[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://${ODL_SYSTEM_IP}:${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 Request    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     : FOR    ${intent}    IN    @{all_intents_bad}
34     \    ${intent_id}=    REST Add Intent    @{intent}
35     \    Append To List    ${all_intents_ids}    ${intent_id}
36     ${resp}=    REST Get List of Intents
37     : FOR    ${intent_id}    IN    @{all_intents_ids}
38     \    Should Contain    ${resp}    ${intent_id}
39     ${size}=    Get Length    ${all_intents_correct}
40     : FOR    ${index}    IN RANGE    ${size}
41     \    ${intent}=    Get From List    ${all_intents_correct}    ${index}
42     \    ${intent_id}=    Get From List    ${all_intents_ids}    ${index}
43     \    REST Update Intent By Id    ${intent_id}    @{intent}
44     \    ${intent_from}=    Get From List    ${intent}    0
45     \    ${intent_to}=    Get From List    ${intent}    1
46     \    ${intent_permission}=    Get From List    ${intent}    2
47     \    ${resp}=    REST Get Intent From Id    ${intent_id}
48     \    Should Contain    ${resp}    ${intent_from}
49     \    Should Contain    ${resp}    ${intent_to}
50     \    Should Contain    ${resp}    ${intent_permission}
51     : FOR    ${id}    IN    @{all_intents_ids}
52     \    REST Delete Intent By Id    ${id}
53
54 *** Keywords ***
55 REST Get List of Intents
56     [Documentation]    Get the list of intents configured
57     ${resp}    RequestsLibrary.Get Request    session    ${INTENT_CONTEXT}
58     Should Be Equal As Strings    ${resp.status_code}    200
59     Should Contain    ${resp.content}    "intents"
60     [Return]    ${resp.content}
61
62 REST Get Intent From Id
63     [Arguments]    ${id}
64     [Documentation]    Get the intent detail from id
65     ${resp}    RequestsLibrary.Get Request    session    ${INTENT_CONTEXT}/intent/${id}
66     Log Json    ${resp.content}
67     Should Be Equal As Strings    ${resp.status_code}    200
68     Should Contain    ${resp.content}    ${id}
69     [Return]    ${resp.content}
70
71 Generate Random UUID
72     [Documentation]    Generates random UUID for use with creating intents on REST API. Has the format
73     ...    (alphanumeric) 8-4-4-4-12.
74     ${id1}=    Generate Random String    8    [NUMBERS]abcdef
75     ${id2}=    Generate Random String    4    [NUMBERS]abcdef
76     ${id3}=    Generate Random String    4    [NUMBERS]abcdef
77     ${id4}=    Generate Random String    4    [NUMBERS]abcdef
78     ${id5}=    Generate Random String    12    [NUMBERS]abcdef
79     ${id}=    Catenate    SEPARATOR=-    ${id1}    ${id2}    ${id3}    ${id4}
80     ...    ${id5}
81     [Return]    ${id}
82
83 REST Add Intent
84     [Arguments]    ${intent_from}    ${intent_to}    ${intent_permission}
85     [Documentation]    Make an Intent and return the id of the new intent
86     ${headers}=    Create Dictionary    Content-Type=application/json
87     ${id}=    Generate Random UUID
88     ${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}": {}}]}}
89     ${resp}    RequestsLibrary.Post Request    session    ${INTENT_CONTEXT}    headers=${headers}    data=${data}
90     Should Be Equal As Strings    ${resp.status_code}    204
91     [Return]    ${id}
92
93 REST Update Intent By Id
94     [Arguments]    ${id}    ${intent_from}    ${intent_to}    ${intent_permission}
95     [Documentation]    Make an Intent and return the id of the new intent
96     ${headers}=    Create Dictionary    Content-Type=application/json
97     ${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}": {}}]}}
98     ${resp}    RequestsLibrary.Put Request    session    ${INTENT_CONTEXT}/intent/${id}    headers=${headers}    data=${data}
99     Should Be Equal As Strings    ${resp.status_code}    200
100     [Return]    ${resp}
101
102 REST Delete All Intents
103     [Documentation]    Delete all of the Intents
104     ${headers}=    Create Dictionary    Content-Type=application/json
105     ${resp}    RequestsLibrary.Delete Request    session    ${INTENT_CONTEXT}    headers=${headers}
106     Log    ${resp}
107     Should Be Equal As Strings    ${resp.status_code}    200
108     [Return]    ${resp.content}
109
110 REST Delete Intent By Id
111     [Arguments]    ${id}
112     [Documentation]    Delete Intent by Id
113     ${headers}=    Create Dictionary    Content-Type=application/json
114     ${resp}    RequestsLibrary.Delete Request    session    ${INTENT_CONTEXT}/intent/${id}    headers=${headers}
115     Log    ${resp}
116     Should Be Equal As Strings    ${resp.status_code}    200
117     [Return]    ${resp.content}