Commit ecf5c068 authored by Chong Gu's avatar Chong Gu Committed by Commit Bot

[Fuchsia] Check for port number in ssh config file.

If port is not defined, don't use it when running ssh commands.

Bug: 1113300
Change-Id: I14681d2b7576f20bc66362cd37cec8cb1dae5137
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2417464
Commit-Queue: Chong Gu <chonggu@google.com>
Reviewed-by: default avatarKevin Marshall <kmarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810557}
parent da4c4c6c
...@@ -87,9 +87,9 @@ class DeviceTarget(target.Target): ...@@ -87,9 +87,9 @@ class DeviceTarget(target.Target):
super(DeviceTarget, self).__init__(out_dir, target_cpu) super(DeviceTarget, self).__init__(out_dir, target_cpu)
self._port = port if port else 22
self._system_log_file = system_log_file self._system_log_file = system_log_file
self._host = host self._host = host
self._port = port
self._fuchsia_out_dir = None self._fuchsia_out_dir = None
if fuchsia_out_dir: if fuchsia_out_dir:
self._fuchsia_out_dir = os.path.expanduser(fuchsia_out_dir) self._fuchsia_out_dir = os.path.expanduser(fuchsia_out_dir)
...@@ -133,7 +133,7 @@ class DeviceTarget(target.Target): ...@@ -133,7 +133,7 @@ class DeviceTarget(target.Target):
device_args.add_argument('--port', device_args.add_argument('--port',
'-p', '-p',
type=int, type=int,
default=22, default=None,
help='The port of the SSH service running on the ' help='The port of the SSH service running on the '
'device. Optional.') 'device. Optional.')
device_args.add_argument('--ssh-config', device_args.add_argument('--ssh-config',
......
...@@ -42,7 +42,10 @@ class CommandRunner(object): ...@@ -42,7 +42,10 @@ class CommandRunner(object):
self._port = port self._port = port
def _GetSshCommandLinePrefix(self): def _GetSshCommandLinePrefix(self):
return _SSH + ['-F', self._config_path, self._host, '-p', str(self._port)] cmd_prefix = _SSH + ['-F', self._config_path, self._host]
if self._port:
cmd_prefix += ['-p', str(self._port)]
return cmd_prefix
def RunCommand(self, command, silent, timeout_secs=None): def RunCommand(self, command, silent, timeout_secs=None):
"""Executes an SSH command on the remote host and blocks until completion. """Executes an SSH command on the remote host and blocks until completion.
...@@ -55,6 +58,7 @@ class CommandRunner(object): ...@@ -55,6 +58,7 @@ class CommandRunner(object):
Returns the exit code from the remote command.""" Returns the exit code from the remote command."""
ssh_command = self._GetSshCommandLinePrefix() + command ssh_command = self._GetSshCommandLinePrefix() + command
logging.warning(ssh_command)
_SSH_LOGGER.debug('ssh exec: ' + ' '.join(ssh_command)) _SSH_LOGGER.debug('ssh exec: ' + ' '.join(ssh_command))
retval, _, _ = SubprocessCallWithTimeout(ssh_command, silent, timeout_secs) retval, _, _ = SubprocessCallWithTimeout(ssh_command, silent, timeout_secs)
return retval return retval
...@@ -81,6 +85,7 @@ class CommandRunner(object): ...@@ -81,6 +85,7 @@ class CommandRunner(object):
ssh_args = [] ssh_args = []
ssh_command = self._GetSshCommandLinePrefix() + ssh_args + ['--'] + command ssh_command = self._GetSshCommandLinePrefix() + ssh_args + ['--'] + command
logging.warning(ssh_command)
_SSH_LOGGER.debug(' '.join(ssh_command)) _SSH_LOGGER.debug(' '.join(ssh_command))
return subprocess.Popen(ssh_command, stdout=stdout, stderr=stderr, **kwargs) return subprocess.Popen(ssh_command, stdout=stdout, stderr=stderr, **kwargs)
...@@ -111,7 +116,9 @@ class CommandRunner(object): ...@@ -111,7 +116,9 @@ class CommandRunner(object):
else: else:
sources = ["%s:%s" % (host, source) for source in sources] sources = ["%s:%s" % (host, source) for source in sources]
scp_command += ['-F', self._config_path, '-P', str(self._port)] scp_command += ['-F', self._config_path]
if self._port:
scp_command += ['-P', str(self._port)]
scp_command += sources scp_command += sources
scp_command += [dest] scp_command += [dest]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment