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>
-*** Settings ***
Documentation Resource enhancing SSHLibrary with Keywords used in multiple suites.
...
... Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
# 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}
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
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