Add Library/Keywords to dynamically generate URI
[integration/test.git] / csit / libraries / Restconf.robot
1 *** Settings ***
2
3 *** Variables ***
4 ${USE_RFC8040} =    False
5
6 *** Keywords ***
7
8 Generate URI
9     [Arguments]    ${identifier}    ${datastore}=config    @{node_value_list}
10     [Documentation]    Returns the proper URI to use depending on if RFC8040 is to be used or not. Variable input
11     ...    error checking is done to ensure the ${USE_RFC8040} Flag is one of True or False and the ${datastore} variable
12     ...    must be config or operational. @{node_value_list} is expected to be in the format of node=value. RFC8040 can
13     ...    use that as is with '=' delimiter, but older restconf URI will convert the '=' to a '/'
14     ${uri} =    Run Keyword If    "${USE_RFC8040}" == "True"    Generate RFC8040 URI    ${identifier}    ${datastore}    @{node_value_list}
15     Return From Keyword If    "${USE_RFC8040}" == "True"    ${uri}
16     Run Keyword If    "${USE_RFC8040}" != "False"    Fail    Invalid Value for RFC8040 Flag: ${USE_RFC8040}
17     Run Keyword If    "${datastore}"!="config" and "${datastore}"!="operational"    Fail    Invalid value for datastore: ${datastore}
18     ${uri} =    Run Keyword If    "${datastore}"=="config"    Set Variable    ${CONFIG_API}/${identifier}
19     ...    ELSE    Set Variable    ${OPERATIONAL_API}/${identifier}
20     ${node_value_path} =    Set Variable    ${EMPTY}
21     FOR    ${nv}    IN    @{node_value_list}
22         ${nv} =    String.Replace String    ${nv}    =    /
23         ${node_value_path} =    Set Variable    ${node_value_path}/${nv}
24     END
25     [Return]    ${uri}${node_value_path}
26
27 Generate RFC8040 URI
28     [Arguments]    ${identifier}    ${datastore}=config    @{node_value_list}
29     ${node_value_path} =    Set Variable    ${EMPTY}
30     FOR    ${nv}    IN    @{node_value_list}
31         ${node_value_path} =    Set Variable    ${node_value_path}/${nv}
32     END
33     ${uri} =    Run Keyword If    "${datastore}" == "config"    Set Variable    rests/data/${identifier}${node_value_path}?content=config
34     ...    ELSE    Set Variable    rests/data/${identifier}${node_value_path}?content=nonconfig
35     [Return]    ${uri}