Move send_command() into ZuulApp

We can start to remove some duplicate code and make it easier to add
commandsocket support to other processes.

Change-Id: I605ca36b6627ac4fbea960205b9a88abdeed67f5
Signed-off-by: Paul Belanger <pabelanger@redhat.com>
changes/11/523211/4
Paul Belanger 5 years ago
parent 2092091541
commit ba0f202cfa
No known key found for this signature in database
GPG Key ID: 611A80832067AF38
  1. 10
      zuul/cmd/__init__.py
  2. 10
      zuul/cmd/executor.py
  3. 11
      zuul/cmd/merger.py

@ -23,6 +23,7 @@ import logging
import logging.config
import os
import signal
import socket
import sys
import traceback
import threading
@ -184,3 +185,12 @@ class ZuulDaemonApp(ZuulApp):
pass
with daemon.DaemonContext(pidfile=pid):
self.run()
def send_command(self, cmd):
command_socket = get_default(
self.config, self.app_name, 'command_socket',
'/var/lib/zuul/%s.socket' % self.app_name)
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.connect(command_socket)
cmd = '%s\n' % cmd
s.sendall(cmd.encode('utf8'))

@ -18,7 +18,6 @@ import grp
import logging
import os
import pwd
import socket
import sys
import signal
import tempfile
@ -52,15 +51,6 @@ class Executor(zuul.cmd.ZuulDaemonApp):
if self.args.command:
self.args.nodaemon = True
def send_command(self, cmd):
command_socket = get_default(
self.config, 'executor', 'command_socket',
'/var/lib/zuul/executor.socket')
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.connect(command_socket)
cmd = '%s\n' % cmd
s.sendall(cmd.encode('utf8'))
def exit_handler(self):
self.executor.stop()
self.executor.join()

@ -15,12 +15,10 @@
# under the License.
import signal
import socket
import sys
import zuul.cmd
import zuul.merger.server
from zuul.lib.config import get_default
# No zuul imports here because they pull in paramiko which must not be
# imported until after the daemonization.
@ -44,15 +42,6 @@ class Merger(zuul.cmd.ZuulDaemonApp):
if self.args.command:
self.args.nodaemon = True
def send_command(self, cmd):
command_socket = get_default(
self.config, 'merger', 'command_socket',
'/var/lib/zuul/merger.socket')
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.connect(command_socket)
cmd = '%s\n' % cmd
s.sendall(cmd.encode('utf8'))
def exit_handler(self):
self.merger.stop()
self.merger.join()

Loading…
Cancel
Save