summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
authorluca fancellu <luca.fancellu@arm.com>2023-11-09 14:36:31 +0000
committerSteve Sakoman <steve@sakoman.com>2023-11-24 05:01:37 -1000
commit20a4de703c2e584e322175674c8cc6dcfa3a0735 (patch)
treec31a4d44b3d2b93eebaf08446ff9fd454fb51d4d /meta
parent2dec4dcecf07aa0f950fb0659bc9929ada2f0b24 (diff)
downloadpoky-20a4de703c2e584e322175674c8cc6dcfa3a0735.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. (From OE-Core rev: 82215c855ee39b4e39f24113241a7fb3f20f9531) Signed-off-by: Luca Fancellu <luca.fancellu@arm.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> (cherry picked from commit 948fecca1db4c7a30fcca5fcf5eef95cd12efb00) Signed-off-by: Steve Sakoman <steve@sakoman.com>
Diffstat (limited to 'meta')
-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):
232 output_raw = b'' 232 output_raw = b''
233 starttime = time.time() 233 starttime = time.time()
234 process = subprocess.Popen(command, **options) 234 process = subprocess.Popen(command, **options)
235 has_timeout = False
235 if timeout: 236 if timeout:
236 endtime = starttime + timeout 237 endtime = starttime + timeout
237 eof = False 238 eof = False
238 os.set_blocking(process.stdout.fileno(), False) 239 os.set_blocking(process.stdout.fileno(), False)
239 while time.time() < endtime and not eof: 240 while not has_timeout and not eof:
240 try: 241 try:
241 logger.debug('Waiting for process output: time: %s, endtime: %s' % (time.time(), endtime)) 242 logger.debug('Waiting for process output: time: %s, endtime: %s' % (time.time(), endtime))
242 if select.select([process.stdout], [], [], 5)[0] != []: 243 if select.select([process.stdout], [], [], 5)[0] != []:
@@ -257,6 +258,10 @@ def SSHCall(command, logger, timeout=None, **opts):
257 logger.debug('BlockingIOError') 258 logger.debug('BlockingIOError')
258 continue 259 continue
259 260
261 if time.time() >= endtime:
262 logger.debug('SSHCall has timeout! Time: %s, endtime: %s' % (time.time(), endtime))
263 has_timeout = True
264
260 process.stdout.close() 265 process.stdout.close()
261 266
262 # process hasn't returned yet 267 # process hasn't returned yet
@@ -293,6 +298,16 @@ def SSHCall(command, logger, timeout=None, **opts):
293 pass 298 pass
294 process.wait() 299 process.wait()
295 300
301 if has_timeout:
302 # Version of openssh before 8.6_p1 returns error code 0 when killed
303 # by a signal, when the timeout occurs we will receive a 0 error
304 # code because the process is been terminated and it's wrong because
305 # that value means success, but the process timed out.
306 # Afterwards, from version 8.6_p1 onwards, the returned code is 255.
307 # Fix this behaviour by checking the return code
308 if process.returncode == 0:
309 process.returncode = 255
310
296 options = { 311 options = {
297 "stdout": subprocess.PIPE, 312 "stdout": subprocess.PIPE,
298 "stderr": subprocess.STDOUT, 313 "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):
13 @OETestDepends(['ping.PingTest.test_ping']) 13 @OETestDepends(['ping.PingTest.test_ping'])
14 @OEHasPackage(['dropbear', 'openssh-sshd']) 14 @OEHasPackage(['dropbear', 'openssh-sshd'])
15 def test_ssh(self): 15 def test_ssh(self):
16 (status, output) = self.target.run('sleep 20', timeout=2)
17 msg='run() timed out but return code was zero.'
18 self.assertNotEqual(status, 0, msg=msg)
16 (status, output) = self.target.run('uname -a') 19 (status, output) = self.target.run('uname -a')
17 self.assertEqual(status, 0, msg='SSH Test failed: %s' % output) 20 self.assertEqual(status, 0, msg='SSH Test failed: %s' % output)
18 (status, output) = self.target.run('cat /etc/controllerimage') 21 (status, output) = self.target.run('cat /etc/controllerimage')