Skip to content

Commit

Permalink
netvm.robot: Wait for local_port to be free
Browse files Browse the repository at this point in the history
SSH Local Port Forwarding is used to connect to the NetVM, but for some
reason some times there is a lag between freeing the bound socket,
causing "Adress is already in use" -error when trying to bind to it
again.

Signed-off-by: Mika Tammi <mika.tammi@unikie.com>
  • Loading branch information
Mika Tammi committed Nov 4, 2023
1 parent 2ce1bd8 commit 7c642d6
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion Robot-Framework/test-suites/bat-tests/netvm.robot
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,27 @@ Connect to ghaf host
Set Global Variable ${ghaf_host} ${connection}
[Return] ${connection}

Port Should Be Free
[Arguments] ${port}
${result} Run Keyword If os.sep == '/'
... Run netstat -tulpn
... ELSE
... Run netstat -an
Should Not Contain ${result} :${port}
[Return] ${result}

Connect to netvm via tunnel
[Documentation] Create tunnel using port ${local_port}, connect to netvm directly from test run machine,
... allow using standard SSHLibrary commands, like 'Execute Command'
Switch connection ${ghaf_host}
Log To Console Configuring tunnel...
Write ssh-keygen -R ${netvm_ip}
# TODO: Remove this workaround when the issue gets fixed upstream.
# There's an issue in robotframework-sshlibrary, which causes that the port
# is left open for some time even after explicitly calling
# "Close All Connections":
# https://github.com/robotframework/SSHLibrary/issues/435
# https://github.com/robotframework/SSHLibrary/pull/436
Wait Until Keyword Succeeds 1 min 5s Port Should Be Free ${local_port}
Create Local Ssh Tunnel local_port=${local_port} remote_host=${NETVM_IP} remote_port=22 bind_address=127.0.0.1
Log To Console Connecting to NetVM via tunnel
${connection}= Connect IP=localhost PORT=${local_port} target_output=${LOGIN}@${NETVM_NAME}
Expand Down

0 comments on commit 7c642d6

Please sign in to comment.