Use RFC8040 URL for JSON-RPC tests
[integration/test.git] / csit / libraries / JsonrpcKeywords.robot
1 *** Settings ***
2 Library           OperatingSystem
3 Library           SSHLibrary
4 Library           Collections
5 Library           RequestsLibrary
6 Resource          ClusterManagement.robot
7 Resource          ../variables/jsonrpc/JsonrpcVariables.robot
8 Resource          ../variables/Variables.robot
9 Resource          SSHKeywords.robot
10 Resource          Utils.robot
11
12 *** Keywords ***
13 Run Read Service Python Script on Controller Vm
14     [Arguments]    ${host_index}=${FIRST_CONTROLLER_INDEX}
15     [Documentation]    This keyword creates a new virtual environment, installs pyzmq & zmq and starts the read service on controller vm
16     ${host_index}    Builtin.Convert To Integer    ${host_index}
17     ${host}    ClusterManagement.Resolve IP Address For Member    ${host_index}
18     ${connections}    SSHKeywords.Open_Connection_To_ODL_System    ${host}
19     SSHLibrary.Switch Connection    ${connections}
20     SSHLibrary.Put File    ${READ_SERVICE_SCRIPT}    ${WORKSPACE}/${BUNDLEFOLDER}/    mode=664
21     ${module}    OperatingSystem.Get File    ${JSONRPCCONFIG_MODULE_JSON}
22     ${data}    OperatingSystem.Get File    ${JSONRPCCONFIG_DATA_JSON}
23     ${cmd}    Builtin.Set Variable    nohup python ${WORKSPACE}/${BUNDLEFOLDER}/odl-jsonrpc-test-read tcp://0.0.0.0:${DEFAULT_PORT} 'config' ${DEFAULT_ENDPOINT} '${module.replace("\n","").replace(" ","")}' '${data.replace("\n","").replace(" ","")}'
24     Log    ${cmd}
25     SSHKeywords.Virtual_Env_Set_Path    /tmp/jsonrpc_venv
26     SSHKeywords.Virtual_Env_Create_Python3    True
27     SSHKeywords.Virtual_Env_Install_Package    pyzmq
28     SSHKeywords.Virtual_Env_Install_Package    zmq
29     SSHKeywords.Virtual_Env_Activate_On_Current_Session    True
30     ${stdout}    SSHLibrary.Write    rm -rf nohup.out
31     ${stdout}    SSHLibrary.Write    ${cmd} &
32     ${stdout}    SSHLibrary.Write    echo
33     Log    ${stdout}
34     BuiltIn.Sleep    2s
35     ${stdout}    SSHLibrary.Execute Command    /usr/sbin/ss -nlt
36     Log    ${stdout}
37     ${stdout}    SSHLibrary.Execute Command    cat nohup.out
38     Log    ${stdout}
39     SSHLibrary.Close_Connection
40
41 Mount Read Service Endpoint
42     [Arguments]    ${controller_index}=${FIRST_CONTROLLER_INDEX}    ${file}=${READ_SERVICE_PEER_PAYLOAD}    ${endpoint}=${DEFAULT_ENDPOINT}
43     [Documentation]    This keyword mounts an endpoint after starting service
44     ${JSON1}    OperatingSystem.Get File    ${file}
45     Log    ${JSON1}
46     ${response_json}    ClusterManagement.Put_As_Json_To_Member    ${READ_SERVICE_PEER_URL}=${endpoint}    ${JSON1}    ${controller_index}
47     Builtin.Log    ${response_json}
48
49 Verify Data On Mounted Endpoint
50     [Arguments]    ${controller_index}=${FIRST_CONTROLLER_INDEX}    ${endpoint}=${DEFAULT_ENDPOINT}
51     [Documentation]    This keyword verifies if the data we get on the mount point is same as what we put
52     ${resp}    ClusterManagement.Get_From_Member    ${READ_SERVICE_PEER_URL}=${endpoint}${READ_SERVICE_PEER_MOUNT_PATH}?content=config    ${controller_index}
53     ${response_json}    Builtin.Convert To String    ${resp}
54     Log    ${response_json}
55     Verify Restconf Get On Mounted Endpoint    ${response_json}    ${READSERVICE_NAME}
56
57 Verify Restconf Get On Mounted Endpoint
58     [Arguments]    ${output}    ${name}
59     [Documentation]    This keyword parses restconf get of mountpoint
60     Builtin.Should Match Regexp    ${output}    "name":"${name}"