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 os
import grp import grp
from glob import glob from glob import glob
import multiprocessing as mp
import pytoml as toml import pytoml as toml
import pwd import pwd
import shutil import shutil
@ -34,7 +35,23 @@ from pylorax.base import DataHolder
from pylorax.installer import novirt_install from pylorax.installer import novirt_install
from pylorax.sysutils import joinpaths 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): def monitor(cfg):
"""Monitor the queue for new compose requests """Monitor the queue for new compose requests

View File

@ -26,7 +26,6 @@ yum_log = logging.getLogger("yum")
import argparse import argparse
import grp import grp
import multiprocessing as mp
import os import os
import pwd import pwd
import sys import sys
@ -36,11 +35,10 @@ from gevent.wsgi import WSGIServer
from pylorax import vernum from pylorax import vernum
from pylorax.api.config import configure, make_yum_dirs, make_queue_dirs 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.recipes import open_or_create_repo, commit_recipe_directory
from pylorax.api.server import server, GitLock, YumLock from pylorax.api.server import server, GitLock, YumLock
from pylorax.api.yumbase import get_base_object from pylorax.api.yumbase import get_base_object
from pylorax.base import DataHolder
VERSION = "{0}-{1}".format(os.path.basename(sys.argv[0]), vernum) VERSION = "{0}-{1}".format(os.path.basename(sys.argv[0]), vernum)
@ -204,12 +202,7 @@ if __name__ == '__main__':
os.chown(opts.socket, 0, gid) os.chown(opts.socket, 0, gid)
listener.listen(1) listener.listen(1)
# Start queue monitor thread as root start_queue_monitor(server.config["COMPOSER_CFG"], uid, gid)
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()
# Drop root privileges on the main process # Drop root privileges on the main process
os.setgid(gid) os.setgid(gid)