Move queue monitor startup into a function

This allows it to be used by the test framework.
This commit is contained in:
Brian C. Lane 2018-02-09 11:36:12 -08:00
parent 63a7897457
commit eb2a7208c8
2 changed files with 20 additions and 10 deletions

View File

@ -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

View File

@ -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)