From 5cb23b67c53437fc51a6b37acac477fba4d6a7ab Mon Sep 17 00:00:00 2001 From: Sean McGinnis Date: Fri, 26 Sep 2014 15:21:35 -0500 Subject: [PATCH] Handle eqlx SSH connection close on abort. EqualLogic array CLI operation timeout causes the SSH thread to be aborted. This would cause SSH sessions to be orphaned and hit a max connection limit on the array. This fix catches these aborts and makes sure the connection is closed. Change-Id: I9392fd5dd79eb44f252bf50217f17cc473e6f2f0 Closes-Bug: 1374613 --- cinder/volume/drivers/eqlx.py | 55 ++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/cinder/volume/drivers/eqlx.py b/cinder/volume/drivers/eqlx.py index ab54ca156..a4a778c67 100644 --- a/cinder/volume/drivers/eqlx.py +++ b/cinder/volume/drivers/eqlx.py @@ -151,29 +151,36 @@ class DellEQLSanISCSIDriver(SanISCSIDriver): def _ssh_execute(self, ssh, command, *arg, **kwargs): transport = ssh.get_transport() chan = transport.open_session() - chan.invoke_shell() + completed = False - LOG.debug("Reading CLI MOTD") - self._get_output(chan) - - cmd = 'stty columns 255' - LOG.debug("Setting CLI terminal width: '%s'.", cmd) - chan.send(cmd + '\r') - out = self._get_output(chan) - - LOG.debug("Sending CLI command: '%s'.", command) - chan.send(command + '\r') - out = self._get_output(chan) - - chan.close() - - if any(line.startswith(('% Error', 'Error:')) for line in out): - desc = _("Error executing EQL command") - cmdout = '\n'.join(out) - LOG.error(cmdout) - raise processutils.ProcessExecutionError( - stdout=cmdout, cmd=command, description=desc) - return out + try: + chan.invoke_shell() + + LOG.debug("Reading CLI MOTD") + self._get_output(chan) + + cmd = 'stty columns 255' + LOG.debug("Setting CLI terminal width: '%s'", cmd) + chan.send(cmd + '\r') + out = self._get_output(chan) + + LOG.debug("Sending CLI command: '%s'", command) + chan.send(command + '\r') + out = self._get_output(chan) + + completed = True + + if any(ln.startswith(('% Error', 'Error:')) for ln in out): + desc = _("Error executing EQL command") + cmdout = '\n'.join(out) + LOG.error(cmdout) + raise processutils.ProcessExecutionError( + stdout=cmdout, cmd=command, description=desc) + return out + finally: + if not completed: + LOG.debug("Timed out executing command: '%s'", command) + chan.close() def _run_ssh(self, cmd_list, attempts=1): utils.check_ssh_injection(cmd_list) @@ -295,11 +302,11 @@ class DellEQLSanISCSIDriver(SanISCSIDriver): and returns the correct connection id. """ lines = [line for line in out if line != ''] - #Every record has 2 lines + # Every record has 2 lines for i in xrange(0, len(lines), 2): try: int(lines[i][0]) - #sanity check + # sanity check if len(lines[i + 1].split()) == 1: check = lines[i].split()[1] + lines[i + 1].strip() if connector['initiator'] == check: -- 2.45.2