Merge "Set keepalives for gerrit connections"

This commit is contained in:
Jenkins 2017-02-09 14:49:09 +00:00 committed by Gerrit Code Review
commit 10b71820c4
3 changed files with 13 additions and 2 deletions

View File

@ -38,6 +38,9 @@ Create a connection with gerrit.
Path to SSH key to use when logging into above server.
``sshkey=/home/zuul/.ssh/id_rsa``
**keepalive**
Optional: Keepalive timeout, 0 means no keepalive.
``keepalive=60``
Gerrit Configuration
~~~~~~~~~~~~~~~~~~~~

View File

@ -36,6 +36,7 @@ server=review.example.com
;baseurl=https://review.example.com/r
user=jenkins
sshkey=/home/jenkins/.ssh/id_rsa
;keepalive=60
[connection smtp]
driver=smtp

View File

@ -135,13 +135,14 @@ class GerritWatcher(threading.Thread):
poll_timeout = 500
def __init__(self, gerrit_connection, username, hostname, port=29418,
keyfile=None):
keyfile=None, keepalive=60):
threading.Thread.__init__(self)
self.username = username
self.keyfile = keyfile
self.hostname = hostname
self.port = port
self.gerrit_connection = gerrit_connection
self.keepalive = keepalive
self._stopped = False
def _read(self, fd):
@ -172,6 +173,8 @@ class GerritWatcher(threading.Thread):
username=self.username,
port=self.port,
key_filename=self.keyfile)
transport = client.get_transport()
transport.set_keepalive(self.keepalive)
stdin, stdout, stderr = client.exec_command("gerrit stream-events")
@ -224,6 +227,7 @@ class GerritConnection(BaseConnection):
self.server = self.connection_config.get('server')
self.port = int(self.connection_config.get('port', 29418))
self.keyfile = self.connection_config.get('sshkey', None)
self.keepalive = int(self.connection_config.get('keepalive', 60))
self.watcher_thread = None
self.event_queue = None
self.client = None
@ -356,6 +360,8 @@ class GerritConnection(BaseConnection):
username=self.user,
port=self.port,
key_filename=self.keyfile)
transport = client.get_transport()
transport.set_keepalive(self.keepalive)
self.client = client
def _ssh(self, command, stdin_data=None):
@ -461,7 +467,8 @@ class GerritConnection(BaseConnection):
self.user,
self.server,
self.port,
keyfile=self.keyfile)
keyfile=self.keyfile,
keepalive=self.keepalive)
self.watcher_thread.start()
def _stop_event_connector(self):