From 1a4a4defccd4a526b4ca1cbd084339073bedad5d Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Wed, 14 Mar 2018 15:32:16 -0700 Subject: [PATCH] Make sure lorax-composer tests only use temporary directories It was using /var/tmp/composer/, now it places everything under a temporary directory that is removed when it is finished. --- src/pylorax/api/config.py | 3 ++- src/pylorax/api/yumbase.py | 4 ++-- tests/pylorax/test_yumbase.py | 14 ++++++++------ 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/pylorax/api/config.py b/src/pylorax/api/config.py index e5f35152..8b2333e8 100644 --- a/src/pylorax/api/config.py +++ b/src/pylorax/api/config.py @@ -45,6 +45,7 @@ def configure(conf_file="/etc/lorax/composer.conf", root_dir="/", test_config=Fa conf.set("composer", "share_dir", os.path.realpath(joinpaths(root_dir, "/usr/share/lorax/"))) conf.set("composer", "lib_dir", os.path.realpath(joinpaths(root_dir, "/var/lib/lorax/composer/"))) conf.set("composer", "yum_conf", os.path.realpath(joinpaths(root_dir, "/var/tmp/composer/yum.conf"))) + conf.set("composer", "yum_root", os.path.realpath(joinpaths(root_dir, "/var/tmp/composer/yum/root/"))) conf.set("composer", "repo_dir", os.path.realpath(joinpaths(root_dir, "/var/tmp/composer/repos.d/"))) conf.set("composer", "cache_dir", os.path.realpath(joinpaths(root_dir, "/var/tmp/composer/cache/"))) @@ -70,7 +71,7 @@ def make_yum_dirs(conf): :type conf: ComposerConfig :returns: None """ - for p in ["yum_conf", "repo_dir", "cache_dir"]: + for p in ["yum_conf", "repo_dir", "cache_dir", "yum_root"]: p_dir = os.path.dirname(conf.get("composer", p)) if not os.path.exists(p_dir): os.makedirs(p_dir) diff --git a/src/pylorax/api/yumbase.py b/src/pylorax/api/yumbase.py index 972a07f4..4b3da3bc 100644 --- a/src/pylorax/api/yumbase.py +++ b/src/pylorax/api/yumbase.py @@ -39,6 +39,7 @@ def get_base_object(conf): """ cachedir = os.path.abspath(conf.get("composer", "cache_dir")) yumconf = os.path.abspath(conf.get("composer", "yum_conf")) + yumroot = os.path.abspath(conf.get("composer", "yum_root")) repodir = os.path.abspath(conf.get("composer", "repo_dir")) c = ConfigParser.ConfigParser() @@ -71,8 +72,7 @@ def get_base_object(conf): yb.preconf.fn = yumconf - # TODO How to handle this? - yb.preconf.root = "/var/tmp/composer/yum/root" + yb.preconf.root = yumroot if not os.path.isdir(yb.preconf.root): os.makedirs(yb.preconf.root) diff --git a/tests/pylorax/test_yumbase.py b/tests/pylorax/test_yumbase.py index 7443a1f6..b0569028 100644 --- a/tests/pylorax/test_yumbase.py +++ b/tests/pylorax/test_yumbase.py @@ -18,7 +18,6 @@ import os import shutil import tempfile import unittest -from glob import glob import ConfigParser @@ -73,14 +72,17 @@ use_system_repos = False class CreateYumDirsTest(unittest.TestCase): @classmethod def setUpClass(self): - # remove this directory - if os.path.exists('/var/tmp/composer/yum/root'): - shutil.rmtree('/var/tmp/composer/yum/root') + self.tmp_dir = tempfile.mkdtemp(prefix="lorax.test.yumbase.") + + @classmethod + def tearDownClass(self): + shutil.rmtree(self.tmp_dir) def test_creates_missing_yum_root_directory(self): - config = configure(test_config=True) + config = configure(test_config=True, root_dir=self.tmp_dir) # will create the above directory if missing + make_yum_dirs(config) _ = get_base_object(config) - self.assertTrue(os.path.exists('/var/tmp/composer/yum/root')) + self.assertTrue(os.path.exists(self.tmp_dir + '/var/tmp/composer/yum/root'))