Commit 652d6694 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

SshRunner: Add parameter to always accept peer's SSH key

This will be used to add nodes without user interaction, specifically
in QA tests.

Reviewed-by: ultrotter
parent f6d9f4c3
...@@ -78,7 +78,8 @@ class SshRunner: ...@@ -78,7 +78,8 @@ class SshRunner:
else: else:
self.sstore = sstore self.sstore = sstore
def _BuildSshOptions(self, batch, ask_key, use_cluster_key): def _BuildSshOptions(self, batch, ask_key, use_cluster_key,
strict_host_check):
options = [ options = [
"-oEscapeChar=none", "-oEscapeChar=none",
"-oHashKnownHosts=no", "-oHashKnownHosts=no",
...@@ -89,15 +90,20 @@ class SshRunner: ...@@ -89,15 +90,20 @@ class SshRunner:
if use_cluster_key: if use_cluster_key:
options.append("-oHostKeyAlias=%s" % self.sstore.GetClusterName()) options.append("-oHostKeyAlias=%s" % self.sstore.GetClusterName())
# TODO: Too many boolean options, maybe convert them to more descriptive
# constants.
# Note: ask_key conflicts with batch mode # Note: ask_key conflicts with batch mode
if batch: if batch:
if ask_key: if ask_key:
raise errors.ProgrammerError("SSH call requested conflicting options") raise errors.ProgrammerError("SSH call requested conflicting options")
options.extend([ options.append("-oBatchMode=yes")
"-oBatchMode=yes",
"-oStrictHostKeyChecking=yes", if strict_host_check:
]) options.append("-oStrictHostKeyChecking=yes")
else:
options.append("-oStrictHostKeyChecking=no")
elif ask_key: elif ask_key:
options.extend([ options.extend([
...@@ -107,7 +113,7 @@ class SshRunner: ...@@ -107,7 +113,7 @@ class SshRunner:
return options return options
def BuildCmd(self, hostname, user, command, batch=True, ask_key=False, def BuildCmd(self, hostname, user, command, batch=True, ask_key=False,
tty=False, use_cluster_key=True): tty=False, use_cluster_key=True, strict_host_check=True):
"""Build an ssh command to execute a command on a remote node. """Build an ssh command to execute a command on a remote node.
Args: Args:
...@@ -118,13 +124,15 @@ class SshRunner: ...@@ -118,13 +124,15 @@ class SshRunner:
ask_key: if true, ssh will run with StrictHostKeyChecking=ask, so that ask_key: if true, ssh will run with StrictHostKeyChecking=ask, so that
we can connect to an unknown host (not valid in batch mode) we can connect to an unknown host (not valid in batch mode)
use_cluster_key: Whether to expect and use the cluster-global SSH key use_cluster_key: Whether to expect and use the cluster-global SSH key
strict_host_check: Whether to check the host's SSH key at all
Returns: Returns:
The ssh call to run 'command' on the remote host. The ssh call to run 'command' on the remote host.
""" """
argv = [constants.SSH, "-q"] argv = [constants.SSH, "-q"]
argv.extend(self._BuildSshOptions(batch, ask_key, use_cluster_key)) argv.extend(self._BuildSshOptions(batch, ask_key, use_cluster_key,
strict_host_check))
if tty: if tty:
argv.append("-t") argv.append("-t")
argv.extend(["%s@%s" % (user, hostname), command]) argv.extend(["%s@%s" % (user, hostname), command])
...@@ -165,7 +173,7 @@ class SshRunner: ...@@ -165,7 +173,7 @@ class SshRunner:
return False return False
command = [constants.SCP, "-q", "-p"] command = [constants.SCP, "-q", "-p"]
command.extend(self._BuildSshOptions(True, False, True)) command.extend(self._BuildSshOptions(True, False, True, True))
command.append(filename) command.append(filename)
command.append("%s:%s" % (node, filename)) command.append("%s:%s" % (node, filename))
......
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