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.
This commit is contained in:
Brian C. Lane 2018-03-14 15:32:16 -07:00
parent 597c19466e
commit 1a4a4defcc
3 changed files with 12 additions and 9 deletions

View File

@ -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", "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", "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_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", "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/"))) 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 :type conf: ComposerConfig
:returns: None :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)) p_dir = os.path.dirname(conf.get("composer", p))
if not os.path.exists(p_dir): if not os.path.exists(p_dir):
os.makedirs(p_dir) os.makedirs(p_dir)

View File

@ -39,6 +39,7 @@ def get_base_object(conf):
""" """
cachedir = os.path.abspath(conf.get("composer", "cache_dir")) cachedir = os.path.abspath(conf.get("composer", "cache_dir"))
yumconf = os.path.abspath(conf.get("composer", "yum_conf")) 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")) repodir = os.path.abspath(conf.get("composer", "repo_dir"))
c = ConfigParser.ConfigParser() c = ConfigParser.ConfigParser()
@ -71,8 +72,7 @@ def get_base_object(conf):
yb.preconf.fn = yumconf yb.preconf.fn = yumconf
# TODO How to handle this? yb.preconf.root = yumroot
yb.preconf.root = "/var/tmp/composer/yum/root"
if not os.path.isdir(yb.preconf.root): if not os.path.isdir(yb.preconf.root):
os.makedirs(yb.preconf.root) os.makedirs(yb.preconf.root)

View File

@ -18,7 +18,6 @@ import os
import shutil import shutil
import tempfile import tempfile
import unittest import unittest
from glob import glob
import ConfigParser import ConfigParser
@ -73,14 +72,17 @@ use_system_repos = False
class CreateYumDirsTest(unittest.TestCase): class CreateYumDirsTest(unittest.TestCase):
@classmethod @classmethod
def setUpClass(self): def setUpClass(self):
# remove this directory self.tmp_dir = tempfile.mkdtemp(prefix="lorax.test.yumbase.")
if os.path.exists('/var/tmp/composer/yum/root'):
shutil.rmtree('/var/tmp/composer/yum/root') @classmethod
def tearDownClass(self):
shutil.rmtree(self.tmp_dir)
def test_creates_missing_yum_root_directory(self): 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 # will create the above directory if missing
make_yum_dirs(config)
_ = get_base_object(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'))