From 021f6f418d3c0c2d9e975f394cdf43621161a5ba Mon Sep 17 00:00:00 2001 From: Deli Zhang Date: Wed, 20 Sep 2023 14:41:54 +0800 Subject: [PATCH] CA-382842: Fix issue of "Connection refused" - If VM network has not yet started completely, ssh to it may encounter failure. Here the fix is raising the exception to let ssh command caller do retry. Signed-off-by: Deli Zhang --- autocertkit/common.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/autocertkit/common.py b/autocertkit/common.py index 606914d..3b9a8d9 100644 --- a/autocertkit/common.py +++ b/autocertkit/common.py @@ -104,7 +104,10 @@ def run_cmd_ext(self, cmd): with open(f'/tmp/{fcmd}', 'w') as f: f.write(cmd) - self.put_file(f'/tmp/{fcmd}') + res = self.put_file(f'/tmp/{fcmd}') + if res['returncode']: + os.remove(f'/tmp/{fcmd}') + raise Exception(f'{SCP} failed, maybe {self.ip} is not yet ready.') self.run_cmd(fr'sh {fcmd} >{fout} 2>{ferr}; echo "$?" >{frc}')