summaryrefslogtreecommitdiff
path: root/pygerrit/ssh.py
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@sonymobile.com>2012-10-23 17:39:50 +0900
committerDavid Pursehouse <david.pursehouse@sonymobile.com>2012-10-23 17:45:10 +0900
commit12a5109267d3a91e311ab92fd0ec2cc3482a13f1 (patch)
treeae1a162c65dc39ce3e4ebfaa3bbe2b49276f30dc /pygerrit/ssh.py
parent99bc14d073c6fbce7dea00d758b114332539d083 (diff)
downloadpygerrit-12a5109267d3a91e311ab92fd0ec2cc3482a13f1.tar.gz
Handle exception when running ssh command
Also make sure the lock is released when an exception occurs. Change-Id: Id4af1d4950f604f47b11fdd7d84f94f769aecd4d
Diffstat (limited to 'pygerrit/ssh.py')
-rw-r--r--pygerrit/ssh.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/pygerrit/ssh.py b/pygerrit/ssh.py
index fad32ed..06154c4 100644
--- a/pygerrit/ssh.py
+++ b/pygerrit/ssh.py
@@ -30,6 +30,7 @@ from threading import Lock
from pygerrit.error import GerritError
from paramiko import SSHClient, SSHConfig
+from paramiko.ssh_exception import SSHException
class GerritSSHClient(SSHClient):
@@ -81,6 +82,10 @@ class GerritSSHClient(SSHClient):
else:
gerrit_command.append(command)
self.lock.acquire()
- stdin, stdout, stderr = self.exec_command(" ".join(gerrit_command))
- self.lock.release()
+ try:
+ stdin, stdout, stderr = self.exec_command(" ".join(gerrit_command))
+ except SSHException, err:
+ raise GerritError("Command execution error: %s" % err)
+ finally:
+ self.lock.release()
return stdin, stdout, stderr