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