Skip to content

[test] Check for sftp-server for remote-run --debug-as-local tests #18759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion test/lit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,8 @@ ENV_VAR_PREFIXES = {
}
TARGET_ENV_PREFIX = ENV_VAR_PREFIXES.get(config.target_sdk_name, "")

if not config.target_run and 'remote_run_host' in lit_config.params:
if (not getattr(config, 'target_run', None) and
'remote_run_host' in lit_config.params):
if 'remote_run_tmpdir' not in lit_config.params:
lit_config.fatal("'remote_run_host' provided, but no "
"'remote_run_tmpdir'")
Expand Down Expand Up @@ -1039,6 +1040,21 @@ base_runtime_lib_name = (
if os.path.exists(make_path(compiler_rt_dir, base_runtime_lib_name)):
config.available_features.add('c_runtime')

# For testing the remote-run utility itself, see if we can find an sftp-server
# binary.
def find_sftp_server():
paths_to_try = ['/usr/libexec/sftp-server', '/usr/lib/sftp-server',
'/usr/libexec/openssh/sftp-server',
'/usr/lib/openssh/sftp-server']
return next((path for path in paths_to_try if os.path.isfile(path)), None)

sftp_server_path = find_sftp_server()
if sftp_server_path:
config.available_features.add('sftp_server')
config.substitutions.append(('%sftp-server',
sftp_server_path or 'no-sftp-server'))


if not getattr(config, 'target_run_simple_swift', None):
config.target_run_simple_swift = (
'%%empty-directory(%%t) && '
Expand Down
2 changes: 2 additions & 0 deletions test/remote-run/download.test-sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
REQUIRES: sftp_server

RUN: %empty-directory(%t)
RUN: %empty-directory(%t-REMOTE)
RUN: %debug-remote-run --output-prefix %t touch %t/output
Expand Down
2 changes: 1 addition & 1 deletion test/remote-run/lit.local.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
config.substitutions = list(config.substitutions)

config.substitutions.insert(0, ('%debug-remote-run',
'%utils/remote-run --debug-as-local --remote-dir %t-REMOTE') )
'%utils/remote-run --debug-as-local %sftp-server --remote-dir %t-REMOTE') )
2 changes: 2 additions & 0 deletions test/remote-run/upload-and-download.test-sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
REQUIRES: sftp_server

RUN: %empty-directory(%t)
RUN: %empty-directory(%t-REMOTE)
RUN: touch %t/input %t/BAD
Expand Down
2 changes: 2 additions & 0 deletions test/remote-run/upload-stderr.test-sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
REQUIRES: sftp_server

RUN: %empty-directory(%t)
RUN: %empty-directory(%t/REMOTE/input)
RUN: chmod a-w %t/REMOTE/input
Expand Down
2 changes: 2 additions & 0 deletions test/remote-run/upload.test-sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
REQUIRES: sftp_server

RUN: %debug-remote-run --input-prefix %S/Inputs/upload/ ls %S/Inputs/upload/1.txt %S/Inputs/upload/2.txt | %FileCheck -check-prefix CHECK-REMOTE %s
RUN: ls %t-REMOTE/input/ | %FileCheck %s

Expand Down
18 changes: 5 additions & 13 deletions utils/remote-run
Original file line number Diff line number Diff line change
Expand Up @@ -119,22 +119,14 @@ class RemoteCommandRunner(CommandRunner):
[self.remote_host])

class LocalCommandRunner(CommandRunner):
def __init__(self):
self.cached_sftp_server_path = None

def sftp_server_path(self):
if not self.cached_sftp_server_path:
paths_to_try = ['/usr/libexec/sftp-server', '/usr/lib/sftp-server']
self.cached_sftp_server_path = next(
(path for path in paths_to_try if os.path.exists(path)),
paths_to_try[0])
return self.cached_sftp_server_path
def __init__(self, sftp_server_path):
self.sftp_server_path = sftp_server_path

def remote_invocation(self, command):
return command

def sftp_invocation(self):
return ['/usr/bin/sftp', '-b', '-', '-q', '-D', self.sftp_server_path()]
return ['/usr/bin/sftp', '-b', '-', '-q', '-D', self.sftp_server_path]

def find_transfers(args, source_prefix, dest_prefix):
if source_prefix.endswith(os.path.sep):
Expand Down Expand Up @@ -172,7 +164,7 @@ def main():

parser.add_argument('-i', '--identity', dest='identity', metavar='FILE',
help='an SSH identity file (private key) to use')
parser.add_argument('--debug-as-local', action='store_true',
parser.add_argument('--debug-as-local', metavar='/PATH/TO/SFTP-SERVER',
help='run commands locally instead of over SSH, for '
'debugging purposes. The "host" argument is '
'omitted.')
Expand All @@ -185,7 +177,7 @@ def main():
args = parser.parse_args()

if args.debug_as_local:
runner = LocalCommandRunner()
runner = LocalCommandRunner(args.debug_as_local)
args.command.insert(0, args.host)
del args.host
else:
Expand Down