Set timeout for parmiko ssh connection

Set manila-server connection timeout enabled via configuration
file on generic driver to prevent ssh connections getting
stuck if manila-server is slow in responding or some network
problems occur.

Closes-Bug: #1528203
Change-Id: Icd72c561aa37fad447e3f6e1eade3b2f57d74521
This commit is contained in:
darkwsh 2015-12-25 23:05:03 -08:00
parent 2cc722e125
commit f6d54dde0c
2 changed files with 5 additions and 2 deletions

View File

@ -147,10 +147,11 @@ class GenericShareDriver(driver.ExecuteMixin, driver.ShareDriver):
def _ssh_exec(self, server, command):
connection = self.ssh_connections.get(server['instance_id'])
ssh_conn_timeout = self.configuration.ssh_conn_timeout
if not connection:
ssh_pool = utils.SSHPool(server['ip'],
22,
None,
ssh_conn_timeout,
server['username'],
server.get('password'),
server.get('pk_path'),

View File

@ -1267,6 +1267,8 @@ class GenericShareDriverTestCase(test.TestCase):
self._driver.admin_context, server_details)
def test_ssh_exec_connection_not_exist(self):
ssh_conn_timeout = 30
CONF.set_default('ssh_conn_timeout', ssh_conn_timeout)
ssh_output = 'fake_ssh_output'
cmd = ['fake', 'command']
ssh = mock.Mock()
@ -1282,7 +1284,7 @@ class GenericShareDriverTestCase(test.TestCase):
result = self._driver._ssh_exec(self.server, cmd)
utils.SSHPool.assert_called_once_with(
self.server['ip'], 22, None, self.server['username'],
self.server['ip'], 22, ssh_conn_timeout, self.server['username'],
self.server['password'], self.server['pk_path'], max_size=1)
ssh_pool.create.assert_called_once_with()
processutils.ssh_execute.assert_called_once_with(ssh, 'fake command')