From eb2a7208c850703414974f636d50219cbbeaa759 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Fri, 9 Feb 2018 11:36:12 -0800 Subject: [PATCH] Move queue monitor startup into a function This allows it to be used by the test framework. --- src/pylorax/api/queue.py | 19 ++++++++++++++++++- src/sbin/lorax-composer | 11 ++--------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/pylorax/api/queue.py b/src/pylorax/api/queue.py index 53be67d2..f22f0209 100644 --- a/src/pylorax/api/queue.py +++ b/src/pylorax/api/queue.py @@ -20,6 +20,7 @@ log = logging.getLogger("pylorax") import os import grp from glob import glob +import multiprocessing as mp import pytoml as toml import pwd import shutil @@ -34,7 +35,23 @@ from pylorax.base import DataHolder from pylorax.installer import novirt_install from pylorax.sysutils import joinpaths -# TODO needs a quit queue to cleanly manage quitting +def start_queue_monitor(cfg, uid, gid): + """Start the queue monitor as a mp process + + :param cfg: Configuration settings + :type cfg: ComposerConfig + :param uid: User ID that owns the queue + :type uid: int + :param gid: Group ID that owns the queue + :type gid: int + :returns: None + """ + lib_dir = cfg.get("composer", "lib_dir") + monitor_cfg = DataHolder(composer_dir=lib_dir, uid=uid, gid=gid) + p = mp.Process(target=monitor, args=(monitor_cfg,)) + p.daemon = True + p.start() + def monitor(cfg): """Monitor the queue for new compose requests diff --git a/src/sbin/lorax-composer b/src/sbin/lorax-composer index 72e65379..d03f218f 100755 --- a/src/sbin/lorax-composer +++ b/src/sbin/lorax-composer @@ -26,7 +26,6 @@ yum_log = logging.getLogger("yum") import argparse import grp -import multiprocessing as mp import os import pwd import sys @@ -36,11 +35,10 @@ from gevent.wsgi import WSGIServer from pylorax import vernum from pylorax.api.config import configure, make_yum_dirs, make_queue_dirs -from pylorax.api.queue import monitor +from pylorax.api.queue import start_queue_monitor from pylorax.api.recipes import open_or_create_repo, commit_recipe_directory from pylorax.api.server import server, GitLock, YumLock from pylorax.api.yumbase import get_base_object -from pylorax.base import DataHolder VERSION = "{0}-{1}".format(os.path.basename(sys.argv[0]), vernum) @@ -204,12 +202,7 @@ if __name__ == '__main__': os.chown(opts.socket, 0, gid) listener.listen(1) - # Start queue monitor thread as root - lib_dir = server.config["COMPOSER_CFG"].get("composer", "lib_dir") - cfg = DataHolder(composer_dir=lib_dir, uid=uid, gid=gid) - p = mp.Process(target=monitor, args=(cfg,)) - p.daemon = True - p.start() + start_queue_monitor(server.config["COMPOSER_CFG"], uid, gid) # Drop root privileges on the main process os.setgid(gid)