diff options
| author | David Pursehouse <david.pursehouse@sonymobile.com> | 2012-10-23 17:39:50 +0900 |
|---|---|---|
| committer | David Pursehouse <david.pursehouse@sonymobile.com> | 2012-10-23 17:45:10 +0900 |
| commit | 12a5109267d3a91e311ab92fd0ec2cc3482a13f1 (patch) | |
| tree | ae1a162c65dc39ce3e4ebfaa3bbe2b49276f30dc /pygerrit | |
| parent | 99bc14d073c6fbce7dea00d758b114332539d083 (diff) | |
| download | pygerrit-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')
| -rw-r--r-- | pygerrit/ssh.py | 9 |
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 |
