summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluca fancellu <luca.fancellu@arm.com>2023-11-09 14:36:31 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-11-10 17:44:15 +0000
commit948fecca1db4c7a30fcca5fcf5eef95cd12efb00 (patch)
treefd2fdebd4225b07c76d71e15fdd0b31f2bcd6856
parent5356afef9f0ee70fb804ff9fc8746bcaa47c02ba (diff)
downloadopenembedded-core-contrib-948fecca1db4c7a30fcca5fcf5eef95cd12efb00.tar.gz
oeqa/ssh: Handle SSHCall timeout error code
The current code in ssh.py is terminating the ssh process that does not finish its computation in a given timeout (when timeout is passed), the SSHCall function is returning the process error code. The Openssl ssh before version 8.6_p1 is returning 0 when it is terminated, from commit 8a9520836e71830f4fccca066dba73fea3d16bda onwards (version >= 8.6_p1) ssh is returning 255 instead. So for version of ssh older than 8.6_p1 when the SSHCall time out, the return code will be 0, meaning success, which is wrong. Fix this issue checking if the process has timeout (hence it's been terminated) and checking if the returned code is 0, in that case set it to 255 to advertise that an error occurred. Add a test case excercising the timeout in the SSHTest, test_ssh test function. Signed-off-by: Luca Fancellu <luca.fancellu@arm.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
-rw-r--r--meta/lib/oeqa/core/target/ssh.py17
-rw-r--r--meta/lib/oeqa/runtime/cases/ssh.py3
2 files changed, 19 insertions, 1 deletions
diff --git a/meta/lib/oeqa/core/target/ssh.py b/meta/lib/oeqa/core/target/ssh.py
index f22836d390..f4dd0ca417 100644
--- a/meta/lib/oeqa/core/target/ssh.py
+++ b/meta/lib/oeqa/core/target/ssh.py
@@ -232,11 +232,12 @@ def SSHCall(command, logger, timeout=None, **opts):
output_raw = b''
starttime = time.time()
process = subprocess.Popen(command, **options)
+ has_timeout = False
if timeout:
endtime = starttime + timeout
eof = False
os.set_blocking(process.stdout.fileno(), False)
- while time.time() < endtime and not eof:
+ while not has_timeout and not eof:
try:
logger.debug('Waiting for process output: time: %s, endtime: %s' % (time.time(), endtime))
if select.select([process.stdout], [], [], 5)[0] != []:
@@ -257,6 +258,10 @@ def SSHCall(command, logger, timeout=None, **opts):
logger.debug('BlockingIOError')
continue
+ if time.time() >= endtime:
+ logger.debug('SSHCall has timeout! Time: %s, endtime: %s' % (time.time(), endtime))
+ has_timeout = True
+
process.stdout.close()
# process hasn't returned yet
@@ -293,6 +298,16 @@ def SSHCall(command, logger, timeout=None, **opts):
pass
process.wait()
+ if has_timeout:
+ # Version of openssh before 8.6_p1 returns error code 0 when killed
+ # by a signal, when the timeout occurs we will receive a 0 error
+ # code because the process is been terminated and it's wrong because
+ # that value means success, but the process timed out.
+ # Afterwards, from version 8.6_p1 onwards, the returned code is 255.
+ # Fix this behaviour by checking the return code
+ if process.returncode == 0:
+ process.returncode = 255
+
options = {
"stdout": subprocess.PIPE,
"stderr": subprocess.STDOUT,
diff --git a/meta/lib/oeqa/runtime/cases/ssh.py b/meta/lib/oeqa/runtime/cases/ssh.py
index 13aac54396..cdbef59500 100644
--- a/meta/lib/oeqa/runtime/cases/ssh.py
+++ b/meta/lib/oeqa/runtime/cases/ssh.py
@@ -13,6 +13,9 @@ class SSHTest(OERuntimeTestCase):
@OETestDepends(['ping.PingTest.test_ping'])
@OEHasPackage(['dropbear', 'openssh-sshd'])
def test_ssh(self):
+ (status, output) = self.target.run('sleep 20', timeout=2)
+ msg='run() timed out but return code was zero.'
+ self.assertNotEqual(status, 0, msg=msg)
(status, output) = self.target.run('uname -a')
self.assertEqual(status, 0, msg='SSH Test failed: %s' % output)
(status, output) = self.target.run('cat /etc/controllerimage')