From 04aa5551d524c062ef5475aeaf6269e7e2e52166 Mon Sep 17 00:00:00 2001 From: Rushikesh Jadhav Date: Mon, 16 Jun 2025 19:03:01 +0530 Subject: [PATCH] lib/host: Avoid using identical source and destination paths in execute_script scp Using the same path for both source and destination may cause scp to fail, especially when the source path (e.g. a temp path on macOS) does not exist on the remote system. Thus, resorting to use mktemp on destination. Signed-off-by: Rushikesh Jadhav --- lib/host.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/host.py b/lib/host.py index c5ffe5ff3..1e77a2c6a 100644 --- a/lib/host.py +++ b/lib/host.py @@ -231,13 +231,19 @@ def execute_script(self, script_contents, shebang='sh', simple_output=True): script.write('#!/usr/bin/env ' + shebang + '\n') script.write(script_contents) script.flush() - self.scp(script.name, script.name) + try: + remote_path = self.ssh("mktemp").strip() + self.scp(script.name, remote_path) + self.ssh(['chmod', '0755', remote_path]) + except Exception as e: + logging.error("Failed to create temporary file. %s", e) + raise try: logging.debug(f"[{self}] # Will execute this temporary script:\n{script_contents.strip()}") - return self.ssh([script.name], simple_output=simple_output) + return self.ssh([remote_path], simple_output=simple_output) finally: - self.ssh(['rm', '-f', script.name]) + self.ssh(['rm', '-f', remote_path]) def _get_xensource_inventory(self) -> Dict[str, str]: output = self.ssh(['cat', '/etc/xensource-inventory'])