Install net-tools if not already installed 10/113110/14
authorlubos-cicut <lubos.cicut@pantheon.tech>
Wed, 14 Aug 2024 11:48:58 +0000 (13:48 +0200)
committerLubos Cicut <lubos.cicut@pantheon.tech>
Wed, 21 Aug 2024 10:09:29 +0000 (10:09 +0000)
To check if the device is up, we use netstat, which is not pre-installed
in newer versions of Ubuntu.

Change-Id: Iab6c5773c441fe0f110f804fd2f66b37624b2828
Signed-off-by: lubos-cicut <lubos.cicut@pantheon.tech>
csit/libraries/SSHKeywords.robot

index c2073d5347dd8642a8d4e86a313ad4329af0b785..3f348d010dfd5babef57092e73da6ed3eb1a3d86 100644 (file)
@@ -197,10 +197,23 @@ Assure_Library_Counter
 Count_Port_Occurences
     [Documentation]    Run 'netstat' on the remote machine and count occurences of given port in the given state connected to process with the given name.
     [Arguments]    ${port}    ${state}    ${name}
+    BuiltIn.Run Keyword And Ignore Error    Check_And_Install_Netstat
     ${output} =    SSHLibrary.Execute_Command
     ...    ${NETSTAT_COMMAND} 2> /dev/null | grep -E ":${port} .+ ${state} .+${name}" | wc -l
     RETURN    ${output}
 
+Check_And_Install_Netstat
+    [Documentation]    Check if netstat is installed and install it if not.
+    ${netstat_installed} =    SSHLibrary.Execute_Command    netstat --version
+    IF    '${netstat_installed}' is not string and '${netstat_installed}' != '0'
+        Install_Netstat
+    END
+
+Install_Netstat
+    [Documentation]    Install netstat if it is not already installed.
+    SSHLibrary.Execute_Command    sudo apt-get update
+    SSHLibrary.Execute_Command    sudo apt-get install -y net-tools
+
 Virtual_Env_Set_Path
     [Documentation]    Set \${SSHKeywords__current_venv_path} variable to ${venv_path}. Path should be absolute.
     [Arguments]    ${venv_path}