Skip to content

Commit 1963450

Browse files
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 <[email protected]>
1 parent 2f30ecc commit 1963450

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/host.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,15 @@ def execute_script(self, script_contents, shebang='sh', simple_output=True):
231231
script.write('#!/usr/bin/env ' + shebang + '\n')
232232
script.write(script_contents)
233233
script.flush()
234-
self.scp(script.name, script.name)
234+
remote_path = self.ssh("mktemp").strip()
235+
self.scp(script.name, remote_path)
236+
self.ssh(['chmod', '0755', remote_path])
235237

236238
try:
237239
logging.debug(f"[{self}] # Will execute this temporary script:\n{script_contents.strip()}")
238-
return self.ssh([script.name], simple_output=simple_output)
240+
return self.ssh([remote_path], simple_output=simple_output)
239241
finally:
240-
self.ssh(['rm', '-f', script.name])
242+
self.ssh(['rm', '-f', remote_path])
241243

242244
def _get_xensource_inventory(self) -> Dict[str, str]:
243245
output = self.ssh(['cat', '/etc/xensource-inventory'])

0 commit comments

Comments
 (0)