From ca0fd64999c7bf15871998af9b1e01742eb59699 Mon Sep 17 00:00:00 2001 From: Riccardo Mancini Date: Mon, 16 Dec 2024 14:15:04 +0000 Subject: [PATCH] fix(test): do not use absolute path to true when opening ssh connection In #4955 the executable to check the ssh connection liveliness was changed from `true` to `/usr/bin/true`, but that is not its path in all rootfs, causing failures in the `test-populat-containers` suite. Also, since the error is retried but the control socket is not cleaned up, subsequent retries would fail for the assertion. This change fixes both issues by using the binary name `true` and cleaning up the control socket on error before the next retry. Fixes: 3b2c2d4d6 ("test: use single SSH connection for lifetime of microvm") Signed-off-by: Riccardo Mancini --- tests/host_tools/network.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/host_tools/network.py b/tests/host_tools/network.py index ff6e58be2b9..11fc756e2cb 100644 --- a/tests/host_tools/network.py +++ b/tests/host_tools/network.py @@ -129,14 +129,20 @@ def _init_connection(self): "ControlPersist=yes", *self.options, self.user_host, - "/usr/bin/true", + "true", ] - # don't set a low timeout here, because otherwise we might get into a race condition - # where ssh already forked off the persisted connection daemon, but gets killed here - # before exiting itself. In that case, self._control_path will exist, and the retry - # will hit the assert at the start of this function. - self._exec(establish_cmd, check=True) + try: + # don't set a low timeout here, because otherwise we might get into a race condition + # where ssh already forked off the persisted connection daemon, but gets killed here + # before exiting itself. In that case, self._control_path will exist, and the retry + # will hit the assert at the start of this function. + self._exec(establish_cmd, check=True) + except Exception: + # cleanup the control socket to allow for retries + if self._control_path.exists(): + self._control_path.unlink() + raise def _check_liveness(self) -> int: """Checks whether the ControlPersist connection is still alive"""