Fix the JSONRPC read service issue 47/98247/12
authorSangwook Ha <sangwook.ha@verizon.com>
Fri, 29 Oct 2021 19:56:21 +0000 (12:56 -0700)
committerLuis Gomez <ecelgp@gmail.com>
Sun, 31 Oct 2021 20:09:01 +0000 (20:09 +0000)
The steps to upgrade pip and install pyzmq & zmq were failing
because it's done with an old version of OS default pip.

Add a new keyword to support Python 3 virtual environment in
SSHKeywords.robot, and start the read service in a new Python 3
virtual environment created with the new keyword - a new keyword
was created, instead of updating the existing keyword, in order
not to interfere with other test cases.

Replace 'send' with 'send_string' in the odl-jsonrpc-test-read
Python script because the former cannot be used to send a unicode
string in Python 3.

And remove new lines & spaces from the configuration data when
creating the script command to make it a little simpler.

Signed-off-by: Sangwook Ha <sangwook.ha@verizon.com>
Change-Id: I70e694bb1a4fa21c2133b262e291791e6afe5ce8

csit/libraries/JsonrpcKeywords.robot
csit/libraries/SSHKeywords.robot
csit/variables/jsonrpc/odl-jsonrpc-test-read

index 5eedc9047c5eddfcccb8db29b955d2e6d6c36f9f..45cc03a8a1573bea09f5d2541a91267f41bf5474 100644 (file)
@@ -6,35 +6,34 @@ Library           RequestsLibrary
 Resource          ClusterManagement.robot
 Resource          ../variables/jsonrpc/JsonrpcVariables.robot
 Resource          ../variables/Variables.robot
+Resource          SSHKeywords.robot
 Resource          Utils.robot
 
 *** Keywords ***
 Run Read Service Python Script on Controller Vm
-    [Arguments]    ${host_index}=${FIRST_CONTROLLER_INDEX}    ${ub_system}=${FALSE}
-    [Documentation]    This keyword installs pip,zmq,pyzmq and starts the read service on controller vm
-    ${cmd}    Builtin.Set Variable If    ${ub_system}    ${UB_PIP}    ${CENTOS_PIP}
+    [Arguments]    ${host_index}=${FIRST_CONTROLLER_INDEX}
+    [Documentation]    This keyword creates a new virtual environment, installs pyzmq & zmq and starts the read service on controller vm
     ${host_index}    Builtin.Convert To Integer    ${host_index}
     ${host}    ClusterManagement.Resolve IP Address For Member    ${host_index}
     ${connections}    SSHKeywords.Open_Connection_To_ODL_System    ${host}
     SSHLibrary.Switch Connection    ${connections}
     SSHLibrary.Put File    ${READ_SERVICE_SCRIPT}    ${WORKSPACE}/${BUNDLEFOLDER}/    mode=664
-    ${stdout}    ${stderr}    ${rc}=    SSHLibrary.Execute Command    ${cmd}    return_stdout=True    return_stderr=True
-    ...    return_rc=True
-    Log    ${stdout}
-    ${stdout}    ${stderr}    ${rc}=    SSHLibrary.Execute Command    sudo pip install --upgrade pip    return_stdout=True    return_stderr=True
-    ...    return_rc=True
-    Log    ${stdout}
-    ${stdout}    ${stderr}    ${rc}=    SSHLibrary.Execute Command    sudo pip install zmq pyzmq    return_stdout=True    return_stderr=True
-    ...    return_rc=True
-    Log    ${stdout}
     ${module}    OperatingSystem.Get File    ${JSONRPCCONFIG_MODULE_JSON}
     ${data}    OperatingSystem.Get File    ${JSONRPCCONFIG_DATA_JSON}
-    ${cmd}    Builtin.Set Variable    nohup python ${WORKSPACE}/${BUNDLEFOLDER}/odl-jsonrpc-test-read tcp://0.0.0.0:${DEFAULT_PORT} 'config' ${DEFAULT_ENDPOINT} '${module}' '${data}'
+    ${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(" ","")}'
     Log    ${cmd}
-    ${stdout}    SSHLibrary.Write    echo | rm -rf nohup.out
-    ${stdout}    SSHLibrary.Write    echo | nohup python ${WORKSPACE}/${BUNDLEFOLDER}/odl-jsonrpc-test-read tcp://0.0.0.0:${DEFAULT_PORT} 'config' ${DEFAULT_ENDPOINT} '${module}' '${data}' &
+    SSHKeywords.Virtual_Env_Set_Path    /tmp/jsonrpc_venv
+    SSHKeywords.Virtual_Env_Create_Python3    True
+    SSHKeywords.Virtual_Env_Install_Package    pyzmq
+    SSHKeywords.Virtual_Env_Install_Package    zmq
+    SSHKeywords.Virtual_Env_Activate_On_Current_Session    True
+    ${stdout}    SSHLibrary.Write    rm -rf nohup.out
+    ${stdout}    SSHLibrary.Write    ${cmd} &
     ${stdout}    SSHLibrary.Write    echo
     Log    ${stdout}
+    BuiltIn.Sleep    2s
+    ${stdout}    SSHLibrary.Execute Command    /usr/sbin/ss -nlt
+    Log    ${stdout}
     ${stdout}    SSHLibrary.Execute Command    cat nohup.out
     Log    ${stdout}
     SSHLibrary.Close_Connection
index 2d2080063304b749979c0a19d5ea558ac6d61047..adfefcc5211f1c0cd2d6ffcc2abca39581f6b1cf 100644 (file)
@@ -170,6 +170,12 @@ Virtual_Env_Create
     Execute_Command_At_Cwd_Should_Pass    virtualenv ${SSHKeywords__current_venv_path}
     BuiltIn.Run_Keyword_And_Return_If    ${upgrade_pip}    Virtual_Env_Run_Cmd_At_Cwd    pip install --upgrade pip    stderr_must_be_empty=False
 
+Virtual_Env_Create_Python3
+    [Arguments]    ${upgrade_pip}=True
+    [Documentation]    Creates virtual env. If not to use the default name, use Virtual_Env_Set_Path kw. Returns stdout.
+    Execute_Command_At_Cwd_Should_Pass    python3 -m venv ${SSHKeywords__current_venv_path}
+    BuiltIn.Run_Keyword_And_Return_If    ${upgrade_pip}    Virtual_Env_Run_Cmd_At_Cwd    pip install --upgrade pip    stderr_must_be_empty=False
+
 Virtual_Env_Delete
     [Documentation]    Deletes a directory with virtual env.
     Execute_Command_At_Cwd_Should_Pass    rm -rf ${SSHKeywords__current_venv_path}
index 62303f1242375f366cad2ca06e445f0083ca13ef..40c42147341ace48b317340b816a439cdc83b73e 100755 (executable)
@@ -166,7 +166,7 @@ def main():
     logging.info(">%s", request)
     (code, response) = service.execute_json(request)
     logging.info("<%s", response)
-    zock.send(response)
+    zock.send_string(response)
     logging.info("exiting with code %d", code)
     zock.close()
     sys.exit(code)