f648ed8e825b470b72ca3f208b6571505d804703
[integration/test.git] / csit / suites / genius / ID_manager.robot
1 *** Settings ***
2 Documentation       Test Suite for IdManager
3
4 Library             OperatingSystem
5 Library             String
6 Library             RequestsLibrary
7 Library             Collections
8 Library             re
9 Variables           ../../variables/genius/Modules.py
10 Resource            ../../libraries/DataModels.robot
11 Resource            ../../libraries/Utils.robot
12 Resource            ../../libraries/Genius.robot
13 Resource            ../../variables/Variables.robot
14
15 Suite Setup         Create Session    session    http://${ODL_SYSTEM_IP}:${RESTCONFPORT}    auth=${AUTH}    headers=${HEADERS}    timeout=5
16 Suite Teardown      Delete All Sessions
17 Test Setup          Genius Test Setup
18 Test Teardown       Get Model Dump    ${ODL_SYSTEM_IP}    ${idmanager_data_models}
19
20
21 *** Variables ***
22 ${genius_config_dir}        ${CURDIR}/../../variables/genius
23 ${pool-name}                test-pool
24 @{test_keys}                test-key1    test-key2    test-key3
25 ${create_json}              createIdpool.json
26 ${allocaterange_json}       allocateIdRange.json
27 ${OPERATIONS_API}           /restconf/operations
28
29
30 *** Test Cases ***
31 Create ID pool in range 10:20
32     [Documentation]    This testcase creates Id pool in range 10 to 20.
33     Utils.Post Elements To URI From File
34     ...    ${OPERATIONS_API}/id-manager:createIdPool
35     ...    ${genius_config_dir}/${create_json}
36     @{poolrange} =    BuiltIn.Create list    ${pool-name}    10    20
37     Utils.Check For Elements At URI    ${CONFIG_API}/id-manager:id-pools/id-pool/${pool-name}/    ${poolrange}
38     @{availiable_pool} =    BuiltIn.Create list    10    20    10
39     Utils.Check For Elements At URI
40     ...    ${CONFIG_API}/id-manager:id-pools/id-pool/${pool-name}/available-ids-holder/
41     ...    ${availiable_pool}
42
43 Allocate Ids from pool created within size as 5
44     [Documentation]    This testcase allocated IDs of specified size for the pool created in 1st testcase.
45     ${body} =    OperatingSystem.Get File    ${genius_config_dir}/${allocaterange_json}
46     ${body} =    String.Replace string    ${body}    test-key    ${test_keys[0]}
47     BuiltIn.Log    ${body}
48     Utils.Post Elements To URI    ${OPERATIONS_API}/id-manager:allocateIdRange    ${body}
49     get Id pool
50
51 Neg_Allocate ids of size 10 from the same pool
52     [Documentation]    This is a Negative testcase where when trying to allocate Id range out of the availiable IDs we have, the IDs are not allocated.
53     ${pool-name} =    BuiltIn.Set Variable    test-pool
54     ${body} =    OperatingSystem.Get File    ${genius_config_dir}/${allocaterange_json}
55     ${body} =    String.Replace String    ${body}    5    6
56     ${body} =    String.Replace String    ${body}    test-key    ${test_keys[1]}
57     BuiltIn.Log    ${body}
58     ${resp} =    RequestsLibrary.Post Request
59     ...    session
60     ...    ${OPERATIONS_API}/id-manager:allocateIdRange
61     ...    data=${body}
62     BuiltIn.Log    ${resp.content}
63     BuiltIn.Should Be Equal As Strings    ${resp.status_code}    500
64
65 Allocate IDs of size 3 from the pool
66     [Documentation]    This testcase allocates 3 Ids from the created pool in test case 1
67     ${body} =    OperatingSystem.Get File    ${genius_config_dir}/${allocaterange_json}
68     ${body} =    String.Replace string    ${body}    test-key    ${test_keys[2]}
69     ${body} =    String.Replace string    ${body}    5    3
70     BuiltIn.Log    ${body}
71     Utils.Post Elements To URI    ${OPERATIONS_API}/id-manager:allocateIdRange    ${body}
72     ${get_resp} =    RequestsLibrary.Get Request
73     ...    session
74     ...    ${CONFIG_API}/id-manager:id-pools/id-pool/${pool-name}/available-ids-holder/
75     ${respjson} =    RequestsLibrary.To Json    ${get_resp.content}    pretty_print=True
76     BuiltIn.Log    ${respjson}
77     BuiltIn.Should Contain    ${get_resp.text}    17
78     BuiltIn.Should Be Equal As Strings    ${get_resp.status_code}    200
79
80 Release a block of IDs allocated using releaseIds RPC
81     [Documentation]    This testcase Releases the block of Ids by using the key which is sent in json.
82     ${body} =    OperatingSystem.Get File    ${genius_config_dir}/releaseIds.json
83     BuiltIn.Log    ${body}
84     ${body} =    String.Replace String    ${body}    test-key    ${test_keys[2]}
85     Utils.Post Elements To URI    ${OPERATIONS_API}/id-manager:releaseId    ${body}
86     ${get_resp} =    RequestsLibrary.Get Request    session    ${CONFIG_API}/id-manager:id-pools/id-pool/${pool-name}/
87     ${respjson} =    RequestsLibrary.To Json    ${get_resp.text}    pretty_print=True
88     BuiltIn.Log    ${respjson}
89     BuiltIn.Should Be Equal As Strings    ${get_resp.status_code}    200
90     ${child-pool-name} =    BuiltIn.Should Match Regexp    ${get_resp.text}    ${pool-name}\.[-]?[0-9]+
91     BuiltIn.Log    ${child-pool-name}
92     ${get_releasedIds} =    RequestsLibrary.Get Request
93     ...    session
94     ...    ${CONFIG_API}/id-manager:id-pools/id-pool/${child-pool-name}/released-ids-holder/
95     ${respjson} =    RequestsLibrary.To Json    ${get_releasedIds.text}    pretty_print=True
96     BuiltIn.Log    ${respjson}
97     Should Be Equal As Strings    ${get_releasedIds.status_code}    200
98     @{released_ids} =    re.Findall    <id>[0-9]+    ${get_releasedIds.text}
99     BuiltIn.Log    ${released_ids}
100
101 Delete the ID Pool using deleteIdPool RPC
102     [Documentation]    This testcase deletes the ID pool craeted in the 1st testcase.
103     ${body} =    OperatingSystem.Get File    ${genius_config_dir}/deleteIdPool.json
104     ${body} =    String.Replace String    ${body}    poolname    ${pool-name}
105     BuiltIn.Log    ${body}
106     Utils.Post Elements To URI    ${OPERATIONS_API}/id-manager:deleteIdPool    ${body}
107     Utils.No Content From URI    session    ${CONFIG_API}/id-manager:id-pools/id-pool/${pool-name}/
108
109
110 *** Keywords ***
111 get Id pool
112     [Documentation]    This keyword checks the created ID pool by doing GET.
113     ${get_resp} =    RequestsLibrary.Get Request
114     ...    session
115     ...    ${CONFIG_API}/id-manager:id-pools/id-pool/${pool-name}/available-ids-holder/
116     ${respjson} =    RequestsLibrary.To Json    ${get_resp.content}    pretty_print=True
117     BuiltIn.Log    ${respjson}
118     BuiltIn.Should Contain    ${get_resp.text}    14
119     BuiltIn.Should Be Equal As Strings    ${get_resp.status_code}    200