Skip to content

Commit

Permalink
start_background_process: Use sftp instead of scp for Windows VM
Browse files Browse the repository at this point in the history
scp is used in the start_background_process() method to transfer the
script file to the host before executing it.

On Windows 11, OpenSSH doesn't support the scp legacy protocol which is
the only one supported by scp running on AlmaLinux 8, the distro behind
our Jenkins server.

Since AlmaLinux 8 and all of our Windows images support sftp, this patch
makes use of the sftp() function instead of the scp() one to transfer
the script file for VMs running any Windows version.
The destination path is also tweaked a bit and the file is sent to the
Windows Temp folder of the root user instead of /tmp. Since the script
is executed in the git-bash context of the root user, it will be located
as expected in /tmp, which is mapped on the Windows user Temp folder.

With this patch also comes a sftp_put() helper function taking source
and destination files as parameters like the scp() function does.

Signed-off-by: Thierry Escande <[email protected]>
  • Loading branch information
tescande committed Oct 26, 2023
1 parent a4f8a03 commit 07acd83
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ def scp(self, src, dest, check=True, suppress_fingerprint_warnings=True, local_d
local_dest=local_dest
)

def sftp_put(self, src, dest, check=True, suppress_fingerprint_warnings=True):
cmd = "put {} {}".format(src, dest)
return commands.sftp(
self.ip, [ cmd ], check,
suppress_fingerprint_warnings=suppress_fingerprint_warnings
)

def is_ssh_up(self):
try:
return self.ssh_with_result(['true']).returncode == 0
Expand Down Expand Up @@ -234,7 +241,10 @@ def start_background_process(self, cmd):
cmd + '\n'
])
f.flush()
self.scp(f.name, script)
if self.is_windows:
self.sftp_put(f.name, script.replace("/tmp/", "/Users/root/AppData/Local/Temp/"))
else:
self.scp(f.name, script)
# Use bash to run the script, to avoid being hit by differences between shells, for example on FreeBSD
# It is a documented requirement that bash is present on all test VMs.
self.ssh(['bash', script], background=True)
Expand Down

0 comments on commit 07acd83

Please sign in to comment.