From ebb107f274c90c80c51546b758ae34d2874c32fd Mon Sep 17 00:00:00 2001 From: Tom Hromatka Date: Mon, 3 Jul 2023 09:51:58 -0600 Subject: [PATCH] ftests: Retry run() command after websocket failure LXC/LXD will sometimes throw an "Error: websocket: bad handshake" error on underpowered machines. Wait a bit (arbitrarily chosen 5 seconds) and retry the command. Signed-off-by: Tom Hromatka Reviewed-by: Kamalesh Babulal --- tests/ftests/run.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/ftests/run.py b/tests/ftests/run.py index b6bd3824..c985162d 100644 --- a/tests/ftests/run.py +++ b/tests/ftests/run.py @@ -9,11 +9,12 @@ from subprocess import TimeoutExpired from log import Log import subprocess +import time class Run(object): @staticmethod - def run(command, shell_bool=False, ignore_profiling_errors=True, timeout=None): + def __run(command, shell_bool, timeout): if shell_bool: if isinstance(command, str): # nothing to do. command is already formatted as a string @@ -68,6 +69,19 @@ class Run(object): ''.format(' '.join(command), ret, out, err) ) + return ret, out, err + + @staticmethod + def run(command, shell_bool=False, ignore_profiling_errors=True, timeout=None): + ret, out, err = Run.__run(command, shell_bool, timeout) + + if err.find('Error: websocket: bad handshake') >= 0: + # LXD sometimes throws this error on underpowered machines. + # Wait a bit, then try the request again + Log.log_error('Received \'{}\' error. Re-running command'.format(err)) + time.sleep(5) + ret, out, err = Run.__run(command, shell_bool, timeout) + if ret != 0: raise RunError("Command '{}' failed".format(''.join(command)), command, ret, out, err) -- 2.47.2