Skip to content
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 3 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ in development

Added
~~~~~

* Add support for a configurable connect timeout for SSH connections as requested in #4715
by adding the new configuration parameter ``ssh_connect_timeout`` to the ``ssh_runner``
group in st2.conf.
* Add support for blacklisting / whitelisting hosts to the HTTP runner by adding new
``url_hosts_blacklist`` and ``url_hosts_whitelist`` runner attribute. (new feature)
#4757
Expand Down
5 changes: 4 additions & 1 deletion st2common/st2common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,10 @@ def register_opts(ignore_errors=False):
help='Use the .ssh/config file. Useful to override ports etc.'),
cfg.StrOpt(
'ssh_config_file_path', default='~/.ssh/config',
help='Path to the ssh config file.')
help='Path to the ssh config file.'),
cfg.IntOpt(
'ssh_connect_timeout', default=60,
help='Max time in seconds to establish the SSH connection.')
]

do_register_opts(ssh_runner_opts, group='ssh_runner')
Expand Down
30 changes: 18 additions & 12 deletions st2common/st2common/runners/paramiko_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SSHCommandTimeoutError(Exception):
Exception which is raised when an SSH command times out.
"""

def __init__(self, cmd, timeout, stdout=None, stderr=None):
def __init__(self, cmd, timeout, ssh_connect_timeout, stdout=None, stderr=None):
"""
:param stdout: Stdout which was consumed until the timeout occured.
:type stdout: ``str``
Expand All @@ -59,14 +59,16 @@ def __init__(self, cmd, timeout, stdout=None, stderr=None):
"""
self.cmd = cmd
self.timeout = timeout
self.ssh_connect_timeout = ssh_connect_timeout
self.stdout = stdout
self.stderr = stderr
self.message = 'Command didn\'t finish in %s seconds' % (timeout)
self.message = 'Command didn\'t finish in %s seconds or the SSH connection did not succeed in %s seconds' % \
(timeout, ssh_connect_timeout)
super(SSHCommandTimeoutError, self).__init__(self.message)

def __repr__(self):
return ('<SSHCommandTimeoutError: cmd="%s",timeout=%s)>' %
(self.cmd, self.timeout))
return ('<SSHCommandTimeoutError: cmd="%s", timeout=%s, ssh_connect_timeout=%s)>' %
(self.cmd, self.timeout, self.ssh_connect_timeout))

def __str__(self):
return self.message
Expand All @@ -83,9 +85,6 @@ class ParamikoSSHClient(object):
# How long to sleep while waiting for command to finish to prevent busy waiting
SLEEP_DELAY = 0.2

# Connect socket timeout
CONNECT_TIMEOUT = 60

def __init__(self, hostname, port=DEFAULT_SSH_PORT, username=None, password=None,
bastion_host=None, key_files=None, key_material=None, timeout=None,
passphrase=None, handle_stdout_line_func=None, handle_stderr_line_func=None):
Expand All @@ -105,17 +104,23 @@ def __init__(self, hostname, port=DEFAULT_SSH_PORT, username=None, password=None
self.username = username
self.password = password
self.key_files = key_files
self.timeout = timeout or ParamikoSSHClient.CONNECT_TIMEOUT
self.timeout = timeout
self.key_material = key_material
self.bastion_host = bastion_host
self.passphrase = passphrase
self.ssh_connect_timeout = cfg.CONF.ssh_runner.ssh_connect_timeout
self._handle_stdout_line_func = handle_stdout_line_func
self._handle_stderr_line_func = handle_stderr_line_func

self.ssh_config_file = os.path.expanduser(
cfg.CONF.ssh_runner.ssh_config_file_path or
'~/.ssh/config'
)

if self.timeout and self.ssh_connect_timeout > self.timeout - 2:
# the connect timeout should not be greater than the action timeout
self.ssh_connect_timeout = self.timeout - 2

self.logger = logging.getLogger(__name__)

self.client = None
Expand Down Expand Up @@ -415,8 +420,9 @@ def run(self, cmd, timeout=None, quote=False, call_line_handler_func=False):

stdout = sanitize_output(stdout.getvalue(), uses_pty=uses_pty)
stderr = sanitize_output(stderr.getvalue(), uses_pty=uses_pty)
raise SSHCommandTimeoutError(cmd=cmd, timeout=timeout, stdout=stdout,
stderr=stderr)
raise SSHCommandTimeoutError(cmd=cmd, timeout=timeout,
ssh_connect_timeout=self.ssh_connect_timeout,
stdout=stdout, stderr=stderr)

stdout_data = self._consume_stdout(chan=chan,
call_line_handler_func=call_line_handler_func)
Expand Down Expand Up @@ -633,7 +639,7 @@ def _connect(self, host, socket=None):
conninfo = {'hostname': host,
'allow_agent': False,
'look_for_keys': False,
'timeout': self.timeout}
'timeout': self.ssh_connect_timeout}

ssh_config_file_info = {}
if cfg.CONF.ssh_runner.use_ssh_config:
Expand Down Expand Up @@ -702,7 +708,7 @@ def _connect(self, host, socket=None):
conninfo['look_for_keys'] = True

extra = {'_hostname': host, '_port': self.port,
'_username': self.username, '_timeout': self.timeout}
'_username': self.username, '_timeout': self.ssh_connect_timeout}
self.logger.debug('Connecting to server', extra=extra)

self.socket = socket or ssh_config_file_info.get('sock', None)
Expand Down
Empty file.
17 changes: 0 additions & 17 deletions st2tests/st2tests/fixtures/aliases/actions/action1.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions st2tests/st2tests/fixtures/aliases/actions/action2.yaml

This file was deleted.

13 changes: 0 additions & 13 deletions st2tests/st2tests/fixtures/aliases/aliases/alias1.yaml

This file was deleted.

11 changes: 0 additions & 11 deletions st2tests/st2tests/fixtures/aliases/aliases/alias2.yaml

This file was deleted.

8 changes: 0 additions & 8 deletions st2tests/st2tests/fixtures/aliases/aliases/alias3.yaml

This file was deleted.

11 changes: 0 additions & 11 deletions st2tests/st2tests/fixtures/aliases/aliases/alias4.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions st2tests/st2tests/fixtures/aliases/aliases/alias5.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions st2tests/st2tests/fixtures/aliases/aliases/alias_fixes1.yaml

This file was deleted.

10 changes: 0 additions & 10 deletions st2tests/st2tests/fixtures/aliases/aliases/alias_fixes2.yaml

This file was deleted.

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions st2tests/st2tests/fixtures/aliases/runners/runner1.yaml

This file was deleted.

13 changes: 0 additions & 13 deletions st2tests/st2tests/fixtures/backstop/rules/backstop.yaml

This file was deleted.

14 changes: 0 additions & 14 deletions st2tests/st2tests/fixtures/backstop/rules/fail.yaml

This file was deleted.

14 changes: 0 additions & 14 deletions st2tests/st2tests/fixtures/backstop/rules/success.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions st2tests/st2tests/fixtures/backstop/triggers/trigger1.yaml

This file was deleted.

This file was deleted.

44 changes: 0 additions & 44 deletions st2tests/st2tests/fixtures/conf/logging.api.audit.conf

This file was deleted.

Loading