Step 1: Move vm scripts to the right place
[integration/test.git] / test / csit / libraries / DatastoreCRUD.robot
1 *** Settings ***
2 Library           Collections
3 Library           RequestsLibrary
4 Variables         ../variables/Variables.py
5
6 *** Keywords ***
7 Create Records
8     [Arguments]    ${controller_ip}    ${node}    ${first}    ${last}    ${prefix}    ${field bases}    ${postfix}
9     [Documentation]    POSTs records to a controller's data store. First and last index numbers are specified
10     ...    as is a dictionary called field_bases containing the base name for the field contents
11     ...    onto which will be appended the index number. Prefix and postfix are used to complete
12     ...    the JSON payload. The keyword passes if return code is correct.
13     ${last}    Convert to Integer    ${last}
14     : FOR    ${INDEX}    IN RANGE    ${first}    ${last+1}
15     \    ${payload}=    Assemble Payload    ${INDEX}    ${prefix}    ${field bases}    ${postfix}
16     \    Log    ${payload}
17     \    Create_Session    session    http://${controller_ip}:${RESTCONFPORT}${CONFIG_API}    headers=${HEADERS}    auth=${AUTH}
18     \    ${resp}    RequestsLibrary.Post    session    ${node}    ${payload}
19     \    Log    ${resp}
20     \    Should Be Equal As Strings    ${resp}    <Response [204]>
21
22 Read Records
23     [Arguments]    ${controller_ip}    ${node}
24     [Documentation]    GETs records from a shard on a controller's data store.
25     Create_Session    session    http://${controller_ip}:${RESTCONFPORT}${CONFIG_API}    headers=${HEADERS}    auth=${AUTH}
26     ${resp}=    RequestsLibrary.Get    session    ${node}
27     [Return]    ${resp.json()}
28
29 Update Records
30     [Arguments]    ${controller_ip}    ${node}    ${first}    ${last}    ${prefix}    ${field bases}    ${postfix}
31     [Documentation]    PUTs records to shard on a controller's data store. First and last index numbers are specified
32     ...    as is a dictionary called field_bases containing the base name for the field contents
33     ...    onto which will be appended the index number. Prefix and postfix are used to complete
34     ...    the JSON payload. The keyword passes if return code is correct.
35     ${last}    Convert to Integer    ${last}
36     : FOR    ${INDEX}    IN RANGE    ${first}    ${last+1}
37     \    ${payload}=    Assemble Payload    ${INDEX}    ${prefix}    ${field bases}    ${postfix}
38     \    Log    ${payload}
39     \    Create_Session    session    http://${controller_ip}:${RESTCONFPORT}${CONFIG_API}    headers=${HEADERS}    auth=${AUTH}
40     \    ${resp}=    RequestsLibrary.Put    session    ${node}/${INDEX}    ${payload}
41     \    Log    ${resp}
42     \    Should Be Equal As Strings    ${resp}    <Response [200]>
43
44 Delete Records
45     [Arguments]    ${controller_ip}    ${node}    ${first}    ${last}
46     [Documentation]    DELETEs specified range of records from a shard on a contrsoller's data store.
47     ${last}    Convert to Integer    ${last}
48     : FOR    ${INDEX}    IN RANGE    ${first}    ${last+1}
49     \    Create_Session    session    http://${controller_ip}:${RESTCONFPORT}${CONFIG_API}    headers=${HEADERS}    auth=${AUTH}
50     \    ${resp}=    RequestsLibrary.Delete    session    ${node}/${INDEX}
51     \    Should Be Equal As Strings    ${resp}    <Response [200]>
52
53 Delete All Records
54     [Arguments]    ${controller_ip}    ${node}
55     [Documentation]    DELETEs all records from a shard on a controller's data store.
56     Create_Session    session    http://${controller_ip}:${RESTCONFPORT}${CONFIG_API}    headers=${HEADERS}    auth=${AUTH}
57     ${resp}=    RequestsLibrary.Delete    session    ${node}
58     Should Be Equal As Strings    ${resp}    <Response [200]>
59
60 Assemble Payload
61     [Arguments]    ${id}    ${prefix}    ${field bases}    ${postfix}
62     [Documentation]    Populates a payload for creating or updating a shard record.
63     ...    id: The record number and is also appended onto each field to uniquely identify it.
64     ...    prefix: The portion of the json payload before the records.
65     ...    field bases: A dictionary of records onto which the id is appended.
66     ...    prefix: The portion of the json payload after the records.
67     ${length}=    Get Length    ${field bases}
68     ${keys}=    Get Dictionary Keys    ${field bases}
69     ${payload}=    Set Variable    ${prefix}
70     : FOR    ${key string}    IN    @{keys}
71     \    ${value string}=    Get From Dictionary    ${field bases}    ${key string}
72     \    ${payload}=    Catenate    ${payload}    "${key string}": "${value string}${id}",
73     ${payload}=    Get Substring    ${payload}    ${EMPTY}    -1
74     ${payload}=    Catenate    ${payload}    ${postfix}
75     [Return]    ${payload}