From 3fd5e50c803d269c680ec2829df6812b73a80062 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Fri, 27 Jul 2018 16:43:37 -0700 Subject: [PATCH] Use the first enabled system repo for the test --- tests/pylorax/test_server.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/tests/pylorax/test_server.py b/tests/pylorax/test_server.py index 7973603c..c5fbc251 100644 --- a/tests/pylorax/test_server.py +++ b/tests/pylorax/test_server.py @@ -15,7 +15,7 @@ # along with this program. If not, see . # import os -from ConfigParser import SafeConfigParser +from ConfigParser import SafeConfigParser, NoOptionError from glob import glob import shutil import tempfile @@ -32,6 +32,26 @@ from pylorax.api.server import server, GitLock, YumLock from pylorax.api.yumbase import get_base_object from pylorax.sysutils import joinpaths +def get_system_repo(): + """Get an enabled system repo from /etc/yum.repos.d/*repo + + This will be used for test_projects_source_01_delete_system() + """ + # The sources delete test needs the name of a system repo, get it from /etc/yum.repos.d/ + for sys_repo in sorted(glob("/etc/yum.repos.d/*repo")): + cfg = SafeConfigParser() + cfg.read(sys_repo) + for section in cfg.sections(): + try: + if cfg.get(section, "enabled") == "1": + # The API only supports repo filenames, return that. + return os.path.basename(sys_repo)[:-5] + except NoOptionError: + pass + + # Failed to find one, fall back to using base + return "base" + class ServerTestCase(unittest.TestCase): @classmethod @@ -83,10 +103,7 @@ class ServerTestCase(unittest.TestCase): commit_recipe_directory(server.config["GITLOCK"].repo, "master", self.examples_path) # The sources delete test needs the name of a system repo, get it from /etc/yum.repos.d/ - sys_repo = glob("/etc/yum.repos.d/*repo")[0] - cfg = SafeConfigParser() - cfg.read(sys_repo) - self.system_repo = cfg.sections()[0] + self.system_repo = get_system_repo() start_queue_monitor(server.config["COMPOSER_CFG"], 0, 0)