Fixed "close connection" action in MDSAL suite 62/29662/2
authorJozef Behran <jbehran@cisco.com>
Fri, 13 Nov 2015 11:29:19 +0000 (12:29 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 16 Nov 2015 16:36:55 +0000 (16:36 +0000)
Sending "^D" to the netconf connection does not guarantee
that the connection is closed properly, leading to a
spurious test failure due to failed teardown.

The proper way is to open two connections, one "control" and
one "netconf". The "netconf" connection then connects to
netconf as usual and the "control" connection is used to
control the SSH process connecting to netconf. It is used to
obtain the PID of the "sshpass" process which governs the
connection and to send the kill signal to that process
once the connection is to be closed.

Change-Id: I3a0bc1e03d1af9619ced3fa7dfcd45aad3d696fa
Signed-off-by: Jozef Behran <jbehran@cisco.com>
csit/suites/netconf/MDSAL/northbound.robot

index b3df4cde05963d0cbbe360047ea39595904e6709..68b9322e0bebdb08d8ba11723c1d5d774ca204cf 100644 (file)
@@ -29,6 +29,7 @@ Library           RequestsLibrary
 Library           SSHLibrary
 Resource          ${CURDIR}/../../../libraries/FailFast.robot
 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
+Resource          ${CURDIR}/../../../libraries/SSHKeywords.robot
 Resource          ${CURDIR}/../../../libraries/Utils.robot
 Variables         ${CURDIR}/../../../variables/Variables.py
 
@@ -261,10 +262,19 @@ Open_ODL_Netconf_Connection
     #    going to need to use this operation (Netconf Performance and Scaling
     #    comes to my mind now as one of the things tested is the performance
     #    of the direct netconf connection.
-    SSHLibrary.Open_Connection    ${host}    prompt=${ODL_SYSTEM_PROMPT}    timeout=10s
+    ${control}=    SSHLibrary.Open_Connection    ${host}    prompt=${ODL_SYSTEM_PROMPT}    timeout=10s
     Utils.Flexible_Controller_Login
+    BuiltIn.Set_Suite_Variable    ${ssh_control}    ${control}
+    ${netconf}=    SSHLibrary.Open_Connection    ${host}    prompt=${ODL_SYSTEM_PROMPT}    timeout=10s
+    Utils.Flexible_Controller_Login
+    BuiltIn.Set_Suite_Variable    ${ssh_netconf}    ${netconf}
     SSHLibrary.Write    sshpass -p ${password} ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ${user}\@127.0.0.1 -p ${port} -s netconf
     ${hello}=    SSHLibrary.Read_Until    ${ODL_NETCONF_PROMPT}
+    SSHLibrary.Switch_Connection    ${ssh_control}
+    SSHLibrary.Write    ps -A | grep sshpass | cut -b 1-6
+    ${pid}=    SSHKeywords.Read_Command_Response
+    BuiltIn.Set_Suite_Variable    ${ssh_netconf_pid}    ${pid}
+    SSHLibrary.Switch_Connection    ${ssh_netconf}
     [Return]    ${hello}
 
 Transmit_Message
@@ -307,7 +317,10 @@ Load_Expected_Reply
 
 Close_ODL_Netconf_Connection
     [Documentation]    Correctly close the Netconf connection and make sure it is really dead.
-    Utils.Write_Bare_Ctrl_D
+    SSHLibrary.Switch_Connection    ${ssh_control}
+    SSHLibrary.Write    kill ${ssh_netconf_pid}
+    SSHLibrary.Read_Until_Prompt
+    SSHLibrary.Switch_Connection    ${ssh_netconf}
     SSHLibrary.Read_Until_Prompt
 
 Setup_Everything