Import Zuul modules at top of files

We had to make sure to not import Paramiko before daemonization.  The
zuul-server would hang when establishing a Gerrit ssh connection due to
Random.Crypto() failling to acquire random number from /dev/urandom. It
would block on read() and never process.

When the Server command line invokes the daemonization, python-daemon
closes all file descriptors. Including /dev/urandom. Then the daemonized
establishes the SSH connection and fails to get random number because
Random.Crypto() locks on read() on a closed file description.

Paramiko issue is https://github.com/paramiko/paramiko/issues/59 and the
fix is to use os.random:
6f211115f4

That has been released with Paramiko 1.11.6 and we now require 2.0+.

Move Zuul imports at top of files and drop the comments hinting at the
Paramiko bug.

Change-Id: I5fe956df74815761e3eac2bd25f6fd7f167fc854
This commit is contained in:
Antoine Musso 2018-03-05 11:17:19 +01:00
parent 8660c0662b
commit 1c80f506db
4 changed files with 7 additions and 30 deletions

View File

@ -40,11 +40,6 @@ from zuul.ansible import logconfig
import zuul.lib.connections
from zuul.lib.config import get_default
# Do not import modules that will pull in paramiko which must not be
# imported until after the daemonization.
# https://github.com/paramiko/paramiko/issues/59
# Similar situation with gear and statsd.
def stack_dump_handler(signum, frame):
signal.signal(signal.SIGUSR2, signal.SIG_IGN)

View File

@ -22,12 +22,8 @@ import tempfile
import zuul.cmd
import zuul.executor.server
from zuul.lib.config import get_default
# No zuul imports that pull in paramiko here; it must not be
# imported until after the daemonization.
# https://github.com/paramiko/paramiko/issues/59
# Similar situation with gear and statsd.
from zuul.lib.config import get_default
class Executor(zuul.cmd.ZuulDaemonApp):

View File

@ -20,11 +20,6 @@ import sys
import zuul.cmd
import zuul.merger.server
# No zuul imports here because they pull in paramiko which must not be
# imported until after the daemonization.
# https://github.com/paramiko/paramiko/issues/59
# Similar situation with gear and statsd.
class Merger(zuul.cmd.ZuulDaemonApp):
app_name = 'merger'
@ -48,8 +43,6 @@ class Merger(zuul.cmd.ZuulDaemonApp):
sys.exit(0)
def run(self):
# See comment at top of file about zuul imports
import zuul.merger.server
if self.args.command in zuul.merger.server.COMMANDS:
self.send_command(self.args.command)
sys.exit(0)

View File

@ -20,14 +20,14 @@ import sys
import signal
import zuul.cmd
import zuul.executor.client
import zuul.merger.client
import zuul.nodepool
import zuul.scheduler
import zuul.zk
from zuul.lib.config import get_default
from zuul.lib.statsd import get_statsd_config
import zuul.scheduler
# No zuul imports here because they pull in paramiko which must not be
# imported until after the daemonization.
# https://github.com/paramiko/paramiko/issues/59
# Similar situation with gear and statsd.
class Scheduler(zuul.cmd.ZuulDaemonApp):
@ -111,16 +111,9 @@ class Scheduler(zuul.cmd.ZuulDaemonApp):
os.kill(self.gear_server_pid, signal.SIGKILL)
def run(self):
# See comment at top of file about zuul imports
import zuul.scheduler
if self.args.command in zuul.scheduler.COMMANDS:
self.send_command(self.args.command)
sys.exit(0)
# See comment at top of file about zuul imports
import zuul.executor.client
import zuul.merger.client
import zuul.nodepool
import zuul.zk
if (self.config.has_option('gearman_server', 'start') and
self.config.getboolean('gearman_server', 'start')):