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