Fix yum config directory creation for projects and server tests

This commit is contained in:
Brian C. Lane 2018-02-05 10:40:39 -08:00
parent b99a7756de
commit 22c03ceba7
4 changed files with 18 additions and 7 deletions

View File

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

View File

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

View File

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

View File

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