Skip to content

Commit

Permalink
[connections] Made SSH timeouts parameters configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed Apr 22, 2019
1 parent b31a6ed commit c21f1fa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
11 changes: 5 additions & 6 deletions openwisp_controller/connection/connectors/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
from jsonschema import validate
from jsonschema.exceptions import ValidationError as SchemaError

from .. import settings as app_settings

if sys.version_info.major > 2: # pragma: nocover
from io import StringIO
else: # pragma: nocover
from StringIO import StringIO


logger = logging.getLogger(__name__)
SSH_CONNECTION_TIMEOUT = 5
SSH_AUTH_TIMEOUT = 2
SSH_COMMAND_TIMEOUT = 30


class Ssh(object):
Expand Down Expand Up @@ -66,8 +65,8 @@ def connect(self):
for address in addresses:
try:
self.shell.connect(address,
timeout=SSH_CONNECTION_TIMEOUT,
auth_timeout=SSH_AUTH_TIMEOUT,
timeout=app_settings.SSH_CONNECTION_TIMEOUT,
auth_timeout=app_settings.SSH_AUTH_TIMEOUT,
**self.params)
except Exception as e:
exception = e
Expand All @@ -80,7 +79,7 @@ def connect(self):
def disconnect(self):
self.shell.close()

def exec_command(self, command, timeout=SSH_COMMAND_TIMEOUT,
def exec_command(self, command, timeout=app_settings.SSH_COMMAND_TIMEOUT,
exit_codes=[0], raise_unexpected_exit=True):
"""
Executes a command and performs the following operations
Expand Down
4 changes: 4 additions & 0 deletions openwisp_controller/connection/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@
CONFIG_UPDATE_MAPPING = getattr(settings, 'OPENWISP_CONFIG_UPDATE_MAPPING', {
'netjsonconfig.OpenWrt': DEFAULT_UPDATE_STRATEGIES[0][0],
})

SSH_CONNECTION_TIMEOUT = getattr(settings, 'OPENWISP_SSH_CONNECTION_TIMEOUT', 5)
SSH_AUTH_TIMEOUT = getattr(settings, 'OPENWISP_SSH_AUTH_TIMEOUT', 2)
SSH_COMMAND_TIMEOUT = getattr(settings, 'OPENWISP_SSH_COMMAND_TIMEOUT', 30)

0 comments on commit c21f1fa

Please sign in to comment.