From: Tom Hromatka Date: Wed, 30 Mar 2022 14:12:52 +0000 (-0600) Subject: ftests: Init LXC in a separate thread X-Git-Tag: v3.1.0~308^2~2^2~21 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=546c9bd0159abe0c3ddc6c59e1bd2fbc0bacd0fb;p=thirdparty%2Flibcgroup.git ftests: Init LXC in a separate thread Occasionally LXC fails with a socket timeout error when running on Github Actions. To alleviate this, run `lxc init` in a separate thread. While init is running, periodically print an inane log message in an attempt to appease Github Actions. If `lxc init` fails, Container() will now retry the init up to five times. Error: Failed instance creation: write unix @->/var/snap/lxd/common/lxd/unix.socket: i/o timeout Error: Failed instance creation: websocket: close 1006 (abnormal closure): unexpected EOF Signed-off-by: Tom Hromatka Reviewed-by: Kamalesh Babulal --- diff --git a/ftests/container.py b/ftests/container.py index a3f1e5a9..a54f6a3a 100644 --- a/ftests/container.py +++ b/ftests/container.py @@ -6,8 +6,12 @@ # Author: Tom Hromatka # -from run import Run +from run import Run, RunError +from queue import Queue +import threading as tp +from log import Log import consts +import time import os @@ -82,7 +86,7 @@ class Container(object): return Run.run(cmd2) - def create(self): + def _init_container(self, q): cmd = list() if self.privileged: @@ -95,7 +99,46 @@ class Container(object): cmd.append(self.name) - return Run.run(cmd) + try: + Run.run(cmd) + q.put(True) + except Exception: # noqa: E722 + q.put(False) + except BaseException: # noqa: E722 + q.put(False) + + def create(self): + # Github Actions sometimes has timeout issues with the LXC sockets. + # Try this command multiple times in an attempt to work around this + # limitation + + queue = Queue() + sleep_time = 5 + ret = False + + for i in range(5): + thread = tp.Thread(target=self._init_container, args=(queue, )) + thread.start() + + time_cnt = 0 + while thread.is_alive(): + time.sleep(sleep_time) + time_cnt += sleep_time + Log.log_debug('Waiting... {}'.format(time_cnt)) + + ret = queue.get() + if ret: + break + else: + try: + self.delete() + except RunError: + pass + + thread.join() + + if not ret: + raise ContainerError('Failed to create the container') def delete(self): cmd = list()