Add keyword for watching TCP ports on remote machine 09/28809/4
authorJozef Behran <jbehran@cisco.com>
Mon, 26 Oct 2015 15:55:23 +0000 (16:55 +0100)
committerJozef Behran <jbehran@cisco.com>
Wed, 28 Oct 2015 11:55:44 +0000 (12:55 +0100)
This keyword gets a TCP port number, a state (LISTEN or
ESTABLISHED are the most useful but other states produced
by netstat may be used) and a process name. It then runs
netstat, greps through its output and reports the number of
occurences of a line mentioning the port, state and process.

An instance where this is needed was found in the BGPCEP
suite and transformed to use the new keyword. This can serve
as an example of how to use the keyword and additionally
serves as a test that the keyword is correct.

Change-Id: Ica59958e9b5ade564904a1725e9ef77154f84317
Signed-off-by: Jozef Behran <jbehran@cisco.com>
csit/libraries/SSHKeywords.robot
csit/suites/bgpcep/bgpuser/cases.robot

index d49ce199cec893f5f2ffbd2cd37824b58a821c24..763dfe707704decd222d77a7484370366a9019b9 100644 (file)
@@ -1,4 +1,3 @@
-*** Settings ***
 Documentation     Resource enhancing SSHLibrary with Keywords used in multiple suites.
 ...
 ...               Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
@@ -45,3 +44,9 @@ Assure_Library_Counter
     # TODO: Move the bash-cd wrapper to separate keyword?
     BuiltIn.Return_From_Keyword_If    ${passed}
     SSHLibrary.Put_File    ${CURDIR}/Counter.py    ${target_dir}/
+
+Count_Port_Occurences
+    [Arguments]    ${port}    ${state}    ${name}
+    [Documentation]    Run 'netstat' on the remote machine and count occurences of given port in the given state connected to process with the given name.
+    ${output}=    SSHLibrary.Execute_Command    netstat -natp 2> /dev/null | grep -E ":${port} .+ ${state} .+${name}" | wc -l
+    [Return]    ${output}
index 83d9b84f990b284811aacd9aea9c4c52bc40aabe..73e49a8b86c7db6a5d066ced6db9622c4cfcd342 100644 (file)
@@ -26,6 +26,7 @@ Resource          ${CURDIR}/../../../libraries/FailFast.robot
 Resource          ${CURDIR}/../../../libraries/KarafKeywords.robot
 Resource          ${CURDIR}/../../../libraries/KillPythonTool.robot
 Resource          ${CURDIR}/../../../libraries/SetupUtils.robot
+Resource          ${CURDIR}/../../../libraries/SSHKeywords.robot
 Resource          ${CURDIR}/../../../libraries/Utils.robot
 Resource          ${CURDIR}/../../../libraries/WaitForFailure.robot
 
@@ -201,7 +202,7 @@ Check_Speaker_Is_Connected
 Check_Number_Of_Speaker_Connections
     [Arguments]    ${howmany}
     [Documentation]    Run netstat in mininet machine and parse it for number of established connections. Check it is ${howmany}.
-    ${output}=    SSHLibrary.Execute_Command    netstat -npt 2> /dev/null | grep -E ":17900 .+ ESTABLISHED .+python" | wc -l
+    ${output}=    SSHKeywords.Count_Port_Occurences    17900    ESTABLISHED    python
     BuiltIn.Should_Be_Equal_As_Strings    ${output}    ${howmany}
 
 Read_And_Fail_If_Prompt_Is_Seen