summaryrefslogtreecommitdiff
path: root/pygerrit/ssh.py
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@sonymobile.com>2012-12-14 17:33:28 +0900
committerDavid Pursehouse <david.pursehouse@sonymobile.com>2012-12-14 19:02:59 +0900
commit9f9673da2975359eeb582bcec4e62e6f8b37c434 (patch)
tree1815239a93c8f2a3350d43237b4260a7e0fab54b /pygerrit/ssh.py
parent89b5d495c329143f433d1fbe89c962c5ff1f81b4 (diff)
downloadpygerrit-9f9673da2975359eeb582bcec4e62e6f8b37c434.tar.gz
Handle socket connection error in SSH client
Catch socket error raised when connecting to the server over SSH and raise a GerritError. Change-Id: I140a26be4bc04ec229d95faaa80b94477cf96645
Diffstat (limited to 'pygerrit/ssh.py')
-rw-r--r--pygerrit/ssh.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/pygerrit/ssh.py b/pygerrit/ssh.py
index 2a019f5..270a63f 100644
--- a/pygerrit/ssh.py
+++ b/pygerrit/ssh.py
@@ -26,6 +26,7 @@ THE SOFTWARE.
from os.path import abspath, expanduser, isfile
import re
+import socket
from pygerrit.error import GerritError
@@ -84,10 +85,13 @@ class GerritSSHClient(SSHClient):
port = int(data['port'])
except ValueError:
raise GerritError("Invalid port: %s" % data['port'])
- self.connect(hostname=data['hostname'],
- port=port,
- username=data['user'],
- key_filename=key_filename)
+ try:
+ self.connect(hostname=data['hostname'],
+ port=port,
+ username=data['user'],
+ key_filename=key_filename)
+ except socket.error as e:
+ raise GerritError("Failed to connect to server: %s" % e)
def get_remote_version(self):
""" Return the version of the remote Gerrit server. """