diff --git a/src/pylorax/api/config.py b/src/pylorax/api/config.py index b4663541..c15e0e6e 100644 --- a/src/pylorax/api/config.py +++ b/src/pylorax/api/config.py @@ -61,3 +61,15 @@ def configure(conf_file="/etc/lorax/composer.conf", root_dir="/", test_config=Fa conf.read(conf_file) return conf + +def make_yum_dirs(conf): + """Make any missing yum directories + + :param conf: The configuration to use + :type conf: ComposerConfig + :returns: None + """ + for p in ["yum_conf", "repo_dir", "cache_dir"]: + p_dir = os.path.dirname(conf.get("composer", p)) + if not os.path.exists(p_dir): + os.makedirs(p_dir) diff --git a/src/sbin/lorax-composer b/src/sbin/lorax-composer index af87a21d..89e65b4b 100755 --- a/src/sbin/lorax-composer +++ b/src/sbin/lorax-composer @@ -37,7 +37,7 @@ from gevent.wsgi import WSGIServer from pyanaconda.queue import QueueFactory from pylorax import vernum -from pylorax.api.config import configure +from pylorax.api.config import configure, make_yum_dirs from pylorax.api.queue import monitor from pylorax.api.recipes import open_or_create_repo, commit_recipe_directory from pylorax.api.server import server, GitLock, YumLock @@ -232,10 +232,7 @@ if __name__ == '__main__': log.debug("user is now %s:%s", os.getresuid(), os.getresgid()) # Make sure yumbase directories are created - for p in ["yum_conf", "repo_dir", "cache_dir"]: - p_dir = os.path.dirname(server.config["COMPOSER_CFG"].get("composer", p)) - if not os.path.exists(p_dir): - os.makedirs(p_dir) + make_yum_dirs(server.config["COMPOSER_CFG"]) # Get a YumBase to share with the requests yb = get_base_object(server.config["COMPOSER_CFG"]) diff --git a/tests/pylorax/test_projects.py b/tests/pylorax/test_projects.py index ffd764f8..ce9588ec 100644 --- a/tests/pylorax/test_projects.py +++ b/tests/pylorax/test_projects.py @@ -20,7 +20,7 @@ import shutil import tempfile import unittest -from pylorax.api.config import configure +from pylorax.api.config import configure, make_yum_dirs from pylorax.api.projects import api_time, api_changelog, yaps_to_project, yaps_to_project_info from pylorax.api.projects import tm_to_dep, yaps_to_module, projects_list, projects_info, projects_depsolve from pylorax.api.projects import modules_list, modules_info, ProjectsError, dep_evra @@ -58,6 +58,7 @@ class ProjectsTest(unittest.TestCase): def setUpClass(self): self.tmp_dir = tempfile.mkdtemp(prefix="lorax.test.repo.") self.config = configure(root_dir=self.tmp_dir, test_config=True) + make_yum_dirs(self.config) self.yb = get_base_object(self.config) os.environ["TZ"] = "UTC" time.tzset() diff --git a/tests/pylorax/test_server.py b/tests/pylorax/test_server.py index 36406d7c..2f121afd 100644 --- a/tests/pylorax/test_server.py +++ b/tests/pylorax/test_server.py @@ -21,7 +21,7 @@ import unittest from flask import json import pytoml as toml -from pylorax.api.config import configure +from pylorax.api.config import configure, make_yum_dirs 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 @@ -37,6 +37,7 @@ class ServerTestCase(unittest.TestCase): server.config["GITLOCK"] = GitLock(repo=repo, lock=Lock(), dir=repo_dir) server.config["COMPOSER_CFG"] = configure(root_dir=repo_dir, test_config=True) + make_yum_dirs(server.config["COMPOSER_CFG"]) yb = get_base_object(server.config["COMPOSER_CFG"]) server.config["YUMLOCK"] = YumLock(yb=yb, lock=Lock())